blob: 0cd385acccfa19660072ee3550d89a461246aa72 [file] [log] [blame]
Paul E. McKenneybbad9372010-04-02 16:17:17 -07001/*
Paul E. McKenneya57eb942010-06-29 16:49:16 -07002 * Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition
Paul E. McKenneybbad9372010-04-02 16:17:17 -07003 * Internal non-public definitions that provide either classic
Paul E. McKenneya57eb942010-06-29 16:49:16 -07004 * or preemptible semantics.
Paul E. McKenneybbad9372010-04-02 16:17:17 -07005 *
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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
Paul E. McKenneya57eb942010-06-29 16:49:16 -070020 * Copyright (c) 2010 Linaro
Paul E. McKenneybbad9372010-04-02 16:17:17 -070021 *
22 * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
23 */
24
Paul E. McKenneyb2c07102010-09-09 13:40:39 -070025#include <linux/kthread.h>
Paul Gortmakerbdfa97b2011-10-25 13:13:57 -040026#include <linux/module.h>
Paul E. McKenney9e571a82010-09-30 21:26:52 -070027#include <linux/debugfs.h>
28#include <linux/seq_file.h>
29
Paul E. McKenney24278d12010-09-27 17:25:23 -070030/* 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. */
Paul E. McKenney9e571a82010-09-30 21:26:52 -070035 RCU_TRACE(long qlen); /* Number of pending CBs. */
Paul E. McKenney6bfc09e2012-10-19 12:49:17 -070036 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. */
Paul E. McKenneye99033c2011-06-21 00:13:44 -070039 RCU_TRACE(char *name); /* Name of RCU type. */
Paul E. McKenney24278d12010-09-27 17:25:23 -070040};
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,
Paul E. McKenneye99033c2011-06-21 00:13:44 -070046 RCU_TRACE(.name = "rcu_sched")
Paul E. McKenney24278d12010-09-27 17:25:23 -070047};
48
49static struct rcu_ctrlblk rcu_bh_ctrlblk = {
50 .donetail = &rcu_bh_ctrlblk.rcucblist,
51 .curtail = &rcu_bh_ctrlblk.rcucblist,
Paul E. McKenneye99033c2011-06-21 00:13:44 -070052 RCU_TRACE(.name = "rcu_bh")
Paul E. McKenney24278d12010-09-27 17:25:23 -070053};
54
55#ifdef CONFIG_DEBUG_LOCK_ALLOC
Paul E. McKenney318bdcd2013-03-27 10:43:02 -070056#include <linux/kernel_stat.h>
57
Paul E. McKenney24278d12010-09-27 17:25:23 -070058int rcu_scheduler_active __read_mostly;
59EXPORT_SYMBOL_GPL(rcu_scheduler_active);
Paul E. McKenneybbad9372010-04-02 16:17:17 -070060
61/*
62 * During boot, we forgive RCU lockdep issues. After this function is
63 * invoked, we start taking RCU lockdep issues seriously.
64 */
Paul E. McKenneyb2c07102010-09-09 13:40:39 -070065void __init rcu_scheduler_starting(void)
Paul E. McKenneybbad9372010-04-02 16:17:17 -070066{
67 WARN_ON(nr_context_switches() > 0);
68 rcu_scheduler_active = 1;
69}
70
71#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
Paul E. McKenney24278d12010-09-27 17:25:23 -070072
Paul E. McKenney9e571a82010-09-30 21:26:52 -070073#ifdef CONFIG_RCU_TRACE
74
Paul E. McKenney9e571a82010-09-30 21:26:52 -070075static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
76{
77 unsigned long flags;
78
Paul E. McKenney7a11e202012-08-21 12:14:19 -070079 local_irq_save(flags);
Paul E. McKenney9e571a82010-09-30 21:26:52 -070080 rcp->qlen -= n;
Paul E. McKenney7a11e202012-08-21 12:14:19 -070081 local_irq_restore(flags);
Paul E. McKenney9e571a82010-09-30 21:26:52 -070082}
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{
Paul E. McKenney9e571a82010-09-30 21:26:52 -070089 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}
125
126static void __exit rcutiny_trace_cleanup(void)
127{
128 debugfs_remove_recursive(rcudir);
129}
130
131module_init(rcutiny_trace_init);
132module_exit(rcutiny_trace_cleanup);
133
134MODULE_AUTHOR("Paul E. McKenney");
135MODULE_DESCRIPTION("Read-Copy Update tracing for tiny implementation");
136MODULE_LICENSE("GPL");
137
Paul E. McKenney318bdcd2013-03-27 10:43:02 -0700138static void check_cpu_stall(struct rcu_ctrlblk *rcp)
139{
140 unsigned long j;
141 unsigned long js;
142
143 if (rcu_cpu_stall_suppress)
144 return;
145 rcp->ticks_this_gp++;
146 j = jiffies;
147 js = rcp->jiffies_stall;
148 if (*rcp->curtail && ULONG_CMP_GE(j, js)) {
149 pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
150 rcp->name, rcp->ticks_this_gp, rcu_dynticks_nesting,
151 jiffies - rcp->gp_start, rcp->qlen);
152 dump_stack();
153 }
154 if (*rcp->curtail && ULONG_CMP_GE(j, js))
155 rcp->jiffies_stall = jiffies +
156 3 * rcu_jiffies_till_stall_check() + 3;
157 else if (ULONG_CMP_GE(j, js))
158 rcp->jiffies_stall = jiffies + rcu_jiffies_till_stall_check();
159}
160
Paul E. McKenney318bdcd2013-03-27 10:43:02 -0700161static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
162{
Paul E. McKenney318bdcd2013-03-27 10:43:02 -0700163 rcp->ticks_this_gp = 0;
164 rcp->gp_start = jiffies;
165 rcp->jiffies_stall = jiffies + rcu_jiffies_till_stall_check();
Paul E. McKenney318bdcd2013-03-27 10:43:02 -0700166}
167
168static void check_cpu_stalls(void)
169{
170 RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk));
171 RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk));
172}
Paul E. McKenney14961442013-04-16 07:49:22 -0700173
174#endif /* #ifdef CONFIG_RCU_TRACE */