timer_list.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * kernel/time/timer_list.c
  3. *
  4. * List pending timers
  5. *
  6. * Copyright(C) 2006, Red Hat, Inc., Ingo Molnar
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/proc_fs.h>
  13. #include <linux/module.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/sched.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/kallsyms.h>
  18. #include <linux/tick.h>
  19. #include <asm/uaccess.h>
  20. typedef void (*print_fn_t)(struct seq_file *m, unsigned int *classes);
  21. DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  22. /*
  23. * This allows printing both to /proc/timer_list and
  24. * to the console (on SysRq-Q):
  25. */
  26. #define SEQ_printf(m, x...) \
  27. do { \
  28. if (m) \
  29. seq_printf(m, x); \
  30. else \
  31. printk(x); \
  32. } while (0)
  33. static void print_name_offset(struct seq_file *m, void *sym)
  34. {
  35. char symname[KSYM_NAME_LEN];
  36. if (lookup_symbol_name((unsigned long)sym, symname) < 0)
  37. SEQ_printf(m, "<%p>", sym);
  38. else
  39. SEQ_printf(m, "%s", symname);
  40. }
  41. static void
  42. print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
  43. int idx, u64 now)
  44. {
  45. #ifdef CONFIG_TIMER_STATS
  46. char tmp[TASK_COMM_LEN + 1];
  47. #endif
  48. SEQ_printf(m, " #%d: ", idx);
  49. print_name_offset(m, taddr);
  50. SEQ_printf(m, ", ");
  51. print_name_offset(m, timer->function);
  52. SEQ_printf(m, ", S:%02lx", timer->state);
  53. #ifdef CONFIG_TIMER_STATS
  54. SEQ_printf(m, ", ");
  55. print_name_offset(m, timer->start_site);
  56. memcpy(tmp, timer->start_comm, TASK_COMM_LEN);
  57. tmp[TASK_COMM_LEN] = 0;
  58. SEQ_printf(m, ", %s/%d", tmp, timer->start_pid);
  59. #endif
  60. SEQ_printf(m, "\n");
  61. SEQ_printf(m, " # expires at %Lu nsecs [in %Ld nsecs]\n",
  62. (unsigned long long)ktime_to_ns(timer->expires),
  63. (long long)(ktime_to_ns(timer->expires) - now));
  64. }
  65. static void
  66. print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
  67. u64 now)
  68. {
  69. struct hrtimer *timer, tmp;
  70. unsigned long next = 0, i;
  71. struct rb_node *curr;
  72. unsigned long flags;
  73. next_one:
  74. i = 0;
  75. spin_lock_irqsave(&base->cpu_base->lock, flags);
  76. curr = base->first;
  77. /*
  78. * Crude but we have to do this O(N*N) thing, because
  79. * we have to unlock the base when printing:
  80. */
  81. while (curr && i < next) {
  82. curr = rb_next(curr);
  83. i++;
  84. }
  85. if (curr) {
  86. timer = rb_entry(curr, struct hrtimer, node);
  87. tmp = *timer;
  88. spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  89. print_timer(m, timer, &tmp, i, now);
  90. next++;
  91. goto next_one;
  92. }
  93. spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  94. }
  95. static void
  96. print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
  97. {
  98. SEQ_printf(m, " .base: %p\n", base);
  99. SEQ_printf(m, " .index: %d\n",
  100. base->index);
  101. SEQ_printf(m, " .resolution: %Lu nsecs\n",
  102. (unsigned long long)ktime_to_ns(base->resolution));
  103. SEQ_printf(m, " .get_time: ");
  104. print_name_offset(m, base->get_time);
  105. SEQ_printf(m, "\n");
  106. #ifdef CONFIG_HIGH_RES_TIMERS
  107. SEQ_printf(m, " .offset: %Lu nsecs\n",
  108. (unsigned long long) ktime_to_ns(base->offset));
  109. #endif
  110. SEQ_printf(m, "active timers:\n");
  111. print_active_timers(m, base, now);
  112. }
  113. static void print_cpu(struct seq_file *m, int cpu, u64 now)
  114. {
  115. struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
  116. int i;
  117. SEQ_printf(m, "\n");
  118. SEQ_printf(m, "cpu: %d\n", cpu);
  119. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  120. SEQ_printf(m, " clock %d:\n", i);
  121. print_base(m, cpu_base->clock_base + i, now);
  122. }
  123. #define P(x) \
  124. SEQ_printf(m, " .%-15s: %Lu\n", #x, \
  125. (unsigned long long)(cpu_base->x))
  126. #define P_ns(x) \
  127. SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
  128. (unsigned long long)(ktime_to_ns(cpu_base->x)))
  129. #ifdef CONFIG_HIGH_RES_TIMERS
  130. P_ns(expires_next);
  131. P(hres_active);
  132. P(nr_events);
  133. #endif
  134. #undef P
  135. #undef P_ns
  136. #ifdef CONFIG_TICK_ONESHOT
  137. # define P(x) \
  138. SEQ_printf(m, " .%-15s: %Lu\n", #x, \
  139. (unsigned long long)(ts->x))
  140. # define P_ns(x) \
  141. SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
  142. (unsigned long long)(ktime_to_ns(ts->x)))
  143. {
  144. struct tick_sched *ts = tick_get_tick_sched(cpu);
  145. P(nohz_mode);
  146. P_ns(idle_tick);
  147. P(tick_stopped);
  148. P(idle_jiffies);
  149. P(idle_calls);
  150. P(idle_sleeps);
  151. P_ns(idle_entrytime);
  152. P_ns(idle_waketime);
  153. P_ns(idle_exittime);
  154. P_ns(idle_sleeptime);
  155. P(last_jiffies);
  156. P(next_jiffies);
  157. P_ns(idle_expires);
  158. SEQ_printf(m, "jiffies: %Lu\n",
  159. (unsigned long long)jiffies);
  160. }
  161. #endif
  162. #undef P
  163. #undef P_ns
  164. }
  165. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  166. static void
  167. print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
  168. {
  169. struct clock_event_device *dev = td->evtdev;
  170. SEQ_printf(m, "\n");
  171. SEQ_printf(m, "Tick Device: mode: %d\n", td->mode);
  172. if (cpu < 0)
  173. SEQ_printf(m, "Broadcast device\n");
  174. else
  175. SEQ_printf(m, "Per CPU device: %d\n", cpu);
  176. SEQ_printf(m, "Clock Event Device: ");
  177. if (!dev) {
  178. SEQ_printf(m, "<NULL>\n");
  179. return;
  180. }
  181. SEQ_printf(m, "%s\n", dev->name);
  182. SEQ_printf(m, " max_delta_ns: %lu\n", dev->max_delta_ns);
  183. SEQ_printf(m, " min_delta_ns: %lu\n", dev->min_delta_ns);
  184. SEQ_printf(m, " mult: %lu\n", dev->mult);
  185. SEQ_printf(m, " shift: %d\n", dev->shift);
  186. SEQ_printf(m, " mode: %d\n", dev->mode);
  187. SEQ_printf(m, " next_event: %Ld nsecs\n",
  188. (unsigned long long) ktime_to_ns(dev->next_event));
  189. SEQ_printf(m, " set_next_event: ");
  190. print_name_offset(m, dev->set_next_event);
  191. SEQ_printf(m, "\n");
  192. SEQ_printf(m, " set_mode: ");
  193. print_name_offset(m, dev->set_mode);
  194. SEQ_printf(m, "\n");
  195. SEQ_printf(m, " event_handler: ");
  196. print_name_offset(m, dev->event_handler);
  197. SEQ_printf(m, "\n");
  198. }
  199. static void timer_list_show_tickdevices(struct seq_file *m)
  200. {
  201. int cpu;
  202. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  203. print_tickdevice(m, tick_get_broadcast_device(), -1);
  204. SEQ_printf(m, "tick_broadcast_mask: %08lx\n",
  205. tick_get_broadcast_mask()->bits[0]);
  206. #ifdef CONFIG_TICK_ONESHOT
  207. SEQ_printf(m, "tick_broadcast_oneshot_mask: %08lx\n",
  208. tick_get_broadcast_oneshot_mask()->bits[0]);
  209. #endif
  210. SEQ_printf(m, "\n");
  211. #endif
  212. for_each_online_cpu(cpu)
  213. print_tickdevice(m, tick_get_device(cpu), cpu);
  214. SEQ_printf(m, "\n");
  215. }
  216. #else
  217. static void timer_list_show_tickdevices(struct seq_file *m) { }
  218. #endif
  219. static int timer_list_show(struct seq_file *m, void *v)
  220. {
  221. u64 now = ktime_to_ns(ktime_get());
  222. int cpu;
  223. SEQ_printf(m, "Timer List Version: v0.4\n");
  224. SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
  225. SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
  226. for_each_online_cpu(cpu)
  227. print_cpu(m, cpu, now);
  228. SEQ_printf(m, "\n");
  229. timer_list_show_tickdevices(m);
  230. return 0;
  231. }
  232. void sysrq_timer_list_show(void)
  233. {
  234. timer_list_show(NULL, NULL);
  235. }
  236. static int timer_list_open(struct inode *inode, struct file *filp)
  237. {
  238. return single_open(filp, timer_list_show, NULL);
  239. }
  240. static struct file_operations timer_list_fops = {
  241. .open = timer_list_open,
  242. .read = seq_read,
  243. .llseek = seq_lseek,
  244. .release = single_release,
  245. };
  246. static int __init init_timer_list_procfs(void)
  247. {
  248. struct proc_dir_entry *pe;
  249. pe = proc_create("timer_list", 0644, NULL, &timer_list_fops);
  250. if (!pe)
  251. return -ENOMEM;
  252. return 0;
  253. }
  254. __initcall(init_timer_list_procfs);