Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / kernel / rcutree_trace.c
blob3f1811333d48f1ae439cb7d4b446b00bcd94e26e
1 /*
2 * Read-Copy Update tracing for classic implementation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright IBM Corporation, 2008
20 * Papers: http://www.rdrop.com/users/paulmck/RCU
22 * For detailed explanation of Read-Copy Update mechanism see -
23 * Documentation/RCU
26 #include <linux/types.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/spinlock.h>
30 #include <linux/smp.h>
31 #include <linux/rcupdate.h>
32 #include <linux/interrupt.h>
33 #include <linux/module.h>
34 #include <linux/sched.h>
35 #include <linux/atomic.h>
36 #include <linux/bitops.h>
37 #include <linux/export.h>
38 #include <linux/completion.h>
39 #include <linux/moduleparam.h>
40 #include <linux/percpu.h>
41 #include <linux/notifier.h>
42 #include <linux/cpu.h>
43 #include <linux/mutex.h>
44 #include <linux/debugfs.h>
45 #include <linux/seq_file.h>
47 #define RCU_TREE_NONCORE
48 #include "rcutree.h"
50 #ifdef CONFIG_RCU_BOOST
52 static char convert_kthread_status(unsigned int kthread_status)
54 if (kthread_status > RCU_KTHREAD_MAX)
55 return '?';
56 return "SRWOY"[kthread_status];
59 #endif /* #ifdef CONFIG_RCU_BOOST */
61 static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
63 if (!rdp->beenonline)
64 return;
65 seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pgp=%lu qp=%d",
66 rdp->cpu,
67 cpu_is_offline(rdp->cpu) ? '!' : ' ',
68 rdp->completed, rdp->gpnum,
69 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70 rdp->qs_pending);
71 #ifdef CONFIG_NO_HZ
72 seq_printf(m, " dt=%d/%d/%d df=%lu",
73 atomic_read(&rdp->dynticks->dynticks),
74 rdp->dynticks->dynticks_nesting,
75 rdp->dynticks->dynticks_nmi_nesting,
76 rdp->dynticks_fqs);
77 #endif /* #ifdef CONFIG_NO_HZ */
78 seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
79 seq_printf(m, " ql=%ld qs=%c%c%c%c",
80 rdp->qlen,
81 ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
82 rdp->nxttail[RCU_NEXT_TAIL]],
83 ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
84 rdp->nxttail[RCU_NEXT_READY_TAIL]],
85 ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
86 rdp->nxttail[RCU_WAIT_TAIL]],
87 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
88 #ifdef CONFIG_RCU_BOOST
89 seq_printf(m, " kt=%d/%c/%d ktl=%x",
90 per_cpu(rcu_cpu_has_work, rdp->cpu),
91 convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
92 rdp->cpu)),
93 per_cpu(rcu_cpu_kthread_cpu, rdp->cpu),
94 per_cpu(rcu_cpu_kthread_loops, rdp->cpu) & 0xffff);
95 #endif /* #ifdef CONFIG_RCU_BOOST */
96 seq_printf(m, " b=%ld", rdp->blimit);
97 seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
98 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
101 #define PRINT_RCU_DATA(name, func, m) \
102 do { \
103 int _p_r_d_i; \
105 for_each_possible_cpu(_p_r_d_i) \
106 func(m, &per_cpu(name, _p_r_d_i)); \
107 } while (0)
109 static int show_rcudata(struct seq_file *m, void *unused)
111 #ifdef CONFIG_TREE_PREEMPT_RCU
112 seq_puts(m, "rcu_preempt:\n");
113 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data, m);
114 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
115 seq_puts(m, "rcu_sched:\n");
116 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m);
117 seq_puts(m, "rcu_bh:\n");
118 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
119 return 0;
122 static int rcudata_open(struct inode *inode, struct file *file)
124 return single_open(file, show_rcudata, NULL);
127 static const struct file_operations rcudata_fops = {
128 .owner = THIS_MODULE,
129 .open = rcudata_open,
130 .read = seq_read,
131 .llseek = seq_lseek,
132 .release = single_release,
135 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
137 if (!rdp->beenonline)
138 return;
139 seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
140 rdp->cpu,
141 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
142 rdp->completed, rdp->gpnum,
143 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
144 rdp->qs_pending);
145 #ifdef CONFIG_NO_HZ
146 seq_printf(m, ",%d,%d,%d,%lu",
147 atomic_read(&rdp->dynticks->dynticks),
148 rdp->dynticks->dynticks_nesting,
149 rdp->dynticks->dynticks_nmi_nesting,
150 rdp->dynticks_fqs);
151 #endif /* #ifdef CONFIG_NO_HZ */
152 seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
153 seq_printf(m, ",%ld,\"%c%c%c%c\"", rdp->qlen,
154 ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
155 rdp->nxttail[RCU_NEXT_TAIL]],
156 ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
157 rdp->nxttail[RCU_NEXT_READY_TAIL]],
158 ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
159 rdp->nxttail[RCU_WAIT_TAIL]],
160 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
161 #ifdef CONFIG_RCU_BOOST
162 seq_printf(m, ",%d,\"%c\"",
163 per_cpu(rcu_cpu_has_work, rdp->cpu),
164 convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
165 rdp->cpu)));
166 #endif /* #ifdef CONFIG_RCU_BOOST */
167 seq_printf(m, ",%ld", rdp->blimit);
168 seq_printf(m, ",%lu,%lu,%lu\n",
169 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
172 static int show_rcudata_csv(struct seq_file *m, void *unused)
174 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pgp\",\"pq\",");
175 #ifdef CONFIG_NO_HZ
176 seq_puts(m, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\",");
177 #endif /* #ifdef CONFIG_NO_HZ */
178 seq_puts(m, "\"of\",\"ri\",\"ql\",\"qs\"");
179 #ifdef CONFIG_RCU_BOOST
180 seq_puts(m, "\"kt\",\"ktl\"");
181 #endif /* #ifdef CONFIG_RCU_BOOST */
182 seq_puts(m, ",\"b\",\"ci\",\"co\",\"ca\"\n");
183 #ifdef CONFIG_TREE_PREEMPT_RCU
184 seq_puts(m, "\"rcu_preempt:\"\n");
185 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data_csv, m);
186 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
187 seq_puts(m, "\"rcu_sched:\"\n");
188 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m);
189 seq_puts(m, "\"rcu_bh:\"\n");
190 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
191 return 0;
194 static int rcudata_csv_open(struct inode *inode, struct file *file)
196 return single_open(file, show_rcudata_csv, NULL);
199 static const struct file_operations rcudata_csv_fops = {
200 .owner = THIS_MODULE,
201 .open = rcudata_csv_open,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
207 #ifdef CONFIG_RCU_BOOST
209 static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
211 seq_printf(m, "%d:%d tasks=%c%c%c%c kt=%c ntb=%lu neb=%lu nnb=%lu "
212 "j=%04x bt=%04x\n",
213 rnp->grplo, rnp->grphi,
214 "T."[list_empty(&rnp->blkd_tasks)],
215 "N."[!rnp->gp_tasks],
216 "E."[!rnp->exp_tasks],
217 "B."[!rnp->boost_tasks],
218 convert_kthread_status(rnp->boost_kthread_status),
219 rnp->n_tasks_boosted, rnp->n_exp_boosts,
220 rnp->n_normal_boosts,
221 (int)(jiffies & 0xffff),
222 (int)(rnp->boost_time & 0xffff));
223 seq_printf(m, "%s: nt=%lu egt=%lu bt=%lu nb=%lu ny=%lu nos=%lu\n",
224 " balk",
225 rnp->n_balk_blkd_tasks,
226 rnp->n_balk_exp_gp_tasks,
227 rnp->n_balk_boost_tasks,
228 rnp->n_balk_notblocked,
229 rnp->n_balk_notyet,
230 rnp->n_balk_nos);
233 static int show_rcu_node_boost(struct seq_file *m, void *unused)
235 struct rcu_node *rnp;
237 rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
238 print_one_rcu_node_boost(m, rnp);
239 return 0;
242 static int rcu_node_boost_open(struct inode *inode, struct file *file)
244 return single_open(file, show_rcu_node_boost, NULL);
247 static const struct file_operations rcu_node_boost_fops = {
248 .owner = THIS_MODULE,
249 .open = rcu_node_boost_open,
250 .read = seq_read,
251 .llseek = seq_lseek,
252 .release = single_release,
256 * Create the rcuboost debugfs entry. Standard error return.
258 static int rcu_boost_trace_create_file(struct dentry *rcudir)
260 return !debugfs_create_file("rcuboost", 0444, rcudir, NULL,
261 &rcu_node_boost_fops);
264 #else /* #ifdef CONFIG_RCU_BOOST */
266 static int rcu_boost_trace_create_file(struct dentry *rcudir)
268 return 0; /* There cannot be an error if we didn't create it! */
271 #endif /* #else #ifdef CONFIG_RCU_BOOST */
273 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
275 unsigned long gpnum;
276 int level = 0;
277 struct rcu_node *rnp;
279 gpnum = rsp->gpnum;
280 seq_printf(m, "c=%lu g=%lu s=%d jfq=%ld j=%x "
281 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
282 rsp->completed, gpnum, rsp->signaled,
283 (long)(rsp->jiffies_force_qs - jiffies),
284 (int)(jiffies & 0xffff),
285 rsp->n_force_qs, rsp->n_force_qs_ngp,
286 rsp->n_force_qs - rsp->n_force_qs_ngp,
287 rsp->n_force_qs_lh);
288 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
289 if (rnp->level != level) {
290 seq_puts(m, "\n");
291 level = rnp->level;
293 seq_printf(m, "%lx/%lx %c%c>%c %d:%d ^%d ",
294 rnp->qsmask, rnp->qsmaskinit,
295 ".G"[rnp->gp_tasks != NULL],
296 ".E"[rnp->exp_tasks != NULL],
297 ".T"[!list_empty(&rnp->blkd_tasks)],
298 rnp->grplo, rnp->grphi, rnp->grpnum);
300 seq_puts(m, "\n");
303 static int show_rcuhier(struct seq_file *m, void *unused)
305 #ifdef CONFIG_TREE_PREEMPT_RCU
306 seq_puts(m, "rcu_preempt:\n");
307 print_one_rcu_state(m, &rcu_preempt_state);
308 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
309 seq_puts(m, "rcu_sched:\n");
310 print_one_rcu_state(m, &rcu_sched_state);
311 seq_puts(m, "rcu_bh:\n");
312 print_one_rcu_state(m, &rcu_bh_state);
313 return 0;
316 static int rcuhier_open(struct inode *inode, struct file *file)
318 return single_open(file, show_rcuhier, NULL);
321 static const struct file_operations rcuhier_fops = {
322 .owner = THIS_MODULE,
323 .open = rcuhier_open,
324 .read = seq_read,
325 .llseek = seq_lseek,
326 .release = single_release,
329 static void show_one_rcugp(struct seq_file *m, struct rcu_state *rsp)
331 unsigned long flags;
332 unsigned long completed;
333 unsigned long gpnum;
334 unsigned long gpage;
335 unsigned long gpmax;
336 struct rcu_node *rnp = &rsp->node[0];
338 raw_spin_lock_irqsave(&rnp->lock, flags);
339 completed = rsp->completed;
340 gpnum = rsp->gpnum;
341 if (rsp->completed == rsp->gpnum)
342 gpage = 0;
343 else
344 gpage = jiffies - rsp->gp_start;
345 gpmax = rsp->gp_max;
346 raw_spin_unlock_irqrestore(&rnp->lock, flags);
347 seq_printf(m, "%s: completed=%ld gpnum=%lu age=%ld max=%ld\n",
348 rsp->name, completed, gpnum, gpage, gpmax);
351 static int show_rcugp(struct seq_file *m, void *unused)
353 #ifdef CONFIG_TREE_PREEMPT_RCU
354 show_one_rcugp(m, &rcu_preempt_state);
355 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
356 show_one_rcugp(m, &rcu_sched_state);
357 show_one_rcugp(m, &rcu_bh_state);
358 return 0;
361 static int rcugp_open(struct inode *inode, struct file *file)
363 return single_open(file, show_rcugp, NULL);
366 static const struct file_operations rcugp_fops = {
367 .owner = THIS_MODULE,
368 .open = rcugp_open,
369 .read = seq_read,
370 .llseek = seq_lseek,
371 .release = single_release,
374 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
376 seq_printf(m, "%3d%cnp=%ld "
377 "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
378 "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
379 rdp->cpu,
380 cpu_is_offline(rdp->cpu) ? '!' : ' ',
381 rdp->n_rcu_pending,
382 rdp->n_rp_qs_pending,
383 rdp->n_rp_report_qs,
384 rdp->n_rp_cb_ready,
385 rdp->n_rp_cpu_needs_gp,
386 rdp->n_rp_gp_completed,
387 rdp->n_rp_gp_started,
388 rdp->n_rp_need_fqs,
389 rdp->n_rp_need_nothing);
392 static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
394 int cpu;
395 struct rcu_data *rdp;
397 for_each_possible_cpu(cpu) {
398 rdp = per_cpu_ptr(rsp->rda, cpu);
399 if (rdp->beenonline)
400 print_one_rcu_pending(m, rdp);
404 static int show_rcu_pending(struct seq_file *m, void *unused)
406 #ifdef CONFIG_TREE_PREEMPT_RCU
407 seq_puts(m, "rcu_preempt:\n");
408 print_rcu_pendings(m, &rcu_preempt_state);
409 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
410 seq_puts(m, "rcu_sched:\n");
411 print_rcu_pendings(m, &rcu_sched_state);
412 seq_puts(m, "rcu_bh:\n");
413 print_rcu_pendings(m, &rcu_bh_state);
414 return 0;
417 static int rcu_pending_open(struct inode *inode, struct file *file)
419 return single_open(file, show_rcu_pending, NULL);
422 static const struct file_operations rcu_pending_fops = {
423 .owner = THIS_MODULE,
424 .open = rcu_pending_open,
425 .read = seq_read,
426 .llseek = seq_lseek,
427 .release = single_release,
430 static int show_rcutorture(struct seq_file *m, void *unused)
432 seq_printf(m, "rcutorture test sequence: %lu %s\n",
433 rcutorture_testseq >> 1,
434 (rcutorture_testseq & 0x1) ? "(test in progress)" : "");
435 seq_printf(m, "rcutorture update version number: %lu\n",
436 rcutorture_vernum);
437 return 0;
440 static int rcutorture_open(struct inode *inode, struct file *file)
442 return single_open(file, show_rcutorture, NULL);
445 static const struct file_operations rcutorture_fops = {
446 .owner = THIS_MODULE,
447 .open = rcutorture_open,
448 .read = seq_read,
449 .llseek = seq_lseek,
450 .release = single_release,
453 static struct dentry *rcudir;
455 static int __init rcutree_trace_init(void)
457 struct dentry *retval;
459 rcudir = debugfs_create_dir("rcu", NULL);
460 if (!rcudir)
461 goto free_out;
463 retval = debugfs_create_file("rcudata", 0444, rcudir,
464 NULL, &rcudata_fops);
465 if (!retval)
466 goto free_out;
468 retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
469 NULL, &rcudata_csv_fops);
470 if (!retval)
471 goto free_out;
473 if (rcu_boost_trace_create_file(rcudir))
474 goto free_out;
476 retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
477 if (!retval)
478 goto free_out;
480 retval = debugfs_create_file("rcuhier", 0444, rcudir,
481 NULL, &rcuhier_fops);
482 if (!retval)
483 goto free_out;
485 retval = debugfs_create_file("rcu_pending", 0444, rcudir,
486 NULL, &rcu_pending_fops);
487 if (!retval)
488 goto free_out;
490 retval = debugfs_create_file("rcutorture", 0444, rcudir,
491 NULL, &rcutorture_fops);
492 if (!retval)
493 goto free_out;
494 return 0;
495 free_out:
496 debugfs_remove_recursive(rcudir);
497 return 1;
500 static void __exit rcutree_trace_cleanup(void)
502 debugfs_remove_recursive(rcudir);
506 module_init(rcutree_trace_init);
507 module_exit(rcutree_trace_cleanup);
509 MODULE_AUTHOR("Paul E. McKenney");
510 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
511 MODULE_LICENSE("GPL");