trace_mmiotrace.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Memory mapped I/O tracing
  3. *
  4. * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
  5. */
  6. #define DEBUG 1
  7. #include <linux/kernel.h>
  8. #include <linux/mmiotrace.h>
  9. #include "trace.h"
  10. static struct trace_array *mmio_trace_array;
  11. static void mmio_reset_data(struct trace_array *tr)
  12. {
  13. int cpu;
  14. tr->time_start = ftrace_now(tr->cpu);
  15. for_each_online_cpu(cpu)
  16. tracing_reset(tr->data[cpu]);
  17. }
  18. static void mmio_trace_init(struct trace_array *tr)
  19. {
  20. pr_debug("in %s\n", __func__);
  21. mmio_trace_array = tr;
  22. if (tr->ctrl) {
  23. mmio_reset_data(tr);
  24. enable_mmiotrace();
  25. }
  26. }
  27. static void mmio_trace_reset(struct trace_array *tr)
  28. {
  29. pr_debug("in %s\n", __func__);
  30. if (tr->ctrl)
  31. disable_mmiotrace();
  32. mmio_reset_data(tr);
  33. mmio_trace_array = NULL;
  34. }
  35. static void mmio_trace_ctrl_update(struct trace_array *tr)
  36. {
  37. pr_debug("in %s\n", __func__);
  38. if (tr->ctrl) {
  39. mmio_reset_data(tr);
  40. enable_mmiotrace();
  41. } else {
  42. disable_mmiotrace();
  43. }
  44. }
  45. /* XXX: This is not called for trace_pipe file! */
  46. void mmio_print_header(struct trace_iterator *iter)
  47. {
  48. struct trace_seq *s = &iter->seq;
  49. trace_seq_printf(s, "VERSION broken 20070824\n");
  50. /* TODO: print /proc/bus/pci/devices contents as PCIDEV lines */
  51. }
  52. static int mmio_print_rw(struct trace_iterator *iter)
  53. {
  54. struct trace_entry *entry = iter->ent;
  55. struct mmiotrace_rw *rw = &entry->mmiorw;
  56. struct trace_seq *s = &iter->seq;
  57. unsigned long long t = ns2usecs(entry->t);
  58. unsigned long usec_rem = do_div(t, 1000000ULL);
  59. unsigned secs = (unsigned long)t;
  60. int ret = 1;
  61. switch (entry->mmiorw.opcode) {
  62. case MMIO_READ:
  63. ret = trace_seq_printf(s,
  64. "R %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
  65. rw->width, secs, usec_rem, rw->map_id, rw->phys,
  66. rw->value, rw->pc, entry->pid);
  67. break;
  68. case MMIO_WRITE:
  69. ret = trace_seq_printf(s,
  70. "W %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
  71. rw->width, secs, usec_rem, rw->map_id, rw->phys,
  72. rw->value, rw->pc, entry->pid);
  73. break;
  74. case MMIO_UNKNOWN_OP:
  75. ret = trace_seq_printf(s,
  76. "UNKNOWN %lu.%06lu %d 0x%lx %02x,%02x,%02x 0x%lx %d\n",
  77. secs, usec_rem, rw->map_id, rw->phys,
  78. (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
  79. (rw->value >> 0) & 0xff, rw->pc, entry->pid);
  80. break;
  81. default:
  82. ret = trace_seq_printf(s, "rw what?\n");
  83. break;
  84. }
  85. if (ret)
  86. return 1;
  87. return 0;
  88. }
  89. static int mmio_print_map(struct trace_iterator *iter)
  90. {
  91. struct trace_entry *entry = iter->ent;
  92. struct mmiotrace_map *m = &entry->mmiomap;
  93. struct trace_seq *s = &iter->seq;
  94. unsigned long long t = ns2usecs(entry->t);
  95. unsigned long usec_rem = do_div(t, 1000000ULL);
  96. unsigned secs = (unsigned long)t;
  97. int ret = 1;
  98. switch (entry->mmiorw.opcode) {
  99. case MMIO_PROBE:
  100. ret = trace_seq_printf(s,
  101. "MAP %lu.%06lu %d 0x%lx 0x%lx 0x%lx 0x%lx %d\n",
  102. secs, usec_rem, m->map_id, m->phys, m->virt, m->len,
  103. 0UL, entry->pid);
  104. break;
  105. case MMIO_UNPROBE:
  106. ret = trace_seq_printf(s,
  107. "UNMAP %lu.%06lu %d 0x%lx %d\n",
  108. secs, usec_rem, m->map_id, 0UL, entry->pid);
  109. break;
  110. default:
  111. ret = trace_seq_printf(s, "map what?\n");
  112. break;
  113. }
  114. if (ret)
  115. return 1;
  116. return 0;
  117. }
  118. /* return 0 to abort printing without consuming current entry in pipe mode */
  119. static int mmio_print_line(struct trace_iterator *iter)
  120. {
  121. switch (iter->ent->type) {
  122. case TRACE_MMIO_RW:
  123. return mmio_print_rw(iter);
  124. case TRACE_MMIO_MAP:
  125. return mmio_print_map(iter);
  126. default:
  127. return 1; /* ignore unknown entries */
  128. }
  129. }
  130. static struct tracer mmio_tracer __read_mostly =
  131. {
  132. .name = "mmiotrace",
  133. .init = mmio_trace_init,
  134. .reset = mmio_trace_reset,
  135. .open = mmio_print_header,
  136. .ctrl_update = mmio_trace_ctrl_update,
  137. .print_line = mmio_print_line,
  138. };
  139. __init static int init_mmio_trace(void)
  140. {
  141. return register_tracer(&mmio_tracer);
  142. }
  143. device_initcall(init_mmio_trace);
  144. void mmio_trace_rw(struct mmiotrace_rw *rw)
  145. {
  146. struct trace_array *tr = mmio_trace_array;
  147. struct trace_array_cpu *data = tr->data[smp_processor_id()];
  148. __trace_mmiotrace_rw(tr, data, rw);
  149. }
  150. void mmio_trace_mapping(struct mmiotrace_map *map)
  151. {
  152. struct trace_array *tr = mmio_trace_array;
  153. struct trace_array_cpu *data;
  154. preempt_disable();
  155. data = tr->data[smp_processor_id()];
  156. __trace_mmiotrace_map(tr, data, map);
  157. preempt_enable();
  158. }