hrtimer: Make the statistics fields smaller
[linux-2.6-block.git] / kernel / time / timer_list.c
CommitLineData
289f480a
IM
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
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>
289f480a
IM
19
20#include <asm/uaccess.h>
21
c1797baf 22#include "tick-internal.h"
b3956a89
NZ
23
24struct timer_list_iter {
25 int cpu;
26 bool second_pass;
27 u64 now;
28};
29
289f480a
IM
30typedef 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 */
7de4e744
JP
38__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}
289f480a
IM
52
53static void print_name_offset(struct seq_file *m, void *sym)
54{
9281acea 55 char symname[KSYM_NAME_LEN];
289f480a 56
9d65cb4a 57 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
f5903085 58 SEQ_printf(m, "<%pK>", sym);
9d65cb4a
AD
59 else
60 SEQ_printf(m, "%s", symname);
289f480a
IM
61}
62
63static void
e67ef25a
TG
64print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
65 int idx, u64 now)
289f480a
IM
66{
67#ifdef CONFIG_TIMER_STATS
68 char tmp[TASK_COMM_LEN + 1];
69#endif
70 SEQ_printf(m, " #%d: ", idx);
e67ef25a 71 print_name_offset(m, taddr);
289f480a
IM
72 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");
704af52b
AV
83 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)),
cc584b21 85 (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
704af52b 86 (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
cc584b21 87 (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
289f480a
IM
88}
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;
998adc3d 96 struct timerqueue_node *curr;
289f480a
IM
97 unsigned long flags;
98
99next_one:
100 i = 0;
ecb49d1a 101 raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
289f480a 102
998adc3d 103 curr = timerqueue_getnext(&base->active);
289f480a
IM
104 /*
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) {
998adc3d 109 curr = timerqueue_iterate_next(curr);
289f480a
IM
110 i++;
111 }
112
113 if (curr) {
114
998adc3d 115 timer = container_of(curr, struct hrtimer, node);
289f480a 116 tmp = *timer;
ecb49d1a 117 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
289f480a 118
e67ef25a 119 print_timer(m, timer, &tmp, i, now);
289f480a
IM
120 next++;
121 goto next_one;
122 }
ecb49d1a 123 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
289f480a
IM
124}
125
126static void
127print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
128{
f5903085 129 SEQ_printf(m, " .base: %pK\n", base);
398ca17f
TG
130 SEQ_printf(m, " .index: %d\n", base->index);
131
132 SEQ_printf(m, " .resolution: %u nsecs\n", (unsigned) hrtimer_resolution);
133
289f480a
IM
134 SEQ_printf(m, " .get_time: ");
135 print_name_offset(m, base->get_time);
136 SEQ_printf(m, "\n");
137#ifdef CONFIG_HIGH_RES_TIMERS
9b04bd27
DM
138 SEQ_printf(m, " .offset: %Lu nsecs\n",
139 (unsigned long long) ktime_to_ns(base->offset));
289f480a
IM
140#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
129f1d2c 150 SEQ_printf(m, "cpu: %d\n", cpu);
289f480a
IM
151 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) \
9b04bd27
DM
156 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
157 (unsigned long long)(cpu_base->x))
289f480a 158#define P_ns(x) \
9b04bd27
DM
159 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
160 (unsigned long long)(ktime_to_ns(cpu_base->x)))
289f480a
IM
161
162#ifdef CONFIG_HIGH_RES_TIMERS
163 P_ns(expires_next);
164 P(hres_active);
165 P(nr_events);
41d2e494
TG
166 P(nr_retries);
167 P(nr_hangs);
a6ffebce 168 P(max_hang_time);
289f480a
IM
169#endif
170#undef P
171#undef P_ns
172
173#ifdef CONFIG_TICK_ONESHOT
174# define P(x) \
9b04bd27
DM
175 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
176 (unsigned long long)(ts->x))
289f480a 177# define P_ns(x) \
9b04bd27
DM
178 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
179 (unsigned long long)(ktime_to_ns(ts->x)))
289f480a
IM
180 {
181 struct tick_sched *ts = tick_get_tick_sched(cpu);
182 P(nohz_mode);
f5d411c9 183 P_ns(last_tick);
289f480a
IM
184 P(tick_stopped);
185 P(idle_jiffies);
186 P(idle_calls);
187 P(idle_sleeps);
188 P_ns(idle_entrytime);
5df7fa1c
TG
189 P_ns(idle_waketime);
190 P_ns(idle_exittime);
289f480a 191 P_ns(idle_sleeptime);
0224cf4c 192 P_ns(iowait_sleeptime);
289f480a
IM
193 P(last_jiffies);
194 P(next_jiffies);
195 P_ns(idle_expires);
9b04bd27
DM
196 SEQ_printf(m, "jiffies: %Lu\n",
197 (unsigned long long)jiffies);
289f480a
IM
198 }
199#endif
200
201#undef P
202#undef P_ns
60cf7ea8 203 SEQ_printf(m, "\n");
289f480a
IM
204}
205
206#ifdef CONFIG_GENERIC_CLOCKEVENTS
207static void
c5b77a3d 208print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
289f480a
IM
209{
210 struct clock_event_device *dev = td->evtdev;
211
129f1d2c 212 SEQ_printf(m, "Tick Device: mode: %d\n", td->mode);
c5b77a3d
TG
213 if (cpu < 0)
214 SEQ_printf(m, "Broadcast device\n");
215 else
216 SEQ_printf(m, "Per CPU device: %d\n", cpu);
289f480a
IM
217
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);
97813f2f
JH
224 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);
23af368e
TG
228 SEQ_printf(m, " mult: %u\n", dev->mult);
229 SEQ_printf(m, " shift: %u\n", dev->shift);
289f480a
IM
230 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
bd624d75
VK
238 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 {
77e32c89 243 if (dev->set_state_shutdown) {
bd624d75 244 SEQ_printf(m, " shutdown: ");
77e32c89 245 print_name_offset(m, dev->set_state_shutdown);
bd624d75
VK
246 SEQ_printf(m, "\n");
247 }
248
77e32c89 249 if (dev->set_state_periodic) {
bd624d75 250 SEQ_printf(m, " periodic: ");
77e32c89 251 print_name_offset(m, dev->set_state_periodic);
bd624d75
VK
252 SEQ_printf(m, "\n");
253 }
254
77e32c89 255 if (dev->set_state_oneshot) {
bd624d75 256 SEQ_printf(m, " oneshot: ");
77e32c89 257 print_name_offset(m, dev->set_state_oneshot);
bd624d75
VK
258 SEQ_printf(m, "\n");
259 }
260
554ef387 261 if (dev->tick_resume) {
bd624d75 262 SEQ_printf(m, " resume: ");
554ef387 263 print_name_offset(m, dev->tick_resume);
bd624d75
VK
264 SEQ_printf(m, "\n");
265 }
266 }
289f480a
IM
267
268 SEQ_printf(m, " event_handler: ");
269 print_name_offset(m, dev->event_handler);
270 SEQ_printf(m, "\n");
80a05b9f 271 SEQ_printf(m, " retries: %lu\n", dev->retries);
60cf7ea8 272 SEQ_printf(m, "\n");
289f480a
IM
273}
274
60cf7ea8 275static void timer_list_show_tickdevices_header(struct seq_file *m)
289f480a 276{
289f480a 277#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
c5b77a3d 278 print_tickdevice(m, tick_get_broadcast_device(), -1);
289f480a 279 SEQ_printf(m, "tick_broadcast_mask: %08lx\n",
62ac1279 280 cpumask_bits(tick_get_broadcast_mask())[0]);
289f480a
IM
281#ifdef CONFIG_TICK_ONESHOT
282 SEQ_printf(m, "tick_broadcast_oneshot_mask: %08lx\n",
62ac1279 283 cpumask_bits(tick_get_broadcast_oneshot_mask())[0]);
289f480a
IM
284#endif
285 SEQ_printf(m, "\n");
286#endif
289f480a 287}
289f480a
IM
288#endif
289
b3956a89 290static inline void timer_list_header(struct seq_file *m, u64 now)
289f480a 291{
f5d411c9 292 SEQ_printf(m, "Timer List Version: v0.7\n");
289f480a
IM
293 SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
294 SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
60cf7ea8 295 SEQ_printf(m, "\n");
b3956a89
NZ
296}
297
298static int timer_list_show(struct seq_file *m, void *v)
299{
300 struct timer_list_iter *iter = v;
b3956a89
NZ
301
302 if (iter->cpu == -1 && !iter->second_pass)
84a78a65 303 timer_list_header(m, iter->now);
b3956a89
NZ
304 else if (!iter->second_pass)
305 print_cpu(m, iter->cpu, iter->now);
306#ifdef CONFIG_GENERIC_CLOCKEVENTS
307 else if (iter->cpu == -1 && iter->second_pass)
308 timer_list_show_tickdevices_header(m);
309 else
310 print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
311#endif
312 return 0;
313}
314
315void sysrq_timer_list_show(void)
316{
317 u64 now = ktime_to_ns(ktime_get());
318 int cpu;
319
320 timer_list_header(NULL, now);
289f480a
IM
321
322 for_each_online_cpu(cpu)
b3956a89 323 print_cpu(NULL, cpu, now);
289f480a 324
60cf7ea8 325#ifdef CONFIG_GENERIC_CLOCKEVENTS
b3956a89 326 timer_list_show_tickdevices_header(NULL);
60cf7ea8 327 for_each_online_cpu(cpu)
b3956a89 328 print_tickdevice(NULL, tick_get_device(cpu), cpu);
60cf7ea8 329#endif
b3956a89
NZ
330 return;
331}
289f480a 332
84a78a65 333static void *move_iter(struct timer_list_iter *iter, loff_t offset)
b3956a89 334{
84a78a65
NZ
335 for (; offset; offset--) {
336 iter->cpu = cpumask_next(iter->cpu, cpu_online_mask);
337 if (iter->cpu >= nr_cpu_ids) {
b3956a89 338#ifdef CONFIG_GENERIC_CLOCKEVENTS
84a78a65
NZ
339 if (!iter->second_pass) {
340 iter->cpu = -1;
341 iter->second_pass = true;
342 } else
343 return NULL;
b3956a89 344#else
84a78a65 345 return NULL;
b3956a89 346#endif
84a78a65 347 }
b3956a89
NZ
348 }
349 return iter;
289f480a
IM
350}
351
84a78a65
NZ
352static void *timer_list_start(struct seq_file *file, loff_t *offset)
353{
354 struct timer_list_iter *iter = file->private;
355
356 if (!*offset)
357 iter->now = ktime_to_ns(ktime_get());
358 iter->cpu = -1;
359 iter->second_pass = false;
360 return move_iter(iter, *offset);
361}
362
b3956a89 363static void *timer_list_next(struct seq_file *file, void *v, loff_t *offset)
289f480a 364{
b3956a89 365 struct timer_list_iter *iter = file->private;
b3956a89 366 ++*offset;
84a78a65 367 return move_iter(iter, 1);
289f480a
IM
368}
369
b3956a89
NZ
370static void timer_list_stop(struct seq_file *seq, void *v)
371{
372}
373
374static const struct seq_operations timer_list_sops = {
375 .start = timer_list_start,
376 .next = timer_list_next,
377 .stop = timer_list_stop,
378 .show = timer_list_show,
379};
380
289f480a
IM
381static int timer_list_open(struct inode *inode, struct file *filp)
382{
b3956a89
NZ
383 return seq_open_private(filp, &timer_list_sops,
384 sizeof(struct timer_list_iter));
289f480a
IM
385}
386
828c0950 387static const struct file_operations timer_list_fops = {
289f480a
IM
388 .open = timer_list_open,
389 .read = seq_read,
390 .llseek = seq_lseek,
b3956a89 391 .release = seq_release_private,
289f480a
IM
392};
393
394static int __init init_timer_list_procfs(void)
395{
396 struct proc_dir_entry *pe;
397
de809347 398 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
289f480a
IM
399 if (!pe)
400 return -ENOMEM;
289f480a
IM
401 return 0;
402}
403__initcall(init_timer_list_procfs);