trace_output.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /*
  2. * trace_output.c
  3. *
  4. * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  5. *
  6. */
  7. #include <linux/module.h>
  8. #include <linux/mutex.h>
  9. #include <linux/ftrace.h>
  10. #include <linux/sched/clock.h>
  11. #include <linux/sched/mm.h>
  12. #include "trace_output.h"
  13. /* must be a power of 2 */
  14. #define EVENT_HASHSIZE 128
  15. DECLARE_RWSEM(trace_event_sem);
  16. static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
  17. static int next_event_type = __TRACE_LAST_TYPE + 1;
  18. enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
  19. {
  20. struct trace_seq *s = &iter->seq;
  21. struct trace_entry *entry = iter->ent;
  22. struct bputs_entry *field;
  23. trace_assign_type(field, entry);
  24. trace_seq_puts(s, field->str);
  25. return trace_handle_return(s);
  26. }
  27. enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
  28. {
  29. struct trace_seq *s = &iter->seq;
  30. struct trace_entry *entry = iter->ent;
  31. struct bprint_entry *field;
  32. trace_assign_type(field, entry);
  33. trace_seq_bprintf(s, field->fmt, field->buf);
  34. return trace_handle_return(s);
  35. }
  36. enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
  37. {
  38. struct trace_seq *s = &iter->seq;
  39. struct trace_entry *entry = iter->ent;
  40. struct print_entry *field;
  41. trace_assign_type(field, entry);
  42. trace_seq_puts(s, field->buf);
  43. return trace_handle_return(s);
  44. }
  45. const char *
  46. trace_print_flags_seq(struct trace_seq *p, const char *delim,
  47. unsigned long flags,
  48. const struct trace_print_flags *flag_array)
  49. {
  50. unsigned long mask;
  51. const char *str;
  52. const char *ret = trace_seq_buffer_ptr(p);
  53. int i, first = 1;
  54. for (i = 0; flag_array[i].name && flags; i++) {
  55. mask = flag_array[i].mask;
  56. if ((flags & mask) != mask)
  57. continue;
  58. str = flag_array[i].name;
  59. flags &= ~mask;
  60. if (!first && delim)
  61. trace_seq_puts(p, delim);
  62. else
  63. first = 0;
  64. trace_seq_puts(p, str);
  65. }
  66. /* check for left over flags */
  67. if (flags) {
  68. if (!first && delim)
  69. trace_seq_puts(p, delim);
  70. trace_seq_printf(p, "0x%lx", flags);
  71. }
  72. trace_seq_putc(p, 0);
  73. return ret;
  74. }
  75. EXPORT_SYMBOL(trace_print_flags_seq);
  76. const char *
  77. trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  78. const struct trace_print_flags *symbol_array)
  79. {
  80. int i;
  81. const char *ret = trace_seq_buffer_ptr(p);
  82. for (i = 0; symbol_array[i].name; i++) {
  83. if (val != symbol_array[i].mask)
  84. continue;
  85. trace_seq_puts(p, symbol_array[i].name);
  86. break;
  87. }
  88. if (ret == (const char *)(trace_seq_buffer_ptr(p)))
  89. trace_seq_printf(p, "0x%lx", val);
  90. trace_seq_putc(p, 0);
  91. return ret;
  92. }
  93. EXPORT_SYMBOL(trace_print_symbols_seq);
  94. #if BITS_PER_LONG == 32
  95. const char *
  96. trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
  97. unsigned long long flags,
  98. const struct trace_print_flags_u64 *flag_array)
  99. {
  100. unsigned long long mask;
  101. const char *str;
  102. const char *ret = trace_seq_buffer_ptr(p);
  103. int i, first = 1;
  104. for (i = 0; flag_array[i].name && flags; i++) {
  105. mask = flag_array[i].mask;
  106. if ((flags & mask) != mask)
  107. continue;
  108. str = flag_array[i].name;
  109. flags &= ~mask;
  110. if (!first && delim)
  111. trace_seq_puts(p, delim);
  112. else
  113. first = 0;
  114. trace_seq_puts(p, str);
  115. }
  116. /* check for left over flags */
  117. if (flags) {
  118. if (!first && delim)
  119. trace_seq_puts(p, delim);
  120. trace_seq_printf(p, "0x%llx", flags);
  121. }
  122. trace_seq_putc(p, 0);
  123. return ret;
  124. }
  125. EXPORT_SYMBOL(trace_print_flags_seq_u64);
  126. const char *
  127. trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
  128. const struct trace_print_flags_u64 *symbol_array)
  129. {
  130. int i;
  131. const char *ret = trace_seq_buffer_ptr(p);
  132. for (i = 0; symbol_array[i].name; i++) {
  133. if (val != symbol_array[i].mask)
  134. continue;
  135. trace_seq_puts(p, symbol_array[i].name);
  136. break;
  137. }
  138. if (ret == (const char *)(trace_seq_buffer_ptr(p)))
  139. trace_seq_printf(p, "0x%llx", val);
  140. trace_seq_putc(p, 0);
  141. return ret;
  142. }
  143. EXPORT_SYMBOL(trace_print_symbols_seq_u64);
  144. #endif
  145. const char *
  146. trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
  147. unsigned int bitmask_size)
  148. {
  149. const char *ret = trace_seq_buffer_ptr(p);
  150. trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
  151. trace_seq_putc(p, 0);
  152. return ret;
  153. }
  154. EXPORT_SYMBOL_GPL(trace_print_bitmask_seq);
  155. /**
  156. * trace_print_hex_seq - print buffer as hex sequence
  157. * @p: trace seq struct to write to
  158. * @buf: The buffer to print
  159. * @buf_len: Length of @buf in bytes
  160. * @concatenate: Print @buf as single hex string or with spacing
  161. *
  162. * Prints the passed buffer as a hex sequence either as a whole,
  163. * single hex string if @concatenate is true or with spacing after
  164. * each byte in case @concatenate is false.
  165. */
  166. const char *
  167. trace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len,
  168. bool concatenate)
  169. {
  170. int i;
  171. const char *ret = trace_seq_buffer_ptr(p);
  172. for (i = 0; i < buf_len; i++)
  173. trace_seq_printf(p, "%s%2.2x", concatenate || i == 0 ? "" : " ",
  174. buf[i]);
  175. trace_seq_putc(p, 0);
  176. return ret;
  177. }
  178. EXPORT_SYMBOL(trace_print_hex_seq);
  179. const char *
  180. trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
  181. size_t el_size)
  182. {
  183. const char *ret = trace_seq_buffer_ptr(p);
  184. const char *prefix = "";
  185. void *ptr = (void *)buf;
  186. size_t buf_len = count * el_size;
  187. trace_seq_putc(p, '{');
  188. while (ptr < buf + buf_len) {
  189. switch (el_size) {
  190. case 1:
  191. trace_seq_printf(p, "%s0x%x", prefix,
  192. *(u8 *)ptr);
  193. break;
  194. case 2:
  195. trace_seq_printf(p, "%s0x%x", prefix,
  196. *(u16 *)ptr);
  197. break;
  198. case 4:
  199. trace_seq_printf(p, "%s0x%x", prefix,
  200. *(u32 *)ptr);
  201. break;
  202. case 8:
  203. trace_seq_printf(p, "%s0x%llx", prefix,
  204. *(u64 *)ptr);
  205. break;
  206. default:
  207. trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
  208. *(u8 *)ptr);
  209. el_size = 1;
  210. }
  211. prefix = ",";
  212. ptr += el_size;
  213. }
  214. trace_seq_putc(p, '}');
  215. trace_seq_putc(p, 0);
  216. return ret;
  217. }
  218. EXPORT_SYMBOL(trace_print_array_seq);
  219. int trace_raw_output_prep(struct trace_iterator *iter,
  220. struct trace_event *trace_event)
  221. {
  222. struct trace_event_call *event;
  223. struct trace_seq *s = &iter->seq;
  224. struct trace_seq *p = &iter->tmp_seq;
  225. struct trace_entry *entry;
  226. event = container_of(trace_event, struct trace_event_call, event);
  227. entry = iter->ent;
  228. if (entry->type != event->event.type) {
  229. WARN_ON_ONCE(1);
  230. return TRACE_TYPE_UNHANDLED;
  231. }
  232. trace_seq_init(p);
  233. trace_seq_printf(s, "%s: ", trace_event_name(event));
  234. return trace_handle_return(s);
  235. }
  236. EXPORT_SYMBOL(trace_raw_output_prep);
  237. static int trace_output_raw(struct trace_iterator *iter, char *name,
  238. char *fmt, va_list ap)
  239. {
  240. struct trace_seq *s = &iter->seq;
  241. trace_seq_printf(s, "%s: ", name);
  242. trace_seq_vprintf(s, fmt, ap);
  243. return trace_handle_return(s);
  244. }
  245. int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
  246. {
  247. va_list ap;
  248. int ret;
  249. va_start(ap, fmt);
  250. ret = trace_output_raw(iter, name, fmt, ap);
  251. va_end(ap);
  252. return ret;
  253. }
  254. EXPORT_SYMBOL_GPL(trace_output_call);
  255. #ifdef CONFIG_KRETPROBES
  256. static inline const char *kretprobed(const char *name)
  257. {
  258. static const char tramp_name[] = "kretprobe_trampoline";
  259. int size = sizeof(tramp_name);
  260. if (strncmp(tramp_name, name, size) == 0)
  261. return "[unknown/kretprobe'd]";
  262. return name;
  263. }
  264. #else
  265. static inline const char *kretprobed(const char *name)
  266. {
  267. return name;
  268. }
  269. #endif /* CONFIG_KRETPROBES */
  270. static void
  271. seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
  272. {
  273. char str[KSYM_SYMBOL_LEN];
  274. #ifdef CONFIG_KALLSYMS
  275. const char *name;
  276. kallsyms_lookup(address, NULL, NULL, NULL, str);
  277. name = kretprobed(str);
  278. if (name && strlen(name)) {
  279. trace_seq_printf(s, fmt, name);
  280. return;
  281. }
  282. #endif
  283. snprintf(str, KSYM_SYMBOL_LEN, "0x%08lx", address);
  284. trace_seq_printf(s, fmt, str);
  285. }
  286. static void
  287. seq_print_sym_offset(struct trace_seq *s, const char *fmt,
  288. unsigned long address)
  289. {
  290. char str[KSYM_SYMBOL_LEN];
  291. #ifdef CONFIG_KALLSYMS
  292. const char *name;
  293. sprint_symbol(str, address);
  294. name = kretprobed(str);
  295. if (name && strlen(name)) {
  296. trace_seq_printf(s, fmt, name);
  297. return;
  298. }
  299. #endif
  300. snprintf(str, KSYM_SYMBOL_LEN, "0x%08lx", address);
  301. trace_seq_printf(s, fmt, str);
  302. }
  303. #ifndef CONFIG_64BIT
  304. # define IP_FMT "%08lx"
  305. #else
  306. # define IP_FMT "%016lx"
  307. #endif
  308. static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
  309. unsigned long ip, unsigned long sym_flags)
  310. {
  311. struct file *file = NULL;
  312. unsigned long vmstart = 0;
  313. int ret = 1;
  314. if (s->full)
  315. return 0;
  316. if (mm) {
  317. const struct vm_area_struct *vma;
  318. down_read(&mm->mmap_sem);
  319. vma = find_vma(mm, ip);
  320. if (vma) {
  321. file = vma->vm_file;
  322. vmstart = vma->vm_start;
  323. }
  324. if (file) {
  325. ret = trace_seq_path(s, &file->f_path);
  326. if (ret)
  327. trace_seq_printf(s, "[+0x%lx]",
  328. ip - vmstart);
  329. }
  330. up_read(&mm->mmap_sem);
  331. }
  332. if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
  333. trace_seq_printf(s, " <" IP_FMT ">", ip);
  334. return !trace_seq_has_overflowed(s);
  335. }
  336. int
  337. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  338. {
  339. if (!ip) {
  340. trace_seq_putc(s, '0');
  341. goto out;
  342. }
  343. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  344. seq_print_sym_offset(s, "%s", ip);
  345. else
  346. seq_print_sym_short(s, "%s", ip);
  347. if (sym_flags & TRACE_ITER_SYM_ADDR)
  348. trace_seq_printf(s, " <" IP_FMT ">", ip);
  349. out:
  350. return !trace_seq_has_overflowed(s);
  351. }
  352. /**
  353. * trace_print_lat_fmt - print the irq, preempt and lockdep fields
  354. * @s: trace seq struct to write to
  355. * @entry: The trace entry field from the ring buffer
  356. *
  357. * Prints the generic fields of irqs off, in hard or softirq, preempt
  358. * count.
  359. */
  360. int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
  361. {
  362. char hardsoft_irq;
  363. char need_resched;
  364. char irqs_off;
  365. int hardirq;
  366. int softirq;
  367. int nmi;
  368. nmi = entry->flags & TRACE_FLAG_NMI;
  369. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  370. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  371. irqs_off =
  372. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  373. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
  374. '.';
  375. switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
  376. TRACE_FLAG_PREEMPT_RESCHED)) {
  377. case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
  378. need_resched = 'N';
  379. break;
  380. case TRACE_FLAG_NEED_RESCHED:
  381. need_resched = 'n';
  382. break;
  383. case TRACE_FLAG_PREEMPT_RESCHED:
  384. need_resched = 'p';
  385. break;
  386. default:
  387. need_resched = '.';
  388. break;
  389. }
  390. hardsoft_irq =
  391. (nmi && hardirq) ? 'Z' :
  392. nmi ? 'z' :
  393. (hardirq && softirq) ? 'H' :
  394. hardirq ? 'h' :
  395. softirq ? 's' :
  396. '.' ;
  397. trace_seq_printf(s, "%c%c%c",
  398. irqs_off, need_resched, hardsoft_irq);
  399. if (entry->preempt_count)
  400. trace_seq_printf(s, "%x", entry->preempt_count);
  401. else
  402. trace_seq_putc(s, '.');
  403. return !trace_seq_has_overflowed(s);
  404. }
  405. static int
  406. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  407. {
  408. char comm[TASK_COMM_LEN];
  409. trace_find_cmdline(entry->pid, comm);
  410. trace_seq_printf(s, "%8.8s-%-5d %3d",
  411. comm, entry->pid, cpu);
  412. return trace_print_lat_fmt(s, entry);
  413. }
  414. #undef MARK
  415. #define MARK(v, s) {.val = v, .sym = s}
  416. /* trace overhead mark */
  417. static const struct trace_mark {
  418. unsigned long long val; /* unit: nsec */
  419. char sym;
  420. } mark[] = {
  421. MARK(1000000000ULL , '$'), /* 1 sec */
  422. MARK(100000000ULL , '@'), /* 100 msec */
  423. MARK(10000000ULL , '*'), /* 10 msec */
  424. MARK(1000000ULL , '#'), /* 1000 usecs */
  425. MARK(100000ULL , '!'), /* 100 usecs */
  426. MARK(10000ULL , '+'), /* 10 usecs */
  427. };
  428. #undef MARK
  429. char trace_find_mark(unsigned long long d)
  430. {
  431. int i;
  432. int size = ARRAY_SIZE(mark);
  433. for (i = 0; i < size; i++) {
  434. if (d > mark[i].val)
  435. break;
  436. }
  437. return (i == size) ? ' ' : mark[i].sym;
  438. }
  439. static int
  440. lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
  441. {
  442. struct trace_array *tr = iter->tr;
  443. unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
  444. unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
  445. unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
  446. unsigned long long rel_ts = next_ts - iter->ts;
  447. struct trace_seq *s = &iter->seq;
  448. if (in_ns) {
  449. abs_ts = ns2usecs(abs_ts);
  450. rel_ts = ns2usecs(rel_ts);
  451. }
  452. if (verbose && in_ns) {
  453. unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
  454. unsigned long abs_msec = (unsigned long)abs_ts;
  455. unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
  456. unsigned long rel_msec = (unsigned long)rel_ts;
  457. trace_seq_printf(
  458. s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
  459. ns2usecs(iter->ts),
  460. abs_msec, abs_usec,
  461. rel_msec, rel_usec);
  462. } else if (verbose && !in_ns) {
  463. trace_seq_printf(
  464. s, "[%016llx] %lld (+%lld): ",
  465. iter->ts, abs_ts, rel_ts);
  466. } else if (!verbose && in_ns) {
  467. trace_seq_printf(
  468. s, " %4lldus%c: ",
  469. abs_ts,
  470. trace_find_mark(rel_ts * NSEC_PER_USEC));
  471. } else { /* !verbose && !in_ns */
  472. trace_seq_printf(s, " %4lld: ", abs_ts);
  473. }
  474. return !trace_seq_has_overflowed(s);
  475. }
  476. int trace_print_context(struct trace_iterator *iter)
  477. {
  478. struct trace_array *tr = iter->tr;
  479. struct trace_seq *s = &iter->seq;
  480. struct trace_entry *entry = iter->ent;
  481. unsigned long long t;
  482. unsigned long secs, usec_rem;
  483. char comm[TASK_COMM_LEN];
  484. trace_find_cmdline(entry->pid, comm);
  485. trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
  486. if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
  487. unsigned int tgid = trace_find_tgid(entry->pid);
  488. if (!tgid)
  489. trace_seq_printf(s, "(-----) ");
  490. else
  491. trace_seq_printf(s, "(%5d) ", tgid);
  492. }
  493. trace_seq_printf(s, "[%03d] ", iter->cpu);
  494. if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
  495. trace_print_lat_fmt(s, entry);
  496. if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
  497. t = ns2usecs(iter->ts);
  498. usec_rem = do_div(t, USEC_PER_SEC);
  499. secs = (unsigned long)t;
  500. trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
  501. } else
  502. trace_seq_printf(s, " %12llu: ", iter->ts);
  503. return !trace_seq_has_overflowed(s);
  504. }
  505. int trace_print_lat_context(struct trace_iterator *iter)
  506. {
  507. struct trace_array *tr = iter->tr;
  508. /* trace_find_next_entry will reset ent_size */
  509. int ent_size = iter->ent_size;
  510. struct trace_seq *s = &iter->seq;
  511. u64 next_ts;
  512. struct trace_entry *entry = iter->ent,
  513. *next_entry = trace_find_next_entry(iter, NULL,
  514. &next_ts);
  515. unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
  516. /* Restore the original ent_size */
  517. iter->ent_size = ent_size;
  518. if (!next_entry)
  519. next_ts = iter->ts;
  520. if (verbose) {
  521. char comm[TASK_COMM_LEN];
  522. trace_find_cmdline(entry->pid, comm);
  523. trace_seq_printf(
  524. s, "%16s %5d %3d %d %08x %08lx ",
  525. comm, entry->pid, iter->cpu, entry->flags,
  526. entry->preempt_count, iter->idx);
  527. } else {
  528. lat_print_generic(s, entry, iter->cpu);
  529. }
  530. lat_print_timestamp(iter, next_ts);
  531. return !trace_seq_has_overflowed(s);
  532. }
  533. /**
  534. * ftrace_find_event - find a registered event
  535. * @type: the type of event to look for
  536. *
  537. * Returns an event of type @type otherwise NULL
  538. * Called with trace_event_read_lock() held.
  539. */
  540. struct trace_event *ftrace_find_event(int type)
  541. {
  542. struct trace_event *event;
  543. unsigned key;
  544. key = type & (EVENT_HASHSIZE - 1);
  545. hlist_for_each_entry(event, &event_hash[key], node) {
  546. if (event->type == type)
  547. return event;
  548. }
  549. return NULL;
  550. }
  551. static LIST_HEAD(ftrace_event_list);
  552. static int trace_search_list(struct list_head **list)
  553. {
  554. struct trace_event *e;
  555. int last = __TRACE_LAST_TYPE;
  556. if (list_empty(&ftrace_event_list)) {
  557. *list = &ftrace_event_list;
  558. return last + 1;
  559. }
  560. /*
  561. * We used up all possible max events,
  562. * lets see if somebody freed one.
  563. */
  564. list_for_each_entry(e, &ftrace_event_list, list) {
  565. if (e->type != last + 1)
  566. break;
  567. last++;
  568. }
  569. /* Did we used up all 65 thousand events??? */
  570. if ((last + 1) > TRACE_EVENT_TYPE_MAX)
  571. return 0;
  572. *list = &e->list;
  573. return last + 1;
  574. }
  575. void trace_event_read_lock(void)
  576. {
  577. down_read(&trace_event_sem);
  578. }
  579. void trace_event_read_unlock(void)
  580. {
  581. up_read(&trace_event_sem);
  582. }
  583. /**
  584. * register_trace_event - register output for an event type
  585. * @event: the event type to register
  586. *
  587. * Event types are stored in a hash and this hash is used to
  588. * find a way to print an event. If the @event->type is set
  589. * then it will use that type, otherwise it will assign a
  590. * type to use.
  591. *
  592. * If you assign your own type, please make sure it is added
  593. * to the trace_type enum in trace.h, to avoid collisions
  594. * with the dynamic types.
  595. *
  596. * Returns the event type number or zero on error.
  597. */
  598. int register_trace_event(struct trace_event *event)
  599. {
  600. unsigned key;
  601. int ret = 0;
  602. down_write(&trace_event_sem);
  603. if (WARN_ON(!event))
  604. goto out;
  605. if (WARN_ON(!event->funcs))
  606. goto out;
  607. INIT_LIST_HEAD(&event->list);
  608. if (!event->type) {
  609. struct list_head *list = NULL;
  610. if (next_event_type > TRACE_EVENT_TYPE_MAX) {
  611. event->type = trace_search_list(&list);
  612. if (!event->type)
  613. goto out;
  614. } else {
  615. event->type = next_event_type++;
  616. list = &ftrace_event_list;
  617. }
  618. if (WARN_ON(ftrace_find_event(event->type)))
  619. goto out;
  620. list_add_tail(&event->list, list);
  621. } else if (event->type > __TRACE_LAST_TYPE) {
  622. printk(KERN_WARNING "Need to add type to trace.h\n");
  623. WARN_ON(1);
  624. goto out;
  625. } else {
  626. /* Is this event already used */
  627. if (ftrace_find_event(event->type))
  628. goto out;
  629. }
  630. if (event->funcs->trace == NULL)
  631. event->funcs->trace = trace_nop_print;
  632. if (event->funcs->raw == NULL)
  633. event->funcs->raw = trace_nop_print;
  634. if (event->funcs->hex == NULL)
  635. event->funcs->hex = trace_nop_print;
  636. if (event->funcs->binary == NULL)
  637. event->funcs->binary = trace_nop_print;
  638. key = event->type & (EVENT_HASHSIZE - 1);
  639. hlist_add_head(&event->node, &event_hash[key]);
  640. ret = event->type;
  641. out:
  642. up_write(&trace_event_sem);
  643. return ret;
  644. }
  645. EXPORT_SYMBOL_GPL(register_trace_event);
  646. /*
  647. * Used by module code with the trace_event_sem held for write.
  648. */
  649. int __unregister_trace_event(struct trace_event *event)
  650. {
  651. hlist_del(&event->node);
  652. list_del(&event->list);
  653. return 0;
  654. }
  655. /**
  656. * unregister_trace_event - remove a no longer used event
  657. * @event: the event to remove
  658. */
  659. int unregister_trace_event(struct trace_event *event)
  660. {
  661. down_write(&trace_event_sem);
  662. __unregister_trace_event(event);
  663. up_write(&trace_event_sem);
  664. return 0;
  665. }
  666. EXPORT_SYMBOL_GPL(unregister_trace_event);
  667. /*
  668. * Standard events
  669. */
  670. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
  671. struct trace_event *event)
  672. {
  673. trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
  674. return trace_handle_return(&iter->seq);
  675. }
  676. /* TRACE_FN */
  677. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
  678. struct trace_event *event)
  679. {
  680. struct ftrace_entry *field;
  681. struct trace_seq *s = &iter->seq;
  682. trace_assign_type(field, iter->ent);
  683. seq_print_ip_sym(s, field->ip, flags);
  684. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  685. trace_seq_puts(s, " <-");
  686. seq_print_ip_sym(s, field->parent_ip, flags);
  687. }
  688. trace_seq_putc(s, '\n');
  689. return trace_handle_return(s);
  690. }
  691. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
  692. struct trace_event *event)
  693. {
  694. struct ftrace_entry *field;
  695. trace_assign_type(field, iter->ent);
  696. trace_seq_printf(&iter->seq, "%lx %lx\n",
  697. field->ip,
  698. field->parent_ip);
  699. return trace_handle_return(&iter->seq);
  700. }
  701. static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
  702. struct trace_event *event)
  703. {
  704. struct ftrace_entry *field;
  705. struct trace_seq *s = &iter->seq;
  706. trace_assign_type(field, iter->ent);
  707. SEQ_PUT_HEX_FIELD(s, field->ip);
  708. SEQ_PUT_HEX_FIELD(s, field->parent_ip);
  709. return trace_handle_return(s);
  710. }
  711. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
  712. struct trace_event *event)
  713. {
  714. struct ftrace_entry *field;
  715. struct trace_seq *s = &iter->seq;
  716. trace_assign_type(field, iter->ent);
  717. SEQ_PUT_FIELD(s, field->ip);
  718. SEQ_PUT_FIELD(s, field->parent_ip);
  719. return trace_handle_return(s);
  720. }
  721. static struct trace_event_functions trace_fn_funcs = {
  722. .trace = trace_fn_trace,
  723. .raw = trace_fn_raw,
  724. .hex = trace_fn_hex,
  725. .binary = trace_fn_bin,
  726. };
  727. static struct trace_event trace_fn_event = {
  728. .type = TRACE_FN,
  729. .funcs = &trace_fn_funcs,
  730. };
  731. /* TRACE_GRAPH_ENT */
  732. static enum print_line_t trace_graph_ent_trace(struct trace_iterator *iter, int flags,
  733. struct trace_event *event)
  734. {
  735. struct trace_seq *s = &iter->seq;
  736. struct ftrace_graph_ent_entry *field;
  737. trace_assign_type(field, iter->ent);
  738. trace_seq_puts(s, "graph_ent: func=");
  739. if (trace_seq_has_overflowed(s))
  740. return TRACE_TYPE_PARTIAL_LINE;
  741. if (!seq_print_ip_sym(s, field->graph_ent.func, flags))
  742. return TRACE_TYPE_PARTIAL_LINE;
  743. trace_seq_puts(s, "\n");
  744. if (trace_seq_has_overflowed(s))
  745. return TRACE_TYPE_PARTIAL_LINE;
  746. return TRACE_TYPE_HANDLED;
  747. }
  748. static enum print_line_t trace_graph_ent_raw(struct trace_iterator *iter, int flags,
  749. struct trace_event *event)
  750. {
  751. struct ftrace_graph_ent_entry *field;
  752. trace_assign_type(field, iter->ent);
  753. trace_seq_printf(&iter->seq, "%lx %d\n",
  754. field->graph_ent.func,
  755. field->graph_ent.depth);
  756. if (trace_seq_has_overflowed(&iter->seq))
  757. return TRACE_TYPE_PARTIAL_LINE;
  758. return TRACE_TYPE_HANDLED;
  759. }
  760. static enum print_line_t trace_graph_ent_hex(struct trace_iterator *iter, int flags,
  761. struct trace_event *event)
  762. {
  763. struct ftrace_graph_ent_entry *field;
  764. struct trace_seq *s = &iter->seq;
  765. trace_assign_type(field, iter->ent);
  766. SEQ_PUT_HEX_FIELD(s, field->graph_ent.func);
  767. SEQ_PUT_HEX_FIELD(s, field->graph_ent.depth);
  768. return TRACE_TYPE_HANDLED;
  769. }
  770. static enum print_line_t trace_graph_ent_bin(struct trace_iterator *iter, int flags,
  771. struct trace_event *event)
  772. {
  773. struct ftrace_graph_ent_entry *field;
  774. struct trace_seq *s = &iter->seq;
  775. trace_assign_type(field, iter->ent);
  776. SEQ_PUT_FIELD(s, field->graph_ent.func);
  777. SEQ_PUT_FIELD(s, field->graph_ent.depth);
  778. return TRACE_TYPE_HANDLED;
  779. }
  780. static struct trace_event_functions trace_graph_ent_funcs = {
  781. .trace = trace_graph_ent_trace,
  782. .raw = trace_graph_ent_raw,
  783. .hex = trace_graph_ent_hex,
  784. .binary = trace_graph_ent_bin,
  785. };
  786. static struct trace_event trace_graph_ent_event = {
  787. .type = TRACE_GRAPH_ENT,
  788. .funcs = &trace_graph_ent_funcs,
  789. };
  790. /* TRACE_GRAPH_RET */
  791. static enum print_line_t trace_graph_ret_trace(struct trace_iterator *iter, int flags,
  792. struct trace_event *event)
  793. {
  794. struct trace_seq *s = &iter->seq;
  795. struct trace_entry *entry = iter->ent;
  796. struct ftrace_graph_ret_entry *field;
  797. trace_assign_type(field, entry);
  798. trace_seq_puts(s, "graph_ret: func=");
  799. if (trace_seq_has_overflowed(s))
  800. return TRACE_TYPE_PARTIAL_LINE;
  801. if (!seq_print_ip_sym(s, field->ret.func, flags))
  802. return TRACE_TYPE_PARTIAL_LINE;
  803. trace_seq_puts(s, "\n");
  804. if (trace_seq_has_overflowed(s))
  805. return TRACE_TYPE_PARTIAL_LINE;
  806. return TRACE_TYPE_HANDLED;
  807. }
  808. static enum print_line_t trace_graph_ret_raw(struct trace_iterator *iter, int flags,
  809. struct trace_event *event)
  810. {
  811. struct ftrace_graph_ret_entry *field;
  812. trace_assign_type(field, iter->ent);
  813. trace_seq_printf(&iter->seq, "%lx %lld %lld %ld %d\n",
  814. field->ret.func,
  815. field->ret.calltime,
  816. field->ret.rettime,
  817. field->ret.overrun,
  818. field->ret.depth);
  819. if (trace_seq_has_overflowed(&iter->seq))
  820. return TRACE_TYPE_PARTIAL_LINE;
  821. return TRACE_TYPE_HANDLED;
  822. }
  823. static enum print_line_t trace_graph_ret_hex(struct trace_iterator *iter, int flags,
  824. struct trace_event *event)
  825. {
  826. struct ftrace_graph_ret_entry *field;
  827. struct trace_seq *s = &iter->seq;
  828. trace_assign_type(field, iter->ent);
  829. SEQ_PUT_HEX_FIELD(s, field->ret.func);
  830. SEQ_PUT_HEX_FIELD(s, field->ret.calltime);
  831. SEQ_PUT_HEX_FIELD(s, field->ret.rettime);
  832. SEQ_PUT_HEX_FIELD(s, field->ret.overrun);
  833. SEQ_PUT_HEX_FIELD(s, field->ret.depth);
  834. return TRACE_TYPE_HANDLED;
  835. }
  836. static enum print_line_t trace_graph_ret_bin(struct trace_iterator *iter, int flags,
  837. struct trace_event *event)
  838. {
  839. struct ftrace_graph_ret_entry *field;
  840. struct trace_seq *s = &iter->seq;
  841. trace_assign_type(field, iter->ent);
  842. SEQ_PUT_FIELD(s, field->ret.func);
  843. SEQ_PUT_FIELD(s, field->ret.calltime);
  844. SEQ_PUT_FIELD(s, field->ret.rettime);
  845. SEQ_PUT_FIELD(s, field->ret.overrun);
  846. SEQ_PUT_FIELD(s, field->ret.depth);
  847. return TRACE_TYPE_HANDLED;
  848. }
  849. static struct trace_event_functions trace_graph_ret_funcs = {
  850. .trace = trace_graph_ret_trace,
  851. .raw = trace_graph_ret_raw,
  852. .hex = trace_graph_ret_hex,
  853. .binary = trace_graph_ret_bin,
  854. };
  855. static struct trace_event trace_graph_ret_event = {
  856. .type = TRACE_GRAPH_RET,
  857. .funcs = &trace_graph_ret_funcs,
  858. };
  859. /* TRACE_CTX an TRACE_WAKE */
  860. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  861. char *delim)
  862. {
  863. struct ctx_switch_entry *field;
  864. char comm[TASK_COMM_LEN];
  865. int S, T;
  866. trace_assign_type(field, iter->ent);
  867. T = __task_state_to_char(field->next_state);
  868. S = __task_state_to_char(field->prev_state);
  869. trace_find_cmdline(field->next_pid, comm);
  870. trace_seq_printf(&iter->seq,
  871. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  872. field->prev_pid,
  873. field->prev_prio,
  874. S, delim,
  875. field->next_cpu,
  876. field->next_pid,
  877. field->next_prio,
  878. T, comm);
  879. return trace_handle_return(&iter->seq);
  880. }
  881. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
  882. struct trace_event *event)
  883. {
  884. return trace_ctxwake_print(iter, "==>");
  885. }
  886. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  887. int flags, struct trace_event *event)
  888. {
  889. return trace_ctxwake_print(iter, " +");
  890. }
  891. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  892. {
  893. struct ctx_switch_entry *field;
  894. int T;
  895. trace_assign_type(field, iter->ent);
  896. if (!S)
  897. S = __task_state_to_char(field->prev_state);
  898. T = __task_state_to_char(field->next_state);
  899. trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  900. field->prev_pid,
  901. field->prev_prio,
  902. S,
  903. field->next_cpu,
  904. field->next_pid,
  905. field->next_prio,
  906. T);
  907. return trace_handle_return(&iter->seq);
  908. }
  909. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
  910. struct trace_event *event)
  911. {
  912. return trace_ctxwake_raw(iter, 0);
  913. }
  914. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
  915. struct trace_event *event)
  916. {
  917. return trace_ctxwake_raw(iter, '+');
  918. }
  919. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  920. {
  921. struct ctx_switch_entry *field;
  922. struct trace_seq *s = &iter->seq;
  923. int T;
  924. trace_assign_type(field, iter->ent);
  925. if (!S)
  926. S = __task_state_to_char(field->prev_state);
  927. T = __task_state_to_char(field->next_state);
  928. SEQ_PUT_HEX_FIELD(s, field->prev_pid);
  929. SEQ_PUT_HEX_FIELD(s, field->prev_prio);
  930. SEQ_PUT_HEX_FIELD(s, S);
  931. SEQ_PUT_HEX_FIELD(s, field->next_cpu);
  932. SEQ_PUT_HEX_FIELD(s, field->next_pid);
  933. SEQ_PUT_HEX_FIELD(s, field->next_prio);
  934. SEQ_PUT_HEX_FIELD(s, T);
  935. return trace_handle_return(s);
  936. }
  937. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
  938. struct trace_event *event)
  939. {
  940. return trace_ctxwake_hex(iter, 0);
  941. }
  942. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
  943. struct trace_event *event)
  944. {
  945. return trace_ctxwake_hex(iter, '+');
  946. }
  947. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  948. int flags, struct trace_event *event)
  949. {
  950. struct ctx_switch_entry *field;
  951. struct trace_seq *s = &iter->seq;
  952. trace_assign_type(field, iter->ent);
  953. SEQ_PUT_FIELD(s, field->prev_pid);
  954. SEQ_PUT_FIELD(s, field->prev_prio);
  955. SEQ_PUT_FIELD(s, field->prev_state);
  956. SEQ_PUT_FIELD(s, field->next_cpu);
  957. SEQ_PUT_FIELD(s, field->next_pid);
  958. SEQ_PUT_FIELD(s, field->next_prio);
  959. SEQ_PUT_FIELD(s, field->next_state);
  960. return trace_handle_return(s);
  961. }
  962. static struct trace_event_functions trace_ctx_funcs = {
  963. .trace = trace_ctx_print,
  964. .raw = trace_ctx_raw,
  965. .hex = trace_ctx_hex,
  966. .binary = trace_ctxwake_bin,
  967. };
  968. static struct trace_event trace_ctx_event = {
  969. .type = TRACE_CTX,
  970. .funcs = &trace_ctx_funcs,
  971. };
  972. static struct trace_event_functions trace_wake_funcs = {
  973. .trace = trace_wake_print,
  974. .raw = trace_wake_raw,
  975. .hex = trace_wake_hex,
  976. .binary = trace_ctxwake_bin,
  977. };
  978. static struct trace_event trace_wake_event = {
  979. .type = TRACE_WAKE,
  980. .funcs = &trace_wake_funcs,
  981. };
  982. /* TRACE_STACK */
  983. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  984. int flags, struct trace_event *event)
  985. {
  986. struct stack_entry *field;
  987. struct trace_seq *s = &iter->seq;
  988. unsigned long *p;
  989. unsigned long *end;
  990. trace_assign_type(field, iter->ent);
  991. end = (unsigned long *)((long)iter->ent + iter->ent_size);
  992. trace_seq_puts(s, "<stack trace>\n");
  993. for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
  994. if (trace_seq_has_overflowed(s))
  995. break;
  996. trace_seq_puts(s, " => ");
  997. seq_print_ip_sym(s, *p, flags);
  998. trace_seq_putc(s, '\n');
  999. }
  1000. return trace_handle_return(s);
  1001. }
  1002. static struct trace_event_functions trace_stack_funcs = {
  1003. .trace = trace_stack_print,
  1004. };
  1005. static struct trace_event trace_stack_event = {
  1006. .type = TRACE_STACK,
  1007. .funcs = &trace_stack_funcs,
  1008. };
  1009. /* TRACE_USER_STACK */
  1010. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  1011. int flags, struct trace_event *event)
  1012. {
  1013. struct trace_array *tr = iter->tr;
  1014. struct userstack_entry *field;
  1015. struct trace_seq *s = &iter->seq;
  1016. struct mm_struct *mm = NULL;
  1017. unsigned int i;
  1018. trace_assign_type(field, iter->ent);
  1019. trace_seq_puts(s, "<user stack trace>\n");
  1020. if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
  1021. struct task_struct *task;
  1022. /*
  1023. * we do the lookup on the thread group leader,
  1024. * since individual threads might have already quit!
  1025. */
  1026. rcu_read_lock();
  1027. task = find_task_by_vpid(field->tgid);
  1028. if (task)
  1029. mm = get_task_mm(task);
  1030. rcu_read_unlock();
  1031. }
  1032. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  1033. unsigned long ip = field->caller[i];
  1034. if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
  1035. break;
  1036. trace_seq_puts(s, " => ");
  1037. if (!ip) {
  1038. trace_seq_puts(s, "??");
  1039. trace_seq_putc(s, '\n');
  1040. continue;
  1041. }
  1042. seq_print_user_ip(s, mm, ip, flags);
  1043. trace_seq_putc(s, '\n');
  1044. }
  1045. if (mm)
  1046. mmput(mm);
  1047. return trace_handle_return(s);
  1048. }
  1049. static struct trace_event_functions trace_user_stack_funcs = {
  1050. .trace = trace_user_stack_print,
  1051. };
  1052. static struct trace_event trace_user_stack_event = {
  1053. .type = TRACE_USER_STACK,
  1054. .funcs = &trace_user_stack_funcs,
  1055. };
  1056. /* TRACE_HWLAT */
  1057. static enum print_line_t
  1058. trace_hwlat_print(struct trace_iterator *iter, int flags,
  1059. struct trace_event *event)
  1060. {
  1061. struct trace_entry *entry = iter->ent;
  1062. struct trace_seq *s = &iter->seq;
  1063. struct hwlat_entry *field;
  1064. trace_assign_type(field, entry);
  1065. trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
  1066. field->seqnum,
  1067. field->duration,
  1068. field->outer_duration,
  1069. (long long)field->timestamp.tv_sec,
  1070. field->timestamp.tv_nsec);
  1071. if (field->nmi_count) {
  1072. /*
  1073. * The generic sched_clock() is not NMI safe, thus
  1074. * we only record the count and not the time.
  1075. */
  1076. if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
  1077. trace_seq_printf(s, " nmi-total:%llu",
  1078. field->nmi_total_ts);
  1079. trace_seq_printf(s, " nmi-count:%u",
  1080. field->nmi_count);
  1081. }
  1082. trace_seq_putc(s, '\n');
  1083. return trace_handle_return(s);
  1084. }
  1085. static enum print_line_t
  1086. trace_hwlat_raw(struct trace_iterator *iter, int flags,
  1087. struct trace_event *event)
  1088. {
  1089. struct hwlat_entry *field;
  1090. struct trace_seq *s = &iter->seq;
  1091. trace_assign_type(field, iter->ent);
  1092. trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
  1093. field->duration,
  1094. field->outer_duration,
  1095. (long long)field->timestamp.tv_sec,
  1096. field->timestamp.tv_nsec,
  1097. field->seqnum);
  1098. return trace_handle_return(s);
  1099. }
  1100. static struct trace_event_functions trace_hwlat_funcs = {
  1101. .trace = trace_hwlat_print,
  1102. .raw = trace_hwlat_raw,
  1103. };
  1104. static struct trace_event trace_hwlat_event = {
  1105. .type = TRACE_HWLAT,
  1106. .funcs = &trace_hwlat_funcs,
  1107. };
  1108. /* TRACE_BPUTS */
  1109. static enum print_line_t
  1110. trace_bputs_print(struct trace_iterator *iter, int flags,
  1111. struct trace_event *event)
  1112. {
  1113. struct trace_entry *entry = iter->ent;
  1114. struct trace_seq *s = &iter->seq;
  1115. struct bputs_entry *field;
  1116. trace_assign_type(field, entry);
  1117. seq_print_ip_sym(s, field->ip, flags);
  1118. trace_seq_puts(s, ": ");
  1119. trace_seq_puts(s, field->str);
  1120. return trace_handle_return(s);
  1121. }
  1122. static enum print_line_t
  1123. trace_bputs_raw(struct trace_iterator *iter, int flags,
  1124. struct trace_event *event)
  1125. {
  1126. struct bputs_entry *field;
  1127. struct trace_seq *s = &iter->seq;
  1128. trace_assign_type(field, iter->ent);
  1129. trace_seq_printf(s, ": %lx : ", field->ip);
  1130. trace_seq_puts(s, field->str);
  1131. return trace_handle_return(s);
  1132. }
  1133. static struct trace_event_functions trace_bputs_funcs = {
  1134. .trace = trace_bputs_print,
  1135. .raw = trace_bputs_raw,
  1136. };
  1137. static struct trace_event trace_bputs_event = {
  1138. .type = TRACE_BPUTS,
  1139. .funcs = &trace_bputs_funcs,
  1140. };
  1141. /* TRACE_BPRINT */
  1142. static enum print_line_t
  1143. trace_bprint_print(struct trace_iterator *iter, int flags,
  1144. struct trace_event *event)
  1145. {
  1146. struct trace_entry *entry = iter->ent;
  1147. struct trace_seq *s = &iter->seq;
  1148. struct bprint_entry *field;
  1149. trace_assign_type(field, entry);
  1150. seq_print_ip_sym(s, field->ip, flags);
  1151. trace_seq_puts(s, ": ");
  1152. trace_seq_bprintf(s, field->fmt, field->buf);
  1153. return trace_handle_return(s);
  1154. }
  1155. static enum print_line_t
  1156. trace_bprint_raw(struct trace_iterator *iter, int flags,
  1157. struct trace_event *event)
  1158. {
  1159. struct bprint_entry *field;
  1160. struct trace_seq *s = &iter->seq;
  1161. trace_assign_type(field, iter->ent);
  1162. trace_seq_printf(s, ": %lx : ", field->ip);
  1163. trace_seq_bprintf(s, field->fmt, field->buf);
  1164. return trace_handle_return(s);
  1165. }
  1166. static struct trace_event_functions trace_bprint_funcs = {
  1167. .trace = trace_bprint_print,
  1168. .raw = trace_bprint_raw,
  1169. };
  1170. static struct trace_event trace_bprint_event = {
  1171. .type = TRACE_BPRINT,
  1172. .funcs = &trace_bprint_funcs,
  1173. };
  1174. /* TRACE_PRINT */
  1175. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  1176. int flags, struct trace_event *event)
  1177. {
  1178. struct print_entry *field;
  1179. struct trace_seq *s = &iter->seq;
  1180. trace_assign_type(field, iter->ent);
  1181. seq_print_ip_sym(s, field->ip, flags);
  1182. trace_seq_printf(s, ": %s", field->buf);
  1183. return trace_handle_return(s);
  1184. }
  1185. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
  1186. struct trace_event *event)
  1187. {
  1188. struct print_entry *field;
  1189. trace_assign_type(field, iter->ent);
  1190. trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
  1191. return trace_handle_return(&iter->seq);
  1192. }
  1193. static struct trace_event_functions trace_print_funcs = {
  1194. .trace = trace_print_print,
  1195. .raw = trace_print_raw,
  1196. };
  1197. static struct trace_event trace_print_event = {
  1198. .type = TRACE_PRINT,
  1199. .funcs = &trace_print_funcs,
  1200. };
  1201. static enum print_line_t trace_raw_data(struct trace_iterator *iter, int flags,
  1202. struct trace_event *event)
  1203. {
  1204. struct raw_data_entry *field;
  1205. int i;
  1206. trace_assign_type(field, iter->ent);
  1207. trace_seq_printf(&iter->seq, "# %x buf:", field->id);
  1208. for (i = 0; i < iter->ent_size - offsetof(struct raw_data_entry, buf); i++)
  1209. trace_seq_printf(&iter->seq, " %02x",
  1210. (unsigned char)field->buf[i]);
  1211. trace_seq_putc(&iter->seq, '\n');
  1212. return trace_handle_return(&iter->seq);
  1213. }
  1214. static struct trace_event_functions trace_raw_data_funcs = {
  1215. .trace = trace_raw_data,
  1216. .raw = trace_raw_data,
  1217. };
  1218. static struct trace_event trace_raw_data_event = {
  1219. .type = TRACE_RAW_DATA,
  1220. .funcs = &trace_raw_data_funcs,
  1221. };
  1222. static struct trace_event *events[] __initdata = {
  1223. &trace_fn_event,
  1224. &trace_graph_ent_event,
  1225. &trace_graph_ret_event,
  1226. &trace_ctx_event,
  1227. &trace_wake_event,
  1228. &trace_stack_event,
  1229. &trace_user_stack_event,
  1230. &trace_bputs_event,
  1231. &trace_bprint_event,
  1232. &trace_print_event,
  1233. &trace_hwlat_event,
  1234. &trace_raw_data_event,
  1235. NULL
  1236. };
  1237. __init static int init_events(void)
  1238. {
  1239. struct trace_event *event;
  1240. int i, ret;
  1241. for (i = 0; events[i]; i++) {
  1242. event = events[i];
  1243. ret = register_trace_event(event);
  1244. if (!ret) {
  1245. printk(KERN_WARNING "event %d failed to register\n",
  1246. event->type);
  1247. WARN_ON_ONCE(1);
  1248. }
  1249. }
  1250. return 0;
  1251. }
  1252. early_initcall(init_events);