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/%d df=%lu",
61 atomic_read(&rdp->dynticks->dynticks),
62 rdp->dynticks->dynticks_nesting,
63 rdp->dynticks->dynticks_nmi_nesting,
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 qs=%c%c%c%c b=%ld",
69 ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
70 rdp->nxttail[RCU_NEXT_TAIL]],
71 ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
72 rdp->nxttail[RCU_NEXT_READY_TAIL]],
73 ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
74 rdp->nxttail[RCU_WAIT_TAIL]],
75 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]],
77 seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
78 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
81 #define PRINT_RCU_DATA(name, func, m) \
85 for_each_possible_cpu(_p_r_d_i) \
86 func(m, &per_cpu(name, _p_r_d_i)); \
89 static int show_rcudata(struct seq_file *m, void *unused)
91 #ifdef CONFIG_TREE_PREEMPT_RCU
92 seq_puts(m, "rcu_preempt:\n");
93 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data, m);
94 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
95 seq_puts(m, "rcu_sched:\n");
96 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m);
97 seq_puts(m, "rcu_bh:\n");
98 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
102 static int rcudata_open(struct inode *inode, struct file *file)
104 return single_open(file, show_rcudata, NULL);
107 static const struct file_operations rcudata_fops = {
108 .owner = THIS_MODULE,
109 .open = rcudata_open,
112 .release = single_release,
115 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
117 if (!rdp->beenonline)
119 seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
121 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
122 rdp->completed, rdp->gpnum,
123 rdp->passed_quiesc, rdp->passed_quiesc_completed,
126 seq_printf(m, ",%d,%d,%d,%lu",
127 atomic_read(&rdp->dynticks->dynticks),
128 rdp->dynticks->dynticks_nesting,
129 rdp->dynticks->dynticks_nmi_nesting,
131 #endif /* #ifdef CONFIG_NO_HZ */
132 seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
133 seq_printf(m, ",%ld,\"%c%c%c%c\",%ld", rdp->qlen,
134 ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
135 rdp->nxttail[RCU_NEXT_TAIL]],
136 ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
137 rdp->nxttail[RCU_NEXT_READY_TAIL]],
138 ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
139 rdp->nxttail[RCU_WAIT_TAIL]],
140 ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]],
142 seq_printf(m, ",%lu,%lu,%lu\n",
143 rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
146 static int show_rcudata_csv(struct seq_file *m, void *unused)
148 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
150 seq_puts(m, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\",");
151 #endif /* #ifdef CONFIG_NO_HZ */
152 seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\",\"ci\",\"co\",\"ca\"\n");
153 #ifdef CONFIG_TREE_PREEMPT_RCU
154 seq_puts(m, "\"rcu_preempt:\"\n");
155 PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data_csv, m);
156 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
157 seq_puts(m, "\"rcu_sched:\"\n");
158 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m);
159 seq_puts(m, "\"rcu_bh:\"\n");
160 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
164 static int rcudata_csv_open(struct inode *inode, struct file *file)
166 return single_open(file, show_rcudata_csv, NULL);
169 static const struct file_operations rcudata_csv_fops = {
170 .owner = THIS_MODULE,
171 .open = rcudata_csv_open,
174 .release = single_release,
177 #ifdef CONFIG_RCU_BOOST
179 static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
181 seq_printf(m, "%d:%d tasks=%c%c%c%c ntb=%lu neb=%lu nnb=%lu "
183 rnp->grplo, rnp->grphi,
184 "T."[list_empty(&rnp->blkd_tasks)],
185 "N."[!rnp->gp_tasks],
186 "E."[!rnp->exp_tasks],
187 "B."[!rnp->boost_tasks],
188 rnp->n_tasks_boosted, rnp->n_exp_boosts,
189 rnp->n_normal_boosts,
190 (int)(jiffies & 0xffff),
191 (int)(rnp->boost_time & 0xffff));
192 seq_printf(m, "%s: nt=%lu egt=%lu bt=%lu nb=%lu ny=%lu nos=%lu\n",
194 rnp->n_balk_blkd_tasks,
195 rnp->n_balk_exp_gp_tasks,
196 rnp->n_balk_boost_tasks,
197 rnp->n_balk_notblocked,
202 static int show_rcu_node_boost(struct seq_file *m, void *unused)
204 struct rcu_node *rnp;
206 rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
207 print_one_rcu_node_boost(m, rnp);
211 static int rcu_node_boost_open(struct inode *inode, struct file *file)
213 return single_open(file, show_rcu_node_boost, NULL);
216 static const struct file_operations rcu_node_boost_fops = {
217 .owner = THIS_MODULE,
218 .open = rcu_node_boost_open,
221 .release = single_release,
225 * Create the rcuboost debugfs entry. Standard error return.
227 static int rcu_boost_trace_create_file(struct dentry *rcudir)
229 return !debugfs_create_file("rcuboost", 0444, rcudir, NULL,
230 &rcu_node_boost_fops);
233 #else /* #ifdef CONFIG_RCU_BOOST */
235 static int rcu_boost_trace_create_file(struct dentry *rcudir)
237 return 0; /* There cannot be an error if we didn't create it! */
240 #endif /* #else #ifdef CONFIG_RCU_BOOST */
242 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
246 struct rcu_node *rnp;
249 seq_printf(m, "c=%lu g=%lu s=%d jfq=%ld j=%x "
250 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
251 rsp->completed, gpnum, rsp->signaled,
252 (long)(rsp->jiffies_force_qs - jiffies),
253 (int)(jiffies & 0xffff),
254 rsp->n_force_qs, rsp->n_force_qs_ngp,
255 rsp->n_force_qs - rsp->n_force_qs_ngp,
257 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
258 if (rnp->level != level) {
262 seq_printf(m, "%lx/%lx %c%c>%c %d:%d ^%d ",
263 rnp->qsmask, rnp->qsmaskinit,
264 ".G"[rnp->gp_tasks != NULL],
265 ".E"[rnp->exp_tasks != NULL],
266 ".T"[!list_empty(&rnp->blkd_tasks)],
267 rnp->grplo, rnp->grphi, rnp->grpnum);
272 static int show_rcuhier(struct seq_file *m, void *unused)
274 #ifdef CONFIG_TREE_PREEMPT_RCU
275 seq_puts(m, "rcu_preempt:\n");
276 print_one_rcu_state(m, &rcu_preempt_state);
277 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
278 seq_puts(m, "rcu_sched:\n");
279 print_one_rcu_state(m, &rcu_sched_state);
280 seq_puts(m, "rcu_bh:\n");
281 print_one_rcu_state(m, &rcu_bh_state);
285 static int rcuhier_open(struct inode *inode, struct file *file)
287 return single_open(file, show_rcuhier, NULL);
290 static const struct file_operations rcuhier_fops = {
291 .owner = THIS_MODULE,
292 .open = rcuhier_open,
295 .release = single_release,
298 static int show_rcugp(struct seq_file *m, void *unused)
300 #ifdef CONFIG_TREE_PREEMPT_RCU
301 seq_printf(m, "rcu_preempt: completed=%ld gpnum=%lu\n",
302 rcu_preempt_state.completed, rcu_preempt_state.gpnum);
303 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
304 seq_printf(m, "rcu_sched: completed=%ld gpnum=%lu\n",
305 rcu_sched_state.completed, rcu_sched_state.gpnum);
306 seq_printf(m, "rcu_bh: completed=%ld gpnum=%lu\n",
307 rcu_bh_state.completed, rcu_bh_state.gpnum);
311 static int rcugp_open(struct inode *inode, struct file *file)
313 return single_open(file, show_rcugp, NULL);
316 static const struct file_operations rcugp_fops = {
317 .owner = THIS_MODULE,
321 .release = single_release,
324 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
326 seq_printf(m, "%3d%cnp=%ld "
327 "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
328 "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
330 cpu_is_offline(rdp->cpu) ? '!' : ' ',
332 rdp->n_rp_qs_pending,
335 rdp->n_rp_cpu_needs_gp,
336 rdp->n_rp_gp_completed,
337 rdp->n_rp_gp_started,
339 rdp->n_rp_need_nothing);
342 static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
345 struct rcu_data *rdp;
347 for_each_possible_cpu(cpu) {
348 rdp = per_cpu_ptr(rsp->rda, cpu);
350 print_one_rcu_pending(m, rdp);
354 static int show_rcu_pending(struct seq_file *m, void *unused)
356 #ifdef CONFIG_TREE_PREEMPT_RCU
357 seq_puts(m, "rcu_preempt:\n");
358 print_rcu_pendings(m, &rcu_preempt_state);
359 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
360 seq_puts(m, "rcu_sched:\n");
361 print_rcu_pendings(m, &rcu_sched_state);
362 seq_puts(m, "rcu_bh:\n");
363 print_rcu_pendings(m, &rcu_bh_state);
367 static int rcu_pending_open(struct inode *inode, struct file *file)
369 return single_open(file, show_rcu_pending, NULL);
372 static const struct file_operations rcu_pending_fops = {
373 .owner = THIS_MODULE,
374 .open = rcu_pending_open,
377 .release = single_release,
380 static struct dentry *rcudir;
382 static int __init rcutree_trace_init(void)
384 struct dentry *retval;
386 rcudir = debugfs_create_dir("rcu", NULL);
390 retval = debugfs_create_file("rcudata", 0444, rcudir,
391 NULL, &rcudata_fops);
395 retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
396 NULL, &rcudata_csv_fops);
400 if (rcu_boost_trace_create_file(rcudir))
403 retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
407 retval = debugfs_create_file("rcuhier", 0444, rcudir,
408 NULL, &rcuhier_fops);
412 retval = debugfs_create_file("rcu_pending", 0444, rcudir,
413 NULL, &rcu_pending_fops);
418 debugfs_remove_recursive(rcudir);
422 static void __exit rcutree_trace_cleanup(void)
424 debugfs_remove_recursive(rcudir);
428 module_init(rcutree_trace_init);
429 module_exit(rcutree_trace_cleanup);
431 MODULE_AUTHOR("Paul E. McKenney");
432 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
433 MODULE_LICENSE("GPL");