rcu: add callback-queue information to rcudata output
[pandora-kernel.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 static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
50 {
51         if (!rdp->beenonline)
52                 return;
53         seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
54                    rdp->cpu,
55                    cpu_is_offline(rdp->cpu) ? '!' : ' ',
56                    rdp->completed, rdp->gpnum,
57                    rdp->passed_quiesc, rdp->passed_quiesc_completed,
58                    rdp->qs_pending);
59 #ifdef CONFIG_NO_HZ
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,
64                    rdp->dynticks_fqs);
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",
68                    rdp->qlen,
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]],
76                    rdp->blimit);
77         seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
78                    rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
79 }
80
81 #define PRINT_RCU_DATA(name, func, m) \
82         do { \
83                 int _p_r_d_i; \
84                 \
85                 for_each_possible_cpu(_p_r_d_i) \
86                         func(m, &per_cpu(name, _p_r_d_i)); \
87         } while (0)
88
89 static int show_rcudata(struct seq_file *m, void *unused)
90 {
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);
99         return 0;
100 }
101
102 static int rcudata_open(struct inode *inode, struct file *file)
103 {
104         return single_open(file, show_rcudata, NULL);
105 }
106
107 static const struct file_operations rcudata_fops = {
108         .owner = THIS_MODULE,
109         .open = rcudata_open,
110         .read = seq_read,
111         .llseek = seq_lseek,
112         .release = single_release,
113 };
114
115 static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
116 {
117         if (!rdp->beenonline)
118                 return;
119         seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
120                    rdp->cpu,
121                    cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
122                    rdp->completed, rdp->gpnum,
123                    rdp->passed_quiesc, rdp->passed_quiesc_completed,
124                    rdp->qs_pending);
125 #ifdef CONFIG_NO_HZ
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,
130                    rdp->dynticks_fqs);
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]],
141                    rdp->blimit);
142         seq_printf(m, ",%lu,%lu,%lu\n",
143                    rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
144 }
145
146 static int show_rcudata_csv(struct seq_file *m, void *unused)
147 {
148         seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
149 #ifdef CONFIG_NO_HZ
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);
161         return 0;
162 }
163
164 static int rcudata_csv_open(struct inode *inode, struct file *file)
165 {
166         return single_open(file, show_rcudata_csv, NULL);
167 }
168
169 static const struct file_operations rcudata_csv_fops = {
170         .owner = THIS_MODULE,
171         .open = rcudata_csv_open,
172         .read = seq_read,
173         .llseek = seq_lseek,
174         .release = single_release,
175 };
176
177 #ifdef CONFIG_RCU_BOOST
178
179 static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
180 {
181         seq_printf(m,  "%d:%d tasks=%c%c%c%c ntb=%lu neb=%lu nnb=%lu "
182                    "j=%04x bt=%04x\n",
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",
193                    "     balk",
194                    rnp->n_balk_blkd_tasks,
195                    rnp->n_balk_exp_gp_tasks,
196                    rnp->n_balk_boost_tasks,
197                    rnp->n_balk_notblocked,
198                    rnp->n_balk_notyet,
199                    rnp->n_balk_nos);
200 }
201
202 static int show_rcu_node_boost(struct seq_file *m, void *unused)
203 {
204         struct rcu_node *rnp;
205
206         rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
207                 print_one_rcu_node_boost(m, rnp);
208         return 0;
209 }
210
211 static int rcu_node_boost_open(struct inode *inode, struct file *file)
212 {
213         return single_open(file, show_rcu_node_boost, NULL);
214 }
215
216 static const struct file_operations rcu_node_boost_fops = {
217         .owner = THIS_MODULE,
218         .open = rcu_node_boost_open,
219         .read = seq_read,
220         .llseek = seq_lseek,
221         .release = single_release,
222 };
223
224 /*
225  * Create the rcuboost debugfs entry.  Standard error return.
226  */
227 static int rcu_boost_trace_create_file(struct dentry *rcudir)
228 {
229         return !debugfs_create_file("rcuboost", 0444, rcudir, NULL,
230                                     &rcu_node_boost_fops);
231 }
232
233 #else /* #ifdef CONFIG_RCU_BOOST */
234
235 static int rcu_boost_trace_create_file(struct dentry *rcudir)
236 {
237         return 0;  /* There cannot be an error if we didn't create it! */
238 }
239
240 #endif /* #else #ifdef CONFIG_RCU_BOOST */
241
242 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
243 {
244         unsigned long gpnum;
245         int level = 0;
246         struct rcu_node *rnp;
247
248         gpnum = rsp->gpnum;
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,
256                    rsp->n_force_qs_lh);
257         for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
258                 if (rnp->level != level) {
259                         seq_puts(m, "\n");
260                         level = rnp->level;
261                 }
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);
268         }
269         seq_puts(m, "\n");
270 }
271
272 static int show_rcuhier(struct seq_file *m, void *unused)
273 {
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);
282         return 0;
283 }
284
285 static int rcuhier_open(struct inode *inode, struct file *file)
286 {
287         return single_open(file, show_rcuhier, NULL);
288 }
289
290 static const struct file_operations rcuhier_fops = {
291         .owner = THIS_MODULE,
292         .open = rcuhier_open,
293         .read = seq_read,
294         .llseek = seq_lseek,
295         .release = single_release,
296 };
297
298 static int show_rcugp(struct seq_file *m, void *unused)
299 {
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);
308         return 0;
309 }
310
311 static int rcugp_open(struct inode *inode, struct file *file)
312 {
313         return single_open(file, show_rcugp, NULL);
314 }
315
316 static const struct file_operations rcugp_fops = {
317         .owner = THIS_MODULE,
318         .open = rcugp_open,
319         .read = seq_read,
320         .llseek = seq_lseek,
321         .release = single_release,
322 };
323
324 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
325 {
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",
329                    rdp->cpu,
330                    cpu_is_offline(rdp->cpu) ? '!' : ' ',
331                    rdp->n_rcu_pending,
332                    rdp->n_rp_qs_pending,
333                    rdp->n_rp_report_qs,
334                    rdp->n_rp_cb_ready,
335                    rdp->n_rp_cpu_needs_gp,
336                    rdp->n_rp_gp_completed,
337                    rdp->n_rp_gp_started,
338                    rdp->n_rp_need_fqs,
339                    rdp->n_rp_need_nothing);
340 }
341
342 static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
343 {
344         int cpu;
345         struct rcu_data *rdp;
346
347         for_each_possible_cpu(cpu) {
348                 rdp = per_cpu_ptr(rsp->rda, cpu);
349                 if (rdp->beenonline)
350                         print_one_rcu_pending(m, rdp);
351         }
352 }
353
354 static int show_rcu_pending(struct seq_file *m, void *unused)
355 {
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);
364         return 0;
365 }
366
367 static int rcu_pending_open(struct inode *inode, struct file *file)
368 {
369         return single_open(file, show_rcu_pending, NULL);
370 }
371
372 static const struct file_operations rcu_pending_fops = {
373         .owner = THIS_MODULE,
374         .open = rcu_pending_open,
375         .read = seq_read,
376         .llseek = seq_lseek,
377         .release = single_release,
378 };
379
380 static struct dentry *rcudir;
381
382 static int __init rcutree_trace_init(void)
383 {
384         struct dentry *retval;
385
386         rcudir = debugfs_create_dir("rcu", NULL);
387         if (!rcudir)
388                 goto free_out;
389
390         retval = debugfs_create_file("rcudata", 0444, rcudir,
391                                                 NULL, &rcudata_fops);
392         if (!retval)
393                 goto free_out;
394
395         retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
396                                                 NULL, &rcudata_csv_fops);
397         if (!retval)
398                 goto free_out;
399
400         if (rcu_boost_trace_create_file(rcudir))
401                 goto free_out;
402
403         retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
404         if (!retval)
405                 goto free_out;
406
407         retval = debugfs_create_file("rcuhier", 0444, rcudir,
408                                                 NULL, &rcuhier_fops);
409         if (!retval)
410                 goto free_out;
411
412         retval = debugfs_create_file("rcu_pending", 0444, rcudir,
413                                                 NULL, &rcu_pending_fops);
414         if (!retval)
415                 goto free_out;
416         return 0;
417 free_out:
418         debugfs_remove_recursive(rcudir);
419         return 1;
420 }
421
422 static void __exit rcutree_trace_cleanup(void)
423 {
424         debugfs_remove_recursive(rcudir);
425 }
426
427
428 module_init(rcutree_trace_init);
429 module_exit(rcutree_trace_cleanup);
430
431 MODULE_AUTHOR("Paul E. McKenney");
432 MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
433 MODULE_LICENSE("GPL");