fc40e89a028ca0a2781996f51277227a7499355e
[linux-2.6.git] / kernel / rcutree_trace.c
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
46 #define RCU_TREE_NONCORE
47 #include "rcutree.h"
48
49 DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
50 DECLARE_PER_CPU(char, rcu_cpu_has_work);
51
52 static char convert_kthread_status(unsigned int kthread_status)
53 {
54         if (kthread_status > RCU_KTHREAD_MAX)
55                 return '?';
56         return "SRWY"[kthread_status];
57 }
58
59 static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
60 {
61         if (!rdp->beenonline)
62                 return;
63         seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
64                    rdp->cpu,
65                    cpu_is_offline(rdp->cpu) ? '!' : ' ',
66                    rdp->completed, rdp->gpnum,
67                    rdp->passed_quiesc, rdp->passed_quiesc_completed,
68                    rdp->qs_pending);
69 #ifdef CONFIG_NO_HZ
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,
74                    rdp->dynticks_fqs);
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",
78                    rdp->qlen,
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,
88                                           rdp->cpu)),
89                    rdp->blimit);
90         seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
91                    rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
92 }
93
94 #define PRINT_RCU_DATA(name, func, m) \
95         do { \
96                 int _p_r_d_i; \
97                 \
98                 for_each_possible_cpu(_p_r_d_i) \
99                         func(m, &per_cpu(name, _p_r_d_i)); \
100         } while (0)
101
102 static int show_rcudata(struct seq_file *m, void *unused)
103 {
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);
112         return 0;
113 }
114
115 static int rcudata_open(struct inode *inode, struct file *file)
116 {
117         return single_open(file, show_rcudata, NULL);
118 }
119
120 static const struct file_operations rcudata_fops = {
121         .owner = THIS_MODULE,
122         .open = rcudata_open,
123         .read = seq_read,
124         .llseek = seq_lseek,
125         .release = single_release,
126 };
127
128 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
129 {
130         if (!rdp->beenonline)
131                 return;
132         seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
133                    rdp->cpu,
134                    cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
135                    rdp->completed, rdp->gpnum,
136                    rdp->passed_quiesc, rdp->passed_quiesc_completed,
137                    rdp->qs_pending);
138 #ifdef CONFIG_NO_HZ
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,
143                    rdp->dynticks_fqs);
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,
156                                           rdp->cpu)),
157                    rdp->blimit);
158         seq_printf(m, ",%lu,%lu,%lu\n",
159                    rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
160 }
161
162 static int show_rcudata_csv(struct seq_file *m, void *unused)
163 {
164         seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
165 #ifdef CONFIG_NO_HZ
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);
177         return 0;
178 }
179
180 static int rcudata_csv_open(struct inode *inode, struct file *file)
181 {
182         return single_open(file, show_rcudata_csv, NULL);
183 }
184
185 static const struct file_operations rcudata_csv_fops = {
186         .owner = THIS_MODULE,
187         .open = rcudata_csv_open,
188         .read = seq_read,
189         .llseek = seq_lseek,
190         .release = single_release,
191 };
192
193 #ifdef CONFIG_RCU_BOOST
194
195 static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
196 {
197         seq_printf(m,  "%d:%d tasks=%c%c%c%c kt=%c ntb=%lu neb=%lu nnb=%lu "
198                    "j=%04x bt=%04x\n",
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",
210                    "     balk",
211                    rnp->n_balk_blkd_tasks,
212                    rnp->n_balk_exp_gp_tasks,
213                    rnp->n_balk_boost_tasks,
214                    rnp->n_balk_notblocked,
215                    rnp->n_balk_notyet,
216                    rnp->n_balk_nos);
217 }
218
219 static int show_rcu_node_boost(struct seq_file *m, void *unused)
220 {
221         struct rcu_node *rnp;
222
223         rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
224                 print_one_rcu_node_boost(m, rnp);
225         return 0;
226 }
227
228 static int rcu_node_boost_open(struct inode *inode, struct file *file)
229 {
230         return single_open(file, show_rcu_node_boost, NULL);
231 }
232
233 static const struct file_operations rcu_node_boost_fops = {
234         .owner = THIS_MODULE,
235         .open = rcu_node_boost_open,
236         .read = seq_read,
237         .llseek = seq_lseek,
238         .release = single_release,
239 };
240
241 /*
242  * Create the rcuboost debugfs entry.  Standard error return.
243  */
244 static int rcu_boost_trace_create_file(struct dentry *rcudir)
245 {
246         return !debugfs_create_file("rcuboost", 0444, rcudir, NULL,
247                                     &rcu_node_boost_fops);
248 }
249
250 #else /* #ifdef CONFIG_RCU_BOOST */
251
252 static int rcu_boost_trace_create_file(struct dentry *rcudir)
253 {
254         return 0;  /* There cannot be an error if we didn't create it! */
255 }
256
257 #endif /* #else #ifdef CONFIG_RCU_BOOST */
258
259 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
260 {
261         unsigned long gpnum;
262         int level = 0;
263         struct rcu_node *rnp;
264
265         gpnum = rsp->gpnum;
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,
273                    rsp->n_force_qs_lh);
274         for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
275                 if (rnp->level != level) {
276                         seq_puts(m, "\n");
277                         level = rnp->level;
278                 }
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);
285         }
286         seq_puts(m, "\n");
287 }
288
289 static int show_rcuhier(struct seq_file *m, void *unused)
290 {
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);
299         return 0;
300 }
301
302 static int rcuhier_open(struct inode *inode, struct file *file)
303 {
304         return single_open(file, show_rcuhier, NULL);
305 }
306
307 static const struct file_operations rcuhier_fops = {
308         .owner = THIS_MODULE,
309         .open = rcuhier_open,
310         .read = seq_read,
311         .llseek = seq_lseek,
312         .release = single_release,
313 };
314
315 static int show_rcugp(struct seq_file *m, void *unused)
316 {
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);
325         return 0;
326 }
327
328 static int rcugp_open(struct inode *inode, struct file *file)
329 {
330         return single_open(file, show_rcugp, NULL);
331 }
332
333 static const struct file_operations rcugp_fops = {
334         .owner = THIS_MODULE,
335         .open = rcugp_open,
336         .read = seq_read,
337         .llseek = seq_lseek,
338         .release = single_release,
339 };
340
341 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
342 {
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",
346                    rdp->cpu,
347                    cpu_is_offline(rdp->cpu) ? '!' : ' ',
348                    rdp->n_rcu_pending,
349                    rdp->n_rp_qs_pending,
350                    rdp->n_rp_report_qs,
351                    rdp->n_rp_cb_ready,
352                    rdp->n_rp_cpu_needs_gp,
353                    rdp->n_rp_gp_completed,
354                    rdp->n_rp_gp_started,
355                    rdp->n_rp_need_fqs,
356                    rdp->n_rp_need_nothing);
357 }
358
359 static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
360 {
361         int cpu;
362         struct rcu_data *rdp;
363
364         for_each_possible_cpu(cpu) {
365                 rdp = per_cpu_ptr(rsp->rda, cpu);
366                 if (rdp->beenonline)
367                         print_one_rcu_pending(m, rdp);
368         }
369 }
370
371 static int show_rcu_pending(struct seq_file *m, void *unused)
372 {
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);
381         return 0;
382 }
383
384 static int rcu_pending_open(struct inode *inode, struct file *file)
385 {
386         return single_open(file, show_rcu_pending, NULL);
387 }
388
389 static const struct file_operations rcu_pending_fops = {
390         .owner = THIS_MODULE,
391         .open = rcu_pending_open,
392         .read = seq_read,
393         .llseek = seq_lseek,
394         .release = single_release,
395 };
396
397 static struct dentry *rcudir;
398
399 static int __init rcutree_trace_init(void)
400 {
401         struct dentry *retval;
402
403         rcudir = debugfs_create_dir("rcu", NULL);
404         if (!rcudir)
405                 goto free_out;
406
407         retval = debugfs_create_file("rcudata", 0444, rcudir,
408                                                 NULL, &rcudata_fops);
409         if (!retval)
410                 goto free_out;
411
412         retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
413                                                 NULL, &rcudata_csv_fops);
414         if (!retval)
415                 goto free_out;
416
417         if (rcu_boost_trace_create_file(rcudir))
418                 goto free_out;
419
420         retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
421         if (!retval)
422                 goto free_out;
423
424         retval = debugfs_create_file("rcuhier", 0444, rcudir,
425                                                 NULL, &rcuhier_fops);
426         if (!retval)
427                 goto free_out;
428
429         retval = debugfs_create_file("rcu_pending", 0444, rcudir,
430                                                 NULL, &rcu_pending_fops);
431         if (!retval)
432                 goto free_out;
433         return 0;
434 free_out:
435         debugfs_remove_recursive(rcudir);
436         return 1;
437 }
438
439 static void __exit rcutree_trace_cleanup(void)
440 {
441         debugfs_remove_recursive(rcudir);
442 }
443
444
445 module_init(rcutree_trace_init);
446 module_exit(rcutree_trace_cleanup);
447
448 MODULE_AUTHOR("Paul E. McKenney");
449 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
450 MODULE_LICENSE("GPL");