Blame view

kernel/time/timer_list.c 7.49 KB
289f480af   Ingo Molnar   [PATCH] Add debug...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  /*
   * kernel/time/timer_list.c
   *
   * List pending timers
   *
   * Copyright(C) 2006, Red Hat, Inc., Ingo Molnar
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #include <linux/proc_fs.h>
  #include <linux/module.h>
  #include <linux/spinlock.h>
  #include <linux/sched.h>
  #include <linux/seq_file.h>
  #include <linux/kallsyms.h>
  #include <linux/tick.h>
  
  #include <asm/uaccess.h>
  
  typedef void (*print_fn_t)(struct seq_file *m, unsigned int *classes);
  
  DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
  
  /*
   * This allows printing both to /proc/timer_list and
   * to the console (on SysRq-Q):
   */
  #define SEQ_printf(m, x...)			\
   do {						\
  	if (m)					\
  		seq_printf(m, x);		\
  	else					\
  		printk(x);			\
   } while (0)
  
  static void print_name_offset(struct seq_file *m, void *sym)
  {
9281acea6   Tejun Heo   kallsyms: make KS...
41
  	char symname[KSYM_NAME_LEN];
289f480af   Ingo Molnar   [PATCH] Add debug...
42

9d65cb4a1   Alexey Dobriyan   Fix race between ...
43
  	if (lookup_symbol_name((unsigned long)sym, symname) < 0)
f59030853   Kees Cook   timer debug: Hide...
44
  		SEQ_printf(m, "<%pK>", sym);
9d65cb4a1   Alexey Dobriyan   Fix race between ...
45
46
  	else
  		SEQ_printf(m, "%s", symname);
289f480af   Ingo Molnar   [PATCH] Add debug...
47
48
49
  }
  
  static void
e67ef25a3   Thomas Gleixner   timer_list: print...
50
51
  print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
  	    int idx, u64 now)
289f480af   Ingo Molnar   [PATCH] Add debug...
52
53
54
55
56
  {
  #ifdef CONFIG_TIMER_STATS
  	char tmp[TASK_COMM_LEN + 1];
  #endif
  	SEQ_printf(m, " #%d: ", idx);
e67ef25a3   Thomas Gleixner   timer_list: print...
57
  	print_name_offset(m, taddr);
289f480af   Ingo Molnar   [PATCH] Add debug...
58
59
60
61
62
63
64
65
66
67
68
69
  	SEQ_printf(m, ", ");
  	print_name_offset(m, timer->function);
  	SEQ_printf(m, ", S:%02lx", timer->state);
  #ifdef CONFIG_TIMER_STATS
  	SEQ_printf(m, ", ");
  	print_name_offset(m, timer->start_site);
  	memcpy(tmp, timer->start_comm, TASK_COMM_LEN);
  	tmp[TASK_COMM_LEN] = 0;
  	SEQ_printf(m, ", %s/%d", tmp, timer->start_pid);
  #endif
  	SEQ_printf(m, "
  ");
704af52bd   Arjan van de Ven   hrtimer: show the...
70
71
72
  	SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]
  ",
  		(unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
cc584b213   Arjan van de Ven   hrtimer: convert ...
73
  		(unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
704af52bd   Arjan van de Ven   hrtimer: show the...
74
  		(long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
cc584b213   Arjan van de Ven   hrtimer: convert ...
75
  		(long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
289f480af   Ingo Molnar   [PATCH] Add debug...
76
77
78
79
80
81
82
83
  }
  
  static void
  print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
  		    u64 now)
  {
  	struct hrtimer *timer, tmp;
  	unsigned long next = 0, i;
998adc3dd   John Stultz   hrtimers: Convert...
84
  	struct timerqueue_node *curr;
289f480af   Ingo Molnar   [PATCH] Add debug...
85
86
87
88
  	unsigned long flags;
  
  next_one:
  	i = 0;
ecb49d1a6   Thomas Gleixner   hrtimers: Convert...
89
  	raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
289f480af   Ingo Molnar   [PATCH] Add debug...
90

998adc3dd   John Stultz   hrtimers: Convert...
91
  	curr = timerqueue_getnext(&base->active);
289f480af   Ingo Molnar   [PATCH] Add debug...
92
93
94
95
96
  	/*
  	 * Crude but we have to do this O(N*N) thing, because
  	 * we have to unlock the base when printing:
  	 */
  	while (curr && i < next) {
998adc3dd   John Stultz   hrtimers: Convert...
97
  		curr = timerqueue_iterate_next(curr);
289f480af   Ingo Molnar   [PATCH] Add debug...
98
99
100
101
  		i++;
  	}
  
  	if (curr) {
998adc3dd   John Stultz   hrtimers: Convert...
102
  		timer = container_of(curr, struct hrtimer, node);
289f480af   Ingo Molnar   [PATCH] Add debug...
103
  		tmp = *timer;
ecb49d1a6   Thomas Gleixner   hrtimers: Convert...
104
  		raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
289f480af   Ingo Molnar   [PATCH] Add debug...
105

e67ef25a3   Thomas Gleixner   timer_list: print...
106
  		print_timer(m, timer, &tmp, i, now);
289f480af   Ingo Molnar   [PATCH] Add debug...
107
108
109
  		next++;
  		goto next_one;
  	}
ecb49d1a6   Thomas Gleixner   hrtimers: Convert...
110
  	raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
289f480af   Ingo Molnar   [PATCH] Add debug...
111
112
113
114
115
  }
  
  static void
  print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
  {
f59030853   Kees Cook   timer debug: Hide...
116
117
  	SEQ_printf(m, "  .base:       %pK
  ", base);
289f480af   Ingo Molnar   [PATCH] Add debug...
118
119
120
  	SEQ_printf(m, "  .index:      %d
  ",
  			base->index);
9b04bd275   David Miller   Fix printk format...
121
122
  	SEQ_printf(m, "  .resolution: %Lu nsecs
  ",
289f480af   Ingo Molnar   [PATCH] Add debug...
123
124
125
126
127
128
  			(unsigned long long)ktime_to_ns(base->resolution));
  	SEQ_printf(m,   "  .get_time:   ");
  	print_name_offset(m, base->get_time);
  	SEQ_printf(m,   "
  ");
  #ifdef CONFIG_HIGH_RES_TIMERS
9b04bd275   David Miller   Fix printk format...
129
130
131
  	SEQ_printf(m, "  .offset:     %Lu nsecs
  ",
  		   (unsigned long long) ktime_to_ns(base->offset));
289f480af   Ingo Molnar   [PATCH] Add debug...
132
133
134
135
136
137
138
139
140
141
  #endif
  	SEQ_printf(m,   "active timers:
  ");
  	print_active_timers(m, base, now);
  }
  
  static void print_cpu(struct seq_file *m, int cpu, u64 now)
  {
  	struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
  	int i;
129f1d2c5   Vegard Nossum   timer_list: Fix p...
142
143
144
145
  	SEQ_printf(m, "
  ");
  	SEQ_printf(m, "cpu: %d
  ", cpu);
289f480af   Ingo Molnar   [PATCH] Add debug...
146
147
148
149
150
151
  	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  		SEQ_printf(m, " clock %d:
  ", i);
  		print_base(m, cpu_base->clock_base + i, now);
  	}
  #define P(x) \
9b04bd275   David Miller   Fix printk format...
152
153
154
  	SEQ_printf(m, "  .%-15s: %Lu
  ", #x, \
  		   (unsigned long long)(cpu_base->x))
289f480af   Ingo Molnar   [PATCH] Add debug...
155
  #define P_ns(x) \
9b04bd275   David Miller   Fix printk format...
156
157
158
  	SEQ_printf(m, "  .%-15s: %Lu nsecs
  ", #x, \
  		   (unsigned long long)(ktime_to_ns(cpu_base->x)))
289f480af   Ingo Molnar   [PATCH] Add debug...
159
160
161
162
163
  
  #ifdef CONFIG_HIGH_RES_TIMERS
  	P_ns(expires_next);
  	P(hres_active);
  	P(nr_events);
41d2e4949   Thomas Gleixner   hrtimer: Tune hrt...
164
165
166
  	P(nr_retries);
  	P(nr_hangs);
  	P_ns(max_hang_time);
289f480af   Ingo Molnar   [PATCH] Add debug...
167
168
169
170
171
172
  #endif
  #undef P
  #undef P_ns
  
  #ifdef CONFIG_TICK_ONESHOT
  # define P(x) \
9b04bd275   David Miller   Fix printk format...
173
174
175
  	SEQ_printf(m, "  .%-15s: %Lu
  ", #x, \
  		   (unsigned long long)(ts->x))
289f480af   Ingo Molnar   [PATCH] Add debug...
176
  # define P_ns(x) \
9b04bd275   David Miller   Fix printk format...
177
178
179
  	SEQ_printf(m, "  .%-15s: %Lu nsecs
  ", #x, \
  		   (unsigned long long)(ktime_to_ns(ts->x)))
289f480af   Ingo Molnar   [PATCH] Add debug...
180
181
182
183
184
185
186
187
188
  	{
  		struct tick_sched *ts = tick_get_tick_sched(cpu);
  		P(nohz_mode);
  		P_ns(idle_tick);
  		P(tick_stopped);
  		P(idle_jiffies);
  		P(idle_calls);
  		P(idle_sleeps);
  		P_ns(idle_entrytime);
5df7fa1c6   Thomas Gleixner   tick-sched: add m...
189
190
  		P_ns(idle_waketime);
  		P_ns(idle_exittime);
289f480af   Ingo Molnar   [PATCH] Add debug...
191
  		P_ns(idle_sleeptime);
0224cf4c5   Arjan van de Ven   sched: Intoduce g...
192
  		P_ns(iowait_sleeptime);
289f480af   Ingo Molnar   [PATCH] Add debug...
193
194
195
  		P(last_jiffies);
  		P(next_jiffies);
  		P_ns(idle_expires);
9b04bd275   David Miller   Fix printk format...
196
197
198
  		SEQ_printf(m, "jiffies: %Lu
  ",
  			   (unsigned long long)jiffies);
289f480af   Ingo Molnar   [PATCH] Add debug...
199
200
201
202
203
204
205
206
207
  	}
  #endif
  
  #undef P
  #undef P_ns
  }
  
  #ifdef CONFIG_GENERIC_CLOCKEVENTS
  static void
c5b77a3d3   Thomas Gleixner   timer_list: print...
208
  print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
289f480af   Ingo Molnar   [PATCH] Add debug...
209
210
  {
  	struct clock_event_device *dev = td->evtdev;
129f1d2c5   Vegard Nossum   timer_list: Fix p...
211
212
213
214
  	SEQ_printf(m, "
  ");
  	SEQ_printf(m, "Tick Device: mode:     %d
  ", td->mode);
c5b77a3d3   Thomas Gleixner   timer_list: print...
215
216
217
218
219
220
  	if (cpu < 0)
  		SEQ_printf(m, "Broadcast device
  ");
  	else
  		SEQ_printf(m, "Per CPU device: %d
  ", cpu);
289f480af   Ingo Molnar   [PATCH] Add debug...
221
222
223
224
225
226
227
228
229
  
  	SEQ_printf(m, "Clock Event Device: ");
  	if (!dev) {
  		SEQ_printf(m, "<NULL>
  ");
  		return;
  	}
  	SEQ_printf(m, "%s
  ", dev->name);
97813f2fe   Jon Hunter   nohz: Allow 32-bi...
230
231
232
233
234
235
  	SEQ_printf(m, " max_delta_ns:   %llu
  ",
  		   (unsigned long long) dev->max_delta_ns);
  	SEQ_printf(m, " min_delta_ns:   %llu
  ",
  		   (unsigned long long) dev->min_delta_ns);
23af368e9   Thomas Gleixner   clockevents: Use ...
236
237
238
239
  	SEQ_printf(m, " mult:           %u
  ", dev->mult);
  	SEQ_printf(m, " shift:          %u
  ", dev->shift);
289f480af   Ingo Molnar   [PATCH] Add debug...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  	SEQ_printf(m, " mode:           %d
  ", dev->mode);
  	SEQ_printf(m, " next_event:     %Ld nsecs
  ",
  		   (unsigned long long) ktime_to_ns(dev->next_event));
  
  	SEQ_printf(m, " set_next_event: ");
  	print_name_offset(m, dev->set_next_event);
  	SEQ_printf(m, "
  ");
  
  	SEQ_printf(m, " set_mode:       ");
  	print_name_offset(m, dev->set_mode);
  	SEQ_printf(m, "
  ");
  
  	SEQ_printf(m, " event_handler:  ");
  	print_name_offset(m, dev->event_handler);
  	SEQ_printf(m, "
  ");
80a05b9ff   Thomas Gleixner   clockevents: Sani...
260
261
  	SEQ_printf(m, " retries:        %lu
  ", dev->retries);
289f480af   Ingo Molnar   [PATCH] Add debug...
262
263
264
265
266
267
268
  }
  
  static void timer_list_show_tickdevices(struct seq_file *m)
  {
  	int cpu;
  
  #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
c5b77a3d3   Thomas Gleixner   timer_list: print...
269
  	print_tickdevice(m, tick_get_broadcast_device(), -1);
289f480af   Ingo Molnar   [PATCH] Add debug...
270
271
  	SEQ_printf(m, "tick_broadcast_mask: %08lx
  ",
62ac12795   Rusty Russell   cpumask: avoid de...
272
  		   cpumask_bits(tick_get_broadcast_mask())[0]);
289f480af   Ingo Molnar   [PATCH] Add debug...
273
274
275
  #ifdef CONFIG_TICK_ONESHOT
  	SEQ_printf(m, "tick_broadcast_oneshot_mask: %08lx
  ",
62ac12795   Rusty Russell   cpumask: avoid de...
276
  		   cpumask_bits(tick_get_broadcast_oneshot_mask())[0]);
289f480af   Ingo Molnar   [PATCH] Add debug...
277
278
279
280
281
  #endif
  	SEQ_printf(m, "
  ");
  #endif
  	for_each_online_cpu(cpu)
c5b77a3d3   Thomas Gleixner   timer_list: print...
282
  		print_tickdevice(m, tick_get_device(cpu), cpu);
289f480af   Ingo Molnar   [PATCH] Add debug...
283
284
285
286
287
288
289
290
291
292
293
  	SEQ_printf(m, "
  ");
  }
  #else
  static void timer_list_show_tickdevices(struct seq_file *m) { }
  #endif
  
  static int timer_list_show(struct seq_file *m, void *v)
  {
  	u64 now = ktime_to_ns(ktime_get());
  	int cpu;
80a05b9ff   Thomas Gleixner   clockevents: Sani...
294
295
  	SEQ_printf(m, "Timer List Version: v0.6
  ");
289f480af   Ingo Molnar   [PATCH] Add debug...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
  	SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d
  ", HRTIMER_MAX_CLOCK_BASES);
  	SEQ_printf(m, "now at %Ld nsecs
  ", (unsigned long long)now);
  
  	for_each_online_cpu(cpu)
  		print_cpu(m, cpu, now);
  
  	SEQ_printf(m, "
  ");
  	timer_list_show_tickdevices(m);
  
  	return 0;
  }
  
  void sysrq_timer_list_show(void)
  {
  	timer_list_show(NULL, NULL);
  }
  
  static int timer_list_open(struct inode *inode, struct file *filp)
  {
  	return single_open(filp, timer_list_show, NULL);
  }
828c09509   Alexey Dobriyan   const: constify r...
320
  static const struct file_operations timer_list_fops = {
289f480af   Ingo Molnar   [PATCH] Add debug...
321
322
323
  	.open		= timer_list_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
5ea473a1d   Alexey Dobriyan   Fix leaks on /pro...
324
  	.release	= single_release,
289f480af   Ingo Molnar   [PATCH] Add debug...
325
326
327
328
329
  };
  
  static int __init init_timer_list_procfs(void)
  {
  	struct proc_dir_entry *pe;
de809347a   Amerigo Wang   timers: Drop writ...
330
  	pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
289f480af   Ingo Molnar   [PATCH] Add debug...
331
332
  	if (!pe)
  		return -ENOMEM;
289f480af   Ingo Molnar   [PATCH] Add debug...
333
334
335
  	return 0;
  }
  __initcall(init_timer_list_procfs);