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 DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status
);
50 DECLARE_PER_CPU(char, rcu_cpu_has_work
);
52 static char convert_kthread_status(unsigned int kthread_status
)
54 if (kthread_status
> RCU_KTHREAD_MAX
)
56 return "SRWY"[kthread_status
];
59 static void print_one_rcu_data(struct seq_file
*m
, struct rcu_data
*rdp
)
63 seq_printf(m
, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
65 cpu_is_offline(rdp
->cpu
) ? '!' : ' ',
66 rdp
->completed
, rdp
->gpnum
,
67 rdp
->passed_quiesc
, rdp
->passed_quiesc_completed
,
70 seq_printf(m
, " dt=%d/%d/%d df=%lu",
71 atomic_read(&rdp
->dynticks
->dynticks
),
72 rdp
->dynticks
->dynticks_nesting
,
73 rdp
->dynticks
->dynticks_nmi_nesting
,
75 #endif /* #ifdef CONFIG_NO_HZ */
76 seq_printf(m
, " of=%lu ri=%lu", rdp
->offline_fqs
, rdp
->resched_ipi
);
77 seq_printf(m
, " ql=%ld qs=%c%c%c%c kt=%d/%c b=%ld",
79 ".N"[rdp
->nxttail
[RCU_NEXT_READY_TAIL
] !=
80 rdp
->nxttail
[RCU_NEXT_TAIL
]],
81 ".R"[rdp
->nxttail
[RCU_WAIT_TAIL
] !=
82 rdp
->nxttail
[RCU_NEXT_READY_TAIL
]],
83 ".W"[rdp
->nxttail
[RCU_DONE_TAIL
] !=
84 rdp
->nxttail
[RCU_WAIT_TAIL
]],
85 ".D"[&rdp
->nxtlist
!= rdp
->nxttail
[RCU_DONE_TAIL
]],
86 per_cpu(rcu_cpu_has_work
, rdp
->cpu
),
87 convert_kthread_status(per_cpu(rcu_cpu_kthread_status
,
90 seq_printf(m
, " ci=%lu co=%lu ca=%lu\n",
91 rdp
->n_cbs_invoked
, rdp
->n_cbs_orphaned
, rdp
->n_cbs_adopted
);
94 #define PRINT_RCU_DATA(name, func, m) \
98 for_each_possible_cpu(_p_r_d_i) \
99 func(m, &per_cpu(name, _p_r_d_i)); \
102 static int show_rcudata(struct seq_file
*m
, void *unused
)
104 #ifdef CONFIG_TREE_PREEMPT_RCU
105 seq_puts(m
, "rcu_preempt:\n");
106 PRINT_RCU_DATA(rcu_preempt_data
, print_one_rcu_data
, m
);
107 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
108 seq_puts(m
, "rcu_sched:\n");
109 PRINT_RCU_DATA(rcu_sched_data
, print_one_rcu_data
, m
);
110 seq_puts(m
, "rcu_bh:\n");
111 PRINT_RCU_DATA(rcu_bh_data
, print_one_rcu_data
, m
);
115 static int rcudata_open(struct inode
*inode
, struct file
*file
)
117 return single_open(file
, show_rcudata
, NULL
);
120 static const struct file_operations rcudata_fops
= {
121 .owner
= THIS_MODULE
,
122 .open
= rcudata_open
,
125 .release
= single_release
,
128 static void print_one_rcu_data_csv(struct seq_file
*m
, struct rcu_data
*rdp
)
130 if (!rdp
->beenonline
)
132 seq_printf(m
, "%d,%s,%lu,%lu,%d,%lu,%d",
134 cpu_is_offline(rdp
->cpu
) ? "\"N\"" : "\"Y\"",
135 rdp
->completed
, rdp
->gpnum
,
136 rdp
->passed_quiesc
, rdp
->passed_quiesc_completed
,
139 seq_printf(m
, ",%d,%d,%d,%lu",
140 atomic_read(&rdp
->dynticks
->dynticks
),
141 rdp
->dynticks
->dynticks_nesting
,
142 rdp
->dynticks
->dynticks_nmi_nesting
,
144 #endif /* #ifdef CONFIG_NO_HZ */
145 seq_printf(m
, ",%lu,%lu", rdp
->offline_fqs
, rdp
->resched_ipi
);
146 seq_printf(m
, ",%ld,\"%c%c%c%c\",%d,\"%c\",%ld", rdp
->qlen
,
147 ".N"[rdp
->nxttail
[RCU_NEXT_READY_TAIL
] !=
148 rdp
->nxttail
[RCU_NEXT_TAIL
]],
149 ".R"[rdp
->nxttail
[RCU_WAIT_TAIL
] !=
150 rdp
->nxttail
[RCU_NEXT_READY_TAIL
]],
151 ".W"[rdp
->nxttail
[RCU_DONE_TAIL
] !=
152 rdp
->nxttail
[RCU_WAIT_TAIL
]],
153 ".D"[&rdp
->nxtlist
!= rdp
->nxttail
[RCU_DONE_TAIL
]],
154 per_cpu(rcu_cpu_has_work
, rdp
->cpu
),
155 convert_kthread_status(per_cpu(rcu_cpu_kthread_status
,
158 seq_printf(m
, ",%lu,%lu,%lu\n",
159 rdp
->n_cbs_invoked
, rdp
->n_cbs_orphaned
, rdp
->n_cbs_adopted
);
162 static int show_rcudata_csv(struct seq_file
*m
, void *unused
)
164 seq_puts(m
, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
166 seq_puts(m
, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\",");
167 #endif /* #ifdef CONFIG_NO_HZ */
168 seq_puts(m
, "\"of\",\"ri\",\"ql\",\"b\",\"ci\",\"co\",\"ca\"\n");
169 #ifdef CONFIG_TREE_PREEMPT_RCU
170 seq_puts(m
, "\"rcu_preempt:\"\n");
171 PRINT_RCU_DATA(rcu_preempt_data
, print_one_rcu_data_csv
, m
);
172 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
173 seq_puts(m
, "\"rcu_sched:\"\n");
174 PRINT_RCU_DATA(rcu_sched_data
, print_one_rcu_data_csv
, m
);
175 seq_puts(m
, "\"rcu_bh:\"\n");
176 PRINT_RCU_DATA(rcu_bh_data
, print_one_rcu_data_csv
, m
);
180 static int rcudata_csv_open(struct inode
*inode
, struct file
*file
)
182 return single_open(file
, show_rcudata_csv
, NULL
);
185 static const struct file_operations rcudata_csv_fops
= {
186 .owner
= THIS_MODULE
,
187 .open
= rcudata_csv_open
,
190 .release
= single_release
,
193 #ifdef CONFIG_RCU_BOOST
195 static void print_one_rcu_node_boost(struct seq_file
*m
, struct rcu_node
*rnp
)
197 seq_printf(m
, "%d:%d tasks=%c%c%c%c kt=%c ntb=%lu neb=%lu nnb=%lu "
199 rnp
->grplo
, rnp
->grphi
,
200 "T."[list_empty(&rnp
->blkd_tasks
)],
201 "N."[!rnp
->gp_tasks
],
202 "E."[!rnp
->exp_tasks
],
203 "B."[!rnp
->boost_tasks
],
204 convert_kthread_status(rnp
->boost_kthread_status
),
205 rnp
->n_tasks_boosted
, rnp
->n_exp_boosts
,
206 rnp
->n_normal_boosts
,
207 (int)(jiffies
& 0xffff),
208 (int)(rnp
->boost_time
& 0xffff));
209 seq_printf(m
, "%s: nt=%lu egt=%lu bt=%lu nb=%lu ny=%lu nos=%lu\n",
211 rnp
->n_balk_blkd_tasks
,
212 rnp
->n_balk_exp_gp_tasks
,
213 rnp
->n_balk_boost_tasks
,
214 rnp
->n_balk_notblocked
,
219 static int show_rcu_node_boost(struct seq_file
*m
, void *unused
)
221 struct rcu_node
*rnp
;
223 rcu_for_each_leaf_node(&rcu_preempt_state
, rnp
)
224 print_one_rcu_node_boost(m
, rnp
);
228 static int rcu_node_boost_open(struct inode
*inode
, struct file
*file
)
230 return single_open(file
, show_rcu_node_boost
, NULL
);
233 static const struct file_operations rcu_node_boost_fops
= {
234 .owner
= THIS_MODULE
,
235 .open
= rcu_node_boost_open
,
238 .release
= single_release
,
242 * Create the rcuboost debugfs entry. Standard error return.
244 static int rcu_boost_trace_create_file(struct dentry
*rcudir
)
246 return !debugfs_create_file("rcuboost", 0444, rcudir
, NULL
,
247 &rcu_node_boost_fops
);
250 #else /* #ifdef CONFIG_RCU_BOOST */
252 static int rcu_boost_trace_create_file(struct dentry
*rcudir
)
254 return 0; /* There cannot be an error if we didn't create it! */
257 #endif /* #else #ifdef CONFIG_RCU_BOOST */
259 static void print_one_rcu_state(struct seq_file
*m
, struct rcu_state
*rsp
)
263 struct rcu_node
*rnp
;
266 seq_printf(m
, "c=%lu g=%lu s=%d jfq=%ld j=%x "
267 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
268 rsp
->completed
, gpnum
, rsp
->signaled
,
269 (long)(rsp
->jiffies_force_qs
- jiffies
),
270 (int)(jiffies
& 0xffff),
271 rsp
->n_force_qs
, rsp
->n_force_qs_ngp
,
272 rsp
->n_force_qs
- rsp
->n_force_qs_ngp
,
274 for (rnp
= &rsp
->node
[0]; rnp
- &rsp
->node
[0] < NUM_RCU_NODES
; rnp
++) {
275 if (rnp
->level
!= level
) {
279 seq_printf(m
, "%lx/%lx %c%c>%c %d:%d ^%d ",
280 rnp
->qsmask
, rnp
->qsmaskinit
,
281 ".G"[rnp
->gp_tasks
!= NULL
],
282 ".E"[rnp
->exp_tasks
!= NULL
],
283 ".T"[!list_empty(&rnp
->blkd_tasks
)],
284 rnp
->grplo
, rnp
->grphi
, rnp
->grpnum
);
289 static int show_rcuhier(struct seq_file
*m
, void *unused
)
291 #ifdef CONFIG_TREE_PREEMPT_RCU
292 seq_puts(m
, "rcu_preempt:\n");
293 print_one_rcu_state(m
, &rcu_preempt_state
);
294 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
295 seq_puts(m
, "rcu_sched:\n");
296 print_one_rcu_state(m
, &rcu_sched_state
);
297 seq_puts(m
, "rcu_bh:\n");
298 print_one_rcu_state(m
, &rcu_bh_state
);
302 static int rcuhier_open(struct inode
*inode
, struct file
*file
)
304 return single_open(file
, show_rcuhier
, NULL
);
307 static const struct file_operations rcuhier_fops
= {
308 .owner
= THIS_MODULE
,
309 .open
= rcuhier_open
,
312 .release
= single_release
,
315 static int show_rcugp(struct seq_file
*m
, void *unused
)
317 #ifdef CONFIG_TREE_PREEMPT_RCU
318 seq_printf(m
, "rcu_preempt: completed=%ld gpnum=%lu\n",
319 rcu_preempt_state
.completed
, rcu_preempt_state
.gpnum
);
320 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
321 seq_printf(m
, "rcu_sched: completed=%ld gpnum=%lu\n",
322 rcu_sched_state
.completed
, rcu_sched_state
.gpnum
);
323 seq_printf(m
, "rcu_bh: completed=%ld gpnum=%lu\n",
324 rcu_bh_state
.completed
, rcu_bh_state
.gpnum
);
328 static int rcugp_open(struct inode
*inode
, struct file
*file
)
330 return single_open(file
, show_rcugp
, NULL
);
333 static const struct file_operations rcugp_fops
= {
334 .owner
= THIS_MODULE
,
338 .release
= single_release
,
341 static void print_one_rcu_pending(struct seq_file
*m
, struct rcu_data
*rdp
)
343 seq_printf(m
, "%3d%cnp=%ld "
344 "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
345 "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
347 cpu_is_offline(rdp
->cpu
) ? '!' : ' ',
349 rdp
->n_rp_qs_pending
,
352 rdp
->n_rp_cpu_needs_gp
,
353 rdp
->n_rp_gp_completed
,
354 rdp
->n_rp_gp_started
,
356 rdp
->n_rp_need_nothing
);
359 static void print_rcu_pendings(struct seq_file
*m
, struct rcu_state
*rsp
)
362 struct rcu_data
*rdp
;
364 for_each_possible_cpu(cpu
) {
365 rdp
= per_cpu_ptr(rsp
->rda
, cpu
);
367 print_one_rcu_pending(m
, rdp
);
371 static int show_rcu_pending(struct seq_file
*m
, void *unused
)
373 #ifdef CONFIG_TREE_PREEMPT_RCU
374 seq_puts(m
, "rcu_preempt:\n");
375 print_rcu_pendings(m
, &rcu_preempt_state
);
376 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
377 seq_puts(m
, "rcu_sched:\n");
378 print_rcu_pendings(m
, &rcu_sched_state
);
379 seq_puts(m
, "rcu_bh:\n");
380 print_rcu_pendings(m
, &rcu_bh_state
);
384 static int rcu_pending_open(struct inode
*inode
, struct file
*file
)
386 return single_open(file
, show_rcu_pending
, NULL
);
389 static const struct file_operations rcu_pending_fops
= {
390 .owner
= THIS_MODULE
,
391 .open
= rcu_pending_open
,
394 .release
= single_release
,
397 static struct dentry
*rcudir
;
399 static int __init
rcutree_trace_init(void)
401 struct dentry
*retval
;
403 rcudir
= debugfs_create_dir("rcu", NULL
);
407 retval
= debugfs_create_file("rcudata", 0444, rcudir
,
408 NULL
, &rcudata_fops
);
412 retval
= debugfs_create_file("rcudata.csv", 0444, rcudir
,
413 NULL
, &rcudata_csv_fops
);
417 if (rcu_boost_trace_create_file(rcudir
))
420 retval
= debugfs_create_file("rcugp", 0444, rcudir
, NULL
, &rcugp_fops
);
424 retval
= debugfs_create_file("rcuhier", 0444, rcudir
,
425 NULL
, &rcuhier_fops
);
429 retval
= debugfs_create_file("rcu_pending", 0444, rcudir
,
430 NULL
, &rcu_pending_fops
);
435 debugfs_remove_recursive(rcudir
);
439 static void __exit
rcutree_trace_cleanup(void)
441 debugfs_remove_recursive(rcudir
);
445 module_init(rcutree_trace_init
);
446 module_exit(rcutree_trace_cleanup
);
448 MODULE_AUTHOR("Paul E. McKenney");
449 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
450 MODULE_LICENSE("GPL");