2 * kernel/time/timer_list.c
6 * Copyright(C) 2006, Red Hat, Inc., Ingo Molnar
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.
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>
19 #include <linux/nmi.h>
21 #include <linux/uaccess.h>
23 #include "tick-internal.h"
25 struct timer_list_iter
{
32 * This allows printing both to /proc/timer_list and
33 * to the console (on SysRq-Q):
36 static void SEQ_printf(struct seq_file
*m
, const char *fmt
, ...)
43 seq_vprintf(m
, fmt
, args
);
50 static void print_name_offset(struct seq_file
*m
, void *sym
)
52 char symname
[KSYM_NAME_LEN
];
54 if (lookup_symbol_name((unsigned long)sym
, symname
) < 0)
55 SEQ_printf(m
, "<%pK>", sym
);
57 SEQ_printf(m
, "%s", symname
);
61 print_timer(struct seq_file
*m
, struct hrtimer
*taddr
, struct hrtimer
*timer
,
64 SEQ_printf(m
, " #%d: ", idx
);
65 print_name_offset(m
, taddr
);
67 print_name_offset(m
, timer
->function
);
68 SEQ_printf(m
, ", S:%02x", timer
->state
);
70 SEQ_printf(m
, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
71 (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer
)),
72 (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer
)),
73 (long long)(ktime_to_ns(hrtimer_get_softexpires(timer
)) - now
),
74 (long long)(ktime_to_ns(hrtimer_get_expires(timer
)) - now
));
78 print_active_timers(struct seq_file
*m
, struct hrtimer_clock_base
*base
,
81 struct hrtimer
*timer
, tmp
;
82 unsigned long next
= 0, i
;
83 struct timerqueue_node
*curr
;
91 raw_spin_lock_irqsave(&base
->cpu_base
->lock
, flags
);
93 curr
= timerqueue_getnext(&base
->active
);
95 * Crude but we have to do this O(N*N) thing, because
96 * we have to unlock the base when printing:
98 while (curr
&& i
< next
) {
99 curr
= timerqueue_iterate_next(curr
);
105 timer
= container_of(curr
, struct hrtimer
, node
);
107 raw_spin_unlock_irqrestore(&base
->cpu_base
->lock
, flags
);
109 print_timer(m
, timer
, &tmp
, i
, now
);
113 raw_spin_unlock_irqrestore(&base
->cpu_base
->lock
, flags
);
117 print_base(struct seq_file
*m
, struct hrtimer_clock_base
*base
, u64 now
)
119 SEQ_printf(m
, " .base: %pK\n", base
);
120 SEQ_printf(m
, " .index: %d\n", base
->index
);
122 SEQ_printf(m
, " .resolution: %u nsecs\n", hrtimer_resolution
);
124 SEQ_printf(m
, " .get_time: ");
125 print_name_offset(m
, base
->get_time
);
127 #ifdef CONFIG_HIGH_RES_TIMERS
128 SEQ_printf(m
, " .offset: %Lu nsecs\n",
129 (unsigned long long) ktime_to_ns(base
->offset
));
131 SEQ_printf(m
, "active timers:\n");
132 print_active_timers(m
, base
, now
+ ktime_to_ns(base
->offset
));
135 static void print_cpu(struct seq_file
*m
, int cpu
, u64 now
)
137 struct hrtimer_cpu_base
*cpu_base
= &per_cpu(hrtimer_bases
, cpu
);
140 SEQ_printf(m
, "cpu: %d\n", cpu
);
141 for (i
= 0; i
< HRTIMER_MAX_CLOCK_BASES
; i
++) {
142 SEQ_printf(m
, " clock %d:\n", i
);
143 print_base(m
, cpu_base
->clock_base
+ i
, now
);
146 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
147 (unsigned long long)(cpu_base->x))
149 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
150 (unsigned long long)(ktime_to_ns(cpu_base->x)))
152 #ifdef CONFIG_HIGH_RES_TIMERS
163 #ifdef CONFIG_TICK_ONESHOT
165 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
166 (unsigned long long)(ts->x))
168 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
169 (unsigned long long)(ktime_to_ns(ts->x)))
171 struct tick_sched
*ts
= tick_get_tick_sched(cpu
);
178 P_ns(idle_entrytime
);
181 P_ns(idle_sleeptime
);
182 P_ns(iowait_sleeptime
);
186 SEQ_printf(m
, "jiffies: %Lu\n",
187 (unsigned long long)jiffies
);
196 #ifdef CONFIG_GENERIC_CLOCKEVENTS
198 print_tickdevice(struct seq_file
*m
, struct tick_device
*td
, int cpu
)
200 struct clock_event_device
*dev
= td
->evtdev
;
202 touch_nmi_watchdog();
204 SEQ_printf(m
, "Tick Device: mode: %d\n", td
->mode
);
206 SEQ_printf(m
, "Broadcast device\n");
208 SEQ_printf(m
, "Per CPU device: %d\n", cpu
);
210 SEQ_printf(m
, "Clock Event Device: ");
212 SEQ_printf(m
, "<NULL>\n");
215 SEQ_printf(m
, "%s\n", dev
->name
);
216 SEQ_printf(m
, " max_delta_ns: %llu\n",
217 (unsigned long long) dev
->max_delta_ns
);
218 SEQ_printf(m
, " min_delta_ns: %llu\n",
219 (unsigned long long) dev
->min_delta_ns
);
220 SEQ_printf(m
, " mult: %u\n", dev
->mult
);
221 SEQ_printf(m
, " shift: %u\n", dev
->shift
);
222 SEQ_printf(m
, " mode: %d\n", clockevent_get_state(dev
));
223 SEQ_printf(m
, " next_event: %Ld nsecs\n",
224 (unsigned long long) ktime_to_ns(dev
->next_event
));
226 SEQ_printf(m
, " set_next_event: ");
227 print_name_offset(m
, dev
->set_next_event
);
230 if (dev
->set_state_shutdown
) {
231 SEQ_printf(m
, " shutdown: ");
232 print_name_offset(m
, dev
->set_state_shutdown
);
236 if (dev
->set_state_periodic
) {
237 SEQ_printf(m
, " periodic: ");
238 print_name_offset(m
, dev
->set_state_periodic
);
242 if (dev
->set_state_oneshot
) {
243 SEQ_printf(m
, " oneshot: ");
244 print_name_offset(m
, dev
->set_state_oneshot
);
248 if (dev
->set_state_oneshot_stopped
) {
249 SEQ_printf(m
, " oneshot stopped: ");
250 print_name_offset(m
, dev
->set_state_oneshot_stopped
);
254 if (dev
->tick_resume
) {
255 SEQ_printf(m
, " resume: ");
256 print_name_offset(m
, dev
->tick_resume
);
260 SEQ_printf(m
, " event_handler: ");
261 print_name_offset(m
, dev
->event_handler
);
263 SEQ_printf(m
, " retries: %lu\n", dev
->retries
);
267 static void timer_list_show_tickdevices_header(struct seq_file
*m
)
269 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
270 print_tickdevice(m
, tick_get_broadcast_device(), -1);
271 SEQ_printf(m
, "tick_broadcast_mask: %*pb\n",
272 cpumask_pr_args(tick_get_broadcast_mask()));
273 #ifdef CONFIG_TICK_ONESHOT
274 SEQ_printf(m
, "tick_broadcast_oneshot_mask: %*pb\n",
275 cpumask_pr_args(tick_get_broadcast_oneshot_mask()));
282 static inline void timer_list_header(struct seq_file
*m
, u64 now
)
284 SEQ_printf(m
, "Timer List Version: v0.8\n");
285 SEQ_printf(m
, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES
);
286 SEQ_printf(m
, "now at %Ld nsecs\n", (unsigned long long)now
);
290 static int timer_list_show(struct seq_file
*m
, void *v
)
292 struct timer_list_iter
*iter
= v
;
294 if (iter
->cpu
== -1 && !iter
->second_pass
)
295 timer_list_header(m
, iter
->now
);
296 else if (!iter
->second_pass
)
297 print_cpu(m
, iter
->cpu
, iter
->now
);
298 #ifdef CONFIG_GENERIC_CLOCKEVENTS
299 else if (iter
->cpu
== -1 && iter
->second_pass
)
300 timer_list_show_tickdevices_header(m
);
302 print_tickdevice(m
, tick_get_device(iter
->cpu
), iter
->cpu
);
307 void sysrq_timer_list_show(void)
309 u64 now
= ktime_to_ns(ktime_get());
312 timer_list_header(NULL
, now
);
314 for_each_online_cpu(cpu
)
315 print_cpu(NULL
, cpu
, now
);
317 #ifdef CONFIG_GENERIC_CLOCKEVENTS
318 timer_list_show_tickdevices_header(NULL
);
319 for_each_online_cpu(cpu
)
320 print_tickdevice(NULL
, tick_get_device(cpu
), cpu
);
325 static void *move_iter(struct timer_list_iter
*iter
, loff_t offset
)
327 for (; offset
; offset
--) {
328 iter
->cpu
= cpumask_next(iter
->cpu
, cpu_online_mask
);
329 if (iter
->cpu
>= nr_cpu_ids
) {
330 #ifdef CONFIG_GENERIC_CLOCKEVENTS
331 if (!iter
->second_pass
) {
333 iter
->second_pass
= true;
344 static void *timer_list_start(struct seq_file
*file
, loff_t
*offset
)
346 struct timer_list_iter
*iter
= file
->private;
349 iter
->now
= ktime_to_ns(ktime_get());
351 iter
->second_pass
= false;
352 return move_iter(iter
, *offset
);
355 static void *timer_list_next(struct seq_file
*file
, void *v
, loff_t
*offset
)
357 struct timer_list_iter
*iter
= file
->private;
359 return move_iter(iter
, 1);
362 static void timer_list_stop(struct seq_file
*seq
, void *v
)
366 static const struct seq_operations timer_list_sops
= {
367 .start
= timer_list_start
,
368 .next
= timer_list_next
,
369 .stop
= timer_list_stop
,
370 .show
= timer_list_show
,
373 static int __init
init_timer_list_procfs(void)
375 struct proc_dir_entry
*pe
;
377 pe
= proc_create_seq_private("timer_list", 0400, NULL
, &timer_list_sops
,
378 sizeof(struct timer_list_iter
), NULL
);
383 __initcall(init_timer_list_procfs
);