trace_events.c 49 KB

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