blob: c8e97853b970f71ad662732ef46da011cf46ac1d [file] [log] [blame]
Paul E. McKenney64db4cf2008-12-18 21:55:32 +01001/*
2 * Read-Copy Update tracing for classic implementation
3 *
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.
8 *
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.
13 *
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.
17 *
18 * Copyright IBM Corporation, 2008
19 *
20 * Papers: http://www.rdrop.com/users/paulmck/RCU
21 *
22 * For detailed explanation of Read-Copy Update mechanism see -
Paul E. McKenneya71fca52009-09-18 10:28:19 -070023 * Documentation/RCU
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010024 *
25 */
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>
45
Paul E. McKenney9f77da92009-08-22 13:56:45 -070046#define RCU_TREE_NONCORE
Ingo Molnar6258c4f2009-03-25 16:42:24 +010047#include "rcutree.h"
48
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010049static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
50{
51 if (!rdp->beenonline)
52 return;
Paul E. McKenney20133cf2010-02-22 17:05:01 -080053 seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010054 rdp->cpu,
55 cpu_is_offline(rdp->cpu) ? '!' : ' ',
56 rdp->completed, rdp->gpnum,
57 rdp->passed_quiesc, rdp->passed_quiesc_completed,
Paul E. McKenneyef631b02009-04-13 21:31:16 -070058 rdp->qs_pending);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010059#ifdef CONFIG_NO_HZ
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,
64 rdp->dynticks_fqs);
65#endif /* #ifdef CONFIG_NO_HZ */
66 seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
Paul E. McKenney269dcc12010-09-07 14:23:09 -070067 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);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010070}
71
72#define PRINT_RCU_DATA(name, func, m) \
73 do { \
74 int _p_r_d_i; \
75 \
76 for_each_possible_cpu(_p_r_d_i) \
77 func(m, &per_cpu(name, _p_r_d_i)); \
78 } while (0)
79
80static int show_rcudata(struct seq_file *m, void *unused)
81{
Paul E. McKenneyf41d9112009-08-22 13:56:52 -070082#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 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -070086 seq_puts(m, "rcu_sched:\n");
87 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010088 seq_puts(m, "rcu_bh:\n");
89 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
90 return 0;
91}
92
93static int rcudata_open(struct inode *inode, struct file *file)
94{
95 return single_open(file, show_rcudata, NULL);
96}
97
Paul E. McKenney9b2619a2009-09-23 09:50:43 -070098static const struct file_operations rcudata_fops = {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +010099 .owner = THIS_MODULE,
100 .open = rcudata_open,
101 .read = seq_read,
102 .llseek = seq_lseek,
103 .release = single_release,
104};
105
106static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
107{
108 if (!rdp->beenonline)
109 return;
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800110 seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100111 rdp->cpu,
Paul E. McKenney5699ed82009-08-22 13:56:48 -0700112 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100113 rdp->completed, rdp->gpnum,
114 rdp->passed_quiesc, rdp->passed_quiesc_completed,
Paul E. McKenneyef631b02009-04-13 21:31:16 -0700115 rdp->qs_pending);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100116#ifdef CONFIG_NO_HZ
117 seq_printf(m, ",%d,%d,%d,%lu",
118 rdp->dynticks->dynticks,
119 rdp->dynticks->dynticks_nesting,
120 rdp->dynticks->dynticks_nmi,
121 rdp->dynticks_fqs);
122#endif /* #ifdef CONFIG_NO_HZ */
123 seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
Paul E. McKenney269dcc12010-09-07 14:23:09 -0700124 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);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100127}
128
129static int show_rcudata_csv(struct seq_file *m, void *unused)
130{
Paul E. McKenneyef631b02009-04-13 21:31:16 -0700131 seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100132#ifdef CONFIG_NO_HZ
133 seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\",");
134#endif /* #ifdef CONFIG_NO_HZ */
Paul E. McKenney269dcc12010-09-07 14:23:09 -0700135 seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\",\"ci\",\"co\",\"ca\"\n");
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700136#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 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700140 seq_puts(m, "\"rcu_sched:\"\n");
141 PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100142 seq_puts(m, "\"rcu_bh:\"\n");
143 PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
144 return 0;
145}
146
147static int rcudata_csv_open(struct inode *inode, struct file *file)
148{
149 return single_open(file, show_rcudata_csv, NULL);
150}
151
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700152static const struct file_operations rcudata_csv_fops = {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100153 .owner = THIS_MODULE,
154 .open = rcudata_csv_open,
155 .read = seq_read,
156 .llseek = seq_lseek,
157 .release = single_release,
158};
159
160static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
161{
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800162 unsigned long gpnum;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100163 int level = 0;
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800164 int phase;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100165 struct rcu_node *rnp;
166
Paul E. McKenney3397e042009-10-14 16:36:38 -0700167 gpnum = rsp->gpnum;
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800168 seq_printf(m, "c=%lu g=%lu s=%d jfq=%ld j=%x "
Lai Jiangshan29494be2010-10-20 14:13:06 +0800169 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
Paul E. McKenney3397e042009-10-14 16:36:38 -0700170 rsp->completed, gpnum, rsp->signaled,
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100171 (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,
Lai Jiangshan29494be2010-10-20 14:13:06 +0800175 rsp->n_force_qs_lh);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100176 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
177 if (rnp->level != level) {
178 seq_puts(m, "\n");
179 level = rnp->level;
180 }
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800181 phase = gpnum & 0x1;
182 seq_printf(m, "%lx/%lx %c%c>%c%c %d:%d ^%d ",
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100183 rnp->qsmask, rnp->qsmaskinit,
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800184 "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])],
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100188 rnp->grplo, rnp->grphi, rnp->grpnum);
189 }
190 seq_puts(m, "\n");
191}
192
193static int show_rcuhier(struct seq_file *m, void *unused)
194{
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700195#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 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700199 seq_puts(m, "rcu_sched:\n");
200 print_one_rcu_state(m, &rcu_sched_state);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100201 seq_puts(m, "rcu_bh:\n");
202 print_one_rcu_state(m, &rcu_bh_state);
203 return 0;
204}
205
206static int rcuhier_open(struct inode *inode, struct file *file)
207{
208 return single_open(file, show_rcuhier, NULL);
209}
210
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700211static const struct file_operations rcuhier_fops = {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100212 .owner = THIS_MODULE,
213 .open = rcuhier_open,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
217};
218
219static int show_rcugp(struct seq_file *m, void *unused)
220{
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700221#ifdef CONFIG_TREE_PREEMPT_RCU
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800222 seq_printf(m, "rcu_preempt: completed=%ld gpnum=%lu\n",
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700223 rcu_preempt_state.completed, rcu_preempt_state.gpnum);
224#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800225 seq_printf(m, "rcu_sched: completed=%ld gpnum=%lu\n",
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700226 rcu_sched_state.completed, rcu_sched_state.gpnum);
Paul E. McKenney20133cf2010-02-22 17:05:01 -0800227 seq_printf(m, "rcu_bh: completed=%ld gpnum=%lu\n",
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100228 rcu_bh_state.completed, rcu_bh_state.gpnum);
229 return 0;
230}
231
232static int rcugp_open(struct inode *inode, struct file *file)
233{
234 return single_open(file, show_rcugp, NULL);
235}
236
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700237static const struct file_operations rcugp_fops = {
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100238 .owner = THIS_MODULE,
239 .open = rcugp_open,
240 .read = seq_read,
241 .llseek = seq_lseek,
242 .release = single_release,
243};
244
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700245static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
246{
247 seq_printf(m, "%3d%cnp=%ld "
Paul E. McKenneyd21670a2010-04-14 17:39:26 -0700248 "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
249 "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700250 rdp->cpu,
251 cpu_is_offline(rdp->cpu) ? '!' : ' ',
252 rdp->n_rcu_pending,
253 rdp->n_rp_qs_pending,
Paul E. McKenneyd21670a2010-04-14 17:39:26 -0700254 rdp->n_rp_report_qs,
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700255 rdp->n_rp_cb_ready,
256 rdp->n_rp_cpu_needs_gp,
257 rdp->n_rp_gp_completed,
258 rdp->n_rp_gp_started,
259 rdp->n_rp_need_fqs,
260 rdp->n_rp_need_nothing);
261}
262
263static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
264{
265 int cpu;
266 struct rcu_data *rdp;
267
268 for_each_possible_cpu(cpu) {
Lai Jiangshan394f99a2010-06-28 16:25:04 +0800269 rdp = per_cpu_ptr(rsp->rda, cpu);
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700270 if (rdp->beenonline)
271 print_one_rcu_pending(m, rdp);
272 }
273}
274
275static int show_rcu_pending(struct seq_file *m, void *unused)
276{
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700277#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 */
Paul E. McKenneyd6714c22009-08-22 13:56:46 -0700281 seq_puts(m, "rcu_sched:\n");
282 print_rcu_pendings(m, &rcu_sched_state);
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700283 seq_puts(m, "rcu_bh:\n");
284 print_rcu_pendings(m, &rcu_bh_state);
285 return 0;
286}
287
288static int rcu_pending_open(struct inode *inode, struct file *file)
289{
290 return single_open(file, show_rcu_pending, NULL);
291}
292
Paul E. McKenney9b2619a2009-09-23 09:50:43 -0700293static const struct file_operations rcu_pending_fops = {
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700294 .owner = THIS_MODULE,
295 .open = rcu_pending_open,
296 .read = seq_read,
297 .llseek = seq_lseek,
298 .release = single_release,
299};
300
301static struct dentry *rcudir;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700302
Paul E. McKenneydeb7a412010-09-30 21:33:32 -0700303static int __init rcutree_trace_init(void)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100304{
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700305 struct dentry *retval;
306
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100307 rcudir = debugfs_create_dir("rcu", NULL);
308 if (!rcudir)
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700309 goto free_out;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100310
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700311 retval = debugfs_create_file("rcudata", 0444, rcudir,
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100312 NULL, &rcudata_fops);
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700313 if (!retval)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100314 goto free_out;
315
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700316 retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100317 NULL, &rcudata_csv_fops);
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700318 if (!retval)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100319 goto free_out;
320
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700321 retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
322 if (!retval)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100323 goto free_out;
324
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700325 retval = debugfs_create_file("rcuhier", 0444, rcudir,
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100326 NULL, &rcuhier_fops);
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700327 if (!retval)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100328 goto free_out;
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700329
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700330 retval = debugfs_create_file("rcu_pending", 0444, rcudir,
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700331 NULL, &rcu_pending_fops);
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700332 if (!retval)
Paul E. McKenney7ba5c842009-04-13 21:31:17 -0700333 goto free_out;
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100334 return 0;
335free_out:
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700336 debugfs_remove_recursive(rcudir);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100337 return 1;
338}
339
Paul E. McKenneydeb7a412010-09-30 21:33:32 -0700340static void __exit rcutree_trace_cleanup(void)
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100341{
Paul E. McKenney22f00b62009-08-22 13:56:50 -0700342 debugfs_remove_recursive(rcudir);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100343}
344
345
Paul E. McKenneydeb7a412010-09-30 21:33:32 -0700346module_init(rcutree_trace_init);
347module_exit(rcutree_trace_cleanup);
Paul E. McKenney64db4cf2008-12-18 21:55:32 +0100348
349MODULE_AUTHOR("Paul E. McKenney");
350MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
351MODULE_LICENSE("GPL");