0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/proc_fs.h>
0009 #include <linux/module.h>
0010 #include <linux/spinlock.h>
0011 #include <linux/sched.h>
0012 #include <linux/seq_file.h>
0013 #include <linux/kallsyms.h>
0014 #include <linux/nmi.h>
0015
0016 #include <linux/uaccess.h>
0017
0018 #include "tick-internal.h"
0019
0020 struct timer_list_iter {
0021 int cpu;
0022 bool second_pass;
0023 u64 now;
0024 };
0025
0026
0027
0028
0029
0030 __printf(2, 3)
0031 static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
0032 {
0033 va_list args;
0034
0035 va_start(args, fmt);
0036
0037 if (m)
0038 seq_vprintf(m, fmt, args);
0039 else
0040 vprintk(fmt, args);
0041
0042 va_end(args);
0043 }
0044
0045 static void
0046 print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
0047 int idx, u64 now)
0048 {
0049 SEQ_printf(m, " #%d: <%pK>, %ps", idx, taddr, timer->function);
0050 SEQ_printf(m, ", S:%02x", timer->state);
0051 SEQ_printf(m, "\n");
0052 SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",
0053 (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
0054 (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
0055 (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
0056 (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
0057 }
0058
0059 static void
0060 print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
0061 u64 now)
0062 {
0063 struct hrtimer *timer, tmp;
0064 unsigned long next = 0, i;
0065 struct timerqueue_node *curr;
0066 unsigned long flags;
0067
0068 next_one:
0069 i = 0;
0070
0071 touch_nmi_watchdog();
0072
0073 raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
0074
0075 curr = timerqueue_getnext(&base->active);
0076
0077
0078
0079
0080 while (curr && i < next) {
0081 curr = timerqueue_iterate_next(curr);
0082 i++;
0083 }
0084
0085 if (curr) {
0086
0087 timer = container_of(curr, struct hrtimer, node);
0088 tmp = *timer;
0089 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
0090
0091 print_timer(m, timer, &tmp, i, now);
0092 next++;
0093 goto next_one;
0094 }
0095 raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
0096 }
0097
0098 static void
0099 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
0100 {
0101 SEQ_printf(m, " .base: %pK\n", base);
0102 SEQ_printf(m, " .index: %d\n", base->index);
0103
0104 SEQ_printf(m, " .resolution: %u nsecs\n", hrtimer_resolution);
0105
0106 SEQ_printf(m, " .get_time: %ps\n", base->get_time);
0107 #ifdef CONFIG_HIGH_RES_TIMERS
0108 SEQ_printf(m, " .offset: %Lu nsecs\n",
0109 (unsigned long long) ktime_to_ns(base->offset));
0110 #endif
0111 SEQ_printf(m, "active timers:\n");
0112 print_active_timers(m, base, now + ktime_to_ns(base->offset));
0113 }
0114
0115 static void print_cpu(struct seq_file *m, int cpu, u64 now)
0116 {
0117 struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
0118 int i;
0119
0120 SEQ_printf(m, "cpu: %d\n", cpu);
0121 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
0122 SEQ_printf(m, " clock %d:\n", i);
0123 print_base(m, cpu_base->clock_base + i, now);
0124 }
0125 #define P(x) \
0126 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
0127 (unsigned long long)(cpu_base->x))
0128 #define P_ns(x) \
0129 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
0130 (unsigned long long)(ktime_to_ns(cpu_base->x)))
0131
0132 #ifdef CONFIG_HIGH_RES_TIMERS
0133 P_ns(expires_next);
0134 P(hres_active);
0135 P(nr_events);
0136 P(nr_retries);
0137 P(nr_hangs);
0138 P(max_hang_time);
0139 #endif
0140 #undef P
0141 #undef P_ns
0142
0143 #ifdef CONFIG_TICK_ONESHOT
0144 # define P(x) \
0145 SEQ_printf(m, " .%-15s: %Lu\n", #x, \
0146 (unsigned long long)(ts->x))
0147 # define P_ns(x) \
0148 SEQ_printf(m, " .%-15s: %Lu nsecs\n", #x, \
0149 (unsigned long long)(ktime_to_ns(ts->x)))
0150 {
0151 struct tick_sched *ts = tick_get_tick_sched(cpu);
0152 P(nohz_mode);
0153 P_ns(last_tick);
0154 P(tick_stopped);
0155 P(idle_jiffies);
0156 P(idle_calls);
0157 P(idle_sleeps);
0158 P_ns(idle_entrytime);
0159 P_ns(idle_waketime);
0160 P_ns(idle_exittime);
0161 P_ns(idle_sleeptime);
0162 P_ns(iowait_sleeptime);
0163 P(last_jiffies);
0164 P(next_timer);
0165 P_ns(idle_expires);
0166 SEQ_printf(m, "jiffies: %Lu\n",
0167 (unsigned long long)jiffies);
0168 }
0169 #endif
0170
0171 #undef P
0172 #undef P_ns
0173 SEQ_printf(m, "\n");
0174 }
0175
0176 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0177 static void
0178 print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
0179 {
0180 struct clock_event_device *dev = td->evtdev;
0181
0182 touch_nmi_watchdog();
0183
0184 SEQ_printf(m, "Tick Device: mode: %d\n", td->mode);
0185 if (cpu < 0)
0186 SEQ_printf(m, "Broadcast device\n");
0187 else
0188 SEQ_printf(m, "Per CPU device: %d\n", cpu);
0189
0190 SEQ_printf(m, "Clock Event Device: ");
0191 if (!dev) {
0192 SEQ_printf(m, "<NULL>\n");
0193 return;
0194 }
0195 SEQ_printf(m, "%s\n", dev->name);
0196 SEQ_printf(m, " max_delta_ns: %llu\n",
0197 (unsigned long long) dev->max_delta_ns);
0198 SEQ_printf(m, " min_delta_ns: %llu\n",
0199 (unsigned long long) dev->min_delta_ns);
0200 SEQ_printf(m, " mult: %u\n", dev->mult);
0201 SEQ_printf(m, " shift: %u\n", dev->shift);
0202 SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
0203 SEQ_printf(m, " next_event: %Ld nsecs\n",
0204 (unsigned long long) ktime_to_ns(dev->next_event));
0205
0206 SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
0207
0208 if (dev->set_state_shutdown)
0209 SEQ_printf(m, " shutdown: %ps\n",
0210 dev->set_state_shutdown);
0211
0212 if (dev->set_state_periodic)
0213 SEQ_printf(m, " periodic: %ps\n",
0214 dev->set_state_periodic);
0215
0216 if (dev->set_state_oneshot)
0217 SEQ_printf(m, " oneshot: %ps\n",
0218 dev->set_state_oneshot);
0219
0220 if (dev->set_state_oneshot_stopped)
0221 SEQ_printf(m, " oneshot stopped: %ps\n",
0222 dev->set_state_oneshot_stopped);
0223
0224 if (dev->tick_resume)
0225 SEQ_printf(m, " resume: %ps\n",
0226 dev->tick_resume);
0227
0228 SEQ_printf(m, " event_handler: %ps\n", dev->event_handler);
0229 SEQ_printf(m, "\n");
0230 SEQ_printf(m, " retries: %lu\n", dev->retries);
0231
0232 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
0233 if (cpu >= 0) {
0234 const struct clock_event_device *wd = tick_get_wakeup_device(cpu);
0235
0236 SEQ_printf(m, "Wakeup Device: %s\n", wd ? wd->name : "<NULL>");
0237 }
0238 #endif
0239 SEQ_printf(m, "\n");
0240 }
0241
0242 static void timer_list_show_tickdevices_header(struct seq_file *m)
0243 {
0244 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
0245 print_tickdevice(m, tick_get_broadcast_device(), -1);
0246 SEQ_printf(m, "tick_broadcast_mask: %*pb\n",
0247 cpumask_pr_args(tick_get_broadcast_mask()));
0248 #ifdef CONFIG_TICK_ONESHOT
0249 SEQ_printf(m, "tick_broadcast_oneshot_mask: %*pb\n",
0250 cpumask_pr_args(tick_get_broadcast_oneshot_mask()));
0251 #endif
0252 SEQ_printf(m, "\n");
0253 #endif
0254 }
0255 #endif
0256
0257 static inline void timer_list_header(struct seq_file *m, u64 now)
0258 {
0259 SEQ_printf(m, "Timer List Version: v0.9\n");
0260 SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
0261 SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now);
0262 SEQ_printf(m, "\n");
0263 }
0264
0265 void sysrq_timer_list_show(void)
0266 {
0267 u64 now = ktime_to_ns(ktime_get());
0268 int cpu;
0269
0270 timer_list_header(NULL, now);
0271
0272 for_each_online_cpu(cpu)
0273 print_cpu(NULL, cpu, now);
0274
0275 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0276 timer_list_show_tickdevices_header(NULL);
0277 for_each_online_cpu(cpu)
0278 print_tickdevice(NULL, tick_get_device(cpu), cpu);
0279 #endif
0280 return;
0281 }
0282
0283 #ifdef CONFIG_PROC_FS
0284 static int timer_list_show(struct seq_file *m, void *v)
0285 {
0286 struct timer_list_iter *iter = v;
0287
0288 if (iter->cpu == -1 && !iter->second_pass)
0289 timer_list_header(m, iter->now);
0290 else if (!iter->second_pass)
0291 print_cpu(m, iter->cpu, iter->now);
0292 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0293 else if (iter->cpu == -1 && iter->second_pass)
0294 timer_list_show_tickdevices_header(m);
0295 else
0296 print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
0297 #endif
0298 return 0;
0299 }
0300
0301 static void *move_iter(struct timer_list_iter *iter, loff_t offset)
0302 {
0303 for (; offset; offset--) {
0304 iter->cpu = cpumask_next(iter->cpu, cpu_online_mask);
0305 if (iter->cpu >= nr_cpu_ids) {
0306 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0307 if (!iter->second_pass) {
0308 iter->cpu = -1;
0309 iter->second_pass = true;
0310 } else
0311 return NULL;
0312 #else
0313 return NULL;
0314 #endif
0315 }
0316 }
0317 return iter;
0318 }
0319
0320 static void *timer_list_start(struct seq_file *file, loff_t *offset)
0321 {
0322 struct timer_list_iter *iter = file->private;
0323
0324 if (!*offset)
0325 iter->now = ktime_to_ns(ktime_get());
0326 iter->cpu = -1;
0327 iter->second_pass = false;
0328 return move_iter(iter, *offset);
0329 }
0330
0331 static void *timer_list_next(struct seq_file *file, void *v, loff_t *offset)
0332 {
0333 struct timer_list_iter *iter = file->private;
0334 ++*offset;
0335 return move_iter(iter, 1);
0336 }
0337
0338 static void timer_list_stop(struct seq_file *seq, void *v)
0339 {
0340 }
0341
0342 static const struct seq_operations timer_list_sops = {
0343 .start = timer_list_start,
0344 .next = timer_list_next,
0345 .stop = timer_list_stop,
0346 .show = timer_list_show,
0347 };
0348
0349 static int __init init_timer_list_procfs(void)
0350 {
0351 struct proc_dir_entry *pe;
0352
0353 pe = proc_create_seq_private("timer_list", 0400, NULL, &timer_list_sops,
0354 sizeof(struct timer_list_iter), NULL);
0355 if (!pe)
0356 return -ENOMEM;
0357 return 0;
0358 }
0359 __initcall(init_timer_list_procfs);
0360 #endif