trace_events.c 33 KB

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