mm/list_lru.c: fold __list_lru_count_one() into its caller
[linux/fpc-iii.git] / kernel / time / timer_list.c
blobd647dabdac97a3b592b25cdc929909df92b04b8a
1 /*
2 * kernel/time/timer_list.c
4 * List pending timers
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 {
26 int cpu;
27 bool second_pass;
28 u64 now;
32 * This allows printing both to /proc/timer_list and
33 * to the console (on SysRq-Q):
35 __printf(2, 3)
36 static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
38 va_list args;
40 va_start(args, fmt);
42 if (m)
43 seq_vprintf(m, fmt, args);
44 else
45 vprintk(fmt, args);
47 va_end(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);
56 else
57 SEQ_printf(m, "%s", symname);
60 static void
61 print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
62 int idx, u64 now)
64 SEQ_printf(m, " #%d: ", idx);
65 print_name_offset(m, taddr);
66 SEQ_printf(m, ", ");
67 print_name_offset(m, timer->function);
68 SEQ_printf(m, ", S:%02x", timer->state);
69 SEQ_printf(m, "\n");
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));
77 static void
78 print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
79 u64 now)
81 struct hrtimer *timer, tmp;
82 unsigned long next = 0, i;
83 struct timerqueue_node *curr;
84 unsigned long flags;
86 next_one:
87 i = 0;
89 touch_nmi_watchdog();
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);
100 i++;
103 if (curr) {
105 timer = container_of(curr, struct hrtimer, node);
106 tmp = *timer;
107 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
109 print_timer(m, timer, &tmp, i, now);
110 next++;
111 goto next_one;
113 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
116 static void
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);
126 SEQ_printf(m, "\n");
127 #ifdef CONFIG_HIGH_RES_TIMERS
128 SEQ_printf(m, " .offset: %Lu nsecs\n",
129 (unsigned long long) ktime_to_ns(base->offset));
130 #endif
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);
138 int i;
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);
145 #define P(x) \
146 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
147 (unsigned long long)(cpu_base->x))
148 #define P_ns(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
153 P_ns(expires_next);
154 P(hres_active);
155 P(nr_events);
156 P(nr_retries);
157 P(nr_hangs);
158 P(max_hang_time);
159 #endif
160 #undef P
161 #undef P_ns
163 #ifdef CONFIG_TICK_ONESHOT
164 # define P(x) \
165 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
166 (unsigned long long)(ts->x))
167 # define P_ns(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);
172 P(nohz_mode);
173 P_ns(last_tick);
174 P(tick_stopped);
175 P(idle_jiffies);
176 P(idle_calls);
177 P(idle_sleeps);
178 P_ns(idle_entrytime);
179 P_ns(idle_waketime);
180 P_ns(idle_exittime);
181 P_ns(idle_sleeptime);
182 P_ns(iowait_sleeptime);
183 P(last_jiffies);
184 P(next_timer);
185 P_ns(idle_expires);
186 SEQ_printf(m, "jiffies: %Lu\n",
187 (unsigned long long)jiffies);
189 #endif
191 #undef P
192 #undef P_ns
193 SEQ_printf(m, "\n");
196 #ifdef CONFIG_GENERIC_CLOCKEVENTS
197 static void
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);
205 if (cpu < 0)
206 SEQ_printf(m, "Broadcast device\n");
207 else
208 SEQ_printf(m, "Per CPU device: %d\n", cpu);
210 SEQ_printf(m, "Clock Event Device: ");
211 if (!dev) {
212 SEQ_printf(m, "<NULL>\n");
213 return;
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);
228 SEQ_printf(m, "\n");
230 if (dev->set_state_shutdown) {
231 SEQ_printf(m, " shutdown: ");
232 print_name_offset(m, dev->set_state_shutdown);
233 SEQ_printf(m, "\n");
236 if (dev->set_state_periodic) {
237 SEQ_printf(m, " periodic: ");
238 print_name_offset(m, dev->set_state_periodic);
239 SEQ_printf(m, "\n");
242 if (dev->set_state_oneshot) {
243 SEQ_printf(m, " oneshot: ");
244 print_name_offset(m, dev->set_state_oneshot);
245 SEQ_printf(m, "\n");
248 if (dev->set_state_oneshot_stopped) {
249 SEQ_printf(m, " oneshot stopped: ");
250 print_name_offset(m, dev->set_state_oneshot_stopped);
251 SEQ_printf(m, "\n");
254 if (dev->tick_resume) {
255 SEQ_printf(m, " resume: ");
256 print_name_offset(m, dev->tick_resume);
257 SEQ_printf(m, "\n");
260 SEQ_printf(m, " event_handler: ");
261 print_name_offset(m, dev->event_handler);
262 SEQ_printf(m, "\n");
263 SEQ_printf(m, " retries: %lu\n", dev->retries);
264 SEQ_printf(m, "\n");
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()));
276 #endif
277 SEQ_printf(m, "\n");
278 #endif
280 #endif
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);
287 SEQ_printf(m, "\n");
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);
301 else
302 print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
303 #endif
304 return 0;
307 void sysrq_timer_list_show(void)
309 u64 now = ktime_to_ns(ktime_get());
310 int cpu;
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);
321 #endif
322 return;
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) {
332 iter->cpu = -1;
333 iter->second_pass = true;
334 } else
335 return NULL;
336 #else
337 return NULL;
338 #endif
341 return iter;
344 static void *timer_list_start(struct seq_file *file, loff_t *offset)
346 struct timer_list_iter *iter = file->private;
348 if (!*offset)
349 iter->now = ktime_to_ns(ktime_get());
350 iter->cpu = -1;
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;
358 ++*offset;
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);
379 if (!pe)
380 return -ENOMEM;
381 return 0;
383 __initcall(init_timer_list_procfs);