PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/time/timer_list.c

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