trace_events.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. /*
  2. * event tracer
  3. *
  4. * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  5. *
  6. * - Added format output of fields of the trace point.
  7. * This was based off of work by Tom Zanussi <tzanussi@gmail.com>.
  8. *
  9. */
  10. #include <linux/workqueue.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/kthread.h>
  13. #include <linux/debugfs.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/module.h>
  16. #include <linux/ctype.h>
  17. #include <linux/slab.h>
  18. #include <linux/delay.h>
  19. #include <asm/setup.h>
  20. #include "trace_output.h"
  21. #undef TRACE_SYSTEM
  22. #define TRACE_SYSTEM "TRACE_SYSTEM"
  23. DEFINE_MUTEX(event_mutex);
  24. LIST_HEAD(ftrace_events);
  25. LIST_HEAD(ftrace_common_fields);
  26. struct list_head *
  27. trace_get_fields(struct ftrace_event_call *event_call)
  28. {
  29. if (!event_call->class->get_fields)
  30. return &event_call->class->fields;
  31. return event_call->class->get_fields(event_call);
  32. }
  33. static int __trace_define_field(struct list_head *head, const char *type,
  34. const char *name, int offset, int size,
  35. int is_signed, int filter_type)
  36. {
  37. struct ftrace_event_field *field;
  38. field = kzalloc(sizeof(*field), GFP_KERNEL);
  39. if (!field)
  40. goto err;
  41. field->name = kstrdup(name, GFP_KERNEL);
  42. if (!field->name)
  43. goto err;
  44. field->type = kstrdup(type, GFP_KERNEL);
  45. if (!field->type)
  46. goto err;
  47. if (filter_type == FILTER_OTHER)
  48. field->filter_type = filter_assign_type(type);
  49. else
  50. field->filter_type = filter_type;
  51. field->offset = offset;
  52. field->size = size;
  53. field->is_signed = is_signed;
  54. list_add(&field->link, head);
  55. return 0;
  56. err:
  57. if (field)
  58. kfree(field->name);
  59. kfree(field);
  60. return -ENOMEM;
  61. }
  62. int trace_define_field(struct ftrace_event_call *call, const char *type,
  63. const char *name, int offset, int size, int is_signed,
  64. int filter_type)
  65. {
  66. struct list_head *head;
  67. if (WARN_ON(!call->class))
  68. return 0;
  69. head = trace_get_fields(call);
  70. return __trace_define_field(head, type, name, offset, size,
  71. is_signed, filter_type);
  72. }
  73. EXPORT_SYMBOL_GPL(trace_define_field);
  74. #define __common_field(type, item) \
  75. ret = __trace_define_field(&ftrace_common_fields, #type, \
  76. "common_" #item, \
  77. offsetof(typeof(ent), item), \
  78. sizeof(ent.item), \
  79. is_signed_type(type), FILTER_OTHER); \
  80. if (ret) \
  81. return ret;
  82. static int trace_define_common_fields(void)
  83. {
  84. int ret;
  85. struct trace_entry ent;
  86. __common_field(unsigned short, type);
  87. __common_field(unsigned char, flags);
  88. __common_field(unsigned char, preempt_count);
  89. __common_field(int, pid);
  90. __common_field(int, lock_depth);
  91. return ret;
  92. }
  93. void trace_destroy_fields(struct ftrace_event_call *call)
  94. {
  95. struct ftrace_event_field *field, *next;
  96. struct list_head *head;
  97. head = trace_get_fields(call);
  98. list_for_each_entry_safe(field, next, head, link) {
  99. list_del(&field->link);
  100. kfree(field->type);
  101. kfree(field->name);
  102. kfree(field);
  103. }
  104. }
  105. int trace_event_raw_init(struct ftrace_event_call *call)
  106. {
  107. int id;
  108. id = register_ftrace_event(&call->event);
  109. if (!id)
  110. return -ENODEV;
  111. return 0;
  112. }
  113. EXPORT_SYMBOL_GPL(trace_event_raw_init);
  114. static int ftrace_event_enable_disable(struct ftrace_event_call *call,
  115. int enable)
  116. {
  117. int ret = 0;
  118. switch (enable) {
  119. case 0:
  120. if (call->flags & TRACE_EVENT_FL_ENABLED) {
  121. call->flags &= ~TRACE_EVENT_FL_ENABLED;
  122. tracing_stop_cmdline_record();
  123. if (call->class->reg)
  124. call->class->reg(call, TRACE_REG_UNREGISTER);
  125. else
  126. tracepoint_probe_unregister(call->name,
  127. call->class->probe,
  128. call);
  129. }
  130. break;
  131. case 1:
  132. if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
  133. tracing_start_cmdline_record();
  134. if (call->class->reg)
  135. ret = call->class->reg(call, TRACE_REG_REGISTER);
  136. else
  137. ret = tracepoint_probe_register(call->name,
  138. call->class->probe,
  139. call);
  140. if (ret) {
  141. tracing_stop_cmdline_record();
  142. pr_info("event trace: Could not enable event "
  143. "%s\n", call->name);
  144. break;
  145. }
  146. call->flags |= TRACE_EVENT_FL_ENABLED;
  147. }
  148. break;
  149. }
  150. return ret;
  151. }
  152. static void ftrace_clear_events(void)
  153. {
  154. struct ftrace_event_call *call;
  155. mutex_lock(&event_mutex);
  156. list_for_each_entry(call, &ftrace_events, list) {
  157. ftrace_event_enable_disable(call, 0);
  158. }
  159. mutex_unlock(&event_mutex);
  160. }
  161. /*
  162. * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
  163. */
  164. static int __ftrace_set_clr_event(const char *match, const char *sub,
  165. const char *event, int set)
  166. {
  167. struct ftrace_event_call *call;
  168. int ret = -EINVAL;
  169. mutex_lock(&event_mutex);
  170. list_for_each_entry(call, &ftrace_events, list) {
  171. if (!call->name || !call->class ||
  172. (!call->class->probe && !call->class->reg))
  173. continue;
  174. if (match &&
  175. strcmp(match, call->name) != 0 &&
  176. strcmp(match, call->class->system) != 0)
  177. continue;
  178. if (sub && strcmp(sub, call->class->system) != 0)
  179. continue;
  180. if (event && strcmp(event, call->name) != 0)
  181. continue;
  182. ftrace_event_enable_disable(call, set);
  183. ret = 0;
  184. }
  185. mutex_unlock(&event_mutex);
  186. return ret;
  187. }
  188. static int ftrace_set_clr_event(char *buf, int set)
  189. {
  190. char *event = NULL, *sub = NULL, *match;
  191. /*
  192. * The buf format can be <subsystem>:<event-name>
  193. * *:<event-name> means any event by that name.
  194. * :<event-name> is the same.
  195. *
  196. * <subsystem>:* means all events in that subsystem
  197. * <subsystem>: means the same.
  198. *
  199. * <name> (no ':') means all events in a subsystem with
  200. * the name <name> or any event that matches <name>
  201. */
  202. match = strsep(&buf, ":");
  203. if (buf) {
  204. sub = match;
  205. event = buf;
  206. match = NULL;
  207. if (!strlen(sub) || strcmp(sub, "*") == 0)
  208. sub = NULL;
  209. if (!strlen(event) || strcmp(event, "*") == 0)
  210. event = NULL;
  211. }
  212. return __ftrace_set_clr_event(match, sub, event, set);
  213. }
  214. /**
  215. * trace_set_clr_event - enable or disable an event
  216. * @system: system name to match (NULL for any system)
  217. * @event: event name to match (NULL for all events, within system)
  218. * @set: 1 to enable, 0 to disable
  219. *
  220. * This is a way for other parts of the kernel to enable or disable
  221. * event recording.
  222. *
  223. * Returns 0 on success, -EINVAL if the parameters do not match any
  224. * registered events.
  225. */
  226. int trace_set_clr_event(const char *system, const char *event, int set)
  227. {
  228. return __ftrace_set_clr_event(NULL, system, event, set);
  229. }
  230. /* 128 should be much more than enough */
  231. #define EVENT_BUF_SIZE 127
  232. static ssize_t
  233. ftrace_event_write(struct file *file, const char __user *ubuf,
  234. size_t cnt, loff_t *ppos)
  235. {
  236. struct trace_parser parser;
  237. ssize_t read, ret;
  238. if (!cnt)
  239. return 0;
  240. ret = tracing_update_buffers();
  241. if (ret < 0)
  242. return ret;
  243. if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
  244. return -ENOMEM;
  245. read = trace_get_user(&parser, ubuf, cnt, ppos);
  246. if (read >= 0 && trace_parser_loaded((&parser))) {
  247. int set = 1;
  248. if (*parser.buffer == '!')
  249. set = 0;
  250. parser.buffer[parser.idx] = 0;
  251. ret = ftrace_set_clr_event(parser.buffer + !set, set);
  252. if (ret)
  253. goto out_put;
  254. }
  255. ret = read;
  256. out_put:
  257. trace_parser_put(&parser);
  258. return ret;
  259. }
  260. static void *
  261. t_next(struct seq_file *m, void *v, loff_t *pos)
  262. {
  263. struct ftrace_event_call *call = v;
  264. (*pos)++;
  265. list_for_each_entry_continue(call, &ftrace_events, list) {
  266. /*
  267. * The ftrace subsystem is for showing formats only.
  268. * They can not be enabled or disabled via the event files.
  269. */
  270. if (call->class && (call->class->probe || call->class->reg))
  271. return call;
  272. }
  273. return NULL;
  274. }
  275. static void *t_start(struct seq_file *m, loff_t *pos)
  276. {
  277. struct ftrace_event_call *call;
  278. loff_t l;
  279. mutex_lock(&event_mutex);
  280. call = list_entry(&ftrace_events, struct ftrace_event_call, list);
  281. for (l = 0; l <= *pos; ) {
  282. call = t_next(m, call, &l);
  283. if (!call)
  284. break;
  285. }
  286. return call;
  287. }
  288. static void *
  289. s_next(struct seq_file *m, void *v, loff_t *pos)
  290. {
  291. struct ftrace_event_call *call = v;
  292. (*pos)++;
  293. list_for_each_entry_continue(call, &ftrace_events, list) {
  294. if (call->flags & TRACE_EVENT_FL_ENABLED)
  295. return call;
  296. }
  297. return NULL;
  298. }
  299. static void *s_start(struct seq_file *m, loff_t *pos)
  300. {
  301. struct ftrace_event_call *call;
  302. loff_t l;
  303. mutex_lock(&event_mutex);
  304. call = list_entry(&ftrace_events, struct ftrace_event_call, list);
  305. for (l = 0; l <= *pos; ) {
  306. call = s_next(m, call, &l);
  307. if (!call)
  308. break;
  309. }
  310. return call;
  311. }
  312. static int t_show(struct seq_file *m, void *v)
  313. {
  314. struct ftrace_event_call *call = v;
  315. if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
  316. seq_printf(m, "%s:", call->class->system);
  317. seq_printf(m, "%s\n", call->name);
  318. return 0;
  319. }
  320. static void t_stop(struct seq_file *m, void *p)
  321. {
  322. mutex_unlock(&event_mutex);
  323. }
  324. static int
  325. ftrace_event_seq_open(struct inode *inode, struct file *file)
  326. {
  327. const struct seq_operations *seq_ops;
  328. if ((file->f_mode & FMODE_WRITE) &&
  329. (file->f_flags & O_TRUNC))
  330. ftrace_clear_events();
  331. seq_ops = inode->i_private;
  332. return seq_open(file, seq_ops);
  333. }
  334. static ssize_t
  335. event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
  336. loff_t *ppos)
  337. {
  338. struct ftrace_event_call *call = filp->private_data;
  339. char *buf;
  340. if (call->flags & TRACE_EVENT_FL_ENABLED)
  341. buf = "1\n";
  342. else
  343. buf = "0\n";
  344. return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
  345. }
  346. static ssize_t
  347. event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
  348. loff_t *ppos)
  349. {
  350. struct ftrace_event_call *call = filp->private_data;
  351. char buf[64];
  352. unsigned long val;
  353. int ret;
  354. if (cnt >= sizeof(buf))
  355. return -EINVAL;
  356. if (copy_from_user(&buf, ubuf, cnt))
  357. return -EFAULT;
  358. buf[cnt] = 0;
  359. ret = strict_strtoul(buf, 10, &val);
  360. if (ret < 0)
  361. return ret;
  362. ret = tracing_update_buffers();
  363. if (ret < 0)
  364. return ret;
  365. switch (val) {
  366. case 0:
  367. case 1:
  368. mutex_lock(&event_mutex);
  369. ret = ftrace_event_enable_disable(call, val);
  370. mutex_unlock(&event_mutex);
  371. break;
  372. default:
  373. return -EINVAL;
  374. }
  375. *ppos += cnt;
  376. return ret ? ret : cnt;
  377. }
  378. static ssize_t
  379. system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
  380. loff_t *ppos)
  381. {
  382. const char set_to_char[4] = { '?', '0', '1', 'X' };
  383. const char *system = filp->private_data;
  384. struct ftrace_event_call *call;
  385. char buf[2];
  386. int set = 0;
  387. int ret;
  388. mutex_lock(&event_mutex);
  389. list_for_each_entry(call, &ftrace_events, list) {
  390. if (!call->name || !call->class ||
  391. (!call->class->probe && !call->class->reg))
  392. continue;
  393. if (system && strcmp(call->class->system, system) != 0)
  394. continue;
  395. /*
  396. * We need to find out if all the events are set
  397. * or if all events or cleared, or if we have
  398. * a mixture.
  399. */
  400. set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED));
  401. /*
  402. * If we have a mixture, no need to look further.
  403. */
  404. if (set == 3)
  405. break;
  406. }
  407. mutex_unlock(&event_mutex);
  408. buf[0] = set_to_char[set];
  409. buf[1] = '\n';
  410. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
  411. return ret;
  412. }
  413. static ssize_t
  414. system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
  415. loff_t *ppos)
  416. {
  417. const char *system = filp->private_data;
  418. unsigned long val;
  419. char buf[64];
  420. ssize_t ret;
  421. if (cnt >= sizeof(buf))
  422. return -EINVAL;
  423. if (copy_from_user(&buf, ubuf, cnt))
  424. return -EFAULT;
  425. buf[cnt] = 0;
  426. ret = strict_strtoul(buf, 10, &val);
  427. if (ret < 0)
  428. return ret;
  429. ret = tracing_update_buffers();
  430. if (ret < 0)
  431. return ret;
  432. if (val != 0 && val != 1)
  433. return -EINVAL;
  434. ret = __ftrace_set_clr_event(NULL, system, NULL, val);
  435. if (ret)
  436. goto out;
  437. ret = cnt;
  438. out:
  439. *ppos += cnt;
  440. return ret;
  441. }
  442. static void print_event_fields(struct trace_seq *s, struct list_head *head)
  443. {
  444. struct ftrace_event_field *field;
  445. list_for_each_entry_reverse(field, head, link) {
  446. /*
  447. * Smartly shows the array type(except dynamic array).
  448. * Normal:
  449. * field:TYPE VAR
  450. * If TYPE := TYPE[LEN], it is shown:
  451. * field:TYPE VAR[LEN]
  452. */
  453. const char *array_descriptor = strchr(field->type, '[');
  454. if (!strncmp(field->type, "__data_loc", 10))
  455. array_descriptor = NULL;
  456. if (!array_descriptor) {
  457. trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;"
  458. "\tsize:%u;\tsigned:%d;\n",
  459. field->type, field->name, field->offset,
  460. field->size, !!field->is_signed);
  461. } else {
  462. trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;"
  463. "\tsize:%u;\tsigned:%d;\n",
  464. (int)(array_descriptor - field->type),
  465. field->type, field->name,
  466. array_descriptor, field->offset,
  467. field->size, !!field->is_signed);
  468. }
  469. }
  470. }
  471. static ssize_t
  472. event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
  473. loff_t *ppos)
  474. {
  475. struct ftrace_event_call *call = filp->private_data;
  476. struct list_head *head;
  477. struct trace_seq *s;
  478. char *buf;
  479. int r;
  480. if (*ppos)
  481. return 0;
  482. s = kmalloc(sizeof(*s), GFP_KERNEL);
  483. if (!s)
  484. return -ENOMEM;
  485. trace_seq_init(s);
  486. trace_seq_printf(s, "name: %s\n", call->name);
  487. trace_seq_printf(s, "ID: %d\n", call->event.type);
  488. trace_seq_printf(s, "format:\n");
  489. /* print common fields */
  490. print_event_fields(s, &ftrace_common_fields);
  491. trace_seq_putc(s, '\n');
  492. /* print event specific fields */
  493. head = trace_get_fields(call);
  494. print_event_fields(s, head);
  495. r = trace_seq_printf(s, "\nprint fmt: %s\n", call->print_fmt);
  496. if (!r) {
  497. /*
  498. * ug! The format output is bigger than a PAGE!!
  499. */
  500. buf = "FORMAT TOO BIG\n";
  501. r = simple_read_from_buffer(ubuf, cnt, ppos,
  502. buf, strlen(buf));
  503. goto out;
  504. }
  505. r = simple_read_from_buffer(ubuf, cnt, ppos,
  506. s->buffer, s->len);
  507. out:
  508. kfree(s);
  509. return r;
  510. }
  511. static ssize_t
  512. event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
  513. {
  514. struct ftrace_event_call *call = filp->private_data;
  515. struct trace_seq *s;
  516. int r;
  517. if (*ppos)
  518. return 0;
  519. s = kmalloc(sizeof(*s), GFP_KERNEL);
  520. if (!s)
  521. return -ENOMEM;
  522. trace_seq_init(s);
  523. trace_seq_printf(s, "%d\n", call->event.type);
  524. r = simple_read_from_buffer(ubuf, cnt, ppos,
  525. s->buffer, s->len);
  526. kfree(s);
  527. return r;
  528. }
  529. static ssize_t
  530. event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
  531. loff_t *ppos)
  532. {
  533. struct ftrace_event_call *call = filp->private_data;
  534. struct trace_seq *s;
  535. int r;
  536. if (*ppos)
  537. return 0;
  538. s = kmalloc(sizeof(*s), GFP_KERNEL);
  539. if (!s)
  540. return -ENOMEM;
  541. trace_seq_init(s);
  542. print_event_filter(call, s);
  543. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  544. kfree(s);
  545. return r;
  546. }
  547. static ssize_t
  548. event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
  549. loff_t *ppos)
  550. {
  551. struct ftrace_event_call *call = filp->private_data;
  552. char *buf;
  553. int err;
  554. if (cnt >= PAGE_SIZE)
  555. return -EINVAL;
  556. buf = (char *)__get_free_page(GFP_TEMPORARY);
  557. if (!buf)
  558. return -ENOMEM;
  559. if (copy_from_user(buf, ubuf, cnt)) {
  560. free_page((unsigned long) buf);
  561. return -EFAULT;
  562. }
  563. buf[cnt] = '\0';
  564. err = apply_event_filter(call, buf);
  565. free_page((unsigned long) buf);
  566. if (err < 0)
  567. return err;
  568. *ppos += cnt;
  569. return cnt;
  570. }
  571. static ssize_t
  572. subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
  573. loff_t *ppos)
  574. {
  575. struct event_subsystem *system = filp->private_data;
  576. struct trace_seq *s;
  577. int r;
  578. if (*ppos)
  579. return 0;
  580. s = kmalloc(sizeof(*s), GFP_KERNEL);
  581. if (!s)
  582. return -ENOMEM;
  583. trace_seq_init(s);
  584. print_subsystem_event_filter(system, s);
  585. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  586. kfree(s);
  587. return r;
  588. }
  589. static ssize_t
  590. subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
  591. loff_t *ppos)
  592. {
  593. struct event_subsystem *system = filp->private_data;
  594. char *buf;
  595. int err;
  596. if (cnt >= PAGE_SIZE)
  597. return -EINVAL;
  598. buf = (char *)__get_free_page(GFP_TEMPORARY);
  599. if (!buf)
  600. return -ENOMEM;
  601. if (copy_from_user(buf, ubuf, cnt)) {
  602. free_page((unsigned long) buf);
  603. return -EFAULT;
  604. }
  605. buf[cnt] = '\0';
  606. err = apply_subsystem_event_filter(system, buf);
  607. free_page((unsigned long) buf);
  608. if (err < 0)
  609. return err;
  610. *ppos += cnt;
  611. return cnt;
  612. }
  613. static ssize_t
  614. show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
  615. {
  616. int (*func)(struct trace_seq *s) = filp->private_data;
  617. struct trace_seq *s;
  618. int r;
  619. if (*ppos)
  620. return 0;
  621. s = kmalloc(sizeof(*s), GFP_KERNEL);
  622. if (!s)
  623. return -ENOMEM;
  624. trace_seq_init(s);
  625. func(s);
  626. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  627. kfree(s);
  628. return r;
  629. }
  630. static const struct seq_operations show_event_seq_ops = {
  631. .start = t_start,
  632. .next = t_next,
  633. .show = t_show,
  634. .stop = t_stop,
  635. };
  636. static const struct seq_operations show_set_event_seq_ops = {
  637. .start = s_start,
  638. .next = s_next,
  639. .show = t_show,
  640. .stop = t_stop,
  641. };
  642. static const struct file_operations ftrace_avail_fops = {
  643. .open = ftrace_event_seq_open,
  644. .read = seq_read,
  645. .llseek = seq_lseek,
  646. .release = seq_release,
  647. };
  648. static const struct file_operations ftrace_set_event_fops = {
  649. .open = ftrace_event_seq_open,
  650. .read = seq_read,
  651. .write = ftrace_event_write,
  652. .llseek = seq_lseek,
  653. .release = seq_release,
  654. };
  655. static const struct file_operations ftrace_enable_fops = {
  656. .open = tracing_open_generic,
  657. .read = event_enable_read,
  658. .write = event_enable_write,
  659. };
  660. static const struct file_operations ftrace_event_format_fops = {
  661. .open = tracing_open_generic,
  662. .read = event_format_read,
  663. };
  664. static const struct file_operations ftrace_event_id_fops = {
  665. .open = tracing_open_generic,
  666. .read = event_id_read,
  667. };
  668. static const struct file_operations ftrace_event_filter_fops = {
  669. .open = tracing_open_generic,
  670. .read = event_filter_read,
  671. .write = event_filter_write,
  672. };
  673. static const struct file_operations ftrace_subsystem_filter_fops = {
  674. .open = tracing_open_generic,
  675. .read = subsystem_filter_read,
  676. .write = subsystem_filter_write,
  677. };
  678. static const struct file_operations ftrace_system_enable_fops = {
  679. .open = tracing_open_generic,
  680. .read = system_enable_read,
  681. .write = system_enable_write,
  682. };
  683. static const struct file_operations ftrace_show_header_fops = {
  684. .open = tracing_open_generic,
  685. .read = show_header,
  686. };
  687. static struct dentry *event_trace_events_dir(void)
  688. {
  689. static struct dentry *d_tracer;
  690. static struct dentry *d_events;
  691. if (d_events)
  692. return d_events;
  693. d_tracer = tracing_init_dentry();
  694. if (!d_tracer)
  695. return NULL;
  696. d_events = debugfs_create_dir("events", d_tracer);
  697. if (!d_events)
  698. pr_warning("Could not create debugfs "
  699. "'events' directory\n");
  700. return d_events;
  701. }
  702. static LIST_HEAD(event_subsystems);
  703. static struct dentry *
  704. event_subsystem_dir(const char *name, struct dentry *d_events)
  705. {
  706. struct event_subsystem *system;
  707. struct dentry *entry;
  708. /* First see if we did not already create this dir */
  709. list_for_each_entry(system, &event_subsystems, list) {
  710. if (strcmp(system->name, name) == 0) {
  711. system->nr_events++;
  712. return system->entry;
  713. }
  714. }
  715. /* need to create new entry */
  716. system = kmalloc(sizeof(*system), GFP_KERNEL);
  717. if (!system) {
  718. pr_warning("No memory to create event subsystem %s\n",
  719. name);
  720. return d_events;
  721. }
  722. system->entry = debugfs_create_dir(name, d_events);
  723. if (!system->entry) {
  724. pr_warning("Could not create event subsystem %s\n",
  725. name);
  726. kfree(system);
  727. return d_events;
  728. }
  729. system->nr_events = 1;
  730. system->name = kstrdup(name, GFP_KERNEL);
  731. if (!system->name) {
  732. debugfs_remove(system->entry);
  733. kfree(system);
  734. return d_events;
  735. }
  736. list_add(&system->list, &event_subsystems);
  737. system->filter = NULL;
  738. system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
  739. if (!system->filter) {
  740. pr_warning("Could not allocate filter for subsystem "
  741. "'%s'\n", name);
  742. return system->entry;
  743. }
  744. entry = debugfs_create_file("filter", 0644, system->entry, system,
  745. &ftrace_subsystem_filter_fops);
  746. if (!entry) {
  747. kfree(system->filter);
  748. system->filter = NULL;
  749. pr_warning("Could not create debugfs "
  750. "'%s/filter' entry\n", name);
  751. }
  752. trace_create_file("enable", 0644, system->entry,
  753. (void *)system->name,
  754. &ftrace_system_enable_fops);
  755. return system->entry;
  756. }
  757. static int
  758. event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
  759. const struct file_operations *id,
  760. const struct file_operations *enable,
  761. const struct file_operations *filter,
  762. const struct file_operations *format)
  763. {
  764. struct list_head *head;
  765. int ret;
  766. /*
  767. * If the trace point header did not define TRACE_SYSTEM
  768. * then the system would be called "TRACE_SYSTEM".
  769. */
  770. if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
  771. d_events = event_subsystem_dir(call->class->system, d_events);
  772. call->dir = debugfs_create_dir(call->name, d_events);
  773. if (!call->dir) {
  774. pr_warning("Could not create debugfs "
  775. "'%s' directory\n", call->name);
  776. return -1;
  777. }
  778. if (call->class->probe || call->class->reg)
  779. trace_create_file("enable", 0644, call->dir, call,
  780. enable);
  781. #ifdef CONFIG_PERF_EVENTS
  782. if (call->event.type && (call->class->perf_probe || call->class->reg))
  783. trace_create_file("id", 0444, call->dir, call,
  784. id);
  785. #endif
  786. /*
  787. * Other events may have the same class. Only update
  788. * the fields if they are not already defined.
  789. */
  790. head = trace_get_fields(call);
  791. if (list_empty(head)) {
  792. ret = call->class->define_fields(call);
  793. if (ret < 0) {
  794. pr_warning("Could not initialize trace point"
  795. " events/%s\n", call->name);
  796. return ret;
  797. }
  798. }
  799. trace_create_file("filter", 0644, call->dir, call,
  800. filter);
  801. trace_create_file("format", 0444, call->dir, call,
  802. format);
  803. return 0;
  804. }
  805. static int __trace_add_event_call(struct ftrace_event_call *call)
  806. {
  807. struct dentry *d_events;
  808. int ret;
  809. if (!call->name)
  810. return -EINVAL;
  811. if (call->class->raw_init) {
  812. ret = call->class->raw_init(call);
  813. if (ret < 0) {
  814. if (ret != -ENOSYS)
  815. pr_warning("Could not initialize trace "
  816. "events/%s\n", call->name);
  817. return ret;
  818. }
  819. }
  820. d_events = event_trace_events_dir();
  821. if (!d_events)
  822. return -ENOENT;
  823. ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
  824. &ftrace_enable_fops, &ftrace_event_filter_fops,
  825. &ftrace_event_format_fops);
  826. if (!ret)
  827. list_add(&call->list, &ftrace_events);
  828. return ret;
  829. }
  830. /* Add an additional event_call dynamically */
  831. int trace_add_event_call(struct ftrace_event_call *call)
  832. {
  833. int ret;
  834. mutex_lock(&event_mutex);
  835. ret = __trace_add_event_call(call);
  836. mutex_unlock(&event_mutex);
  837. return ret;
  838. }
  839. static void remove_subsystem_dir(const char *name)
  840. {
  841. struct event_subsystem *system;
  842. if (strcmp(name, TRACE_SYSTEM) == 0)
  843. return;
  844. list_for_each_entry(system, &event_subsystems, list) {
  845. if (strcmp(system->name, name) == 0) {
  846. if (!--system->nr_events) {
  847. struct event_filter *filter = system->filter;
  848. debugfs_remove_recursive(system->entry);
  849. list_del(&system->list);
  850. if (filter) {
  851. kfree(filter->filter_string);
  852. kfree(filter);
  853. }
  854. kfree(system->name);
  855. kfree(system);
  856. }
  857. break;
  858. }
  859. }
  860. }
  861. /*
  862. * Must be called under locking both of event_mutex and trace_event_mutex.
  863. */
  864. static void __trace_remove_event_call(struct ftrace_event_call *call)
  865. {
  866. ftrace_event_enable_disable(call, 0);
  867. if (call->event.funcs)
  868. __unregister_ftrace_event(&call->event);
  869. debugfs_remove_recursive(call->dir);
  870. list_del(&call->list);
  871. trace_destroy_fields(call);
  872. destroy_preds(call);
  873. remove_subsystem_dir(call->class->system);
  874. }
  875. /* Remove an event_call */
  876. void trace_remove_event_call(struct ftrace_event_call *call)
  877. {
  878. mutex_lock(&event_mutex);
  879. down_write(&trace_event_mutex);
  880. __trace_remove_event_call(call);
  881. up_write(&trace_event_mutex);
  882. mutex_unlock(&event_mutex);
  883. }
  884. #define for_each_event(event, start, end) \
  885. for (event = start; \
  886. (unsigned long)event < (unsigned long)end; \
  887. event++)
  888. #ifdef CONFIG_MODULES
  889. static LIST_HEAD(ftrace_module_file_list);
  890. /*
  891. * Modules must own their file_operations to keep up with
  892. * reference counting.
  893. */
  894. struct ftrace_module_file_ops {
  895. struct list_head list;
  896. struct module *mod;
  897. struct file_operations id;
  898. struct file_operations enable;
  899. struct file_operations format;
  900. struct file_operations filter;
  901. };
  902. static struct ftrace_module_file_ops *
  903. trace_create_file_ops(struct module *mod)
  904. {
  905. struct ftrace_module_file_ops *file_ops;
  906. /*
  907. * This is a bit of a PITA. To allow for correct reference
  908. * counting, modules must "own" their file_operations.
  909. * To do this, we allocate the file operations that will be
  910. * used in the event directory.
  911. */
  912. file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
  913. if (!file_ops)
  914. return NULL;
  915. file_ops->mod = mod;
  916. file_ops->id = ftrace_event_id_fops;
  917. file_ops->id.owner = mod;
  918. file_ops->enable = ftrace_enable_fops;
  919. file_ops->enable.owner = mod;
  920. file_ops->filter = ftrace_event_filter_fops;
  921. file_ops->filter.owner = mod;
  922. file_ops->format = ftrace_event_format_fops;
  923. file_ops->format.owner = mod;
  924. list_add(&file_ops->list, &ftrace_module_file_list);
  925. return file_ops;
  926. }
  927. static void trace_module_add_events(struct module *mod)
  928. {
  929. struct ftrace_module_file_ops *file_ops = NULL;
  930. struct ftrace_event_call *call, *start, *end;
  931. struct dentry *d_events;
  932. int ret;
  933. start = mod->trace_events;
  934. end = mod->trace_events + mod->num_trace_events;
  935. if (start == end)
  936. return;
  937. d_events = event_trace_events_dir();
  938. if (!d_events)
  939. return;
  940. for_each_event(call, start, end) {
  941. /* The linker may leave blanks */
  942. if (!call->name)
  943. continue;
  944. if (call->class->raw_init) {
  945. ret = call->class->raw_init(call);
  946. if (ret < 0) {
  947. if (ret != -ENOSYS)
  948. pr_warning("Could not initialize trace "
  949. "point events/%s\n", call->name);
  950. continue;
  951. }
  952. }
  953. /*
  954. * This module has events, create file ops for this module
  955. * if not already done.
  956. */
  957. if (!file_ops) {
  958. file_ops = trace_create_file_ops(mod);
  959. if (!file_ops)
  960. return;
  961. }
  962. call->mod = mod;
  963. ret = event_create_dir(call, d_events,
  964. &file_ops->id, &file_ops->enable,
  965. &file_ops->filter, &file_ops->format);
  966. if (!ret)
  967. list_add(&call->list, &ftrace_events);
  968. }
  969. }
  970. static void trace_module_remove_events(struct module *mod)
  971. {
  972. struct ftrace_module_file_ops *file_ops;
  973. struct ftrace_event_call *call, *p;
  974. bool found = false;
  975. down_write(&trace_event_mutex);
  976. list_for_each_entry_safe(call, p, &ftrace_events, list) {
  977. if (call->mod == mod) {
  978. found = true;
  979. __trace_remove_event_call(call);
  980. }
  981. }
  982. /* Now free the file_operations */
  983. list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
  984. if (file_ops->mod == mod)
  985. break;
  986. }
  987. if (&file_ops->list != &ftrace_module_file_list) {
  988. list_del(&file_ops->list);
  989. kfree(file_ops);
  990. }
  991. /*
  992. * It is safest to reset the ring buffer if the module being unloaded
  993. * registered any events.
  994. */
  995. if (found)
  996. tracing_reset_current_online_cpus();
  997. up_write(&trace_event_mutex);
  998. }
  999. static int trace_module_notify(struct notifier_block *self,
  1000. unsigned long val, void *data)
  1001. {
  1002. struct module *mod = data;
  1003. mutex_lock(&event_mutex);
  1004. switch (val) {
  1005. case MODULE_STATE_COMING:
  1006. trace_module_add_events(mod);
  1007. break;
  1008. case MODULE_STATE_GOING:
  1009. trace_module_remove_events(mod);
  1010. break;
  1011. }
  1012. mutex_unlock(&event_mutex);
  1013. return 0;
  1014. }
  1015. #else
  1016. static int trace_module_notify(struct notifier_block *self,
  1017. unsigned long val, void *data)
  1018. {
  1019. return 0;
  1020. }
  1021. #endif /* CONFIG_MODULES */
  1022. static struct notifier_block trace_module_nb = {
  1023. .notifier_call = trace_module_notify,
  1024. .priority = 0,
  1025. };
  1026. extern struct ftrace_event_call __start_ftrace_events[];
  1027. extern struct ftrace_event_call __stop_ftrace_events[];
  1028. static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
  1029. static __init int setup_trace_event(char *str)
  1030. {
  1031. strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
  1032. ring_buffer_expanded = 1;
  1033. tracing_selftest_disabled = 1;
  1034. return 1;
  1035. }
  1036. __setup("trace_event=", setup_trace_event);
  1037. static __init int event_trace_init(void)
  1038. {
  1039. struct ftrace_event_call *call;
  1040. struct dentry *d_tracer;
  1041. struct dentry *entry;
  1042. struct dentry *d_events;
  1043. int ret;
  1044. char *buf = bootup_event_buf;
  1045. char *token;
  1046. d_tracer = tracing_init_dentry();
  1047. if (!d_tracer)
  1048. return 0;
  1049. entry = debugfs_create_file("available_events", 0444, d_tracer,
  1050. (void *)&show_event_seq_ops,
  1051. &ftrace_avail_fops);
  1052. if (!entry)
  1053. pr_warning("Could not create debugfs "
  1054. "'available_events' entry\n");
  1055. entry = debugfs_create_file("set_event", 0644, d_tracer,
  1056. (void *)&show_set_event_seq_ops,
  1057. &ftrace_set_event_fops);
  1058. if (!entry)
  1059. pr_warning("Could not create debugfs "
  1060. "'set_event' entry\n");
  1061. d_events = event_trace_events_dir();
  1062. if (!d_events)
  1063. return 0;
  1064. /* ring buffer internal formats */
  1065. trace_create_file("header_page", 0444, d_events,
  1066. ring_buffer_print_page_header,
  1067. &ftrace_show_header_fops);
  1068. trace_create_file("header_event", 0444, d_events,
  1069. ring_buffer_print_entry_header,
  1070. &ftrace_show_header_fops);
  1071. trace_create_file("enable", 0644, d_events,
  1072. NULL, &ftrace_system_enable_fops);
  1073. if (trace_define_common_fields())
  1074. pr_warning("tracing: Failed to allocate common fields");
  1075. for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
  1076. /* The linker may leave blanks */
  1077. if (!call->name)
  1078. continue;
  1079. if (call->class->raw_init) {
  1080. ret = call->class->raw_init(call);
  1081. if (ret < 0) {
  1082. if (ret != -ENOSYS)
  1083. pr_warning("Could not initialize trace "
  1084. "point events/%s\n", call->name);
  1085. continue;
  1086. }
  1087. }
  1088. ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
  1089. &ftrace_enable_fops,
  1090. &ftrace_event_filter_fops,
  1091. &ftrace_event_format_fops);
  1092. if (!ret)
  1093. list_add(&call->list, &ftrace_events);
  1094. }
  1095. while (true) {
  1096. token = strsep(&buf, ",");
  1097. if (!token)
  1098. break;
  1099. if (!*token)
  1100. continue;
  1101. ret = ftrace_set_clr_event(token, 1);
  1102. if (ret)
  1103. pr_warning("Failed to enable trace event: %s\n", token);
  1104. }
  1105. ret = register_module_notifier(&trace_module_nb);
  1106. if (ret)
  1107. pr_warning("Failed to register trace events module notifier\n");
  1108. return 0;
  1109. }
  1110. fs_initcall(event_trace_init);
  1111. #ifdef CONFIG_FTRACE_STARTUP_TEST
  1112. static DEFINE_SPINLOCK(test_spinlock);
  1113. static DEFINE_SPINLOCK(test_spinlock_irq);
  1114. static DEFINE_MUTEX(test_mutex);
  1115. static __init void test_work(struct work_struct *dummy)
  1116. {
  1117. spin_lock(&test_spinlock);
  1118. spin_lock_irq(&test_spinlock_irq);
  1119. udelay(1);
  1120. spin_unlock_irq(&test_spinlock_irq);
  1121. spin_unlock(&test_spinlock);
  1122. mutex_lock(&test_mutex);
  1123. msleep(1);
  1124. mutex_unlock(&test_mutex);
  1125. }
  1126. static __init int event_test_thread(void *unused)
  1127. {
  1128. void *test_malloc;
  1129. test_malloc = kmalloc(1234, GFP_KERNEL);
  1130. if (!test_malloc)
  1131. pr_info("failed to kmalloc\n");
  1132. schedule_on_each_cpu(test_work);
  1133. kfree(test_malloc);
  1134. set_current_state(TASK_INTERRUPTIBLE);
  1135. while (!kthread_should_stop())
  1136. schedule();
  1137. return 0;
  1138. }
  1139. /*
  1140. * Do various things that may trigger events.
  1141. */
  1142. static __init void event_test_stuff(void)
  1143. {
  1144. struct task_struct *test_thread;
  1145. test_thread = kthread_run(event_test_thread, NULL, "test-events");
  1146. msleep(1);
  1147. kthread_stop(test_thread);
  1148. }
  1149. /*
  1150. * For every trace event defined, we will test each trace point separately,
  1151. * and then by groups, and finally all trace points.
  1152. */
  1153. static __init void event_trace_self_tests(void)
  1154. {
  1155. struct ftrace_event_call *call;
  1156. struct event_subsystem *system;
  1157. int ret;
  1158. pr_info("Running tests on trace events:\n");
  1159. list_for_each_entry(call, &ftrace_events, list) {
  1160. /* Only test those that have a probe */
  1161. if (!call->class || !call->class->probe)
  1162. continue;
  1163. /*
  1164. * Testing syscall events here is pretty useless, but
  1165. * we still do it if configured. But this is time consuming.
  1166. * What we really need is a user thread to perform the
  1167. * syscalls as we test.
  1168. */
  1169. #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
  1170. if (call->class->system &&
  1171. strcmp(call->class->system, "syscalls") == 0)
  1172. continue;
  1173. #endif
  1174. pr_info("Testing event %s: ", call->name);
  1175. /*
  1176. * If an event is already enabled, someone is using
  1177. * it and the self test should not be on.
  1178. */
  1179. if (call->flags & TRACE_EVENT_FL_ENABLED) {
  1180. pr_warning("Enabled event during self test!\n");
  1181. WARN_ON_ONCE(1);
  1182. continue;
  1183. }
  1184. ftrace_event_enable_disable(call, 1);
  1185. event_test_stuff();
  1186. ftrace_event_enable_disable(call, 0);
  1187. pr_cont("OK\n");
  1188. }
  1189. /* Now test at the sub system level */
  1190. pr_info("Running tests on trace event systems:\n");
  1191. list_for_each_entry(system, &event_subsystems, list) {
  1192. /* the ftrace system is special, skip it */
  1193. if (strcmp(system->name, "ftrace") == 0)
  1194. continue;
  1195. pr_info("Testing event system %s: ", system->name);
  1196. ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
  1197. if (WARN_ON_ONCE(ret)) {
  1198. pr_warning("error enabling system %s\n",
  1199. system->name);
  1200. continue;
  1201. }
  1202. event_test_stuff();
  1203. ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
  1204. if (WARN_ON_ONCE(ret))
  1205. pr_warning("error disabling system %s\n",
  1206. system->name);
  1207. pr_cont("OK\n");
  1208. }
  1209. /* Test with all events enabled */
  1210. pr_info("Running tests on all trace events:\n");
  1211. pr_info("Testing all events: ");
  1212. ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
  1213. if (WARN_ON_ONCE(ret)) {
  1214. pr_warning("error enabling all events\n");
  1215. return;
  1216. }
  1217. event_test_stuff();
  1218. /* reset sysname */
  1219. ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
  1220. if (WARN_ON_ONCE(ret)) {
  1221. pr_warning("error disabling all events\n");
  1222. return;
  1223. }
  1224. pr_cont("OK\n");
  1225. }
  1226. #ifdef CONFIG_FUNCTION_TRACER
  1227. static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
  1228. static void
  1229. function_test_events_call(unsigned long ip, unsigned long parent_ip)
  1230. {
  1231. struct ring_buffer_event *event;
  1232. struct ring_buffer *buffer;
  1233. struct ftrace_entry *entry;
  1234. unsigned long flags;
  1235. long disabled;
  1236. int cpu;
  1237. int pc;
  1238. pc = preempt_count();
  1239. preempt_disable_notrace();
  1240. cpu = raw_smp_processor_id();
  1241. disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
  1242. if (disabled != 1)
  1243. goto out;
  1244. local_save_flags(flags);
  1245. event = trace_current_buffer_lock_reserve(&buffer,
  1246. TRACE_FN, sizeof(*entry),
  1247. flags, pc);
  1248. if (!event)
  1249. goto out;
  1250. entry = ring_buffer_event_data(event);
  1251. entry->ip = ip;
  1252. entry->parent_ip = parent_ip;
  1253. trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
  1254. out:
  1255. atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
  1256. preempt_enable_notrace();
  1257. }
  1258. static struct ftrace_ops trace_ops __initdata =
  1259. {
  1260. .func = function_test_events_call,
  1261. };
  1262. static __init void event_trace_self_test_with_function(void)
  1263. {
  1264. register_ftrace_function(&trace_ops);
  1265. pr_info("Running tests again, along with the function tracer\n");
  1266. event_trace_self_tests();
  1267. unregister_ftrace_function(&trace_ops);
  1268. }
  1269. #else
  1270. static __init void event_trace_self_test_with_function(void)
  1271. {
  1272. }
  1273. #endif
  1274. static __init int event_trace_self_tests_init(void)
  1275. {
  1276. if (!tracing_selftest_disabled) {
  1277. event_trace_self_tests();
  1278. event_trace_self_test_with_function();
  1279. }
  1280. return 0;
  1281. }
  1282. late_initcall(event_trace_self_tests_init);
  1283. #endif