blob: 1327004429be6fee0b29a7aa9a19ff16a31362e2 [file] [log] [blame]
Ingo Molnar289f4802007-02-16 01:28:15 -08001/*
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
13#include <linux/proc_fs.h>
14#include <linux/module.h>
15#include <linux/spinlock.h>
16#include <linux/sched.h>
17#include <linux/seq_file.h>
18#include <linux/kallsyms.h>
Ingo Molnar289f4802007-02-16 01:28:15 -080019
20#include <asm/uaccess.h>
21
Thomas Gleixnerc1797ba2015-03-25 13:07:37 +010022#include "tick-internal.h"
Nathan Zimmerb3956a82013-03-26 19:56:30 -050023
24struct timer_list_iter {
25 int cpu;
26 bool second_pass;
27 u64 now;
28};
29
Ingo Molnar289f4802007-02-16 01:28:15 -080030typedef void (*print_fn_t)(struct seq_file *m, unsigned int *classes);
31
32DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
33
34/*
35 * This allows printing both to /proc/timer_list and
36 * to the console (on SysRq-Q):
37 */
Joe Perches7de4e742015-04-17 11:39:18 -070038__printf(2, 3)
39static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
40{
41 va_list args;
42
43 va_start(args, fmt);
44
45 if (m)
46 seq_vprintf(m, fmt, args);
47 else
48 vprintk(fmt, args);
49
50 va_end(args);
51}
Ingo Molnar289f4802007-02-16 01:28:15 -080052
53static void print_name_offset(struct seq_file *m, void *sym)
54{
Tejun Heo9281ace2007-07-17 04:03:51 -070055 char symname[KSYM_NAME_LEN];
Ingo Molnar289f4802007-02-16 01:28:15 -080056
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070057 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
Kees Cookf5903082011-02-11 19:21:25 -080058 SEQ_printf(m, "<%pK>", sym);
Alexey Dobriyan9d65cb42007-05-08 00:28:43 -070059 else
60 SEQ_printf(m, "%s", symname);
Ingo Molnar289f4802007-02-16 01:28:15 -080061}
62
63static void
Thomas Gleixnere67ef252008-09-25 23:50:23 +020064print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
65 int idx, u64 now)
Ingo Molnar289f4802007-02-16 01:28:15 -080066{
67#ifdef CONFIG_TIMER_STATS
68 char tmp[TASK_COMM_LEN + 1];
69#endif
70 SEQ_printf(m, " #%d: ", idx);
Thomas Gleixnere67ef252008-09-25 23:50:23 +020071 print_name_offset(m, taddr);
Ingo Molnar289f4802007-02-16 01:28:15 -080072 SEQ_printf(m, ", ");
73 print_name_offset(m, timer->function);
74 SEQ_printf(m, ", S:%02lx", timer->state);
75#ifdef CONFIG_TIMER_STATS
76 SEQ_printf(m, ", ");
77 print_name_offset(m, timer->start_site);
78 memcpy(tmp, timer->start_comm, TASK_COMM_LEN);
79 tmp[TASK_COMM_LEN] = 0;
80 SEQ_printf(m, ", %s/%d", tmp, timer->start_pid);
81#endif
82 SEQ_printf(m, "\n");
Arjan van de Ven704af522008-09-07 16:10:20 -070083 SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
84 (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
Arjan van de Vencc584b22008-09-01 15:02:30 -070085 (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
Arjan van de Ven704af522008-09-07 16:10:20 -070086 (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
Arjan van de Vencc584b22008-09-01 15:02:30 -070087 (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
Ingo Molnar289f4802007-02-16 01:28:15 -080088}
89
90static void
91print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
92 u64 now)
93{
94 struct hrtimer *timer, tmp;
95 unsigned long next = 0, i;
John Stultz998adc32010-09-20 19:19:17 -070096 struct timerqueue_node *curr;
Ingo Molnar289f4802007-02-16 01:28:15 -080097 unsigned long flags;
98
99next_one:
100 i = 0;
Thomas Gleixnerecb49d12009-11-17 16:36:54 +0100101 raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
Ingo Molnar289f4802007-02-16 01:28:15 -0800102
John Stultz998adc32010-09-20 19:19:17 -0700103 curr = timerqueue_getnext(&base->active);
Ingo Molnar289f4802007-02-16 01:28:15 -0800104 /*
105 * Crude but we have to do this O(N*N) thing, because
106 * we have to unlock the base when printing:
107 */
108 while (curr && i < next) {
John Stultz998adc32010-09-20 19:19:17 -0700109 curr = timerqueue_iterate_next(curr);
Ingo Molnar289f4802007-02-16 01:28:15 -0800110 i++;
111 }
112
113 if (curr) {
114
John Stultz998adc32010-09-20 19:19:17 -0700115 timer = container_of(curr, struct hrtimer, node);
Ingo Molnar289f4802007-02-16 01:28:15 -0800116 tmp = *timer;
Thomas Gleixnerecb49d12009-11-17 16:36:54 +0100117 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
Ingo Molnar289f4802007-02-16 01:28:15 -0800118
Thomas Gleixnere67ef252008-09-25 23:50:23 +0200119 print_timer(m, timer, &tmp, i, now);
Ingo Molnar289f4802007-02-16 01:28:15 -0800120 next++;
121 goto next_one;
122 }
Thomas Gleixnerecb49d12009-11-17 16:36:54 +0100123 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
Ingo Molnar289f4802007-02-16 01:28:15 -0800124}
125
126static void
127print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
128{
Kees Cookf5903082011-02-11 19:21:25 -0800129 SEQ_printf(m, " .base: %pK\n", base);
Thomas Gleixner398ca172015-04-14 21:08:27 +0000130 SEQ_printf(m, " .index: %d\n", base->index);
131
132 SEQ_printf(m, " .resolution: %u nsecs\n", (unsigned) hrtimer_resolution);
133
Ingo Molnar289f4802007-02-16 01:28:15 -0800134 SEQ_printf(m, " .get_time: ");
135 print_name_offset(m, base->get_time);
136 SEQ_printf(m, "\n");
137#ifdef CONFIG_HIGH_RES_TIMERS
David Miller9b04bd22007-05-09 02:33:43 -0700138 SEQ_printf(m, " .offset: %Lu nsecs\n",
139 (unsigned long long) ktime_to_ns(base->offset));
Ingo Molnar289f4802007-02-16 01:28:15 -0800140#endif
141 SEQ_printf(m, "active timers:\n");
142 print_active_timers(m, base, now);
143}
144
145static void print_cpu(struct seq_file *m, int cpu, u64 now)
146{
147 struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
148 int i;
149
Vegard Nossum129f1d22007-10-11 08:23:34 +0200150 SEQ_printf(m, "cpu: %d\n", cpu);
Ingo Molnar289f4802007-02-16 01:28:15 -0800151 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
152 SEQ_printf(m, " clock %d:\n", i);
153 print_base(m, cpu_base->clock_base + i, now);
154 }
155#define P(x) \
David Miller9b04bd22007-05-09 02:33:43 -0700156 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
157 (unsigned long long)(cpu_base->x))
Ingo Molnar289f4802007-02-16 01:28:15 -0800158#define P_ns(x) \
David Miller9b04bd22007-05-09 02:33:43 -0700159 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
160 (unsigned long long)(ktime_to_ns(cpu_base->x)))
Ingo Molnar289f4802007-02-16 01:28:15 -0800161
162#ifdef CONFIG_HIGH_RES_TIMERS
163 P_ns(expires_next);
164 P(hres_active);
165 P(nr_events);
Thomas Gleixner41d2e492009-11-13 17:05:44 +0100166 P(nr_retries);
167 P(nr_hangs);
Thomas Gleixnera6ffebc2015-04-14 21:08:34 +0000168 P(max_hang_time);
Ingo Molnar289f4802007-02-16 01:28:15 -0800169#endif
170#undef P
171#undef P_ns
172
173#ifdef CONFIG_TICK_ONESHOT
174# define P(x) \
David Miller9b04bd22007-05-09 02:33:43 -0700175 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
176 (unsigned long long)(ts->x))
Ingo Molnar289f4802007-02-16 01:28:15 -0800177# define P_ns(x) \
David Miller9b04bd22007-05-09 02:33:43 -0700178 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
179 (unsigned long long)(ktime_to_ns(ts->x)))
Ingo Molnar289f4802007-02-16 01:28:15 -0800180 {
181 struct tick_sched *ts = tick_get_tick_sched(cpu);
182 P(nohz_mode);
Frederic Weisbeckerf5d411c2011-07-31 17:44:12 +0200183 P_ns(last_tick);
Ingo Molnar289f4802007-02-16 01:28:15 -0800184 P(tick_stopped);
185 P(idle_jiffies);
186 P(idle_calls);
187 P(idle_sleeps);
188 P_ns(idle_entrytime);
Thomas Gleixner5df7fa12008-02-01 17:45:14 +0100189 P_ns(idle_waketime);
190 P_ns(idle_exittime);
Ingo Molnar289f4802007-02-16 01:28:15 -0800191 P_ns(idle_sleeptime);
Arjan van de Ven0224cf42010-05-09 08:25:23 -0700192 P_ns(iowait_sleeptime);
Ingo Molnar289f4802007-02-16 01:28:15 -0800193 P(last_jiffies);
Thomas Gleixnerc1ad3482015-04-14 21:08:58 +0000194 P(next_timer);
Ingo Molnar289f4802007-02-16 01:28:15 -0800195 P_ns(idle_expires);
David Miller9b04bd22007-05-09 02:33:43 -0700196 SEQ_printf(m, "jiffies: %Lu\n",
197 (unsigned long long)jiffies);
Ingo Molnar289f4802007-02-16 01:28:15 -0800198 }
199#endif
200
201#undef P
202#undef P_ns
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500203 SEQ_printf(m, "\n");
Ingo Molnar289f4802007-02-16 01:28:15 -0800204}
205
206#ifdef CONFIG_GENERIC_CLOCKEVENTS
207static void
Thomas Gleixnerc5b77a32008-09-29 17:31:41 +0200208print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
Ingo Molnar289f4802007-02-16 01:28:15 -0800209{
210 struct clock_event_device *dev = td->evtdev;
211
Vegard Nossum129f1d22007-10-11 08:23:34 +0200212 SEQ_printf(m, "Tick Device: mode: %d\n", td->mode);
Thomas Gleixnerc5b77a32008-09-29 17:31:41 +0200213 if (cpu < 0)
214 SEQ_printf(m, "Broadcast device\n");
215 else
216 SEQ_printf(m, "Per CPU device: %d\n", cpu);
Ingo Molnar289f4802007-02-16 01:28:15 -0800217
218 SEQ_printf(m, "Clock Event Device: ");
219 if (!dev) {
220 SEQ_printf(m, "<NULL>\n");
221 return;
222 }
223 SEQ_printf(m, "%s\n", dev->name);
Jon Hunter97813f22009-08-18 12:45:11 -0500224 SEQ_printf(m, " max_delta_ns: %llu\n",
225 (unsigned long long) dev->max_delta_ns);
226 SEQ_printf(m, " min_delta_ns: %llu\n",
227 (unsigned long long) dev->min_delta_ns);
Thomas Gleixner23af3682009-11-11 14:05:25 +0000228 SEQ_printf(m, " mult: %u\n", dev->mult);
229 SEQ_printf(m, " shift: %u\n", dev->shift);
Ingo Molnar289f4802007-02-16 01:28:15 -0800230 SEQ_printf(m, " mode: %d\n", dev->mode);
231 SEQ_printf(m, " next_event: %Ld nsecs\n",
232 (unsigned long long) ktime_to_ns(dev->next_event));
233
234 SEQ_printf(m, " set_next_event: ");
235 print_name_offset(m, dev->set_next_event);
236 SEQ_printf(m, "\n");
237
Viresh Kumarbd624d72015-02-13 08:54:56 +0800238 if (dev->set_mode) {
239 SEQ_printf(m, " set_mode: ");
240 print_name_offset(m, dev->set_mode);
241 SEQ_printf(m, "\n");
242 } else {
Viresh Kumar77e32c82015-02-27 17:21:33 +0530243 if (dev->set_state_shutdown) {
Viresh Kumarbd624d72015-02-13 08:54:56 +0800244 SEQ_printf(m, " shutdown: ");
Viresh Kumar77e32c82015-02-27 17:21:33 +0530245 print_name_offset(m, dev->set_state_shutdown);
Viresh Kumarbd624d72015-02-13 08:54:56 +0800246 SEQ_printf(m, "\n");
247 }
248
Viresh Kumar77e32c82015-02-27 17:21:33 +0530249 if (dev->set_state_periodic) {
Viresh Kumarbd624d72015-02-13 08:54:56 +0800250 SEQ_printf(m, " periodic: ");
Viresh Kumar77e32c82015-02-27 17:21:33 +0530251 print_name_offset(m, dev->set_state_periodic);
Viresh Kumarbd624d72015-02-13 08:54:56 +0800252 SEQ_printf(m, "\n");
253 }
254
Viresh Kumar77e32c82015-02-27 17:21:33 +0530255 if (dev->set_state_oneshot) {
Viresh Kumarbd624d72015-02-13 08:54:56 +0800256 SEQ_printf(m, " oneshot: ");
Viresh Kumar77e32c82015-02-27 17:21:33 +0530257 print_name_offset(m, dev->set_state_oneshot);
Viresh Kumarbd624d72015-02-13 08:54:56 +0800258 SEQ_printf(m, "\n");
259 }
260
Viresh Kumar8fff52f2015-04-03 09:04:04 +0530261 if (dev->set_state_oneshot_stopped) {
262 SEQ_printf(m, " oneshot stopped: ");
263 print_name_offset(m, dev->set_state_oneshot_stopped);
264 SEQ_printf(m, "\n");
265 }
266
Viresh Kumar554ef382015-02-27 17:21:32 +0530267 if (dev->tick_resume) {
Viresh Kumarbd624d72015-02-13 08:54:56 +0800268 SEQ_printf(m, " resume: ");
Viresh Kumar554ef382015-02-27 17:21:32 +0530269 print_name_offset(m, dev->tick_resume);
Viresh Kumarbd624d72015-02-13 08:54:56 +0800270 SEQ_printf(m, "\n");
271 }
272 }
Ingo Molnar289f4802007-02-16 01:28:15 -0800273
274 SEQ_printf(m, " event_handler: ");
275 print_name_offset(m, dev->event_handler);
276 SEQ_printf(m, "\n");
Thomas Gleixner80a05b92010-03-12 17:34:14 +0100277 SEQ_printf(m, " retries: %lu\n", dev->retries);
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500278 SEQ_printf(m, "\n");
Ingo Molnar289f4802007-02-16 01:28:15 -0800279}
280
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500281static void timer_list_show_tickdevices_header(struct seq_file *m)
Ingo Molnar289f4802007-02-16 01:28:15 -0800282{
Ingo Molnar289f4802007-02-16 01:28:15 -0800283#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
Thomas Gleixnerc5b77a32008-09-29 17:31:41 +0200284 print_tickdevice(m, tick_get_broadcast_device(), -1);
Preeti U Murthy1ef09cd2015-04-28 14:15:20 +0530285 SEQ_printf(m, "tick_broadcast_mask: %*pb\n",
286 cpumask_pr_args(tick_get_broadcast_mask()));
Ingo Molnar289f4802007-02-16 01:28:15 -0800287#ifdef CONFIG_TICK_ONESHOT
Preeti U Murthy1ef09cd2015-04-28 14:15:20 +0530288 SEQ_printf(m, "tick_broadcast_oneshot_mask: %*pb\n",
289 cpumask_pr_args(tick_get_broadcast_oneshot_mask()));
Ingo Molnar289f4802007-02-16 01:28:15 -0800290#endif
291 SEQ_printf(m, "\n");
292#endif
Ingo Molnar289f4802007-02-16 01:28:15 -0800293}
Ingo Molnar289f4802007-02-16 01:28:15 -0800294#endif
295
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500296static inline void timer_list_header(struct seq_file *m, u64 now)
Ingo Molnar289f4802007-02-16 01:28:15 -0800297{
Thomas Gleixnerc1ad3482015-04-14 21:08:58 +0000298 SEQ_printf(m, "Timer List Version: v0.8\n");
Ingo Molnar289f4802007-02-16 01:28:15 -0800299 SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
300 SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500301 SEQ_printf(m, "\n");
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500302}
Ingo Molnar289f4802007-02-16 01:28:15 -0800303
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500304static int timer_list_show(struct seq_file *m, void *v)
305{
306 struct timer_list_iter *iter = v;
Ingo Molnar289f4802007-02-16 01:28:15 -0800307
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500308 if (iter->cpu == -1 && !iter->second_pass)
Nathan Zimmer84a78a62013-08-28 16:35:14 -0700309 timer_list_header(m, iter->now);
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500310 else if (!iter->second_pass)
311 print_cpu(m, iter->cpu, iter->now);
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500312#ifdef CONFIG_GENERIC_CLOCKEVENTS
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500313 else if (iter->cpu == -1 && iter->second_pass)
314 timer_list_show_tickdevices_header(m);
315 else
316 print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
Nathan Zimmer60cf7ea2013-03-26 19:56:29 -0500317#endif
Ingo Molnar289f4802007-02-16 01:28:15 -0800318 return 0;
319}
320
321void sysrq_timer_list_show(void)
322{
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500323 u64 now = ktime_to_ns(ktime_get());
324 int cpu;
325
326 timer_list_header(NULL, now);
327
328 for_each_online_cpu(cpu)
329 print_cpu(NULL, cpu, now);
330
331#ifdef CONFIG_GENERIC_CLOCKEVENTS
332 timer_list_show_tickdevices_header(NULL);
333 for_each_online_cpu(cpu)
334 print_tickdevice(NULL, tick_get_device(cpu), cpu);
335#endif
336 return;
Ingo Molnar289f4802007-02-16 01:28:15 -0800337}
338
Nathan Zimmer84a78a62013-08-28 16:35:14 -0700339static void *move_iter(struct timer_list_iter *iter, loff_t offset)
340{
341 for (; offset; offset--) {
342 iter->cpu = cpumask_next(iter->cpu, cpu_online_mask);
343 if (iter->cpu >= nr_cpu_ids) {
344#ifdef CONFIG_GENERIC_CLOCKEVENTS
345 if (!iter->second_pass) {
346 iter->cpu = -1;
347 iter->second_pass = true;
348 } else
349 return NULL;
350#else
351 return NULL;
352#endif
353 }
354 }
355 return iter;
356}
357
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500358static void *timer_list_start(struct seq_file *file, loff_t *offset)
359{
360 struct timer_list_iter *iter = file->private;
361
Nathan Zimmer84a78a62013-08-28 16:35:14 -0700362 if (!*offset)
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500363 iter->now = ktime_to_ns(ktime_get());
Nathan Zimmer84a78a62013-08-28 16:35:14 -0700364 iter->cpu = -1;
365 iter->second_pass = false;
366 return move_iter(iter, *offset);
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500367}
368
369static void *timer_list_next(struct seq_file *file, void *v, loff_t *offset)
370{
371 struct timer_list_iter *iter = file->private;
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500372 ++*offset;
Nathan Zimmer84a78a62013-08-28 16:35:14 -0700373 return move_iter(iter, 1);
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500374}
375
376static void timer_list_stop(struct seq_file *seq, void *v)
377{
378}
379
380static const struct seq_operations timer_list_sops = {
381 .start = timer_list_start,
382 .next = timer_list_next,
383 .stop = timer_list_stop,
384 .show = timer_list_show,
385};
386
Ingo Molnar289f4802007-02-16 01:28:15 -0800387static int timer_list_open(struct inode *inode, struct file *filp)
388{
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500389 return seq_open_private(filp, &timer_list_sops,
390 sizeof(struct timer_list_iter));
Ingo Molnar289f4802007-02-16 01:28:15 -0800391}
392
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700393static const struct file_operations timer_list_fops = {
Ingo Molnar289f4802007-02-16 01:28:15 -0800394 .open = timer_list_open,
395 .read = seq_read,
396 .llseek = seq_lseek,
Nathan Zimmerb3956a82013-03-26 19:56:30 -0500397 .release = seq_release_private,
Ingo Molnar289f4802007-02-16 01:28:15 -0800398};
399
400static int __init init_timer_list_procfs(void)
401{
402 struct proc_dir_entry *pe;
403
Amerigo Wangde809342009-08-17 05:43:01 -0400404 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
Ingo Molnar289f4802007-02-16 01:28:15 -0800405 if (!pe)
406 return -ENOMEM;
Ingo Molnar289f4802007-02-16 01:28:15 -0800407 return 0;
408}
409__initcall(init_timer_list_procfs);