trace_events.c 33 KB

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