trace_events.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  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. DEFINE_MUTEX(event_storage_mutex);
  25. EXPORT_SYMBOL_GPL(event_storage_mutex);
  26. char event_storage[EVENT_STORAGE_SIZE];
  27. EXPORT_SYMBOL_GPL(event_storage);
  28. LIST_HEAD(ftrace_events);
  29. LIST_HEAD(ftrace_common_fields);
  30. #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO)
  31. static struct kmem_cache *field_cachep;
  32. static struct kmem_cache *file_cachep;
  33. /* Double loops, do not use break, only goto's work */
  34. #define do_for_each_event_file(tr, file) \
  35. list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
  36. list_for_each_entry(file, &tr->events, list)
  37. #define do_for_each_event_file_safe(tr, file) \
  38. list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
  39. struct ftrace_event_file *___n; \
  40. list_for_each_entry_safe(file, ___n, &tr->events, list)
  41. #define while_for_each_event_file() \
  42. }
  43. struct list_head *
  44. trace_get_fields(struct ftrace_event_call *event_call)
  45. {
  46. if (!event_call->class->get_fields)
  47. return &event_call->class->fields;
  48. return event_call->class->get_fields(event_call);
  49. }
  50. static int __trace_define_field(struct list_head *head, const char *type,
  51. const char *name, int offset, int size,
  52. int is_signed, int filter_type)
  53. {
  54. struct ftrace_event_field *field;
  55. field = kmem_cache_alloc(field_cachep, GFP_TRACE);
  56. if (!field)
  57. goto err;
  58. field->name = name;
  59. field->type = type;
  60. if (filter_type == FILTER_OTHER)
  61. field->filter_type = filter_assign_type(type);
  62. else
  63. field->filter_type = filter_type;
  64. field->offset = offset;
  65. field->size = size;
  66. field->is_signed = is_signed;
  67. list_add(&field->link, head);
  68. return 0;
  69. err:
  70. kmem_cache_free(field_cachep, field);
  71. return -ENOMEM;
  72. }
  73. int trace_define_field(struct ftrace_event_call *call, const char *type,
  74. const char *name, int offset, int size, int is_signed,
  75. int filter_type)
  76. {
  77. struct list_head *head;
  78. if (WARN_ON(!call->class))
  79. return 0;
  80. head = trace_get_fields(call);
  81. return __trace_define_field(head, type, name, offset, size,
  82. is_signed, filter_type);
  83. }
  84. EXPORT_SYMBOL_GPL(trace_define_field);
  85. #define __common_field(type, item) \
  86. ret = __trace_define_field(&ftrace_common_fields, #type, \
  87. "common_" #item, \
  88. offsetof(typeof(ent), item), \
  89. sizeof(ent.item), \
  90. is_signed_type(type), FILTER_OTHER); \
  91. if (ret) \
  92. return ret;
  93. static int trace_define_common_fields(void)
  94. {
  95. int ret;
  96. struct trace_entry ent;
  97. __common_field(unsigned short, type);
  98. __common_field(unsigned char, flags);
  99. __common_field(unsigned char, preempt_count);
  100. __common_field(int, pid);
  101. return ret;
  102. }
  103. void trace_destroy_fields(struct ftrace_event_call *call)
  104. {
  105. struct ftrace_event_field *field, *next;
  106. struct list_head *head;
  107. head = trace_get_fields(call);
  108. list_for_each_entry_safe(field, next, head, link) {
  109. list_del(&field->link);
  110. kmem_cache_free(field_cachep, field);
  111. }
  112. }
  113. int trace_event_raw_init(struct ftrace_event_call *call)
  114. {
  115. int id;
  116. id = register_ftrace_event(&call->event);
  117. if (!id)
  118. return -ENODEV;
  119. return 0;
  120. }
  121. EXPORT_SYMBOL_GPL(trace_event_raw_init);
  122. int ftrace_event_reg(struct ftrace_event_call *call,
  123. enum trace_reg type, void *data)
  124. {
  125. struct ftrace_event_file *file = data;
  126. switch (type) {
  127. case TRACE_REG_REGISTER:
  128. return tracepoint_probe_register(call->name,
  129. call->class->probe,
  130. file);
  131. case TRACE_REG_UNREGISTER:
  132. tracepoint_probe_unregister(call->name,
  133. call->class->probe,
  134. file);
  135. return 0;
  136. #ifdef CONFIG_PERF_EVENTS
  137. case TRACE_REG_PERF_REGISTER:
  138. return tracepoint_probe_register(call->name,
  139. call->class->perf_probe,
  140. call);
  141. case TRACE_REG_PERF_UNREGISTER:
  142. tracepoint_probe_unregister(call->name,
  143. call->class->perf_probe,
  144. call);
  145. return 0;
  146. case TRACE_REG_PERF_OPEN:
  147. case TRACE_REG_PERF_CLOSE:
  148. case TRACE_REG_PERF_ADD:
  149. case TRACE_REG_PERF_DEL:
  150. return 0;
  151. #endif
  152. }
  153. return 0;
  154. }
  155. EXPORT_SYMBOL_GPL(ftrace_event_reg);
  156. void trace_event_enable_cmd_record(bool enable)
  157. {
  158. struct ftrace_event_file *file;
  159. struct trace_array *tr;
  160. mutex_lock(&event_mutex);
  161. do_for_each_event_file(tr, file) {
  162. if (!(file->flags & FTRACE_EVENT_FL_ENABLED))
  163. continue;
  164. if (enable) {
  165. tracing_start_cmdline_record();
  166. file->flags |= FTRACE_EVENT_FL_RECORDED_CMD;
  167. } else {
  168. tracing_stop_cmdline_record();
  169. file->flags &= ~FTRACE_EVENT_FL_RECORDED_CMD;
  170. }
  171. } while_for_each_event_file();
  172. mutex_unlock(&event_mutex);
  173. }
  174. static int ftrace_event_enable_disable(struct ftrace_event_file *file,
  175. int enable)
  176. {
  177. struct ftrace_event_call *call = file->event_call;
  178. int ret = 0;
  179. switch (enable) {
  180. case 0:
  181. if (file->flags & FTRACE_EVENT_FL_ENABLED) {
  182. file->flags &= ~FTRACE_EVENT_FL_ENABLED;
  183. if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) {
  184. tracing_stop_cmdline_record();
  185. file->flags &= ~FTRACE_EVENT_FL_RECORDED_CMD;
  186. }
  187. call->class->reg(call, TRACE_REG_UNREGISTER, file);
  188. }
  189. break;
  190. case 1:
  191. if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) {
  192. if (trace_flags & TRACE_ITER_RECORD_CMD) {
  193. tracing_start_cmdline_record();
  194. file->flags |= FTRACE_EVENT_FL_RECORDED_CMD;
  195. }
  196. ret = call->class->reg(call, TRACE_REG_REGISTER, file);
  197. if (ret) {
  198. tracing_stop_cmdline_record();
  199. pr_info("event trace: Could not enable event "
  200. "%s\n", call->name);
  201. break;
  202. }
  203. file->flags |= FTRACE_EVENT_FL_ENABLED;
  204. }
  205. break;
  206. }
  207. return ret;
  208. }
  209. static void ftrace_clear_events(struct trace_array *tr)
  210. {
  211. struct ftrace_event_file *file;
  212. mutex_lock(&event_mutex);
  213. list_for_each_entry(file, &tr->events, list) {
  214. ftrace_event_enable_disable(file, 0);
  215. }
  216. mutex_unlock(&event_mutex);
  217. }
  218. static void __put_system(struct event_subsystem *system)
  219. {
  220. struct event_filter *filter = system->filter;
  221. WARN_ON_ONCE(system->ref_count == 0);
  222. if (--system->ref_count)
  223. return;
  224. list_del(&system->list);
  225. if (filter) {
  226. kfree(filter->filter_string);
  227. kfree(filter);
  228. }
  229. kfree(system);
  230. }
  231. static void __get_system(struct event_subsystem *system)
  232. {
  233. WARN_ON_ONCE(system->ref_count == 0);
  234. system->ref_count++;
  235. }
  236. static void __get_system_dir(struct ftrace_subsystem_dir *dir)
  237. {
  238. WARN_ON_ONCE(dir->ref_count == 0);
  239. dir->ref_count++;
  240. __get_system(dir->subsystem);
  241. }
  242. static void __put_system_dir(struct ftrace_subsystem_dir *dir)
  243. {
  244. WARN_ON_ONCE(dir->ref_count == 0);
  245. /* If the subsystem is about to be freed, the dir must be too */
  246. WARN_ON_ONCE(dir->subsystem->ref_count == 1 && dir->ref_count != 1);
  247. __put_system(dir->subsystem);
  248. if (!--dir->ref_count)
  249. kfree(dir);
  250. }
  251. static void put_system(struct ftrace_subsystem_dir *dir)
  252. {
  253. mutex_lock(&event_mutex);
  254. __put_system_dir(dir);
  255. mutex_unlock(&event_mutex);
  256. }
  257. /*
  258. * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
  259. */
  260. static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
  261. const char *sub, const char *event, int set)
  262. {
  263. struct ftrace_event_file *file;
  264. struct ftrace_event_call *call;
  265. int ret = -EINVAL;
  266. mutex_lock(&event_mutex);
  267. list_for_each_entry(file, &tr->events, list) {
  268. call = file->event_call;
  269. if (!call->name || !call->class || !call->class->reg)
  270. continue;
  271. if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
  272. continue;
  273. if (match &&
  274. strcmp(match, call->name) != 0 &&
  275. strcmp(match, call->class->system) != 0)
  276. continue;
  277. if (sub && strcmp(sub, call->class->system) != 0)
  278. continue;
  279. if (event && strcmp(event, call->name) != 0)
  280. continue;
  281. ftrace_event_enable_disable(file, set);
  282. ret = 0;
  283. }
  284. mutex_unlock(&event_mutex);
  285. return ret;
  286. }
  287. static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
  288. {
  289. char *event = NULL, *sub = NULL, *match;
  290. /*
  291. * The buf format can be <subsystem>:<event-name>
  292. * *:<event-name> means any event by that name.
  293. * :<event-name> is the same.
  294. *
  295. * <subsystem>:* means all events in that subsystem
  296. * <subsystem>: means the same.
  297. *
  298. * <name> (no ':') means all events in a subsystem with
  299. * the name <name> or any event that matches <name>
  300. */
  301. match = strsep(&buf, ":");
  302. if (buf) {
  303. sub = match;
  304. event = buf;
  305. match = NULL;
  306. if (!strlen(sub) || strcmp(sub, "*") == 0)
  307. sub = NULL;
  308. if (!strlen(event) || strcmp(event, "*") == 0)
  309. event = NULL;
  310. }
  311. return __ftrace_set_clr_event(tr, match, sub, event, set);
  312. }
  313. /**
  314. * trace_set_clr_event - enable or disable an event
  315. * @system: system name to match (NULL for any system)
  316. * @event: event name to match (NULL for all events, within system)
  317. * @set: 1 to enable, 0 to disable
  318. *
  319. * This is a way for other parts of the kernel to enable or disable
  320. * event recording.
  321. *
  322. * Returns 0 on success, -EINVAL if the parameters do not match any
  323. * registered events.
  324. */
  325. int trace_set_clr_event(const char *system, const char *event, int set)
  326. {
  327. struct trace_array *tr = top_trace_array();
  328. return __ftrace_set_clr_event(tr, NULL, system, event, set);
  329. }
  330. EXPORT_SYMBOL_GPL(trace_set_clr_event);
  331. /* 128 should be much more than enough */
  332. #define EVENT_BUF_SIZE 127
  333. static ssize_t
  334. ftrace_event_write(struct file *file, const char __user *ubuf,
  335. size_t cnt, loff_t *ppos)
  336. {
  337. struct trace_parser parser;
  338. struct seq_file *m = file->private_data;
  339. struct trace_array *tr = m->private;
  340. ssize_t read, ret;
  341. if (!cnt)
  342. return 0;
  343. ret = tracing_update_buffers();
  344. if (ret < 0)
  345. return ret;
  346. if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
  347. return -ENOMEM;
  348. read = trace_get_user(&parser, ubuf, cnt, ppos);
  349. if (read >= 0 && trace_parser_loaded((&parser))) {
  350. int set = 1;
  351. if (*parser.buffer == '!')
  352. set = 0;
  353. parser.buffer[parser.idx] = 0;
  354. ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
  355. if (ret)
  356. goto out_put;
  357. }
  358. ret = read;
  359. out_put:
  360. trace_parser_put(&parser);
  361. return ret;
  362. }
  363. static void *
  364. t_next(struct seq_file *m, void *v, loff_t *pos)
  365. {
  366. struct ftrace_event_file *file = v;
  367. struct ftrace_event_call *call;
  368. struct trace_array *tr = m->private;
  369. (*pos)++;
  370. list_for_each_entry_continue(file, &tr->events, list) {
  371. call = file->event_call;
  372. /*
  373. * The ftrace subsystem is for showing formats only.
  374. * They can not be enabled or disabled via the event files.
  375. */
  376. if (call->class && call->class->reg)
  377. return file;
  378. }
  379. return NULL;
  380. }
  381. static void *t_start(struct seq_file *m, loff_t *pos)
  382. {
  383. struct ftrace_event_file *file;
  384. struct trace_array *tr = m->private;
  385. loff_t l;
  386. mutex_lock(&event_mutex);
  387. file = list_entry(&tr->events, struct ftrace_event_file, list);
  388. for (l = 0; l <= *pos; ) {
  389. file = t_next(m, file, &l);
  390. if (!file)
  391. break;
  392. }
  393. return file;
  394. }
  395. static void *
  396. s_next(struct seq_file *m, void *v, loff_t *pos)
  397. {
  398. struct ftrace_event_file *file = v;
  399. struct trace_array *tr = m->private;
  400. (*pos)++;
  401. list_for_each_entry_continue(file, &tr->events, list) {
  402. if (file->flags & FTRACE_EVENT_FL_ENABLED)
  403. return file;
  404. }
  405. return NULL;
  406. }
  407. static void *s_start(struct seq_file *m, loff_t *pos)
  408. {
  409. struct ftrace_event_file *file;
  410. struct trace_array *tr = m->private;
  411. loff_t l;
  412. mutex_lock(&event_mutex);
  413. file = list_entry(&tr->events, struct ftrace_event_file, list);
  414. for (l = 0; l <= *pos; ) {
  415. file = s_next(m, file, &l);
  416. if (!file)
  417. break;
  418. }
  419. return file;
  420. }
  421. static int t_show(struct seq_file *m, void *v)
  422. {
  423. struct ftrace_event_file *file = v;
  424. struct ftrace_event_call *call = file->event_call;
  425. if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
  426. seq_printf(m, "%s:", call->class->system);
  427. seq_printf(m, "%s\n", call->name);
  428. return 0;
  429. }
  430. static void t_stop(struct seq_file *m, void *p)
  431. {
  432. mutex_unlock(&event_mutex);
  433. }
  434. static ssize_t
  435. event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
  436. loff_t *ppos)
  437. {
  438. struct ftrace_event_file *file = filp->private_data;
  439. char *buf;
  440. if (file->flags & FTRACE_EVENT_FL_ENABLED)
  441. buf = "1\n";
  442. else
  443. buf = "0\n";
  444. return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
  445. }
  446. static ssize_t
  447. event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
  448. loff_t *ppos)
  449. {
  450. struct ftrace_event_file *file = filp->private_data;
  451. unsigned long val;
  452. int ret;
  453. if (!file)
  454. return -EINVAL;
  455. ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  456. if (ret)
  457. return ret;
  458. ret = tracing_update_buffers();
  459. if (ret < 0)
  460. return ret;
  461. switch (val) {
  462. case 0:
  463. case 1:
  464. mutex_lock(&event_mutex);
  465. ret = ftrace_event_enable_disable(file, val);
  466. mutex_unlock(&event_mutex);
  467. break;
  468. default:
  469. return -EINVAL;
  470. }
  471. *ppos += cnt;
  472. return ret ? ret : cnt;
  473. }
  474. static ssize_t
  475. system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
  476. loff_t *ppos)
  477. {
  478. const char set_to_char[4] = { '?', '0', '1', 'X' };
  479. struct ftrace_subsystem_dir *dir = filp->private_data;
  480. struct event_subsystem *system = dir->subsystem;
  481. struct ftrace_event_call *call;
  482. struct ftrace_event_file *file;
  483. struct trace_array *tr = dir->tr;
  484. char buf[2];
  485. int set = 0;
  486. int ret;
  487. mutex_lock(&event_mutex);
  488. list_for_each_entry(file, &tr->events, list) {
  489. call = file->event_call;
  490. if (!call->name || !call->class || !call->class->reg)
  491. continue;
  492. if (system && strcmp(call->class->system, system->name) != 0)
  493. continue;
  494. /*
  495. * We need to find out if all the events are set
  496. * or if all events or cleared, or if we have
  497. * a mixture.
  498. */
  499. set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED));
  500. /*
  501. * If we have a mixture, no need to look further.
  502. */
  503. if (set == 3)
  504. break;
  505. }
  506. mutex_unlock(&event_mutex);
  507. buf[0] = set_to_char[set];
  508. buf[1] = '\n';
  509. ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
  510. return ret;
  511. }
  512. static ssize_t
  513. system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
  514. loff_t *ppos)
  515. {
  516. struct ftrace_subsystem_dir *dir = filp->private_data;
  517. struct event_subsystem *system = dir->subsystem;
  518. const char *name = NULL;
  519. unsigned long val;
  520. ssize_t ret;
  521. ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
  522. if (ret)
  523. return ret;
  524. ret = tracing_update_buffers();
  525. if (ret < 0)
  526. return ret;
  527. if (val != 0 && val != 1)
  528. return -EINVAL;
  529. /*
  530. * Opening of "enable" adds a ref count to system,
  531. * so the name is safe to use.
  532. */
  533. if (system)
  534. name = system->name;
  535. ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val);
  536. if (ret)
  537. goto out;
  538. ret = cnt;
  539. out:
  540. *ppos += cnt;
  541. return ret;
  542. }
  543. enum {
  544. FORMAT_HEADER = 1,
  545. FORMAT_FIELD_SEPERATOR = 2,
  546. FORMAT_PRINTFMT = 3,
  547. };
  548. static void *f_next(struct seq_file *m, void *v, loff_t *pos)
  549. {
  550. struct ftrace_event_call *call = m->private;
  551. struct ftrace_event_field *field;
  552. struct list_head *common_head = &ftrace_common_fields;
  553. struct list_head *head = trace_get_fields(call);
  554. (*pos)++;
  555. switch ((unsigned long)v) {
  556. case FORMAT_HEADER:
  557. if (unlikely(list_empty(common_head)))
  558. return NULL;
  559. field = list_entry(common_head->prev,
  560. struct ftrace_event_field, link);
  561. return field;
  562. case FORMAT_FIELD_SEPERATOR:
  563. if (unlikely(list_empty(head)))
  564. return NULL;
  565. field = list_entry(head->prev, struct ftrace_event_field, link);
  566. return field;
  567. case FORMAT_PRINTFMT:
  568. /* all done */
  569. return NULL;
  570. }
  571. field = v;
  572. if (field->link.prev == common_head)
  573. return (void *)FORMAT_FIELD_SEPERATOR;
  574. else if (field->link.prev == head)
  575. return (void *)FORMAT_PRINTFMT;
  576. field = list_entry(field->link.prev, struct ftrace_event_field, link);
  577. return field;
  578. }
  579. static void *f_start(struct seq_file *m, loff_t *pos)
  580. {
  581. loff_t l = 0;
  582. void *p;
  583. /* Start by showing the header */
  584. if (!*pos)
  585. return (void *)FORMAT_HEADER;
  586. p = (void *)FORMAT_HEADER;
  587. do {
  588. p = f_next(m, p, &l);
  589. } while (p && l < *pos);
  590. return p;
  591. }
  592. static int f_show(struct seq_file *m, void *v)
  593. {
  594. struct ftrace_event_call *call = m->private;
  595. struct ftrace_event_field *field;
  596. const char *array_descriptor;
  597. switch ((unsigned long)v) {
  598. case FORMAT_HEADER:
  599. seq_printf(m, "name: %s\n", call->name);
  600. seq_printf(m, "ID: %d\n", call->event.type);
  601. seq_printf(m, "format:\n");
  602. return 0;
  603. case FORMAT_FIELD_SEPERATOR:
  604. seq_putc(m, '\n');
  605. return 0;
  606. case FORMAT_PRINTFMT:
  607. seq_printf(m, "\nprint fmt: %s\n",
  608. call->print_fmt);
  609. return 0;
  610. }
  611. field = v;
  612. /*
  613. * Smartly shows the array type(except dynamic array).
  614. * Normal:
  615. * field:TYPE VAR
  616. * If TYPE := TYPE[LEN], it is shown:
  617. * field:TYPE VAR[LEN]
  618. */
  619. array_descriptor = strchr(field->type, '[');
  620. if (!strncmp(field->type, "__data_loc", 10))
  621. array_descriptor = NULL;
  622. if (!array_descriptor)
  623. seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
  624. field->type, field->name, field->offset,
  625. field->size, !!field->is_signed);
  626. else
  627. seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
  628. (int)(array_descriptor - field->type),
  629. field->type, field->name,
  630. array_descriptor, field->offset,
  631. field->size, !!field->is_signed);
  632. return 0;
  633. }
  634. static void f_stop(struct seq_file *m, void *p)
  635. {
  636. }
  637. static const struct seq_operations trace_format_seq_ops = {
  638. .start = f_start,
  639. .next = f_next,
  640. .stop = f_stop,
  641. .show = f_show,
  642. };
  643. static int trace_format_open(struct inode *inode, struct file *file)
  644. {
  645. struct ftrace_event_call *call = inode->i_private;
  646. struct seq_file *m;
  647. int ret;
  648. ret = seq_open(file, &trace_format_seq_ops);
  649. if (ret < 0)
  650. return ret;
  651. m = file->private_data;
  652. m->private = call;
  653. return 0;
  654. }
  655. static ssize_t
  656. event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
  657. {
  658. struct ftrace_event_call *call = filp->private_data;
  659. struct trace_seq *s;
  660. int r;
  661. if (*ppos)
  662. return 0;
  663. s = kmalloc(sizeof(*s), GFP_KERNEL);
  664. if (!s)
  665. return -ENOMEM;
  666. trace_seq_init(s);
  667. trace_seq_printf(s, "%d\n", call->event.type);
  668. r = simple_read_from_buffer(ubuf, cnt, ppos,
  669. s->buffer, s->len);
  670. kfree(s);
  671. return r;
  672. }
  673. static ssize_t
  674. event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
  675. loff_t *ppos)
  676. {
  677. struct ftrace_event_call *call = filp->private_data;
  678. struct trace_seq *s;
  679. int r;
  680. if (*ppos)
  681. return 0;
  682. s = kmalloc(sizeof(*s), GFP_KERNEL);
  683. if (!s)
  684. return -ENOMEM;
  685. trace_seq_init(s);
  686. print_event_filter(call, s);
  687. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  688. kfree(s);
  689. return r;
  690. }
  691. static ssize_t
  692. event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
  693. loff_t *ppos)
  694. {
  695. struct ftrace_event_call *call = filp->private_data;
  696. char *buf;
  697. int err;
  698. if (cnt >= PAGE_SIZE)
  699. return -EINVAL;
  700. buf = (char *)__get_free_page(GFP_TEMPORARY);
  701. if (!buf)
  702. return -ENOMEM;
  703. if (copy_from_user(buf, ubuf, cnt)) {
  704. free_page((unsigned long) buf);
  705. return -EFAULT;
  706. }
  707. buf[cnt] = '\0';
  708. err = apply_event_filter(call, buf);
  709. free_page((unsigned long) buf);
  710. if (err < 0)
  711. return err;
  712. *ppos += cnt;
  713. return cnt;
  714. }
  715. static LIST_HEAD(event_subsystems);
  716. static int subsystem_open(struct inode *inode, struct file *filp)
  717. {
  718. struct event_subsystem *system = NULL;
  719. struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */
  720. struct trace_array *tr;
  721. int ret;
  722. /* Make sure the system still exists */
  723. mutex_lock(&event_mutex);
  724. list_for_each_entry(tr, &ftrace_trace_arrays, list) {
  725. list_for_each_entry(dir, &tr->systems, list) {
  726. if (dir == inode->i_private) {
  727. /* Don't open systems with no events */
  728. if (dir->nr_events) {
  729. __get_system_dir(dir);
  730. system = dir->subsystem;
  731. }
  732. goto exit_loop;
  733. }
  734. }
  735. }
  736. exit_loop:
  737. mutex_unlock(&event_mutex);
  738. if (!system)
  739. return -ENODEV;
  740. /* Some versions of gcc think dir can be uninitialized here */
  741. WARN_ON(!dir);
  742. ret = tracing_open_generic(inode, filp);
  743. if (ret < 0)
  744. put_system(dir);
  745. return ret;
  746. }
  747. static int system_tr_open(struct inode *inode, struct file *filp)
  748. {
  749. struct ftrace_subsystem_dir *dir;
  750. struct trace_array *tr = inode->i_private;
  751. int ret;
  752. /* Make a temporary dir that has no system but points to tr */
  753. dir = kzalloc(sizeof(*dir), GFP_KERNEL);
  754. if (!dir)
  755. return -ENOMEM;
  756. dir->tr = tr;
  757. ret = tracing_open_generic(inode, filp);
  758. if (ret < 0)
  759. kfree(dir);
  760. filp->private_data = dir;
  761. return ret;
  762. }
  763. static int subsystem_release(struct inode *inode, struct file *file)
  764. {
  765. struct ftrace_subsystem_dir *dir = file->private_data;
  766. /*
  767. * If dir->subsystem is NULL, then this is a temporary
  768. * descriptor that was made for a trace_array to enable
  769. * all subsystems.
  770. */
  771. if (dir->subsystem)
  772. put_system(dir);
  773. else
  774. kfree(dir);
  775. return 0;
  776. }
  777. static ssize_t
  778. subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
  779. loff_t *ppos)
  780. {
  781. struct ftrace_subsystem_dir *dir = filp->private_data;
  782. struct event_subsystem *system = dir->subsystem;
  783. struct trace_seq *s;
  784. int r;
  785. if (*ppos)
  786. return 0;
  787. s = kmalloc(sizeof(*s), GFP_KERNEL);
  788. if (!s)
  789. return -ENOMEM;
  790. trace_seq_init(s);
  791. print_subsystem_event_filter(system, s);
  792. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  793. kfree(s);
  794. return r;
  795. }
  796. static ssize_t
  797. subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
  798. loff_t *ppos)
  799. {
  800. struct ftrace_subsystem_dir *dir = filp->private_data;
  801. char *buf;
  802. int err;
  803. if (cnt >= PAGE_SIZE)
  804. return -EINVAL;
  805. buf = (char *)__get_free_page(GFP_TEMPORARY);
  806. if (!buf)
  807. return -ENOMEM;
  808. if (copy_from_user(buf, ubuf, cnt)) {
  809. free_page((unsigned long) buf);
  810. return -EFAULT;
  811. }
  812. buf[cnt] = '\0';
  813. err = apply_subsystem_event_filter(dir, buf);
  814. free_page((unsigned long) buf);
  815. if (err < 0)
  816. return err;
  817. *ppos += cnt;
  818. return cnt;
  819. }
  820. static ssize_t
  821. show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
  822. {
  823. int (*func)(struct trace_seq *s) = filp->private_data;
  824. struct trace_seq *s;
  825. int r;
  826. if (*ppos)
  827. return 0;
  828. s = kmalloc(sizeof(*s), GFP_KERNEL);
  829. if (!s)
  830. return -ENOMEM;
  831. trace_seq_init(s);
  832. func(s);
  833. r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
  834. kfree(s);
  835. return r;
  836. }
  837. static int ftrace_event_avail_open(struct inode *inode, struct file *file);
  838. static int ftrace_event_set_open(struct inode *inode, struct file *file);
  839. static const struct seq_operations show_event_seq_ops = {
  840. .start = t_start,
  841. .next = t_next,
  842. .show = t_show,
  843. .stop = t_stop,
  844. };
  845. static const struct seq_operations show_set_event_seq_ops = {
  846. .start = s_start,
  847. .next = s_next,
  848. .show = t_show,
  849. .stop = t_stop,
  850. };
  851. static const struct file_operations ftrace_avail_fops = {
  852. .open = ftrace_event_avail_open,
  853. .read = seq_read,
  854. .llseek = seq_lseek,
  855. .release = seq_release,
  856. };
  857. static const struct file_operations ftrace_set_event_fops = {
  858. .open = ftrace_event_set_open,
  859. .read = seq_read,
  860. .write = ftrace_event_write,
  861. .llseek = seq_lseek,
  862. .release = seq_release,
  863. };
  864. static const struct file_operations ftrace_enable_fops = {
  865. .open = tracing_open_generic,
  866. .read = event_enable_read,
  867. .write = event_enable_write,
  868. .llseek = default_llseek,
  869. };
  870. static const struct file_operations ftrace_event_format_fops = {
  871. .open = trace_format_open,
  872. .read = seq_read,
  873. .llseek = seq_lseek,
  874. .release = seq_release,
  875. };
  876. static const struct file_operations ftrace_event_id_fops = {
  877. .open = tracing_open_generic,
  878. .read = event_id_read,
  879. .llseek = default_llseek,
  880. };
  881. static const struct file_operations ftrace_event_filter_fops = {
  882. .open = tracing_open_generic,
  883. .read = event_filter_read,
  884. .write = event_filter_write,
  885. .llseek = default_llseek,
  886. };
  887. static const struct file_operations ftrace_subsystem_filter_fops = {
  888. .open = subsystem_open,
  889. .read = subsystem_filter_read,
  890. .write = subsystem_filter_write,
  891. .llseek = default_llseek,
  892. .release = subsystem_release,
  893. };
  894. static const struct file_operations ftrace_system_enable_fops = {
  895. .open = subsystem_open,
  896. .read = system_enable_read,
  897. .write = system_enable_write,
  898. .llseek = default_llseek,
  899. .release = subsystem_release,
  900. };
  901. static const struct file_operations ftrace_tr_enable_fops = {
  902. .open = system_tr_open,
  903. .read = system_enable_read,
  904. .write = system_enable_write,
  905. .llseek = default_llseek,
  906. .release = subsystem_release,
  907. };
  908. static const struct file_operations ftrace_show_header_fops = {
  909. .open = tracing_open_generic,
  910. .read = show_header,
  911. .llseek = default_llseek,
  912. };
  913. static int
  914. ftrace_event_open(struct inode *inode, struct file *file,
  915. const struct seq_operations *seq_ops)
  916. {
  917. struct seq_file *m;
  918. int ret;
  919. ret = seq_open(file, seq_ops);
  920. if (ret < 0)
  921. return ret;
  922. m = file->private_data;
  923. /* copy tr over to seq ops */
  924. m->private = inode->i_private;
  925. return ret;
  926. }
  927. static int
  928. ftrace_event_avail_open(struct inode *inode, struct file *file)
  929. {
  930. const struct seq_operations *seq_ops = &show_event_seq_ops;
  931. return ftrace_event_open(inode, file, seq_ops);
  932. }
  933. static int
  934. ftrace_event_set_open(struct inode *inode, struct file *file)
  935. {
  936. const struct seq_operations *seq_ops = &show_set_event_seq_ops;
  937. struct trace_array *tr = inode->i_private;
  938. if ((file->f_mode & FMODE_WRITE) &&
  939. (file->f_flags & O_TRUNC))
  940. ftrace_clear_events(tr);
  941. return ftrace_event_open(inode, file, seq_ops);
  942. }
  943. static struct event_subsystem *
  944. create_new_subsystem(const char *name)
  945. {
  946. struct event_subsystem *system;
  947. /* need to create new entry */
  948. system = kmalloc(sizeof(*system), GFP_KERNEL);
  949. if (!system)
  950. return NULL;
  951. system->ref_count = 1;
  952. system->name = name;
  953. system->filter = NULL;
  954. system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
  955. if (!system->filter)
  956. goto out_free;
  957. list_add(&system->list, &event_subsystems);
  958. return system;
  959. out_free:
  960. kfree(system);
  961. return NULL;
  962. }
  963. static struct dentry *
  964. event_subsystem_dir(struct trace_array *tr, const char *name,
  965. struct ftrace_event_file *file, struct dentry *parent)
  966. {
  967. struct ftrace_subsystem_dir *dir;
  968. struct event_subsystem *system;
  969. struct dentry *entry;
  970. /* First see if we did not already create this dir */
  971. list_for_each_entry(dir, &tr->systems, list) {
  972. system = dir->subsystem;
  973. if (strcmp(system->name, name) == 0) {
  974. dir->nr_events++;
  975. file->system = dir;
  976. return dir->entry;
  977. }
  978. }
  979. /* Now see if the system itself exists. */
  980. list_for_each_entry(system, &event_subsystems, list) {
  981. if (strcmp(system->name, name) == 0)
  982. break;
  983. }
  984. /* Reset system variable when not found */
  985. if (&system->list == &event_subsystems)
  986. system = NULL;
  987. dir = kmalloc(sizeof(*dir), GFP_KERNEL);
  988. if (!dir)
  989. goto out_fail;
  990. if (!system) {
  991. system = create_new_subsystem(name);
  992. if (!system)
  993. goto out_free;
  994. } else
  995. __get_system(system);
  996. dir->entry = debugfs_create_dir(name, parent);
  997. if (!dir->entry) {
  998. pr_warning("Failed to create system directory %s\n", name);
  999. __put_system(system);
  1000. goto out_free;
  1001. }
  1002. dir->tr = tr;
  1003. dir->ref_count = 1;
  1004. dir->nr_events = 1;
  1005. dir->subsystem = system;
  1006. file->system = dir;
  1007. entry = debugfs_create_file("filter", 0644, dir->entry, dir,
  1008. &ftrace_subsystem_filter_fops);
  1009. if (!entry) {
  1010. kfree(system->filter);
  1011. system->filter = NULL;
  1012. pr_warning("Could not create debugfs '%s/filter' entry\n", name);
  1013. }
  1014. trace_create_file("enable", 0644, dir->entry, dir,
  1015. &ftrace_system_enable_fops);
  1016. list_add(&dir->list, &tr->systems);
  1017. return dir->entry;
  1018. out_free:
  1019. kfree(dir);
  1020. out_fail:
  1021. /* Only print this message if failed on memory allocation */
  1022. if (!dir || !system)
  1023. pr_warning("No memory to create event subsystem %s\n",
  1024. name);
  1025. return NULL;
  1026. }
  1027. static int
  1028. event_create_dir(struct dentry *parent,
  1029. struct ftrace_event_file *file,
  1030. const struct file_operations *id,
  1031. const struct file_operations *enable,
  1032. const struct file_operations *filter,
  1033. const struct file_operations *format)
  1034. {
  1035. struct ftrace_event_call *call = file->event_call;
  1036. struct trace_array *tr = file->tr;
  1037. struct list_head *head;
  1038. struct dentry *d_events;
  1039. int ret;
  1040. /*
  1041. * If the trace point header did not define TRACE_SYSTEM
  1042. * then the system would be called "TRACE_SYSTEM".
  1043. */
  1044. if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
  1045. d_events = event_subsystem_dir(tr, call->class->system, file, parent);
  1046. if (!d_events)
  1047. return -ENOMEM;
  1048. } else
  1049. d_events = parent;
  1050. file->dir = debugfs_create_dir(call->name, d_events);
  1051. if (!file->dir) {
  1052. pr_warning("Could not create debugfs '%s' directory\n",
  1053. call->name);
  1054. return -1;
  1055. }
  1056. if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
  1057. trace_create_file("enable", 0644, file->dir, file,
  1058. enable);
  1059. #ifdef CONFIG_PERF_EVENTS
  1060. if (call->event.type && call->class->reg)
  1061. trace_create_file("id", 0444, file->dir, call,
  1062. id);
  1063. #endif
  1064. /*
  1065. * Other events may have the same class. Only update
  1066. * the fields if they are not already defined.
  1067. */
  1068. head = trace_get_fields(call);
  1069. if (list_empty(head)) {
  1070. ret = call->class->define_fields(call);
  1071. if (ret < 0) {
  1072. pr_warning("Could not initialize trace point"
  1073. " events/%s\n", call->name);
  1074. return -1;
  1075. }
  1076. }
  1077. trace_create_file("filter", 0644, file->dir, call,
  1078. filter);
  1079. trace_create_file("format", 0444, file->dir, call,
  1080. format);
  1081. return 0;
  1082. }
  1083. static void remove_subsystem(struct ftrace_subsystem_dir *dir)
  1084. {
  1085. if (!dir)
  1086. return;
  1087. if (!--dir->nr_events) {
  1088. debugfs_remove_recursive(dir->entry);
  1089. list_del(&dir->list);
  1090. __put_system_dir(dir);
  1091. }
  1092. }
  1093. static void remove_event_from_tracers(struct ftrace_event_call *call)
  1094. {
  1095. struct ftrace_event_file *file;
  1096. struct trace_array *tr;
  1097. do_for_each_event_file_safe(tr, file) {
  1098. if (file->event_call != call)
  1099. continue;
  1100. list_del(&file->list);
  1101. debugfs_remove_recursive(file->dir);
  1102. remove_subsystem(file->system);
  1103. kmem_cache_free(file_cachep, file);
  1104. /*
  1105. * The do_for_each_event_file_safe() is
  1106. * a double loop. After finding the call for this
  1107. * trace_array, we use break to jump to the next
  1108. * trace_array.
  1109. */
  1110. break;
  1111. } while_for_each_event_file();
  1112. }
  1113. static void event_remove(struct ftrace_event_call *call)
  1114. {
  1115. struct trace_array *tr;
  1116. struct ftrace_event_file *file;
  1117. do_for_each_event_file(tr, file) {
  1118. if (file->event_call != call)
  1119. continue;
  1120. ftrace_event_enable_disable(file, 0);
  1121. /*
  1122. * The do_for_each_event_file() is
  1123. * a double loop. After finding the call for this
  1124. * trace_array, we use break to jump to the next
  1125. * trace_array.
  1126. */
  1127. break;
  1128. } while_for_each_event_file();
  1129. if (call->event.funcs)
  1130. __unregister_ftrace_event(&call->event);
  1131. remove_event_from_tracers(call);
  1132. list_del(&call->list);
  1133. }
  1134. static int event_init(struct ftrace_event_call *call)
  1135. {
  1136. int ret = 0;
  1137. if (WARN_ON(!call->name))
  1138. return -EINVAL;
  1139. if (call->class->raw_init) {
  1140. ret = call->class->raw_init(call);
  1141. if (ret < 0 && ret != -ENOSYS)
  1142. pr_warn("Could not initialize trace events/%s\n",
  1143. call->name);
  1144. }
  1145. return ret;
  1146. }
  1147. static int
  1148. __register_event(struct ftrace_event_call *call, struct module *mod)
  1149. {
  1150. int ret;
  1151. ret = event_init(call);
  1152. if (ret < 0)
  1153. return ret;
  1154. list_add(&call->list, &ftrace_events);
  1155. call->mod = mod;
  1156. return 0;
  1157. }
  1158. /* Add an event to a trace directory */
  1159. static int
  1160. __trace_add_new_event(struct ftrace_event_call *call,
  1161. struct trace_array *tr,
  1162. const struct file_operations *id,
  1163. const struct file_operations *enable,
  1164. const struct file_operations *filter,
  1165. const struct file_operations *format)
  1166. {
  1167. struct ftrace_event_file *file;
  1168. file = kmem_cache_alloc(file_cachep, GFP_TRACE);
  1169. if (!file)
  1170. return -ENOMEM;
  1171. file->event_call = call;
  1172. file->tr = tr;
  1173. list_add(&file->list, &tr->events);
  1174. return event_create_dir(tr->event_dir, file, id, enable, filter, format);
  1175. }
  1176. /*
  1177. * Just create a decriptor for early init. A descriptor is required
  1178. * for enabling events at boot. We want to enable events before
  1179. * the filesystem is initialized.
  1180. */
  1181. static __init int
  1182. __trace_early_add_new_event(struct ftrace_event_call *call,
  1183. struct trace_array *tr)
  1184. {
  1185. struct ftrace_event_file *file;
  1186. file = kmem_cache_alloc(file_cachep, GFP_TRACE);
  1187. if (!file)
  1188. return -ENOMEM;
  1189. file->event_call = call;
  1190. file->tr = tr;
  1191. list_add(&file->list, &tr->events);
  1192. return 0;
  1193. }
  1194. struct ftrace_module_file_ops;
  1195. static void __add_event_to_tracers(struct ftrace_event_call *call,
  1196. struct ftrace_module_file_ops *file_ops);
  1197. /* Add an additional event_call dynamically */
  1198. int trace_add_event_call(struct ftrace_event_call *call)
  1199. {
  1200. int ret;
  1201. mutex_lock(&event_mutex);
  1202. ret = __register_event(call, NULL);
  1203. if (ret >= 0)
  1204. __add_event_to_tracers(call, NULL);
  1205. mutex_unlock(&event_mutex);
  1206. return ret;
  1207. }
  1208. /*
  1209. * Must be called under locking both of event_mutex and trace_event_mutex.
  1210. */
  1211. static void __trace_remove_event_call(struct ftrace_event_call *call)
  1212. {
  1213. event_remove(call);
  1214. trace_destroy_fields(call);
  1215. destroy_preds(call);
  1216. }
  1217. /* Remove an event_call */
  1218. void trace_remove_event_call(struct ftrace_event_call *call)
  1219. {
  1220. mutex_lock(&event_mutex);
  1221. down_write(&trace_event_mutex);
  1222. __trace_remove_event_call(call);
  1223. up_write(&trace_event_mutex);
  1224. mutex_unlock(&event_mutex);
  1225. }
  1226. #define for_each_event(event, start, end) \
  1227. for (event = start; \
  1228. (unsigned long)event < (unsigned long)end; \
  1229. event++)
  1230. #ifdef CONFIG_MODULES
  1231. static LIST_HEAD(ftrace_module_file_list);
  1232. /*
  1233. * Modules must own their file_operations to keep up with
  1234. * reference counting.
  1235. */
  1236. struct ftrace_module_file_ops {
  1237. struct list_head list;
  1238. struct module *mod;
  1239. struct file_operations id;
  1240. struct file_operations enable;
  1241. struct file_operations format;
  1242. struct file_operations filter;
  1243. };
  1244. static struct ftrace_module_file_ops *find_ftrace_file_ops(struct module *mod)
  1245. {
  1246. struct ftrace_module_file_ops *file_ops;
  1247. list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
  1248. if (file_ops->mod == mod)
  1249. return file_ops;
  1250. }
  1251. return NULL;
  1252. }
  1253. static struct ftrace_module_file_ops *
  1254. trace_create_file_ops(struct module *mod)
  1255. {
  1256. struct ftrace_module_file_ops *file_ops;
  1257. /*
  1258. * This is a bit of a PITA. To allow for correct reference
  1259. * counting, modules must "own" their file_operations.
  1260. * To do this, we allocate the file operations that will be
  1261. * used in the event directory.
  1262. */
  1263. file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
  1264. if (!file_ops)
  1265. return NULL;
  1266. file_ops->mod = mod;
  1267. file_ops->id = ftrace_event_id_fops;
  1268. file_ops->id.owner = mod;
  1269. file_ops->enable = ftrace_enable_fops;
  1270. file_ops->enable.owner = mod;
  1271. file_ops->filter = ftrace_event_filter_fops;
  1272. file_ops->filter.owner = mod;
  1273. file_ops->format = ftrace_event_format_fops;
  1274. file_ops->format.owner = mod;
  1275. list_add(&file_ops->list, &ftrace_module_file_list);
  1276. return file_ops;
  1277. }
  1278. static void trace_module_add_events(struct module *mod)
  1279. {
  1280. struct ftrace_module_file_ops *file_ops = NULL;
  1281. struct ftrace_event_call **call, **start, **end;
  1282. start = mod->trace_events;
  1283. end = mod->trace_events + mod->num_trace_events;
  1284. if (start == end)
  1285. return;
  1286. file_ops = trace_create_file_ops(mod);
  1287. if (!file_ops)
  1288. return;
  1289. for_each_event(call, start, end) {
  1290. __register_event(*call, mod);
  1291. __add_event_to_tracers(*call, file_ops);
  1292. }
  1293. }
  1294. static void trace_module_remove_events(struct module *mod)
  1295. {
  1296. struct ftrace_module_file_ops *file_ops;
  1297. struct ftrace_event_call *call, *p;
  1298. bool found = false;
  1299. down_write(&trace_event_mutex);
  1300. list_for_each_entry_safe(call, p, &ftrace_events, list) {
  1301. if (call->mod == mod) {
  1302. found = true;
  1303. __trace_remove_event_call(call);
  1304. }
  1305. }
  1306. /* Now free the file_operations */
  1307. list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
  1308. if (file_ops->mod == mod)
  1309. break;
  1310. }
  1311. if (&file_ops->list != &ftrace_module_file_list) {
  1312. list_del(&file_ops->list);
  1313. kfree(file_ops);
  1314. }
  1315. /*
  1316. * It is safest to reset the ring buffer if the module being unloaded
  1317. * registered any events.
  1318. */
  1319. if (found)
  1320. tracing_reset_current_online_cpus();
  1321. up_write(&trace_event_mutex);
  1322. }
  1323. static int trace_module_notify(struct notifier_block *self,
  1324. unsigned long val, void *data)
  1325. {
  1326. struct module *mod = data;
  1327. mutex_lock(&event_mutex);
  1328. switch (val) {
  1329. case MODULE_STATE_COMING:
  1330. trace_module_add_events(mod);
  1331. break;
  1332. case MODULE_STATE_GOING:
  1333. trace_module_remove_events(mod);
  1334. break;
  1335. }
  1336. mutex_unlock(&event_mutex);
  1337. return 0;
  1338. }
  1339. #else
  1340. static struct ftrace_module_file_ops *find_ftrace_file_ops(struct module *mod)
  1341. {
  1342. return NULL;
  1343. }
  1344. static int trace_module_notify(struct notifier_block *self,
  1345. unsigned long val, void *data)
  1346. {
  1347. return 0;
  1348. }
  1349. #endif /* CONFIG_MODULES */
  1350. /* Create a new event directory structure for a trace directory. */
  1351. static void
  1352. __trace_add_event_dirs(struct trace_array *tr)
  1353. {
  1354. struct ftrace_module_file_ops *file_ops = NULL;
  1355. struct ftrace_event_call *call;
  1356. int ret;
  1357. list_for_each_entry(call, &ftrace_events, list) {
  1358. if (call->mod) {
  1359. /*
  1360. * Directories for events by modules need to
  1361. * keep module ref counts when opened (as we don't
  1362. * want the module to disappear when reading one
  1363. * of these files). The file_ops keep account of
  1364. * the module ref count.
  1365. *
  1366. * As event_calls are added in groups by module,
  1367. * when we find one file_ops, we don't need to search for
  1368. * each call in that module, as the rest should be the
  1369. * same. Only search for a new one if the last one did
  1370. * not match.
  1371. */
  1372. if (!file_ops || call->mod != file_ops->mod)
  1373. file_ops = find_ftrace_file_ops(call->mod);
  1374. if (!file_ops)
  1375. continue; /* Warn? */
  1376. ret = __trace_add_new_event(call, tr,
  1377. &file_ops->id, &file_ops->enable,
  1378. &file_ops->filter, &file_ops->format);
  1379. if (ret < 0)
  1380. pr_warning("Could not create directory for event %s\n",
  1381. call->name);
  1382. continue;
  1383. }
  1384. ret = __trace_add_new_event(call, tr,
  1385. &ftrace_event_id_fops,
  1386. &ftrace_enable_fops,
  1387. &ftrace_event_filter_fops,
  1388. &ftrace_event_format_fops);
  1389. if (ret < 0)
  1390. pr_warning("Could not create directory for event %s\n",
  1391. call->name);
  1392. }
  1393. }
  1394. /*
  1395. * The top level array has already had its ftrace_event_file
  1396. * descriptors created in order to allow for early events to
  1397. * be recorded. This function is called after the debugfs has been
  1398. * initialized, and we now have to create the files associated
  1399. * to the events.
  1400. */
  1401. static __init void
  1402. __trace_early_add_event_dirs(struct trace_array *tr)
  1403. {
  1404. struct ftrace_event_file *file;
  1405. int ret;
  1406. list_for_each_entry(file, &tr->events, list) {
  1407. ret = event_create_dir(tr->event_dir, file,
  1408. &ftrace_event_id_fops,
  1409. &ftrace_enable_fops,
  1410. &ftrace_event_filter_fops,
  1411. &ftrace_event_format_fops);
  1412. if (ret < 0)
  1413. pr_warning("Could not create directory for event %s\n",
  1414. file->event_call->name);
  1415. }
  1416. }
  1417. /*
  1418. * For early boot up, the top trace array requires to have
  1419. * a list of events that can be enabled. This must be done before
  1420. * the filesystem is set up in order to allow events to be traced
  1421. * early.
  1422. */
  1423. static __init void
  1424. __trace_early_add_events(struct trace_array *tr)
  1425. {
  1426. struct ftrace_event_call *call;
  1427. int ret;
  1428. list_for_each_entry(call, &ftrace_events, list) {
  1429. /* Early boot up should not have any modules loaded */
  1430. if (WARN_ON_ONCE(call->mod))
  1431. continue;
  1432. ret = __trace_early_add_new_event(call, tr);
  1433. if (ret < 0)
  1434. pr_warning("Could not create early event %s\n",
  1435. call->name);
  1436. }
  1437. }
  1438. /* Remove the event directory structure for a trace directory. */
  1439. static void
  1440. __trace_remove_event_dirs(struct trace_array *tr)
  1441. {
  1442. struct ftrace_event_file *file, *next;
  1443. list_for_each_entry_safe(file, next, &tr->events, list) {
  1444. list_del(&file->list);
  1445. debugfs_remove_recursive(file->dir);
  1446. remove_subsystem(file->system);
  1447. kmem_cache_free(file_cachep, file);
  1448. }
  1449. }
  1450. static void
  1451. __add_event_to_tracers(struct ftrace_event_call *call,
  1452. struct ftrace_module_file_ops *file_ops)
  1453. {
  1454. struct trace_array *tr;
  1455. list_for_each_entry(tr, &ftrace_trace_arrays, list) {
  1456. if (file_ops)
  1457. __trace_add_new_event(call, tr,
  1458. &file_ops->id, &file_ops->enable,
  1459. &file_ops->filter, &file_ops->format);
  1460. else
  1461. __trace_add_new_event(call, tr,
  1462. &ftrace_event_id_fops,
  1463. &ftrace_enable_fops,
  1464. &ftrace_event_filter_fops,
  1465. &ftrace_event_format_fops);
  1466. }
  1467. }
  1468. static struct notifier_block trace_module_nb = {
  1469. .notifier_call = trace_module_notify,
  1470. .priority = 0,
  1471. };
  1472. extern struct ftrace_event_call *__start_ftrace_events[];
  1473. extern struct ftrace_event_call *__stop_ftrace_events[];
  1474. static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
  1475. static __init int setup_trace_event(char *str)
  1476. {
  1477. strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
  1478. ring_buffer_expanded = 1;
  1479. tracing_selftest_disabled = 1;
  1480. return 1;
  1481. }
  1482. __setup("trace_event=", setup_trace_event);
  1483. /* Expects to have event_mutex held when called */
  1484. static int
  1485. create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
  1486. {
  1487. struct dentry *d_events;
  1488. struct dentry *entry;
  1489. entry = debugfs_create_file("set_event", 0644, parent,
  1490. tr, &ftrace_set_event_fops);
  1491. if (!entry) {
  1492. pr_warning("Could not create debugfs 'set_event' entry\n");
  1493. return -ENOMEM;
  1494. }
  1495. d_events = debugfs_create_dir("events", parent);
  1496. if (!d_events) {
  1497. pr_warning("Could not create debugfs 'events' directory\n");
  1498. return -ENOMEM;
  1499. }
  1500. /* ring buffer internal formats */
  1501. trace_create_file("header_page", 0444, d_events,
  1502. ring_buffer_print_page_header,
  1503. &ftrace_show_header_fops);
  1504. trace_create_file("header_event", 0444, d_events,
  1505. ring_buffer_print_entry_header,
  1506. &ftrace_show_header_fops);
  1507. trace_create_file("enable", 0644, d_events,
  1508. tr, &ftrace_tr_enable_fops);
  1509. tr->event_dir = d_events;
  1510. return 0;
  1511. }
  1512. /**
  1513. * event_trace_add_tracer - add a instance of a trace_array to events
  1514. * @parent: The parent dentry to place the files/directories for events in
  1515. * @tr: The trace array associated with these events
  1516. *
  1517. * When a new instance is created, it needs to set up its events
  1518. * directory, as well as other files associated with events. It also
  1519. * creates the event hierachry in the @parent/events directory.
  1520. *
  1521. * Returns 0 on success.
  1522. */
  1523. int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
  1524. {
  1525. int ret;
  1526. mutex_lock(&event_mutex);
  1527. ret = create_event_toplevel_files(parent, tr);
  1528. if (ret)
  1529. goto out_unlock;
  1530. down_write(&trace_event_mutex);
  1531. __trace_add_event_dirs(tr);
  1532. up_write(&trace_event_mutex);
  1533. out_unlock:
  1534. mutex_unlock(&event_mutex);
  1535. return ret;
  1536. }
  1537. /*
  1538. * The top trace array already had its file descriptors created.
  1539. * Now the files themselves need to be created.
  1540. */
  1541. static __init int
  1542. early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
  1543. {
  1544. int ret;
  1545. mutex_lock(&event_mutex);
  1546. ret = create_event_toplevel_files(parent, tr);
  1547. if (ret)
  1548. goto out_unlock;
  1549. down_write(&trace_event_mutex);
  1550. __trace_early_add_event_dirs(tr);
  1551. up_write(&trace_event_mutex);
  1552. out_unlock:
  1553. mutex_unlock(&event_mutex);
  1554. return ret;
  1555. }
  1556. int event_trace_del_tracer(struct trace_array *tr)
  1557. {
  1558. /* Disable any running events */
  1559. __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
  1560. mutex_lock(&event_mutex);
  1561. down_write(&trace_event_mutex);
  1562. __trace_remove_event_dirs(tr);
  1563. debugfs_remove_recursive(tr->event_dir);
  1564. up_write(&trace_event_mutex);
  1565. tr->event_dir = NULL;
  1566. mutex_unlock(&event_mutex);
  1567. return 0;
  1568. }
  1569. static __init int event_trace_memsetup(void)
  1570. {
  1571. field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC);
  1572. file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC);
  1573. return 0;
  1574. }
  1575. static __init int event_trace_enable(void)
  1576. {
  1577. struct trace_array *tr = top_trace_array();
  1578. struct ftrace_event_call **iter, *call;
  1579. char *buf = bootup_event_buf;
  1580. char *token;
  1581. int ret;
  1582. for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
  1583. call = *iter;
  1584. ret = event_init(call);
  1585. if (!ret)
  1586. list_add(&call->list, &ftrace_events);
  1587. }
  1588. /*
  1589. * We need the top trace array to have a working set of trace
  1590. * points at early init, before the debug files and directories
  1591. * are created. Create the file entries now, and attach them
  1592. * to the actual file dentries later.
  1593. */
  1594. __trace_early_add_events(tr);
  1595. while (true) {
  1596. token = strsep(&buf, ",");
  1597. if (!token)
  1598. break;
  1599. if (!*token)
  1600. continue;
  1601. ret = ftrace_set_clr_event(tr, token, 1);
  1602. if (ret)
  1603. pr_warn("Failed to enable trace event: %s\n", token);
  1604. }
  1605. trace_printk_start_comm();
  1606. return 0;
  1607. }
  1608. static __init int event_trace_init(void)
  1609. {
  1610. struct trace_array *tr;
  1611. struct dentry *d_tracer;
  1612. struct dentry *entry;
  1613. int ret;
  1614. tr = top_trace_array();
  1615. d_tracer = tracing_init_dentry();
  1616. if (!d_tracer)
  1617. return 0;
  1618. entry = debugfs_create_file("available_events", 0444, d_tracer,
  1619. tr, &ftrace_avail_fops);
  1620. if (!entry)
  1621. pr_warning("Could not create debugfs "
  1622. "'available_events' entry\n");
  1623. if (trace_define_common_fields())
  1624. pr_warning("tracing: Failed to allocate common fields");
  1625. ret = early_event_add_tracer(d_tracer, tr);
  1626. if (ret)
  1627. return ret;
  1628. ret = register_module_notifier(&trace_module_nb);
  1629. if (ret)
  1630. pr_warning("Failed to register trace events module notifier\n");
  1631. return 0;
  1632. }
  1633. early_initcall(event_trace_memsetup);
  1634. core_initcall(event_trace_enable);
  1635. fs_initcall(event_trace_init);
  1636. #ifdef CONFIG_FTRACE_STARTUP_TEST
  1637. static DEFINE_SPINLOCK(test_spinlock);
  1638. static DEFINE_SPINLOCK(test_spinlock_irq);
  1639. static DEFINE_MUTEX(test_mutex);
  1640. static __init void test_work(struct work_struct *dummy)
  1641. {
  1642. spin_lock(&test_spinlock);
  1643. spin_lock_irq(&test_spinlock_irq);
  1644. udelay(1);
  1645. spin_unlock_irq(&test_spinlock_irq);
  1646. spin_unlock(&test_spinlock);
  1647. mutex_lock(&test_mutex);
  1648. msleep(1);
  1649. mutex_unlock(&test_mutex);
  1650. }
  1651. static __init int event_test_thread(void *unused)
  1652. {
  1653. void *test_malloc;
  1654. test_malloc = kmalloc(1234, GFP_KERNEL);
  1655. if (!test_malloc)
  1656. pr_info("failed to kmalloc\n");
  1657. schedule_on_each_cpu(test_work);
  1658. kfree(test_malloc);
  1659. set_current_state(TASK_INTERRUPTIBLE);
  1660. while (!kthread_should_stop())
  1661. schedule();
  1662. return 0;
  1663. }
  1664. /*
  1665. * Do various things that may trigger events.
  1666. */
  1667. static __init void event_test_stuff(void)
  1668. {
  1669. struct task_struct *test_thread;
  1670. test_thread = kthread_run(event_test_thread, NULL, "test-events");
  1671. msleep(1);
  1672. kthread_stop(test_thread);
  1673. }
  1674. /*
  1675. * For every trace event defined, we will test each trace point separately,
  1676. * and then by groups, and finally all trace points.
  1677. */
  1678. static __init void event_trace_self_tests(void)
  1679. {
  1680. struct ftrace_subsystem_dir *dir;
  1681. struct ftrace_event_file *file;
  1682. struct ftrace_event_call *call;
  1683. struct event_subsystem *system;
  1684. struct trace_array *tr;
  1685. int ret;
  1686. tr = top_trace_array();
  1687. pr_info("Running tests on trace events:\n");
  1688. list_for_each_entry(file, &tr->events, list) {
  1689. call = file->event_call;
  1690. /* Only test those that have a probe */
  1691. if (!call->class || !call->class->probe)
  1692. continue;
  1693. /*
  1694. * Testing syscall events here is pretty useless, but
  1695. * we still do it if configured. But this is time consuming.
  1696. * What we really need is a user thread to perform the
  1697. * syscalls as we test.
  1698. */
  1699. #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
  1700. if (call->class->system &&
  1701. strcmp(call->class->system, "syscalls") == 0)
  1702. continue;
  1703. #endif
  1704. pr_info("Testing event %s: ", call->name);
  1705. /*
  1706. * If an event is already enabled, someone is using
  1707. * it and the self test should not be on.
  1708. */
  1709. if (file->flags & FTRACE_EVENT_FL_ENABLED) {
  1710. pr_warning("Enabled event during self test!\n");
  1711. WARN_ON_ONCE(1);
  1712. continue;
  1713. }
  1714. ftrace_event_enable_disable(file, 1);
  1715. event_test_stuff();
  1716. ftrace_event_enable_disable(file, 0);
  1717. pr_cont("OK\n");
  1718. }
  1719. /* Now test at the sub system level */
  1720. pr_info("Running tests on trace event systems:\n");
  1721. list_for_each_entry(dir, &tr->systems, list) {
  1722. system = dir->subsystem;
  1723. /* the ftrace system is special, skip it */
  1724. if (strcmp(system->name, "ftrace") == 0)
  1725. continue;
  1726. pr_info("Testing event system %s: ", system->name);
  1727. ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1);
  1728. if (WARN_ON_ONCE(ret)) {
  1729. pr_warning("error enabling system %s\n",
  1730. system->name);
  1731. continue;
  1732. }
  1733. event_test_stuff();
  1734. ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0);
  1735. if (WARN_ON_ONCE(ret)) {
  1736. pr_warning("error disabling system %s\n",
  1737. system->name);
  1738. continue;
  1739. }
  1740. pr_cont("OK\n");
  1741. }
  1742. /* Test with all events enabled */
  1743. pr_info("Running tests on all trace events:\n");
  1744. pr_info("Testing all events: ");
  1745. ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1);
  1746. if (WARN_ON_ONCE(ret)) {
  1747. pr_warning("error enabling all events\n");
  1748. return;
  1749. }
  1750. event_test_stuff();
  1751. /* reset sysname */
  1752. ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
  1753. if (WARN_ON_ONCE(ret)) {
  1754. pr_warning("error disabling all events\n");
  1755. return;
  1756. }
  1757. pr_cont("OK\n");
  1758. }
  1759. #ifdef CONFIG_FUNCTION_TRACER
  1760. static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
  1761. static void
  1762. function_test_events_call(unsigned long ip, unsigned long parent_ip,
  1763. struct ftrace_ops *op, struct pt_regs *pt_regs)
  1764. {
  1765. struct ring_buffer_event *event;
  1766. struct ring_buffer *buffer;
  1767. struct ftrace_entry *entry;
  1768. unsigned long flags;
  1769. long disabled;
  1770. int cpu;
  1771. int pc;
  1772. pc = preempt_count();
  1773. preempt_disable_notrace();
  1774. cpu = raw_smp_processor_id();
  1775. disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
  1776. if (disabled != 1)
  1777. goto out;
  1778. local_save_flags(flags);
  1779. event = trace_current_buffer_lock_reserve(&buffer,
  1780. TRACE_FN, sizeof(*entry),
  1781. flags, pc);
  1782. if (!event)
  1783. goto out;
  1784. entry = ring_buffer_event_data(event);
  1785. entry->ip = ip;
  1786. entry->parent_ip = parent_ip;
  1787. trace_buffer_unlock_commit(buffer, event, flags, pc);
  1788. out:
  1789. atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
  1790. preempt_enable_notrace();
  1791. }
  1792. static struct ftrace_ops trace_ops __initdata =
  1793. {
  1794. .func = function_test_events_call,
  1795. .flags = FTRACE_OPS_FL_RECURSION_SAFE,
  1796. };
  1797. static __init void event_trace_self_test_with_function(void)
  1798. {
  1799. int ret;
  1800. ret = register_ftrace_function(&trace_ops);
  1801. if (WARN_ON(ret < 0)) {
  1802. pr_info("Failed to enable function tracer for event tests\n");
  1803. return;
  1804. }
  1805. pr_info("Running tests again, along with the function tracer\n");
  1806. event_trace_self_tests();
  1807. unregister_ftrace_function(&trace_ops);
  1808. }
  1809. #else
  1810. static __init void event_trace_self_test_with_function(void)
  1811. {
  1812. }
  1813. #endif
  1814. static __init int event_trace_self_tests_init(void)
  1815. {
  1816. if (!tracing_selftest_disabled) {
  1817. event_trace_self_tests();
  1818. event_trace_self_test_with_function();
  1819. }
  1820. return 0;
  1821. }
  1822. late_initcall(event_trace_self_tests_init);
  1823. #endif