Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target...
[linux-2.6-block.git] / kernel / rcu / tiny_plugin.h
CommitLineData
bbad9379 1/*
a57eb940 2 * Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition
bbad9379 3 * Internal non-public definitions that provide either classic
a57eb940 4 * or preemptible semantics.
bbad9379
PM
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
87de1cfd
PM
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
bbad9379 19 *
a57eb940 20 * Copyright (c) 2010 Linaro
bbad9379
PM
21 *
22 * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
23 */
24
b2c0710c 25#include <linux/kthread.h>
9fc9204e 26#include <linux/init.h>
9e571a82
PM
27#include <linux/debugfs.h>
28#include <linux/seq_file.h>
29
24278d14
PM
30/* Global control variables for rcupdate callback mechanism. */
31struct rcu_ctrlblk {
32 struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */
33 struct rcu_head **donetail; /* ->next pointer of last "done" CB. */
34 struct rcu_head **curtail; /* ->next pointer of last CB. */
9e571a82 35 RCU_TRACE(long qlen); /* Number of pending CBs. */
6bfc09e2
PM
36 RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */
37 RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */
38 RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */
e66c33d5 39 RCU_TRACE(const char *name); /* Name of RCU type. */
24278d14
PM
40};
41
42/* Definition for rcupdate control block. */
43static struct rcu_ctrlblk rcu_sched_ctrlblk = {
44 .donetail = &rcu_sched_ctrlblk.rcucblist,
45 .curtail = &rcu_sched_ctrlblk.rcucblist,
e99033c5 46 RCU_TRACE(.name = "rcu_sched")
24278d14
PM
47};
48
49static struct rcu_ctrlblk rcu_bh_ctrlblk = {
50 .donetail = &rcu_bh_ctrlblk.rcucblist,
51 .curtail = &rcu_bh_ctrlblk.rcucblist,
e99033c5 52 RCU_TRACE(.name = "rcu_bh")
24278d14
PM
53};
54
55#ifdef CONFIG_DEBUG_LOCK_ALLOC
318bdcd9
PM
56#include <linux/kernel_stat.h>
57
24278d14
PM
58int rcu_scheduler_active __read_mostly;
59EXPORT_SYMBOL_GPL(rcu_scheduler_active);
bbad9379
PM
60
61/*
62 * During boot, we forgive RCU lockdep issues. After this function is
63 * invoked, we start taking RCU lockdep issues seriously.
64 */
b2c0710c 65void __init rcu_scheduler_starting(void)
bbad9379
PM
66{
67 WARN_ON(nr_context_switches() > 0);
68 rcu_scheduler_active = 1;
69}
70
71#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
24278d14 72
9e571a82
PM
73#ifdef CONFIG_RCU_TRACE
74
9e571a82
PM
75static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
76{
77 unsigned long flags;
78
7a11e205 79 local_irq_save(flags);
9e571a82 80 rcp->qlen -= n;
7a11e205 81 local_irq_restore(flags);
9e571a82
PM
82}
83
84/*
85 * Dump statistics for TINY_RCU, such as they are.
86 */
87static int show_tiny_stats(struct seq_file *m, void *unused)
88{
9e571a82
PM
89 seq_printf(m, "rcu_sched: qlen: %ld\n", rcu_sched_ctrlblk.qlen);
90 seq_printf(m, "rcu_bh: qlen: %ld\n", rcu_bh_ctrlblk.qlen);
91 return 0;
92}
93
94static int show_tiny_stats_open(struct inode *inode, struct file *file)
95{
96 return single_open(file, show_tiny_stats, NULL);
97}
98
99static const struct file_operations show_tiny_stats_fops = {
100 .owner = THIS_MODULE,
101 .open = show_tiny_stats_open,
102 .read = seq_read,
103 .llseek = seq_lseek,
104 .release = single_release,
105};
106
107static struct dentry *rcudir;
108
109static int __init rcutiny_trace_init(void)
110{
111 struct dentry *retval;
112
113 rcudir = debugfs_create_dir("rcu", NULL);
114 if (!rcudir)
115 goto free_out;
116 retval = debugfs_create_file("rcudata", 0444, rcudir,
117 NULL, &show_tiny_stats_fops);
118 if (!retval)
119 goto free_out;
120 return 0;
121free_out:
122 debugfs_remove_recursive(rcudir);
123 return 1;
124}
9fc9204e 125device_initcall(rcutiny_trace_init);
9e571a82 126
318bdcd9
PM
127static void check_cpu_stall(struct rcu_ctrlblk *rcp)
128{
129 unsigned long j;
130 unsigned long js;
131
132 if (rcu_cpu_stall_suppress)
133 return;
134 rcp->ticks_this_gp++;
135 j = jiffies;
7d0ae808 136 js = READ_ONCE(rcp->jiffies_stall);
ec1fe396 137 if (rcp->rcucblist && ULONG_CMP_GE(j, js)) {
318bdcd9 138 pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
5f6130fa 139 rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE,
318bdcd9
PM
140 jiffies - rcp->gp_start, rcp->qlen);
141 dump_stack();
7d0ae808
PM
142 WRITE_ONCE(rcp->jiffies_stall,
143 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
ec1fe396 144 } else if (ULONG_CMP_GE(j, js)) {
7d0ae808
PM
145 WRITE_ONCE(rcp->jiffies_stall,
146 jiffies + rcu_jiffies_till_stall_check());
ec1fe396 147 }
318bdcd9
PM
148}
149
318bdcd9
PM
150static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
151{
318bdcd9
PM
152 rcp->ticks_this_gp = 0;
153 rcp->gp_start = jiffies;
7d0ae808
PM
154 WRITE_ONCE(rcp->jiffies_stall,
155 jiffies + rcu_jiffies_till_stall_check());
318bdcd9
PM
156}
157
158static void check_cpu_stalls(void)
159{
160 RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk));
161 RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk));
162}
14961444
PM
163
164#endif /* #ifdef CONFIG_RCU_TRACE */