Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 1 | /* |
Paul E. McKenney | a57eb94 | 2010-06-29 16:49:16 -0700 | [diff] [blame] | 2 | * Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 3 | * Internal non-public definitions that provide either classic |
Paul E. McKenney | a57eb94 | 2010-06-29 16:49:16 -0700 | [diff] [blame] | 4 | * or preemptible semantics. |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 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 |
Paul E. McKenney | 87de1cf | 2013-12-03 10:02:52 -0800 | [diff] [blame] | 17 | * along with this program; if not, you can access it online at |
| 18 | * http://www.gnu.org/licenses/gpl-2.0.html. |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 19 | * |
Paul E. McKenney | a57eb94 | 2010-06-29 16:49:16 -0700 | [diff] [blame] | 20 | * Copyright (c) 2010 Linaro |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 21 | * |
| 22 | * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> |
| 23 | */ |
| 24 | |
Paul E. McKenney | b2c0710 | 2010-09-09 13:40:39 -0700 | [diff] [blame] | 25 | #include <linux/kthread.h> |
Paul Gortmaker | 9fc9204 | 2016-01-07 19:05:19 -0500 | [diff] [blame] | 26 | #include <linux/init.h> |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 27 | #include <linux/debugfs.h> |
| 28 | #include <linux/seq_file.h> |
| 29 | |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 30 | /* Global control variables for rcupdate callback mechanism. */ |
| 31 | struct 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. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 35 | RCU_TRACE(long qlen); /* Number of pending CBs. */ |
Paul E. McKenney | 6bfc09e | 2012-10-19 12:49:17 -0700 | [diff] [blame] | 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. */ |
Steven Rostedt (Red Hat) | e66c33d | 2013-07-12 16:50:28 -0400 | [diff] [blame] | 39 | RCU_TRACE(const char *name); /* Name of RCU type. */ |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /* Definition for rcupdate control block. */ |
| 43 | static struct rcu_ctrlblk rcu_sched_ctrlblk = { |
| 44 | .donetail = &rcu_sched_ctrlblk.rcucblist, |
| 45 | .curtail = &rcu_sched_ctrlblk.rcucblist, |
Paul E. McKenney | e99033c | 2011-06-21 00:13:44 -0700 | [diff] [blame] | 46 | RCU_TRACE(.name = "rcu_sched") |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { |
| 50 | .donetail = &rcu_bh_ctrlblk.rcucblist, |
| 51 | .curtail = &rcu_bh_ctrlblk.rcucblist, |
Paul E. McKenney | e99033c | 2011-06-21 00:13:44 -0700 | [diff] [blame] | 52 | RCU_TRACE(.name = "rcu_bh") |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Paul E. McKenney | 900b102 | 2017-02-10 14:32:54 -0800 | [diff] [blame^] | 55 | #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 56 | #include <linux/kernel_stat.h> |
| 57 | |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 58 | int rcu_scheduler_active __read_mostly; |
| 59 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * During boot, we forgive RCU lockdep issues. After this function is |
Paul E. McKenney | 52d7e48 | 2017-01-10 02:28:26 -0800 | [diff] [blame] | 63 | * invoked, we start taking RCU lockdep issues seriously. Note that unlike |
| 64 | * Tree RCU, Tiny RCU transitions directly from RCU_SCHEDULER_INACTIVE |
| 65 | * to RCU_SCHEDULER_RUNNING, skipping the RCU_SCHEDULER_INIT stage. |
| 66 | * The reason for this is that Tiny RCU does not need kthreads, so does |
| 67 | * not have to care about the fact that the scheduler is half-initialized |
Paul E. McKenney | 900b102 | 2017-02-10 14:32:54 -0800 | [diff] [blame^] | 68 | * at a certain phase of the boot process. Unless SRCU is in the mix. |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 69 | */ |
Paul E. McKenney | b2c0710 | 2010-09-09 13:40:39 -0700 | [diff] [blame] | 70 | void __init rcu_scheduler_starting(void) |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 71 | { |
| 72 | WARN_ON(nr_context_switches() > 0); |
Paul E. McKenney | 900b102 | 2017-02-10 14:32:54 -0800 | [diff] [blame^] | 73 | rcu_scheduler_active = IS_ENABLED(CONFIG_SRCU) |
| 74 | ? RCU_SCHEDULER_INIT : RCU_SCHEDULER_RUNNING; |
Paul E. McKenney | bbad937 | 2010-04-02 16:17:17 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Paul E. McKenney | 900b102 | 2017-02-10 14:32:54 -0800 | [diff] [blame^] | 77 | #endif /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ |
Paul E. McKenney | 24278d1 | 2010-09-27 17:25:23 -0700 | [diff] [blame] | 78 | |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 79 | #ifdef CONFIG_RCU_TRACE |
| 80 | |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 81 | static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n) |
| 82 | { |
| 83 | unsigned long flags; |
| 84 | |
Paul E. McKenney | 7a11e20 | 2012-08-21 12:14:19 -0700 | [diff] [blame] | 85 | local_irq_save(flags); |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 86 | rcp->qlen -= n; |
Paul E. McKenney | 7a11e20 | 2012-08-21 12:14:19 -0700 | [diff] [blame] | 87 | local_irq_restore(flags); |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Dump statistics for TINY_RCU, such as they are. |
| 92 | */ |
| 93 | static int show_tiny_stats(struct seq_file *m, void *unused) |
| 94 | { |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 95 | seq_printf(m, "rcu_sched: qlen: %ld\n", rcu_sched_ctrlblk.qlen); |
| 96 | seq_printf(m, "rcu_bh: qlen: %ld\n", rcu_bh_ctrlblk.qlen); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int show_tiny_stats_open(struct inode *inode, struct file *file) |
| 101 | { |
| 102 | return single_open(file, show_tiny_stats, NULL); |
| 103 | } |
| 104 | |
| 105 | static const struct file_operations show_tiny_stats_fops = { |
| 106 | .owner = THIS_MODULE, |
| 107 | .open = show_tiny_stats_open, |
| 108 | .read = seq_read, |
| 109 | .llseek = seq_lseek, |
| 110 | .release = single_release, |
| 111 | }; |
| 112 | |
| 113 | static struct dentry *rcudir; |
| 114 | |
| 115 | static int __init rcutiny_trace_init(void) |
| 116 | { |
| 117 | struct dentry *retval; |
| 118 | |
| 119 | rcudir = debugfs_create_dir("rcu", NULL); |
| 120 | if (!rcudir) |
| 121 | goto free_out; |
| 122 | retval = debugfs_create_file("rcudata", 0444, rcudir, |
| 123 | NULL, &show_tiny_stats_fops); |
| 124 | if (!retval) |
| 125 | goto free_out; |
| 126 | return 0; |
| 127 | free_out: |
| 128 | debugfs_remove_recursive(rcudir); |
| 129 | return 1; |
| 130 | } |
Paul Gortmaker | 9fc9204 | 2016-01-07 19:05:19 -0500 | [diff] [blame] | 131 | device_initcall(rcutiny_trace_init); |
Paul E. McKenney | 9e571a8 | 2010-09-30 21:26:52 -0700 | [diff] [blame] | 132 | |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 133 | static void check_cpu_stall(struct rcu_ctrlblk *rcp) |
| 134 | { |
| 135 | unsigned long j; |
| 136 | unsigned long js; |
| 137 | |
| 138 | if (rcu_cpu_stall_suppress) |
| 139 | return; |
| 140 | rcp->ticks_this_gp++; |
| 141 | j = jiffies; |
Paul E. McKenney | 7d0ae80 | 2015-03-03 14:57:58 -0800 | [diff] [blame] | 142 | js = READ_ONCE(rcp->jiffies_stall); |
Miroslav Benes | ec1fe39 | 2014-12-22 11:10:12 -0800 | [diff] [blame] | 143 | if (rcp->rcucblist && ULONG_CMP_GE(j, js)) { |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 144 | pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n", |
Lai Jiangshan | 5f6130f | 2014-12-09 17:53:34 +0800 | [diff] [blame] | 145 | rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE, |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 146 | jiffies - rcp->gp_start, rcp->qlen); |
| 147 | dump_stack(); |
Paul E. McKenney | 7d0ae80 | 2015-03-03 14:57:58 -0800 | [diff] [blame] | 148 | WRITE_ONCE(rcp->jiffies_stall, |
| 149 | jiffies + 3 * rcu_jiffies_till_stall_check() + 3); |
Miroslav Benes | ec1fe39 | 2014-12-22 11:10:12 -0800 | [diff] [blame] | 150 | } else if (ULONG_CMP_GE(j, js)) { |
Paul E. McKenney | 7d0ae80 | 2015-03-03 14:57:58 -0800 | [diff] [blame] | 151 | WRITE_ONCE(rcp->jiffies_stall, |
| 152 | jiffies + rcu_jiffies_till_stall_check()); |
Miroslav Benes | ec1fe39 | 2014-12-22 11:10:12 -0800 | [diff] [blame] | 153 | } |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 156 | static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp) |
| 157 | { |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 158 | rcp->ticks_this_gp = 0; |
| 159 | rcp->gp_start = jiffies; |
Paul E. McKenney | 7d0ae80 | 2015-03-03 14:57:58 -0800 | [diff] [blame] | 160 | WRITE_ONCE(rcp->jiffies_stall, |
| 161 | jiffies + rcu_jiffies_till_stall_check()); |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void check_cpu_stalls(void) |
| 165 | { |
Paul E. McKenney | 6c8c148 | 2017-01-23 12:02:09 -0800 | [diff] [blame] | 166 | RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk);) |
| 167 | RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk);) |
Paul E. McKenney | 318bdcd | 2013-03-27 10:43:02 -0700 | [diff] [blame] | 168 | } |
Paul E. McKenney | 1496144 | 2013-04-16 07:49:22 -0700 | [diff] [blame] | 169 | |
| 170 | #endif /* #ifdef CONFIG_RCU_TRACE */ |