timer_list.c 7.2 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, "<%pK>", 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. SEQ_printf(m, " #%d: ", idx);
  46. print_name_offset(m, taddr);
  47. SEQ_printf(m, ", ");
  48. print_name_offset(m, timer->function);
  49. SEQ_printf(m, ", S:%02lx", timer->state);
  50. SEQ_printf(m, "\n");
  51. SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
  52. (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
  53. (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
  54. (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
  55. (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
  56. }
  57. static void
  58. print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
  59. u64 now)
  60. {
  61. struct hrtimer *timer, tmp;
  62. unsigned long next = 0, i;
  63. struct timerqueue_node *curr;
  64. unsigned long flags;
  65. next_one:
  66. i = 0;
  67. raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
  68. curr = timerqueue_getnext(&base->active);
  69. /*
  70. * Crude but we have to do this O(N*N) thing, because
  71. * we have to unlock the base when printing:
  72. */
  73. while (curr && i < next) {
  74. curr = timerqueue_iterate_next(curr);
  75. i++;
  76. }
  77. if (curr) {
  78. timer = container_of(curr, struct hrtimer, node);
  79. tmp = *timer;
  80. raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  81. print_timer(m, timer, &tmp, i, now);
  82. next++;
  83. goto next_one;
  84. }
  85. raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  86. }
  87. static void
  88. print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
  89. {
  90. SEQ_printf(m, " .base: %pK\n", base);
  91. SEQ_printf(m, " .index: %d\n",
  92. base->index);
  93. SEQ_printf(m, " .resolution: %Lu nsecs\n",
  94. (unsigned long long)ktime_to_ns(base->resolution));
  95. SEQ_printf(m, " .get_time: ");
  96. print_name_offset(m, base->get_time);
  97. SEQ_printf(m, "\n");
  98. #ifdef CONFIG_HIGH_RES_TIMERS
  99. SEQ_printf(m, " .offset: %Lu nsecs\n",
  100. (unsigned long long) ktime_to_ns(base->offset));
  101. #endif
  102. SEQ_printf(m, "active timers:\n");
  103. print_active_timers(m, base, now);
  104. }
  105. static void print_cpu(struct seq_file *m, int cpu, u64 now)
  106. {
  107. struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
  108. int i;
  109. SEQ_printf(m, "\n");
  110. SEQ_printf(m, "cpu: %d\n", cpu);
  111. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  112. SEQ_printf(m, " clock %d:\n", i);
  113. print_base(m, cpu_base->clock_base + i, now);
  114. }
  115. #define P(x) \
  116. SEQ_printf(m, " .%-15s: %Lu\n", #x, \
  117. (unsigned long long)(cpu_base->x))
  118. #define P_ns(x) \
  119. SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
  120. (unsigned long long)(ktime_to_ns(cpu_base->x)))
  121. #ifdef CONFIG_HIGH_RES_TIMERS
  122. P_ns(expires_next);
  123. P(hres_active);
  124. P(nr_events);
  125. P(nr_retries);
  126. P(nr_hangs);
  127. P_ns(max_hang_time);
  128. #endif
  129. #undef P
  130. #undef P_ns
  131. #ifdef CONFIG_TICK_ONESHOT
  132. # define P(x) \
  133. SEQ_printf(m, " .%-15s: %Lu\n", #x, \
  134. (unsigned long long)(ts->x))
  135. # define P_ns(x) \
  136. SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
  137. (unsigned long long)(ktime_to_ns(ts->x)))
  138. {
  139. struct tick_sched *ts = tick_get_tick_sched(cpu);
  140. P(nohz_mode);
  141. P_ns(idle_tick);
  142. P(tick_stopped);
  143. P(idle_jiffies);
  144. P(idle_calls);
  145. P(idle_sleeps);
  146. P_ns(idle_entrytime);
  147. P_ns(idle_waketime);
  148. P_ns(idle_exittime);
  149. P_ns(idle_sleeptime);
  150. P_ns(iowait_sleeptime);
  151. P(last_jiffies);
  152. P(next_jiffies);
  153. P_ns(idle_expires);
  154. SEQ_printf(m, "jiffies: %Lu\n",
  155. (unsigned long long)jiffies);
  156. }
  157. #endif
  158. #undef P
  159. #undef P_ns
  160. }
  161. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  162. static void
  163. print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
  164. {
  165. struct clock_event_device *dev = td->evtdev;
  166. SEQ_printf(m, "\n");
  167. SEQ_printf(m, "Tick Device: mode: %d\n", td->mode);
  168. if (cpu < 0)
  169. SEQ_printf(m, "Broadcast device\n");
  170. else
  171. SEQ_printf(m, "Per CPU device: %d\n", cpu);
  172. SEQ_printf(m, "Clock Event Device: ");
  173. if (!dev) {
  174. SEQ_printf(m, "<NULL>\n");
  175. return;
  176. }
  177. SEQ_printf(m, "%s\n", dev->name);
  178. SEQ_printf(m, " max_delta_ns: %llu\n",
  179. (unsigned long long) dev->max_delta_ns);
  180. SEQ_printf(m, " min_delta_ns: %llu\n",
  181. (unsigned long long) dev->min_delta_ns);
  182. SEQ_printf(m, " mult: %u\n", dev->mult);
  183. SEQ_printf(m, " shift: %u\n", dev->shift);
  184. SEQ_printf(m, " mode: %d\n", dev->mode);
  185. SEQ_printf(m, " next_event: %Ld nsecs\n",
  186. (unsigned long long) ktime_to_ns(dev->next_event));
  187. SEQ_printf(m, " set_next_event: ");
  188. print_name_offset(m, dev->set_next_event);
  189. SEQ_printf(m, "\n");
  190. SEQ_printf(m, " set_mode: ");
  191. print_name_offset(m, dev->set_mode);
  192. SEQ_printf(m, "\n");
  193. SEQ_printf(m, " event_handler: ");
  194. print_name_offset(m, dev->event_handler);
  195. SEQ_printf(m, "\n");
  196. SEQ_printf(m, " retries: %lu\n", dev->retries);
  197. }
  198. static void timer_list_show_tickdevices(struct seq_file *m)
  199. {
  200. int cpu;
  201. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  202. print_tickdevice(m, tick_get_broadcast_device(), -1);
  203. SEQ_printf(m, "tick_broadcast_mask: %08lx\n",
  204. cpumask_bits(tick_get_broadcast_mask())[0]);
  205. #ifdef CONFIG_TICK_ONESHOT
  206. SEQ_printf(m, "tick_broadcast_oneshot_mask: %08lx\n",
  207. cpumask_bits(tick_get_broadcast_oneshot_mask())[0]);
  208. #endif
  209. SEQ_printf(m, "\n");
  210. #endif
  211. for_each_online_cpu(cpu)
  212. print_tickdevice(m, tick_get_device(cpu), cpu);
  213. SEQ_printf(m, "\n");
  214. }
  215. #else
  216. static void timer_list_show_tickdevices(struct seq_file *m) { }
  217. #endif
  218. static int timer_list_show(struct seq_file *m, void *v)
  219. {
  220. u64 now = ktime_to_ns(ktime_get());
  221. int cpu;
  222. SEQ_printf(m, "Timer List Version: v0.6\n");
  223. SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
  224. SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
  225. for_each_online_cpu(cpu)
  226. print_cpu(m, cpu, now);
  227. SEQ_printf(m, "\n");
  228. timer_list_show_tickdevices(m);
  229. return 0;
  230. }
  231. void sysrq_timer_list_show(void)
  232. {
  233. timer_list_show(NULL, NULL);
  234. }
  235. static int timer_list_open(struct inode *inode, struct file *filp)
  236. {
  237. return single_open(filp, timer_list_show, NULL);
  238. }
  239. static const struct file_operations timer_list_fops = {
  240. .open = timer_list_open,
  241. .read = seq_read,
  242. .llseek = seq_lseek,
  243. .release = single_release,
  244. };
  245. static int __init init_timer_list_procfs(void)
  246. {
  247. struct proc_dir_entry *pe;
  248. pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
  249. if (!pe)
  250. return -ENOMEM;
  251. return 0;
  252. }
  253. __initcall(init_timer_list_procfs);