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 -
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/sched.h>
34 #include <asm/atomic.h>
35 #include <linux/bitops.h>
36 #include <linux/module.h>
37 #include <linux/completion.h>
38 #include <linux/moduleparam.h>
39 #include <linux/percpu.h>
40 #include <linux/notifier.h>
41 #include <linux/cpu.h>
42 #include <linux/mutex.h>
43 #include <linux/debugfs.h>
44 #include <linux/seq_file.h>
46 #define RCU_TREE_NONCORE
49 static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
53 seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
55 cpu_is_offline(rdp->cpu) ? '!' : ' ',
56 rdp->completed, rdp->gpnum,
57 rdp->passed_quiesc, rdp->passed_quiesc_completed,
60 seq_printf(m, " dt=%d/%d dn=%d df=%lu",
61 rdp->dynticks->dynticks,
62 rdp->dynticks->dynticks_nesting,
63 rdp->dynticks->dynticks_nmi,
65 #endif /* #ifdef CONFIG_NO_HZ */
66 seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
67 seq_printf(m, " ql=%ld b=%ld", rdp->qlen, rdp->blimit);
68 seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
69 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
72 #define PRINT_RCU_DATA(name, func, m) \
76 for_each_possible_cpu(_p_r_d_i) \
77 func(m, &per_cpu(name, _p_r_d_i)); \
80 static int show_rcudata(struct seq_file *m, void *unused)
82 #ifdef CONFIG_TREE_PREEMPT_RCU
83 seq_puts(m, "rcu_preempt:\n");
84 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data, m);
85 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
86 seq_puts(m, "rcu_sched:\n");
87 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m);
88 seq_puts(m, "rcu_bh:\n");
89 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
93 static int rcudata_open(struct inode *inode, struct file *file)
95 return single_open(file, show_rcudata, NULL);
98 static const struct file_operations rcudata_fops = {
100 .open = rcudata_open,
103 .release = single_release,
106 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
108 if (!rdp->beenonline)
110 seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
112 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
113 rdp->completed, rdp->gpnum,
114 rdp->passed_quiesc, rdp->passed_quiesc_completed,
117 seq_printf(m, ",%d,%d,%d,%lu",
118 rdp->dynticks->dynticks,
119 rdp->dynticks->dynticks_nesting,
120 rdp->dynticks->dynticks_nmi,
122 #endif /* #ifdef CONFIG_NO_HZ */
123 seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
124 seq_printf(m, ",%ld,%ld", rdp->qlen, rdp->blimit);
125 seq_printf(m, ",%lu,%lu,%lu\n",
126 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
129 static int show_rcudata_csv(struct seq_file *m, void *unused)
131 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
133 seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\",");
134 #endif /* #ifdef CONFIG_NO_HZ */
135 seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\",\"ci\",\"co\",\"ca\"\n");
136 #ifdef CONFIG_TREE_PREEMPT_RCU
137 seq_puts(m, "\"rcu_preempt:\"\n");
138 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data_csv, m);
139 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
140 seq_puts(m, "\"rcu_sched:\"\n");
141 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m);
142 seq_puts(m, "\"rcu_bh:\"\n");
143 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
147 static int rcudata_csv_open(struct inode *inode, struct file *file)
149 return single_open(file, show_rcudata_csv, NULL);
152 static const struct file_operations rcudata_csv_fops = {
153 .owner = THIS_MODULE,
154 .open = rcudata_csv_open,
157 .release = single_release,
160 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
165 struct rcu_node *rnp;
168 seq_printf(m, "c=%lu g=%lu s=%d jfq=%ld j=%x "
169 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld\n",
170 rsp->completed, gpnum, rsp->signaled,
171 (long)(rsp->jiffies_force_qs - jiffies),
172 (int)(jiffies & 0xffff),
173 rsp->n_force_qs, rsp->n_force_qs_ngp,
174 rsp->n_force_qs - rsp->n_force_qs_ngp,
175 rsp->n_force_qs_lh, rsp->orphan_qlen);
176 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
177 if (rnp->level != level) {
182 seq_printf(m, "%lx/%lx %c%c>%c%c %d:%d ^%d ",
183 rnp->qsmask, rnp->qsmaskinit,
184 "T."[list_empty(&rnp->blocked_tasks[phase])],
185 "E."[list_empty(&rnp->blocked_tasks[phase + 2])],
186 "T."[list_empty(&rnp->blocked_tasks[!phase])],
187 "E."[list_empty(&rnp->blocked_tasks[!phase + 2])],
188 rnp->grplo, rnp->grphi, rnp->grpnum);
193 static int show_rcuhier(struct seq_file *m, void *unused)
195 #ifdef CONFIG_TREE_PREEMPT_RCU
196 seq_puts(m, "rcu_preempt:\n");
197 print_one_rcu_state(m, &rcu_preempt_state);
198 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
199 seq_puts(m, "rcu_sched:\n");
200 print_one_rcu_state(m, &rcu_sched_state);
201 seq_puts(m, "rcu_bh:\n");
202 print_one_rcu_state(m, &rcu_bh_state);
206 static int rcuhier_open(struct inode *inode, struct file *file)
208 return single_open(file, show_rcuhier, NULL);
211 static const struct file_operations rcuhier_fops = {
212 .owner = THIS_MODULE,
213 .open = rcuhier_open,
216 .release = single_release,
219 static int show_rcugp(struct seq_file *m, void *unused)
221 #ifdef CONFIG_TREE_PREEMPT_RCU
222 seq_printf(m, "rcu_preempt: completed=%ld gpnum=%lu\n",
223 rcu_preempt_state.completed, rcu_preempt_state.gpnum);
224 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
225 seq_printf(m, "rcu_sched: completed=%ld gpnum=%lu\n",
226 rcu_sched_state.completed, rcu_sched_state.gpnum);
227 seq_printf(m, "rcu_bh: completed=%ld gpnum=%lu\n",
228 rcu_bh_state.completed, rcu_bh_state.gpnum);
232 static int rcugp_open(struct inode *inode, struct file *file)
234 return single_open(file, show_rcugp, NULL);
237 static const struct file_operations rcugp_fops = {
238 .owner = THIS_MODULE,
242 .release = single_release,
245 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
247 seq_printf(m, "%3d%cnp=%ld "
248 "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
249 "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
251 cpu_is_offline(rdp->cpu) ? '!' : ' ',
253 rdp->n_rp_qs_pending,
256 rdp->n_rp_cpu_needs_gp,
257 rdp->n_rp_gp_completed,
258 rdp->n_rp_gp_started,
260 rdp->n_rp_need_nothing);
263 static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
266 struct rcu_data *rdp;
268 for_each_possible_cpu(cpu) {
269 rdp = per_cpu_ptr(rsp->rda, cpu);
271 print_one_rcu_pending(m, rdp);
275 static int show_rcu_pending(struct seq_file *m, void *unused)
277 #ifdef CONFIG_TREE_PREEMPT_RCU
278 seq_puts(m, "rcu_preempt:\n");
279 print_rcu_pendings(m, &rcu_preempt_state);
280 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
281 seq_puts(m, "rcu_sched:\n");
282 print_rcu_pendings(m, &rcu_sched_state);
283 seq_puts(m, "rcu_bh:\n");
284 print_rcu_pendings(m, &rcu_bh_state);
288 static int rcu_pending_open(struct inode *inode, struct file *file)
290 return single_open(file, show_rcu_pending, NULL);
293 static const struct file_operations rcu_pending_fops = {
294 .owner = THIS_MODULE,
295 .open = rcu_pending_open,
298 .release = single_release,
301 static struct dentry *rcudir;
303 static int __init rcuclassic_trace_init(void)
305 struct dentry *retval;
307 rcudir = debugfs_create_dir("rcu", NULL);
311 retval = debugfs_create_file("rcudata", 0444, rcudir,
312 NULL, &rcudata_fops);
316 retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
317 NULL, &rcudata_csv_fops);
321 retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
325 retval = debugfs_create_file("rcuhier", 0444, rcudir,
326 NULL, &rcuhier_fops);
330 retval = debugfs_create_file("rcu_pending", 0444, rcudir,
331 NULL, &rcu_pending_fops);
336 debugfs_remove_recursive(rcudir);
340 static void __exit rcuclassic_trace_cleanup(void)
342 debugfs_remove_recursive(rcudir);
346 module_init(rcuclassic_trace_init);
347 module_exit(rcuclassic_trace_cleanup);
349 MODULE_AUTHOR("Paul E. McKenney");
350 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
351 MODULE_LICENSE("GPL");