trace_events.c 34 KB

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