trace_output.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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->type)
  396. event->type = next_event_type++;
  397. else if (event->type > __TRACE_LAST_TYPE) {
  398. printk(KERN_WARNING "Need to add type to trace.h\n");
  399. WARN_ON(1);
  400. }
  401. if (ftrace_find_event(event->type))
  402. goto out;
  403. if (event->trace == NULL)
  404. event->trace = trace_nop_print;
  405. if (event->raw == NULL)
  406. event->raw = trace_nop_print;
  407. if (event->hex == NULL)
  408. event->hex = trace_nop_print;
  409. if (event->binary == NULL)
  410. event->binary = trace_nop_print;
  411. key = event->type & (EVENT_HASHSIZE - 1);
  412. hlist_add_head_rcu(&event->node, &event_hash[key]);
  413. ret = event->type;
  414. out:
  415. mutex_unlock(&trace_event_mutex);
  416. return ret;
  417. }
  418. /**
  419. * unregister_ftrace_event - remove a no longer used event
  420. * @event: the event to remove
  421. */
  422. int unregister_ftrace_event(struct trace_event *event)
  423. {
  424. mutex_lock(&trace_event_mutex);
  425. hlist_del(&event->node);
  426. mutex_unlock(&trace_event_mutex);
  427. return 0;
  428. }
  429. /*
  430. * Standard events
  431. */
  432. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
  433. {
  434. return TRACE_TYPE_HANDLED;
  435. }
  436. /* TRACE_FN */
  437. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
  438. {
  439. struct ftrace_entry *field;
  440. struct trace_seq *s = &iter->seq;
  441. trace_assign_type(field, iter->ent);
  442. if (!seq_print_ip_sym(s, field->ip, flags))
  443. goto partial;
  444. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  445. if (!trace_seq_printf(s, " <-"))
  446. goto partial;
  447. if (!seq_print_ip_sym(s,
  448. field->parent_ip,
  449. flags))
  450. goto partial;
  451. }
  452. if (!trace_seq_printf(s, "\n"))
  453. goto partial;
  454. return TRACE_TYPE_HANDLED;
  455. partial:
  456. return TRACE_TYPE_PARTIAL_LINE;
  457. }
  458. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
  459. {
  460. struct ftrace_entry *field;
  461. trace_assign_type(field, iter->ent);
  462. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  463. field->ip,
  464. field->parent_ip))
  465. return TRACE_TYPE_PARTIAL_LINE;
  466. return TRACE_TYPE_HANDLED;
  467. }
  468. static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
  469. {
  470. struct ftrace_entry *field;
  471. struct trace_seq *s = &iter->seq;
  472. trace_assign_type(field, iter->ent);
  473. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  474. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  475. return TRACE_TYPE_HANDLED;
  476. }
  477. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
  478. {
  479. struct ftrace_entry *field;
  480. struct trace_seq *s = &iter->seq;
  481. trace_assign_type(field, iter->ent);
  482. SEQ_PUT_FIELD_RET(s, field->ip);
  483. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  484. return TRACE_TYPE_HANDLED;
  485. }
  486. static struct trace_event trace_fn_event = {
  487. .type = TRACE_FN,
  488. .trace = trace_fn_trace,
  489. .raw = trace_fn_raw,
  490. .hex = trace_fn_hex,
  491. .binary = trace_fn_bin,
  492. };
  493. /* TRACE_CTX an TRACE_WAKE */
  494. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  495. char *delim)
  496. {
  497. struct ctx_switch_entry *field;
  498. char comm[TASK_COMM_LEN];
  499. int S, T;
  500. trace_assign_type(field, iter->ent);
  501. T = task_state_char(field->next_state);
  502. S = task_state_char(field->prev_state);
  503. trace_find_cmdline(field->next_pid, comm);
  504. if (!trace_seq_printf(&iter->seq,
  505. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  506. field->prev_pid,
  507. field->prev_prio,
  508. S, delim,
  509. field->next_cpu,
  510. field->next_pid,
  511. field->next_prio,
  512. T, comm))
  513. return TRACE_TYPE_PARTIAL_LINE;
  514. return TRACE_TYPE_HANDLED;
  515. }
  516. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
  517. {
  518. return trace_ctxwake_print(iter, "==>");
  519. }
  520. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  521. int flags)
  522. {
  523. return trace_ctxwake_print(iter, " +");
  524. }
  525. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  526. {
  527. struct ctx_switch_entry *field;
  528. int T;
  529. trace_assign_type(field, iter->ent);
  530. if (!S)
  531. task_state_char(field->prev_state);
  532. T = task_state_char(field->next_state);
  533. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  534. field->prev_pid,
  535. field->prev_prio,
  536. S,
  537. field->next_cpu,
  538. field->next_pid,
  539. field->next_prio,
  540. T))
  541. return TRACE_TYPE_PARTIAL_LINE;
  542. return TRACE_TYPE_HANDLED;
  543. }
  544. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
  545. {
  546. return trace_ctxwake_raw(iter, 0);
  547. }
  548. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
  549. {
  550. return trace_ctxwake_raw(iter, '+');
  551. }
  552. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  553. {
  554. struct ctx_switch_entry *field;
  555. struct trace_seq *s = &iter->seq;
  556. int T;
  557. trace_assign_type(field, iter->ent);
  558. if (!S)
  559. task_state_char(field->prev_state);
  560. T = task_state_char(field->next_state);
  561. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  562. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  563. SEQ_PUT_HEX_FIELD_RET(s, S);
  564. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  565. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  566. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  567. SEQ_PUT_HEX_FIELD_RET(s, T);
  568. return TRACE_TYPE_HANDLED;
  569. }
  570. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
  571. {
  572. return trace_ctxwake_hex(iter, 0);
  573. }
  574. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
  575. {
  576. return trace_ctxwake_hex(iter, '+');
  577. }
  578. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  579. int flags)
  580. {
  581. struct ctx_switch_entry *field;
  582. struct trace_seq *s = &iter->seq;
  583. trace_assign_type(field, iter->ent);
  584. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  585. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  586. SEQ_PUT_FIELD_RET(s, field->prev_state);
  587. SEQ_PUT_FIELD_RET(s, field->next_pid);
  588. SEQ_PUT_FIELD_RET(s, field->next_prio);
  589. SEQ_PUT_FIELD_RET(s, field->next_state);
  590. return TRACE_TYPE_HANDLED;
  591. }
  592. static struct trace_event trace_ctx_event = {
  593. .type = TRACE_CTX,
  594. .trace = trace_ctx_print,
  595. .raw = trace_ctx_raw,
  596. .hex = trace_ctx_hex,
  597. .binary = trace_ctxwake_bin,
  598. };
  599. static struct trace_event trace_wake_event = {
  600. .type = TRACE_WAKE,
  601. .trace = trace_wake_print,
  602. .raw = trace_wake_raw,
  603. .hex = trace_wake_hex,
  604. .binary = trace_ctxwake_bin,
  605. };
  606. /* TRACE_SPECIAL */
  607. static enum print_line_t trace_special_print(struct trace_iterator *iter,
  608. int flags)
  609. {
  610. struct special_entry *field;
  611. trace_assign_type(field, iter->ent);
  612. if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
  613. field->arg1,
  614. field->arg2,
  615. field->arg3))
  616. return TRACE_TYPE_PARTIAL_LINE;
  617. return TRACE_TYPE_HANDLED;
  618. }
  619. static enum print_line_t trace_special_hex(struct trace_iterator *iter,
  620. int flags)
  621. {
  622. struct special_entry *field;
  623. struct trace_seq *s = &iter->seq;
  624. trace_assign_type(field, iter->ent);
  625. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  626. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  627. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  628. return TRACE_TYPE_HANDLED;
  629. }
  630. static enum print_line_t trace_special_bin(struct trace_iterator *iter,
  631. int flags)
  632. {
  633. struct special_entry *field;
  634. struct trace_seq *s = &iter->seq;
  635. trace_assign_type(field, iter->ent);
  636. SEQ_PUT_FIELD_RET(s, field->arg1);
  637. SEQ_PUT_FIELD_RET(s, field->arg2);
  638. SEQ_PUT_FIELD_RET(s, field->arg3);
  639. return TRACE_TYPE_HANDLED;
  640. }
  641. static struct trace_event trace_special_event = {
  642. .type = TRACE_SPECIAL,
  643. .trace = trace_special_print,
  644. .raw = trace_special_print,
  645. .hex = trace_special_hex,
  646. .binary = trace_special_bin,
  647. };
  648. /* TRACE_STACK */
  649. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  650. int flags)
  651. {
  652. struct stack_entry *field;
  653. struct trace_seq *s = &iter->seq;
  654. int i;
  655. trace_assign_type(field, iter->ent);
  656. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  657. if (i) {
  658. if (!trace_seq_puts(s, " <= "))
  659. goto partial;
  660. if (!seq_print_ip_sym(s, field->caller[i], flags))
  661. goto partial;
  662. }
  663. if (!trace_seq_puts(s, "\n"))
  664. goto partial;
  665. }
  666. return TRACE_TYPE_HANDLED;
  667. partial:
  668. return TRACE_TYPE_PARTIAL_LINE;
  669. }
  670. static struct trace_event trace_stack_event = {
  671. .type = TRACE_STACK,
  672. .trace = trace_stack_print,
  673. .raw = trace_special_print,
  674. .hex = trace_special_hex,
  675. .binary = trace_special_bin,
  676. };
  677. /* TRACE_USER_STACK */
  678. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  679. int flags)
  680. {
  681. struct userstack_entry *field;
  682. struct trace_seq *s = &iter->seq;
  683. trace_assign_type(field, iter->ent);
  684. if (!seq_print_userip_objs(field, s, flags))
  685. goto partial;
  686. if (!trace_seq_putc(s, '\n'))
  687. goto partial;
  688. return TRACE_TYPE_HANDLED;
  689. partial:
  690. return TRACE_TYPE_PARTIAL_LINE;
  691. }
  692. static struct trace_event trace_user_stack_event = {
  693. .type = TRACE_USER_STACK,
  694. .trace = trace_user_stack_print,
  695. .raw = trace_special_print,
  696. .hex = trace_special_hex,
  697. .binary = trace_special_bin,
  698. };
  699. /* TRACE_BPRINT */
  700. static enum print_line_t
  701. trace_bprint_print(struct trace_iterator *iter, int flags)
  702. {
  703. struct trace_entry *entry = iter->ent;
  704. struct trace_seq *s = &iter->seq;
  705. struct bprint_entry *field;
  706. trace_assign_type(field, entry);
  707. if (!seq_print_ip_sym(s, field->ip, flags))
  708. goto partial;
  709. if (!trace_seq_puts(s, ": "))
  710. goto partial;
  711. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  712. goto partial;
  713. return TRACE_TYPE_HANDLED;
  714. partial:
  715. return TRACE_TYPE_PARTIAL_LINE;
  716. }
  717. static enum print_line_t
  718. trace_bprint_raw(struct trace_iterator *iter, int flags)
  719. {
  720. struct bprint_entry *field;
  721. struct trace_seq *s = &iter->seq;
  722. trace_assign_type(field, iter->ent);
  723. if (!trace_seq_printf(s, ": %lx : ", field->ip))
  724. goto partial;
  725. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  726. goto partial;
  727. return TRACE_TYPE_HANDLED;
  728. partial:
  729. return TRACE_TYPE_PARTIAL_LINE;
  730. }
  731. static struct trace_event trace_bprint_event = {
  732. .type = TRACE_BPRINT,
  733. .trace = trace_bprint_print,
  734. .raw = trace_bprint_raw,
  735. };
  736. /* TRACE_PRINT */
  737. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  738. int flags)
  739. {
  740. struct print_entry *field;
  741. struct trace_seq *s = &iter->seq;
  742. trace_assign_type(field, iter->ent);
  743. if (!seq_print_ip_sym(s, field->ip, flags))
  744. goto partial;
  745. if (!trace_seq_printf(s, ": %s", field->buf))
  746. goto partial;
  747. return TRACE_TYPE_HANDLED;
  748. partial:
  749. return TRACE_TYPE_PARTIAL_LINE;
  750. }
  751. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
  752. {
  753. struct print_entry *field;
  754. trace_assign_type(field, iter->ent);
  755. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  756. goto partial;
  757. return TRACE_TYPE_HANDLED;
  758. partial:
  759. return TRACE_TYPE_PARTIAL_LINE;
  760. }
  761. static struct trace_event trace_print_event = {
  762. .type = TRACE_PRINT,
  763. .trace = trace_print_print,
  764. .raw = trace_print_raw,
  765. };
  766. static struct trace_event *events[] __initdata = {
  767. &trace_fn_event,
  768. &trace_ctx_event,
  769. &trace_wake_event,
  770. &trace_special_event,
  771. &trace_stack_event,
  772. &trace_user_stack_event,
  773. &trace_bprint_event,
  774. &trace_print_event,
  775. NULL
  776. };
  777. __init static int init_events(void)
  778. {
  779. struct trace_event *event;
  780. int i, ret;
  781. for (i = 0; events[i]; i++) {
  782. event = events[i];
  783. ret = register_ftrace_event(event);
  784. if (!ret) {
  785. printk(KERN_WARNING "event %d failed to register\n",
  786. event->type);
  787. WARN_ON_ONCE(1);
  788. }
  789. }
  790. return 0;
  791. }
  792. device_initcall(init_events);