trace_events.c 34 KB

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