• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 -
23  * 		Documentation/RCU
24  *
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 
print_one_rcu_data(struct seq_file * m,struct rcu_data * rdp)46 static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
47 {
48 	if (!rdp->beenonline)
49 		return;
50 	seq_printf(m, "%3d%cc=%ld g=%ld pq=%d pqc=%ld qp=%d rpfq=%ld rp=%x",
51 		   rdp->cpu,
52 		   cpu_is_offline(rdp->cpu) ? '!' : ' ',
53 		   rdp->completed, rdp->gpnum,
54 		   rdp->passed_quiesc, rdp->passed_quiesc_completed,
55 		   rdp->qs_pending,
56 		   rdp->n_rcu_pending_force_qs - rdp->n_rcu_pending,
57 		   (int)(rdp->n_rcu_pending & 0xffff));
58 #ifdef CONFIG_NO_HZ
59 	seq_printf(m, " dt=%d/%d dn=%d df=%lu",
60 		   rdp->dynticks->dynticks,
61 		   rdp->dynticks->dynticks_nesting,
62 		   rdp->dynticks->dynticks_nmi,
63 		   rdp->dynticks_fqs);
64 #endif /* #ifdef CONFIG_NO_HZ */
65 	seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
66 	seq_printf(m, " ql=%ld b=%ld\n", rdp->qlen, rdp->blimit);
67 }
68 
69 #define PRINT_RCU_DATA(name, func, m) \
70 	do { \
71 		int _p_r_d_i; \
72 		\
73 		for_each_possible_cpu(_p_r_d_i) \
74 			func(m, &per_cpu(name, _p_r_d_i)); \
75 	} while (0)
76 
show_rcudata(struct seq_file * m,void * unused)77 static int show_rcudata(struct seq_file *m, void *unused)
78 {
79 	seq_puts(m, "rcu:\n");
80 	PRINT_RCU_DATA(rcu_data, print_one_rcu_data, m);
81 	seq_puts(m, "rcu_bh:\n");
82 	PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
83 	return 0;
84 }
85 
rcudata_open(struct inode * inode,struct file * file)86 static int rcudata_open(struct inode *inode, struct file *file)
87 {
88 	return single_open(file, show_rcudata, NULL);
89 }
90 
91 static struct file_operations rcudata_fops = {
92 	.owner = THIS_MODULE,
93 	.open = rcudata_open,
94 	.read = seq_read,
95 	.llseek = seq_lseek,
96 	.release = single_release,
97 };
98 
print_one_rcu_data_csv(struct seq_file * m,struct rcu_data * rdp)99 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
100 {
101 	if (!rdp->beenonline)
102 		return;
103 	seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d,%ld,%ld",
104 		   rdp->cpu,
105 		   cpu_is_offline(rdp->cpu) ? "\"Y\"" : "\"N\"",
106 		   rdp->completed, rdp->gpnum,
107 		   rdp->passed_quiesc, rdp->passed_quiesc_completed,
108 		   rdp->qs_pending,
109 		   rdp->n_rcu_pending_force_qs - rdp->n_rcu_pending,
110 		   rdp->n_rcu_pending);
111 #ifdef CONFIG_NO_HZ
112 	seq_printf(m, ",%d,%d,%d,%lu",
113 		   rdp->dynticks->dynticks,
114 		   rdp->dynticks->dynticks_nesting,
115 		   rdp->dynticks->dynticks_nmi,
116 		   rdp->dynticks_fqs);
117 #endif /* #ifdef CONFIG_NO_HZ */
118 	seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
119 	seq_printf(m, ",%ld,%ld\n", rdp->qlen, rdp->blimit);
120 }
121 
show_rcudata_csv(struct seq_file * m,void * unused)122 static int show_rcudata_csv(struct seq_file *m, void *unused)
123 {
124 	seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",\"rpfq\",\"rp\",");
125 #ifdef CONFIG_NO_HZ
126 	seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\",");
127 #endif /* #ifdef CONFIG_NO_HZ */
128 	seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n");
129 	seq_puts(m, "\"rcu:\"\n");
130 	PRINT_RCU_DATA(rcu_data, print_one_rcu_data_csv, m);
131 	seq_puts(m, "\"rcu_bh:\"\n");
132 	PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
133 	return 0;
134 }
135 
rcudata_csv_open(struct inode * inode,struct file * file)136 static int rcudata_csv_open(struct inode *inode, struct file *file)
137 {
138 	return single_open(file, show_rcudata_csv, NULL);
139 }
140 
141 static struct file_operations rcudata_csv_fops = {
142 	.owner = THIS_MODULE,
143 	.open = rcudata_csv_open,
144 	.read = seq_read,
145 	.llseek = seq_lseek,
146 	.release = single_release,
147 };
148 
print_one_rcu_state(struct seq_file * m,struct rcu_state * rsp)149 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
150 {
151 	int level = 0;
152 	struct rcu_node *rnp;
153 
154 	seq_printf(m, "c=%ld g=%ld s=%d jfq=%ld j=%x "
155 	              "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
156 		   rsp->completed, rsp->gpnum, rsp->signaled,
157 		   (long)(rsp->jiffies_force_qs - jiffies),
158 		   (int)(jiffies & 0xffff),
159 		   rsp->n_force_qs, rsp->n_force_qs_ngp,
160 		   rsp->n_force_qs - rsp->n_force_qs_ngp,
161 		   rsp->n_force_qs_lh);
162 	for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
163 		if (rnp->level != level) {
164 			seq_puts(m, "\n");
165 			level = rnp->level;
166 		}
167 		seq_printf(m, "%lx/%lx %d:%d ^%d    ",
168 			   rnp->qsmask, rnp->qsmaskinit,
169 			   rnp->grplo, rnp->grphi, rnp->grpnum);
170 	}
171 	seq_puts(m, "\n");
172 }
173 
show_rcuhier(struct seq_file * m,void * unused)174 static int show_rcuhier(struct seq_file *m, void *unused)
175 {
176 	seq_puts(m, "rcu:\n");
177 	print_one_rcu_state(m, &rcu_state);
178 	seq_puts(m, "rcu_bh:\n");
179 	print_one_rcu_state(m, &rcu_bh_state);
180 	return 0;
181 }
182 
rcuhier_open(struct inode * inode,struct file * file)183 static int rcuhier_open(struct inode *inode, struct file *file)
184 {
185 	return single_open(file, show_rcuhier, NULL);
186 }
187 
188 static struct file_operations rcuhier_fops = {
189 	.owner = THIS_MODULE,
190 	.open = rcuhier_open,
191 	.read = seq_read,
192 	.llseek = seq_lseek,
193 	.release = single_release,
194 };
195 
show_rcugp(struct seq_file * m,void * unused)196 static int show_rcugp(struct seq_file *m, void *unused)
197 {
198 	seq_printf(m, "rcu: completed=%ld  gpnum=%ld\n",
199 		   rcu_state.completed, rcu_state.gpnum);
200 	seq_printf(m, "rcu_bh: completed=%ld  gpnum=%ld\n",
201 		   rcu_bh_state.completed, rcu_bh_state.gpnum);
202 	return 0;
203 }
204 
rcugp_open(struct inode * inode,struct file * file)205 static int rcugp_open(struct inode *inode, struct file *file)
206 {
207 	return single_open(file, show_rcugp, NULL);
208 }
209 
210 static struct file_operations rcugp_fops = {
211 	.owner = THIS_MODULE,
212 	.open = rcugp_open,
213 	.read = seq_read,
214 	.llseek = seq_lseek,
215 	.release = single_release,
216 };
217 
218 static struct dentry *rcudir, *datadir, *datadir_csv, *hierdir, *gpdir;
rcuclassic_trace_init(void)219 static int __init rcuclassic_trace_init(void)
220 {
221 	rcudir = debugfs_create_dir("rcu", NULL);
222 	if (!rcudir)
223 		goto out;
224 
225 	datadir = debugfs_create_file("rcudata", 0444, rcudir,
226 						NULL, &rcudata_fops);
227 	if (!datadir)
228 		goto free_out;
229 
230 	datadir_csv = debugfs_create_file("rcudata.csv", 0444, rcudir,
231 						NULL, &rcudata_csv_fops);
232 	if (!datadir_csv)
233 		goto free_out;
234 
235 	gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
236 	if (!gpdir)
237 		goto free_out;
238 
239 	hierdir = debugfs_create_file("rcuhier", 0444, rcudir,
240 						NULL, &rcuhier_fops);
241 	if (!hierdir)
242 		goto free_out;
243 	return 0;
244 free_out:
245 	if (datadir)
246 		debugfs_remove(datadir);
247 	if (datadir_csv)
248 		debugfs_remove(datadir_csv);
249 	if (gpdir)
250 		debugfs_remove(gpdir);
251 	debugfs_remove(rcudir);
252 out:
253 	return 1;
254 }
255 
rcuclassic_trace_cleanup(void)256 static void __exit rcuclassic_trace_cleanup(void)
257 {
258 	debugfs_remove(datadir);
259 	debugfs_remove(datadir_csv);
260 	debugfs_remove(gpdir);
261 	debugfs_remove(hierdir);
262 	debugfs_remove(rcudir);
263 }
264 
265 
266 module_init(rcuclassic_trace_init);
267 module_exit(rcuclassic_trace_cleanup);
268 
269 MODULE_AUTHOR("Paul E. McKenney");
270 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
271 MODULE_LICENSE("GPL");
272