trace_output.c 21 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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 "trace_output.h"
  11. /* must be a power of 2 */
  12. #define EVENT_HASHSIZE 128
  13. static DEFINE_MUTEX(trace_event_mutex);
  14. static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
  15. static int next_event_type = __TRACE_LAST_TYPE + 1;
  16. enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
  17. {
  18. struct trace_seq *s = &iter->seq;
  19. struct trace_entry *entry = iter->ent;
  20. struct bprint_entry *field;
  21. int ret;
  22. trace_assign_type(field, entry);
  23. ret = trace_seq_bprintf(s, field->fmt, field->buf);
  24. if (!ret)
  25. return TRACE_TYPE_PARTIAL_LINE;
  26. return TRACE_TYPE_HANDLED;
  27. }
  28. enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
  29. {
  30. struct trace_seq *s = &iter->seq;
  31. struct trace_entry *entry = iter->ent;
  32. struct print_entry *field;
  33. int ret;
  34. trace_assign_type(field, entry);
  35. ret = trace_seq_printf(s, "%s", field->buf);
  36. if (!ret)
  37. return TRACE_TYPE_PARTIAL_LINE;
  38. return TRACE_TYPE_HANDLED;
  39. }
  40. /**
  41. * trace_seq_printf - sequence printing of trace information
  42. * @s: trace sequence descriptor
  43. * @fmt: printf format string
  44. *
  45. * The tracer may use either sequence operations or its own
  46. * copy to user routines. To simplify formating of a trace
  47. * trace_seq_printf is used to store strings into a special
  48. * buffer (@s). Then the output may be either used by
  49. * the sequencer or pulled into another buffer.
  50. */
  51. int
  52. trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  53. {
  54. int len = (PAGE_SIZE - 1) - s->len;
  55. va_list ap;
  56. int ret;
  57. if (!len)
  58. return 0;
  59. va_start(ap, fmt);
  60. ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
  61. va_end(ap);
  62. /* If we can't write it all, don't bother writing anything */
  63. if (ret >= len)
  64. return 0;
  65. s->len += ret;
  66. return len;
  67. }
  68. int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
  69. {
  70. int len = (PAGE_SIZE - 1) - s->len;
  71. int ret;
  72. if (!len)
  73. return 0;
  74. ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
  75. /* If we can't write it all, don't bother writing anything */
  76. if (ret >= len)
  77. return 0;
  78. s->len += ret;
  79. return len;
  80. }
  81. /**
  82. * trace_seq_puts - trace sequence printing of simple string
  83. * @s: trace sequence descriptor
  84. * @str: simple string to record
  85. *
  86. * The tracer may use either the sequence operations or its own
  87. * copy to user routines. This function records a simple string
  88. * into a special buffer (@s) for later retrieval by a sequencer
  89. * or other mechanism.
  90. */
  91. int trace_seq_puts(struct trace_seq *s, const char *str)
  92. {
  93. int len = strlen(str);
  94. if (len > ((PAGE_SIZE - 1) - s->len))
  95. return 0;
  96. memcpy(s->buffer + s->len, str, len);
  97. s->len += len;
  98. return len;
  99. }
  100. int trace_seq_putc(struct trace_seq *s, unsigned char c)
  101. {
  102. if (s->len >= (PAGE_SIZE - 1))
  103. return 0;
  104. s->buffer[s->len++] = c;
  105. return 1;
  106. }
  107. int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
  108. {
  109. if (len > ((PAGE_SIZE - 1) - s->len))
  110. return 0;
  111. memcpy(s->buffer + s->len, mem, len);
  112. s->len += len;
  113. return len;
  114. }
  115. int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
  116. {
  117. unsigned char hex[HEX_CHARS];
  118. unsigned char *data = mem;
  119. int i, j;
  120. #ifdef __BIG_ENDIAN
  121. for (i = 0, j = 0; i < len; i++) {
  122. #else
  123. for (i = len-1, j = 0; i >= 0; i--) {
  124. #endif
  125. hex[j++] = hex_asc_hi(data[i]);
  126. hex[j++] = hex_asc_lo(data[i]);
  127. }
  128. hex[j++] = ' ';
  129. return trace_seq_putmem(s, hex, j);
  130. }
  131. int trace_seq_path(struct trace_seq *s, struct path *path)
  132. {
  133. unsigned char *p;
  134. if (s->len >= (PAGE_SIZE - 1))
  135. return 0;
  136. p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
  137. if (!IS_ERR(p)) {
  138. p = mangle_path(s->buffer + s->len, p, "\n");
  139. if (p) {
  140. s->len = p - s->buffer;
  141. return 1;
  142. }
  143. } else {
  144. s->buffer[s->len++] = '?';
  145. return 1;
  146. }
  147. return 0;
  148. }
  149. #ifdef CONFIG_KRETPROBES
  150. static inline const char *kretprobed(const char *name)
  151. {
  152. static const char tramp_name[] = "kretprobe_trampoline";
  153. int size = sizeof(tramp_name);
  154. if (strncmp(tramp_name, name, size) == 0)
  155. return "[unknown/kretprobe'd]";
  156. return name;
  157. }
  158. #else
  159. static inline const char *kretprobed(const char *name)
  160. {
  161. return name;
  162. }
  163. #endif /* CONFIG_KRETPROBES */
  164. static int
  165. seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
  166. {
  167. #ifdef CONFIG_KALLSYMS
  168. char str[KSYM_SYMBOL_LEN];
  169. const char *name;
  170. kallsyms_lookup(address, NULL, NULL, NULL, str);
  171. name = kretprobed(str);
  172. return trace_seq_printf(s, fmt, name);
  173. #endif
  174. return 1;
  175. }
  176. static int
  177. seq_print_sym_offset(struct trace_seq *s, const char *fmt,
  178. unsigned long address)
  179. {
  180. #ifdef CONFIG_KALLSYMS
  181. char str[KSYM_SYMBOL_LEN];
  182. const char *name;
  183. sprint_symbol(str, address);
  184. name = kretprobed(str);
  185. return trace_seq_printf(s, fmt, name);
  186. #endif
  187. return 1;
  188. }
  189. #ifndef CONFIG_64BIT
  190. # define IP_FMT "%08lx"
  191. #else
  192. # define IP_FMT "%016lx"
  193. #endif
  194. int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
  195. unsigned long ip, unsigned long sym_flags)
  196. {
  197. struct file *file = NULL;
  198. unsigned long vmstart = 0;
  199. int ret = 1;
  200. if (mm) {
  201. const struct vm_area_struct *vma;
  202. down_read(&mm->mmap_sem);
  203. vma = find_vma(mm, ip);
  204. if (vma) {
  205. file = vma->vm_file;
  206. vmstart = vma->vm_start;
  207. }
  208. if (file) {
  209. ret = trace_seq_path(s, &file->f_path);
  210. if (ret)
  211. ret = trace_seq_printf(s, "[+0x%lx]",
  212. ip - vmstart);
  213. }
  214. up_read(&mm->mmap_sem);
  215. }
  216. if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
  217. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  218. return ret;
  219. }
  220. int
  221. seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
  222. unsigned long sym_flags)
  223. {
  224. struct mm_struct *mm = NULL;
  225. int ret = 1;
  226. unsigned int i;
  227. if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
  228. struct task_struct *task;
  229. /*
  230. * we do the lookup on the thread group leader,
  231. * since individual threads might have already quit!
  232. */
  233. rcu_read_lock();
  234. task = find_task_by_vpid(entry->ent.tgid);
  235. if (task)
  236. mm = get_task_mm(task);
  237. rcu_read_unlock();
  238. }
  239. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  240. unsigned long ip = entry->caller[i];
  241. if (ip == ULONG_MAX || !ret)
  242. break;
  243. if (i && ret)
  244. ret = trace_seq_puts(s, " <- ");
  245. if (!ip) {
  246. if (ret)
  247. ret = trace_seq_puts(s, "??");
  248. continue;
  249. }
  250. if (!ret)
  251. break;
  252. if (ret)
  253. ret = seq_print_user_ip(s, mm, ip, sym_flags);
  254. }
  255. if (mm)
  256. mmput(mm);
  257. return ret;
  258. }
  259. int
  260. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  261. {
  262. int ret;
  263. if (!ip)
  264. return trace_seq_printf(s, "0");
  265. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  266. ret = seq_print_sym_offset(s, "%s", ip);
  267. else
  268. ret = seq_print_sym_short(s, "%s", ip);
  269. if (!ret)
  270. return 0;
  271. if (sym_flags & TRACE_ITER_SYM_ADDR)
  272. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  273. return ret;
  274. }
  275. static int
  276. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  277. {
  278. int hardirq, softirq;
  279. char comm[TASK_COMM_LEN];
  280. trace_find_cmdline(entry->pid, comm);
  281. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  282. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  283. if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
  284. comm, entry->pid, cpu,
  285. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  286. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
  287. 'X' : '.',
  288. (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
  289. 'N' : '.',
  290. (hardirq && softirq) ? 'H' :
  291. hardirq ? 'h' : softirq ? 's' : '.'))
  292. return 0;
  293. if (entry->preempt_count)
  294. return trace_seq_printf(s, "%x", entry->preempt_count);
  295. return trace_seq_puts(s, ".");
  296. }
  297. static unsigned long preempt_mark_thresh = 100;
  298. static int
  299. lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
  300. unsigned long rel_usecs)
  301. {
  302. return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
  303. rel_usecs > preempt_mark_thresh ? '!' :
  304. rel_usecs > 1 ? '+' : ' ');
  305. }
  306. int trace_print_context(struct trace_iterator *iter)
  307. {
  308. struct trace_seq *s = &iter->seq;
  309. struct trace_entry *entry = iter->ent;
  310. unsigned long long t = ns2usecs(iter->ts);
  311. unsigned long usec_rem = do_div(t, USEC_PER_SEC);
  312. unsigned long secs = (unsigned long)t;
  313. char comm[TASK_COMM_LEN];
  314. trace_find_cmdline(entry->pid, comm);
  315. return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
  316. comm, entry->pid, iter->cpu, secs, usec_rem);
  317. }
  318. int trace_print_lat_context(struct trace_iterator *iter)
  319. {
  320. u64 next_ts;
  321. int ret;
  322. struct trace_seq *s = &iter->seq;
  323. struct trace_entry *entry = iter->ent,
  324. *next_entry = trace_find_next_entry(iter, NULL,
  325. &next_ts);
  326. unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
  327. unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
  328. unsigned long rel_usecs;
  329. if (!next_entry)
  330. next_ts = iter->ts;
  331. rel_usecs = ns2usecs(next_ts - iter->ts);
  332. if (verbose) {
  333. char comm[TASK_COMM_LEN];
  334. trace_find_cmdline(entry->pid, comm);
  335. ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
  336. " %ld.%03ldms (+%ld.%03ldms): ", comm,
  337. entry->pid, iter->cpu, entry->flags,
  338. entry->preempt_count, iter->idx,
  339. ns2usecs(iter->ts),
  340. abs_usecs / USEC_PER_MSEC,
  341. abs_usecs % USEC_PER_MSEC,
  342. rel_usecs / USEC_PER_MSEC,
  343. rel_usecs % USEC_PER_MSEC);
  344. } else {
  345. ret = lat_print_generic(s, entry, iter->cpu);
  346. if (ret)
  347. ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
  348. }
  349. return ret;
  350. }
  351. static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  352. static int task_state_char(unsigned long state)
  353. {
  354. int bit = state ? __ffs(state) + 1 : 0;
  355. return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
  356. }
  357. /**
  358. * ftrace_find_event - find a registered event
  359. * @type: the type of event to look for
  360. *
  361. * Returns an event of type @type otherwise NULL
  362. */
  363. struct trace_event *ftrace_find_event(int type)
  364. {
  365. struct trace_event *event;
  366. struct hlist_node *n;
  367. unsigned key;
  368. key = type & (EVENT_HASHSIZE - 1);
  369. hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
  370. if (event->type == type)
  371. return event;
  372. }
  373. return NULL;
  374. }
  375. /**
  376. * register_ftrace_event - register output for an event type
  377. * @event: the event type to register
  378. *
  379. * Event types are stored in a hash and this hash is used to
  380. * find a way to print an event. If the @event->type is set
  381. * then it will use that type, otherwise it will assign a
  382. * type to use.
  383. *
  384. * If you assign your own type, please make sure it is added
  385. * to the trace_type enum in trace.h, to avoid collisions
  386. * with the dynamic types.
  387. *
  388. * Returns the event type number or zero on error.
  389. */
  390. int register_ftrace_event(struct trace_event *event)
  391. {
  392. unsigned key;
  393. int ret = 0;
  394. mutex_lock(&trace_event_mutex);
  395. if (!event) {
  396. ret = next_event_type++;
  397. goto out;
  398. }
  399. if (!event->type)
  400. event->type = next_event_type++;
  401. else if (event->type > __TRACE_LAST_TYPE) {
  402. printk(KERN_WARNING "Need to add type to trace.h\n");
  403. WARN_ON(1);
  404. }
  405. if (ftrace_find_event(event->type))
  406. goto out;
  407. if (event->trace == NULL)
  408. event->trace = trace_nop_print;
  409. if (event->raw == NULL)
  410. event->raw = trace_nop_print;
  411. if (event->hex == NULL)
  412. event->hex = trace_nop_print;
  413. if (event->binary == NULL)
  414. event->binary = trace_nop_print;
  415. key = event->type & (EVENT_HASHSIZE - 1);
  416. hlist_add_head_rcu(&event->node, &event_hash[key]);
  417. ret = event->type;
  418. out:
  419. mutex_unlock(&trace_event_mutex);
  420. return ret;
  421. }
  422. /**
  423. * unregister_ftrace_event - remove a no longer used event
  424. * @event: the event to remove
  425. */
  426. int unregister_ftrace_event(struct trace_event *event)
  427. {
  428. mutex_lock(&trace_event_mutex);
  429. hlist_del(&event->node);
  430. mutex_unlock(&trace_event_mutex);
  431. return 0;
  432. }
  433. /*
  434. * Standard events
  435. */
  436. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
  437. {
  438. return TRACE_TYPE_HANDLED;
  439. }
  440. /* TRACE_FN */
  441. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
  442. {
  443. struct ftrace_entry *field;
  444. struct trace_seq *s = &iter->seq;
  445. trace_assign_type(field, iter->ent);
  446. if (!seq_print_ip_sym(s, field->ip, flags))
  447. goto partial;
  448. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  449. if (!trace_seq_printf(s, " <-"))
  450. goto partial;
  451. if (!seq_print_ip_sym(s,
  452. field->parent_ip,
  453. flags))
  454. goto partial;
  455. }
  456. if (!trace_seq_printf(s, "\n"))
  457. goto partial;
  458. return TRACE_TYPE_HANDLED;
  459. partial:
  460. return TRACE_TYPE_PARTIAL_LINE;
  461. }
  462. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
  463. {
  464. struct ftrace_entry *field;
  465. trace_assign_type(field, iter->ent);
  466. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  467. field->ip,
  468. field->parent_ip))
  469. return TRACE_TYPE_PARTIAL_LINE;
  470. return TRACE_TYPE_HANDLED;
  471. }
  472. static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
  473. {
  474. struct ftrace_entry *field;
  475. struct trace_seq *s = &iter->seq;
  476. trace_assign_type(field, iter->ent);
  477. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  478. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  479. return TRACE_TYPE_HANDLED;
  480. }
  481. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
  482. {
  483. struct ftrace_entry *field;
  484. struct trace_seq *s = &iter->seq;
  485. trace_assign_type(field, iter->ent);
  486. SEQ_PUT_FIELD_RET(s, field->ip);
  487. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  488. return TRACE_TYPE_HANDLED;
  489. }
  490. static struct trace_event trace_fn_event = {
  491. .type = TRACE_FN,
  492. .trace = trace_fn_trace,
  493. .raw = trace_fn_raw,
  494. .hex = trace_fn_hex,
  495. .binary = trace_fn_bin,
  496. };
  497. /* TRACE_CTX an TRACE_WAKE */
  498. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  499. char *delim)
  500. {
  501. struct ctx_switch_entry *field;
  502. char comm[TASK_COMM_LEN];
  503. int S, T;
  504. trace_assign_type(field, iter->ent);
  505. T = task_state_char(field->next_state);
  506. S = task_state_char(field->prev_state);
  507. trace_find_cmdline(field->next_pid, comm);
  508. if (!trace_seq_printf(&iter->seq,
  509. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  510. field->prev_pid,
  511. field->prev_prio,
  512. S, delim,
  513. field->next_cpu,
  514. field->next_pid,
  515. field->next_prio,
  516. T, comm))
  517. return TRACE_TYPE_PARTIAL_LINE;
  518. return TRACE_TYPE_HANDLED;
  519. }
  520. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
  521. {
  522. return trace_ctxwake_print(iter, "==>");
  523. }
  524. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  525. int flags)
  526. {
  527. return trace_ctxwake_print(iter, " +");
  528. }
  529. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  530. {
  531. struct ctx_switch_entry *field;
  532. int T;
  533. trace_assign_type(field, iter->ent);
  534. if (!S)
  535. task_state_char(field->prev_state);
  536. T = task_state_char(field->next_state);
  537. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  538. field->prev_pid,
  539. field->prev_prio,
  540. S,
  541. field->next_cpu,
  542. field->next_pid,
  543. field->next_prio,
  544. T))
  545. return TRACE_TYPE_PARTIAL_LINE;
  546. return TRACE_TYPE_HANDLED;
  547. }
  548. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
  549. {
  550. return trace_ctxwake_raw(iter, 0);
  551. }
  552. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
  553. {
  554. return trace_ctxwake_raw(iter, '+');
  555. }
  556. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  557. {
  558. struct ctx_switch_entry *field;
  559. struct trace_seq *s = &iter->seq;
  560. int T;
  561. trace_assign_type(field, iter->ent);
  562. if (!S)
  563. task_state_char(field->prev_state);
  564. T = task_state_char(field->next_state);
  565. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  566. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  567. SEQ_PUT_HEX_FIELD_RET(s, S);
  568. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  569. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  570. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  571. SEQ_PUT_HEX_FIELD_RET(s, T);
  572. return TRACE_TYPE_HANDLED;
  573. }
  574. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
  575. {
  576. return trace_ctxwake_hex(iter, 0);
  577. }
  578. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
  579. {
  580. return trace_ctxwake_hex(iter, '+');
  581. }
  582. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  583. int flags)
  584. {
  585. struct ctx_switch_entry *field;
  586. struct trace_seq *s = &iter->seq;
  587. trace_assign_type(field, iter->ent);
  588. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  589. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  590. SEQ_PUT_FIELD_RET(s, field->prev_state);
  591. SEQ_PUT_FIELD_RET(s, field->next_pid);
  592. SEQ_PUT_FIELD_RET(s, field->next_prio);
  593. SEQ_PUT_FIELD_RET(s, field->next_state);
  594. return TRACE_TYPE_HANDLED;
  595. }
  596. static struct trace_event trace_ctx_event = {
  597. .type = TRACE_CTX,
  598. .trace = trace_ctx_print,
  599. .raw = trace_ctx_raw,
  600. .hex = trace_ctx_hex,
  601. .binary = trace_ctxwake_bin,
  602. };
  603. static struct trace_event trace_wake_event = {
  604. .type = TRACE_WAKE,
  605. .trace = trace_wake_print,
  606. .raw = trace_wake_raw,
  607. .hex = trace_wake_hex,
  608. .binary = trace_ctxwake_bin,
  609. };
  610. /* TRACE_SPECIAL */
  611. static enum print_line_t trace_special_print(struct trace_iterator *iter,
  612. int flags)
  613. {
  614. struct special_entry *field;
  615. trace_assign_type(field, iter->ent);
  616. if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
  617. field->arg1,
  618. field->arg2,
  619. field->arg3))
  620. return TRACE_TYPE_PARTIAL_LINE;
  621. return TRACE_TYPE_HANDLED;
  622. }
  623. static enum print_line_t trace_special_hex(struct trace_iterator *iter,
  624. int flags)
  625. {
  626. struct special_entry *field;
  627. struct trace_seq *s = &iter->seq;
  628. trace_assign_type(field, iter->ent);
  629. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  630. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  631. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  632. return TRACE_TYPE_HANDLED;
  633. }
  634. static enum print_line_t trace_special_bin(struct trace_iterator *iter,
  635. int flags)
  636. {
  637. struct special_entry *field;
  638. struct trace_seq *s = &iter->seq;
  639. trace_assign_type(field, iter->ent);
  640. SEQ_PUT_FIELD_RET(s, field->arg1);
  641. SEQ_PUT_FIELD_RET(s, field->arg2);
  642. SEQ_PUT_FIELD_RET(s, field->arg3);
  643. return TRACE_TYPE_HANDLED;
  644. }
  645. static struct trace_event trace_special_event = {
  646. .type = TRACE_SPECIAL,
  647. .trace = trace_special_print,
  648. .raw = trace_special_print,
  649. .hex = trace_special_hex,
  650. .binary = trace_special_bin,
  651. };
  652. /* TRACE_STACK */
  653. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  654. int flags)
  655. {
  656. struct stack_entry *field;
  657. struct trace_seq *s = &iter->seq;
  658. int i;
  659. trace_assign_type(field, iter->ent);
  660. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  661. if (i) {
  662. if (!trace_seq_puts(s, " <= "))
  663. goto partial;
  664. if (!seq_print_ip_sym(s, field->caller[i], flags))
  665. goto partial;
  666. }
  667. if (!trace_seq_puts(s, "\n"))
  668. goto partial;
  669. }
  670. return TRACE_TYPE_HANDLED;
  671. partial:
  672. return TRACE_TYPE_PARTIAL_LINE;
  673. }
  674. static struct trace_event trace_stack_event = {
  675. .type = TRACE_STACK,
  676. .trace = trace_stack_print,
  677. .raw = trace_special_print,
  678. .hex = trace_special_hex,
  679. .binary = trace_special_bin,
  680. };
  681. /* TRACE_USER_STACK */
  682. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  683. int flags)
  684. {
  685. struct userstack_entry *field;
  686. struct trace_seq *s = &iter->seq;
  687. trace_assign_type(field, iter->ent);
  688. if (!seq_print_userip_objs(field, s, flags))
  689. goto partial;
  690. if (!trace_seq_putc(s, '\n'))
  691. goto partial;
  692. return TRACE_TYPE_HANDLED;
  693. partial:
  694. return TRACE_TYPE_PARTIAL_LINE;
  695. }
  696. static struct trace_event trace_user_stack_event = {
  697. .type = TRACE_USER_STACK,
  698. .trace = trace_user_stack_print,
  699. .raw = trace_special_print,
  700. .hex = trace_special_hex,
  701. .binary = trace_special_bin,
  702. };
  703. /* TRACE_BPRINT */
  704. static enum print_line_t
  705. trace_bprint_print(struct trace_iterator *iter, int flags)
  706. {
  707. struct trace_entry *entry = iter->ent;
  708. struct trace_seq *s = &iter->seq;
  709. struct bprint_entry *field;
  710. trace_assign_type(field, entry);
  711. if (!seq_print_ip_sym(s, field->ip, flags))
  712. goto partial;
  713. if (!trace_seq_puts(s, ": "))
  714. goto partial;
  715. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  716. goto partial;
  717. return TRACE_TYPE_HANDLED;
  718. partial:
  719. return TRACE_TYPE_PARTIAL_LINE;
  720. }
  721. static enum print_line_t
  722. trace_bprint_raw(struct trace_iterator *iter, int flags)
  723. {
  724. struct bprint_entry *field;
  725. struct trace_seq *s = &iter->seq;
  726. trace_assign_type(field, iter->ent);
  727. if (!trace_seq_printf(s, ": %lx : ", field->ip))
  728. goto partial;
  729. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  730. goto partial;
  731. return TRACE_TYPE_HANDLED;
  732. partial:
  733. return TRACE_TYPE_PARTIAL_LINE;
  734. }
  735. static struct trace_event trace_bprint_event = {
  736. .type = TRACE_BPRINT,
  737. .trace = trace_bprint_print,
  738. .raw = trace_bprint_raw,
  739. };
  740. /* TRACE_PRINT */
  741. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  742. int flags)
  743. {
  744. struct print_entry *field;
  745. struct trace_seq *s = &iter->seq;
  746. trace_assign_type(field, iter->ent);
  747. if (!seq_print_ip_sym(s, field->ip, flags))
  748. goto partial;
  749. if (!trace_seq_printf(s, ": %s", field->buf))
  750. goto partial;
  751. return TRACE_TYPE_HANDLED;
  752. partial:
  753. return TRACE_TYPE_PARTIAL_LINE;
  754. }
  755. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
  756. {
  757. struct print_entry *field;
  758. trace_assign_type(field, iter->ent);
  759. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  760. goto partial;
  761. return TRACE_TYPE_HANDLED;
  762. partial:
  763. return TRACE_TYPE_PARTIAL_LINE;
  764. }
  765. static struct trace_event trace_print_event = {
  766. .type = TRACE_PRINT,
  767. .trace = trace_print_print,
  768. .raw = trace_print_raw,
  769. };
  770. static struct trace_event *events[] __initdata = {
  771. &trace_fn_event,
  772. &trace_ctx_event,
  773. &trace_wake_event,
  774. &trace_special_event,
  775. &trace_stack_event,
  776. &trace_user_stack_event,
  777. &trace_bprint_event,
  778. &trace_print_event,
  779. NULL
  780. };
  781. __init static int init_events(void)
  782. {
  783. struct trace_event *event;
  784. int i, ret;
  785. for (i = 0; events[i]; i++) {
  786. event = events[i];
  787. ret = register_ftrace_event(event);
  788. if (!ret) {
  789. printk(KERN_WARNING "event %d failed to register\n",
  790. event->type);
  791. WARN_ON_ONCE(1);
  792. }
  793. }
  794. return 0;
  795. }
  796. device_initcall(init_events);