| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Read-Copy Update module-based torture test facility | 
|  | 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 (C) IBM Corporation, 2005, 2006 | 
|  | 19 | * | 
|  | 20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | 
|  | 21 | *	  Josh Triplett <josh@freedesktop.org> | 
|  | 22 | * | 
|  | 23 | * See also:  Documentation/RCU/torture.txt | 
|  | 24 | */ | 
|  | 25 | #include <linux/types.h> | 
|  | 26 | #include <linux/kernel.h> | 
|  | 27 | #include <linux/init.h> | 
|  | 28 | #include <linux/module.h> | 
|  | 29 | #include <linux/kthread.h> | 
|  | 30 | #include <linux/err.h> | 
|  | 31 | #include <linux/spinlock.h> | 
|  | 32 | #include <linux/smp.h> | 
|  | 33 | #include <linux/rcupdate.h> | 
|  | 34 | #include <linux/interrupt.h> | 
|  | 35 | #include <linux/sched.h> | 
|  | 36 | #include <linux/atomic.h> | 
|  | 37 | #include <linux/bitops.h> | 
|  | 38 | #include <linux/completion.h> | 
|  | 39 | #include <linux/moduleparam.h> | 
|  | 40 | #include <linux/percpu.h> | 
|  | 41 | #include <linux/notifier.h> | 
|  | 42 | #include <linux/reboot.h> | 
|  | 43 | #include <linux/freezer.h> | 
|  | 44 | #include <linux/cpu.h> | 
|  | 45 | #include <linux/delay.h> | 
|  | 46 | #include <linux/stat.h> | 
|  | 47 | #include <linux/srcu.h> | 
|  | 48 | #include <linux/slab.h> | 
|  | 49 | #include <asm/byteorder.h> | 
|  | 50 |  | 
|  | 51 | MODULE_LICENSE("GPL"); | 
|  | 52 | MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and " | 
|  | 53 | "Josh Triplett <josh@freedesktop.org>"); | 
|  | 54 |  | 
|  | 55 | static int nreaders = -1;	/* # reader threads, defaults to 2*ncpus */ | 
|  | 56 | static int nfakewriters = 4;	/* # fake writer threads */ | 
|  | 57 | static int stat_interval;	/* Interval between stats, in seconds. */ | 
|  | 58 | /*  Defaults to "only at end of test". */ | 
|  | 59 | static bool verbose;		/* Print more debug info. */ | 
|  | 60 | static bool test_no_idle_hz;	/* Test RCU's support for tickless idle CPUs. */ | 
|  | 61 | static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/ | 
|  | 62 | static int stutter = 5;		/* Start/stop testing interval (in sec) */ | 
|  | 63 | static int irqreader = 1;	/* RCU readers from irq (timers). */ | 
|  | 64 | static int fqs_duration;	/* Duration of bursts (us), 0 to disable. */ | 
|  | 65 | static int fqs_holdoff;		/* Hold time within burst (us). */ | 
|  | 66 | static int fqs_stutter = 3;	/* Wait time between bursts (s). */ | 
|  | 67 | static int onoff_interval;	/* Wait time between CPU hotplugs, 0=disable. */ | 
|  | 68 | static int onoff_holdoff;	/* Seconds after boot before CPU hotplugs. */ | 
|  | 69 | static int shutdown_secs;	/* Shutdown time (s).  <=0 for no shutdown. */ | 
|  | 70 | static int stall_cpu;		/* CPU-stall duration (s).  0 for no stall. */ | 
|  | 71 | static int stall_cpu_holdoff = 10; /* Time to wait until stall (s).  */ | 
|  | 72 | static int test_boost = 1;	/* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */ | 
|  | 73 | static int test_boost_interval = 7; /* Interval between boost tests, seconds. */ | 
|  | 74 | static int test_boost_duration = 4; /* Duration of each boost test, seconds. */ | 
|  | 75 | static char *torture_type = "rcu"; /* What RCU implementation to torture. */ | 
|  | 76 |  | 
|  | 77 | module_param(nreaders, int, 0444); | 
|  | 78 | MODULE_PARM_DESC(nreaders, "Number of RCU reader threads"); | 
|  | 79 | module_param(nfakewriters, int, 0444); | 
|  | 80 | MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads"); | 
|  | 81 | module_param(stat_interval, int, 0644); | 
|  | 82 | MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s"); | 
|  | 83 | module_param(verbose, bool, 0444); | 
|  | 84 | MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); | 
|  | 85 | module_param(test_no_idle_hz, bool, 0444); | 
|  | 86 | MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs"); | 
|  | 87 | module_param(shuffle_interval, int, 0444); | 
|  | 88 | MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles"); | 
|  | 89 | module_param(stutter, int, 0444); | 
|  | 90 | MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test"); | 
|  | 91 | module_param(irqreader, int, 0444); | 
|  | 92 | MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers"); | 
|  | 93 | module_param(fqs_duration, int, 0444); | 
|  | 94 | MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)"); | 
|  | 95 | module_param(fqs_holdoff, int, 0444); | 
|  | 96 | MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)"); | 
|  | 97 | module_param(fqs_stutter, int, 0444); | 
|  | 98 | MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)"); | 
|  | 99 | module_param(onoff_interval, int, 0444); | 
|  | 100 | MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable"); | 
|  | 101 | module_param(onoff_holdoff, int, 0444); | 
|  | 102 | MODULE_PARM_DESC(onoff_holdoff, "Time after boot before CPU hotplugs (s)"); | 
|  | 103 | module_param(shutdown_secs, int, 0444); | 
|  | 104 | MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable."); | 
|  | 105 | module_param(stall_cpu, int, 0444); | 
|  | 106 | MODULE_PARM_DESC(stall_cpu, "Stall duration (s), zero to disable."); | 
|  | 107 | module_param(stall_cpu_holdoff, int, 0444); | 
|  | 108 | MODULE_PARM_DESC(stall_cpu_holdoff, "Time to wait before starting stall (s)."); | 
|  | 109 | module_param(test_boost, int, 0444); | 
|  | 110 | MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes."); | 
|  | 111 | module_param(test_boost_interval, int, 0444); | 
|  | 112 | MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds."); | 
|  | 113 | module_param(test_boost_duration, int, 0444); | 
|  | 114 | MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds."); | 
|  | 115 | module_param(torture_type, charp, 0444); | 
|  | 116 | MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)"); | 
|  | 117 |  | 
|  | 118 | #define TORTURE_FLAG "-torture:" | 
|  | 119 | #define PRINTK_STRING(s) \ | 
|  | 120 | do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) | 
|  | 121 | #define VERBOSE_PRINTK_STRING(s) \ | 
|  | 122 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0) | 
|  | 123 | #define VERBOSE_PRINTK_ERRSTRING(s) \ | 
|  | 124 | do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) | 
|  | 125 |  | 
|  | 126 | static char printk_buf[4096]; | 
|  | 127 |  | 
|  | 128 | static int nrealreaders; | 
|  | 129 | static struct task_struct *writer_task; | 
|  | 130 | static struct task_struct **fakewriter_tasks; | 
|  | 131 | static struct task_struct **reader_tasks; | 
|  | 132 | static struct task_struct *stats_task; | 
|  | 133 | static struct task_struct *shuffler_task; | 
|  | 134 | static struct task_struct *stutter_task; | 
|  | 135 | static struct task_struct *fqs_task; | 
|  | 136 | static struct task_struct *boost_tasks[NR_CPUS]; | 
|  | 137 | static struct task_struct *shutdown_task; | 
|  | 138 | #ifdef CONFIG_HOTPLUG_CPU | 
|  | 139 | static struct task_struct *onoff_task; | 
|  | 140 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | 
|  | 141 | static struct task_struct *stall_task; | 
|  | 142 |  | 
|  | 143 | #define RCU_TORTURE_PIPE_LEN 10 | 
|  | 144 |  | 
|  | 145 | struct rcu_torture { | 
|  | 146 | struct rcu_head rtort_rcu; | 
|  | 147 | int rtort_pipe_count; | 
|  | 148 | struct list_head rtort_free; | 
|  | 149 | int rtort_mbtest; | 
|  | 150 | }; | 
|  | 151 |  | 
|  | 152 | static LIST_HEAD(rcu_torture_freelist); | 
|  | 153 | static struct rcu_torture __rcu *rcu_torture_current; | 
|  | 154 | static unsigned long rcu_torture_current_version; | 
|  | 155 | static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN]; | 
|  | 156 | static DEFINE_SPINLOCK(rcu_torture_lock); | 
|  | 157 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) = | 
|  | 158 | { 0 }; | 
|  | 159 | static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) = | 
|  | 160 | { 0 }; | 
|  | 161 | static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1]; | 
|  | 162 | static atomic_t n_rcu_torture_alloc; | 
|  | 163 | static atomic_t n_rcu_torture_alloc_fail; | 
|  | 164 | static atomic_t n_rcu_torture_free; | 
|  | 165 | static atomic_t n_rcu_torture_mberror; | 
|  | 166 | static atomic_t n_rcu_torture_error; | 
|  | 167 | static long n_rcu_torture_boost_ktrerror; | 
|  | 168 | static long n_rcu_torture_boost_rterror; | 
|  | 169 | static long n_rcu_torture_boost_failure; | 
|  | 170 | static long n_rcu_torture_boosts; | 
|  | 171 | static long n_rcu_torture_timers; | 
|  | 172 | static long n_offline_attempts; | 
|  | 173 | static long n_offline_successes; | 
|  | 174 | static long n_online_attempts; | 
|  | 175 | static long n_online_successes; | 
|  | 176 | static struct list_head rcu_torture_removed; | 
|  | 177 | static cpumask_var_t shuffle_tmp_mask; | 
|  | 178 |  | 
|  | 179 | static int stutter_pause_test; | 
|  | 180 |  | 
|  | 181 | #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE) | 
|  | 182 | #define RCUTORTURE_RUNNABLE_INIT 1 | 
|  | 183 | #else | 
|  | 184 | #define RCUTORTURE_RUNNABLE_INIT 0 | 
|  | 185 | #endif | 
|  | 186 | int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT; | 
|  | 187 | module_param(rcutorture_runnable, int, 0444); | 
|  | 188 | MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot"); | 
|  | 189 |  | 
|  | 190 | #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) | 
|  | 191 | #define rcu_can_boost() 1 | 
|  | 192 | #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ | 
|  | 193 | #define rcu_can_boost() 0 | 
|  | 194 | #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */ | 
|  | 195 |  | 
|  | 196 | static unsigned long shutdown_time;	/* jiffies to system shutdown. */ | 
|  | 197 | static unsigned long boost_starttime;	/* jiffies of next boost test start. */ | 
|  | 198 | DEFINE_MUTEX(boost_mutex);		/* protect setting boost_starttime */ | 
|  | 199 | /*  and boost task create/destroy. */ | 
|  | 200 |  | 
|  | 201 | /* Mediate rmmod and system shutdown.  Concurrent rmmod & shutdown illegal! */ | 
|  | 202 |  | 
|  | 203 | #define FULLSTOP_DONTSTOP 0	/* Normal operation. */ | 
|  | 204 | #define FULLSTOP_SHUTDOWN 1	/* System shutdown with rcutorture running. */ | 
|  | 205 | #define FULLSTOP_RMMOD    2	/* Normal rmmod of rcutorture. */ | 
|  | 206 | static int fullstop = FULLSTOP_RMMOD; | 
|  | 207 | /* | 
|  | 208 | * Protect fullstop transitions and spawning of kthreads. | 
|  | 209 | */ | 
|  | 210 | static DEFINE_MUTEX(fullstop_mutex); | 
|  | 211 |  | 
|  | 212 | /* Forward reference. */ | 
|  | 213 | static void rcu_torture_cleanup(void); | 
|  | 214 |  | 
|  | 215 | /* | 
|  | 216 | * Detect and respond to a system shutdown. | 
|  | 217 | */ | 
|  | 218 | static int | 
|  | 219 | rcutorture_shutdown_notify(struct notifier_block *unused1, | 
|  | 220 | unsigned long unused2, void *unused3) | 
|  | 221 | { | 
|  | 222 | mutex_lock(&fullstop_mutex); | 
|  | 223 | if (fullstop == FULLSTOP_DONTSTOP) | 
|  | 224 | fullstop = FULLSTOP_SHUTDOWN; | 
|  | 225 | else | 
|  | 226 | printk(KERN_WARNING /* but going down anyway, so... */ | 
|  | 227 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | 
|  | 228 | mutex_unlock(&fullstop_mutex); | 
|  | 229 | return NOTIFY_DONE; | 
|  | 230 | } | 
|  | 231 |  | 
|  | 232 | /* | 
|  | 233 | * Absorb kthreads into a kernel function that won't return, so that | 
|  | 234 | * they won't ever access module text or data again. | 
|  | 235 | */ | 
|  | 236 | static void rcutorture_shutdown_absorb(char *title) | 
|  | 237 | { | 
|  | 238 | if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { | 
|  | 239 | printk(KERN_NOTICE | 
|  | 240 | "rcutorture thread %s parking due to system shutdown\n", | 
|  | 241 | title); | 
|  | 242 | schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); | 
|  | 243 | } | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | /* | 
|  | 247 | * Allocate an element from the rcu_tortures pool. | 
|  | 248 | */ | 
|  | 249 | static struct rcu_torture * | 
|  | 250 | rcu_torture_alloc(void) | 
|  | 251 | { | 
|  | 252 | struct list_head *p; | 
|  | 253 |  | 
|  | 254 | spin_lock_bh(&rcu_torture_lock); | 
|  | 255 | if (list_empty(&rcu_torture_freelist)) { | 
|  | 256 | atomic_inc(&n_rcu_torture_alloc_fail); | 
|  | 257 | spin_unlock_bh(&rcu_torture_lock); | 
|  | 258 | return NULL; | 
|  | 259 | } | 
|  | 260 | atomic_inc(&n_rcu_torture_alloc); | 
|  | 261 | p = rcu_torture_freelist.next; | 
|  | 262 | list_del_init(p); | 
|  | 263 | spin_unlock_bh(&rcu_torture_lock); | 
|  | 264 | return container_of(p, struct rcu_torture, rtort_free); | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | /* | 
|  | 268 | * Free an element to the rcu_tortures pool. | 
|  | 269 | */ | 
|  | 270 | static void | 
|  | 271 | rcu_torture_free(struct rcu_torture *p) | 
|  | 272 | { | 
|  | 273 | atomic_inc(&n_rcu_torture_free); | 
|  | 274 | spin_lock_bh(&rcu_torture_lock); | 
|  | 275 | list_add_tail(&p->rtort_free, &rcu_torture_freelist); | 
|  | 276 | spin_unlock_bh(&rcu_torture_lock); | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | struct rcu_random_state { | 
|  | 280 | unsigned long rrs_state; | 
|  | 281 | long rrs_count; | 
|  | 282 | }; | 
|  | 283 |  | 
|  | 284 | #define RCU_RANDOM_MULT 39916801  /* prime */ | 
|  | 285 | #define RCU_RANDOM_ADD	479001701 /* prime */ | 
|  | 286 | #define RCU_RANDOM_REFRESH 10000 | 
|  | 287 |  | 
|  | 288 | #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 } | 
|  | 289 |  | 
|  | 290 | /* | 
|  | 291 | * Crude but fast random-number generator.  Uses a linear congruential | 
|  | 292 | * generator, with occasional help from cpu_clock(). | 
|  | 293 | */ | 
|  | 294 | static unsigned long | 
|  | 295 | rcu_random(struct rcu_random_state *rrsp) | 
|  | 296 | { | 
|  | 297 | if (--rrsp->rrs_count < 0) { | 
|  | 298 | rrsp->rrs_state += (unsigned long)local_clock(); | 
|  | 299 | rrsp->rrs_count = RCU_RANDOM_REFRESH; | 
|  | 300 | } | 
|  | 301 | rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD; | 
|  | 302 | return swahw32(rrsp->rrs_state); | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | static void | 
|  | 306 | rcu_stutter_wait(char *title) | 
|  | 307 | { | 
|  | 308 | while (stutter_pause_test || !rcutorture_runnable) { | 
|  | 309 | if (rcutorture_runnable) | 
|  | 310 | schedule_timeout_interruptible(1); | 
|  | 311 | else | 
|  | 312 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); | 
|  | 313 | rcutorture_shutdown_absorb(title); | 
|  | 314 | } | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | /* | 
|  | 318 | * Operations vector for selecting different types of tests. | 
|  | 319 | */ | 
|  | 320 |  | 
|  | 321 | struct rcu_torture_ops { | 
|  | 322 | void (*init)(void); | 
|  | 323 | void (*cleanup)(void); | 
|  | 324 | int (*readlock)(void); | 
|  | 325 | void (*read_delay)(struct rcu_random_state *rrsp); | 
|  | 326 | void (*readunlock)(int idx); | 
|  | 327 | int (*completed)(void); | 
|  | 328 | void (*deferred_free)(struct rcu_torture *p); | 
|  | 329 | void (*sync)(void); | 
|  | 330 | void (*cb_barrier)(void); | 
|  | 331 | void (*fqs)(void); | 
|  | 332 | int (*stats)(char *page); | 
|  | 333 | int irq_capable; | 
|  | 334 | int can_boost; | 
|  | 335 | char *name; | 
|  | 336 | }; | 
|  | 337 |  | 
|  | 338 | static struct rcu_torture_ops *cur_ops; | 
|  | 339 |  | 
|  | 340 | /* | 
|  | 341 | * Definitions for rcu torture testing. | 
|  | 342 | */ | 
|  | 343 |  | 
|  | 344 | static int rcu_torture_read_lock(void) __acquires(RCU) | 
|  | 345 | { | 
|  | 346 | rcu_read_lock(); | 
|  | 347 | return 0; | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | static void rcu_read_delay(struct rcu_random_state *rrsp) | 
|  | 351 | { | 
|  | 352 | const unsigned long shortdelay_us = 200; | 
|  | 353 | const unsigned long longdelay_ms = 50; | 
|  | 354 |  | 
|  | 355 | /* We want a short delay sometimes to make a reader delay the grace | 
|  | 356 | * period, and we want a long delay occasionally to trigger | 
|  | 357 | * force_quiescent_state. */ | 
|  | 358 |  | 
|  | 359 | if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) | 
|  | 360 | mdelay(longdelay_ms); | 
|  | 361 | if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us))) | 
|  | 362 | udelay(shortdelay_us); | 
|  | 363 | #ifdef CONFIG_PREEMPT | 
|  | 364 | if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000))) | 
|  | 365 | preempt_schedule();  /* No QS if preempt_disable() in effect */ | 
|  | 366 | #endif | 
|  | 367 | } | 
|  | 368 |  | 
|  | 369 | static void rcu_torture_read_unlock(int idx) __releases(RCU) | 
|  | 370 | { | 
|  | 371 | rcu_read_unlock(); | 
|  | 372 | } | 
|  | 373 |  | 
|  | 374 | static int rcu_torture_completed(void) | 
|  | 375 | { | 
|  | 376 | return rcu_batches_completed(); | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | static void | 
|  | 380 | rcu_torture_cb(struct rcu_head *p) | 
|  | 381 | { | 
|  | 382 | int i; | 
|  | 383 | struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu); | 
|  | 384 |  | 
|  | 385 | if (fullstop != FULLSTOP_DONTSTOP) { | 
|  | 386 | /* Test is ending, just drop callbacks on the floor. */ | 
|  | 387 | /* The next initialization will pick up the pieces. */ | 
|  | 388 | return; | 
|  | 389 | } | 
|  | 390 | i = rp->rtort_pipe_count; | 
|  | 391 | if (i > RCU_TORTURE_PIPE_LEN) | 
|  | 392 | i = RCU_TORTURE_PIPE_LEN; | 
|  | 393 | atomic_inc(&rcu_torture_wcount[i]); | 
|  | 394 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | 
|  | 395 | rp->rtort_mbtest = 0; | 
|  | 396 | rcu_torture_free(rp); | 
|  | 397 | } else | 
|  | 398 | cur_ops->deferred_free(rp); | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 | static int rcu_no_completed(void) | 
|  | 402 | { | 
|  | 403 | return 0; | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | static void rcu_torture_deferred_free(struct rcu_torture *p) | 
|  | 407 | { | 
|  | 408 | call_rcu(&p->rtort_rcu, rcu_torture_cb); | 
|  | 409 | } | 
|  | 410 |  | 
|  | 411 | static struct rcu_torture_ops rcu_ops = { | 
|  | 412 | .init		= NULL, | 
|  | 413 | .cleanup	= NULL, | 
|  | 414 | .readlock	= rcu_torture_read_lock, | 
|  | 415 | .read_delay	= rcu_read_delay, | 
|  | 416 | .readunlock	= rcu_torture_read_unlock, | 
|  | 417 | .completed	= rcu_torture_completed, | 
|  | 418 | .deferred_free	= rcu_torture_deferred_free, | 
|  | 419 | .sync		= synchronize_rcu, | 
|  | 420 | .cb_barrier	= rcu_barrier, | 
|  | 421 | .fqs		= rcu_force_quiescent_state, | 
|  | 422 | .stats		= NULL, | 
|  | 423 | .irq_capable	= 1, | 
|  | 424 | .can_boost	= rcu_can_boost(), | 
|  | 425 | .name		= "rcu" | 
|  | 426 | }; | 
|  | 427 |  | 
|  | 428 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) | 
|  | 429 | { | 
|  | 430 | int i; | 
|  | 431 | struct rcu_torture *rp; | 
|  | 432 | struct rcu_torture *rp1; | 
|  | 433 |  | 
|  | 434 | cur_ops->sync(); | 
|  | 435 | list_add(&p->rtort_free, &rcu_torture_removed); | 
|  | 436 | list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) { | 
|  | 437 | i = rp->rtort_pipe_count; | 
|  | 438 | if (i > RCU_TORTURE_PIPE_LEN) | 
|  | 439 | i = RCU_TORTURE_PIPE_LEN; | 
|  | 440 | atomic_inc(&rcu_torture_wcount[i]); | 
|  | 441 | if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) { | 
|  | 442 | rp->rtort_mbtest = 0; | 
|  | 443 | list_del(&rp->rtort_free); | 
|  | 444 | rcu_torture_free(rp); | 
|  | 445 | } | 
|  | 446 | } | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | static void rcu_sync_torture_init(void) | 
|  | 450 | { | 
|  | 451 | INIT_LIST_HEAD(&rcu_torture_removed); | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | static struct rcu_torture_ops rcu_sync_ops = { | 
|  | 455 | .init		= rcu_sync_torture_init, | 
|  | 456 | .cleanup	= NULL, | 
|  | 457 | .readlock	= rcu_torture_read_lock, | 
|  | 458 | .read_delay	= rcu_read_delay, | 
|  | 459 | .readunlock	= rcu_torture_read_unlock, | 
|  | 460 | .completed	= rcu_torture_completed, | 
|  | 461 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 462 | .sync		= synchronize_rcu, | 
|  | 463 | .cb_barrier	= NULL, | 
|  | 464 | .fqs		= rcu_force_quiescent_state, | 
|  | 465 | .stats		= NULL, | 
|  | 466 | .irq_capable	= 1, | 
|  | 467 | .can_boost	= rcu_can_boost(), | 
|  | 468 | .name		= "rcu_sync" | 
|  | 469 | }; | 
|  | 470 |  | 
|  | 471 | static struct rcu_torture_ops rcu_expedited_ops = { | 
|  | 472 | .init		= rcu_sync_torture_init, | 
|  | 473 | .cleanup	= NULL, | 
|  | 474 | .readlock	= rcu_torture_read_lock, | 
|  | 475 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 476 | .readunlock	= rcu_torture_read_unlock, | 
|  | 477 | .completed	= rcu_no_completed, | 
|  | 478 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 479 | .sync		= synchronize_rcu_expedited, | 
|  | 480 | .cb_barrier	= NULL, | 
|  | 481 | .fqs		= rcu_force_quiescent_state, | 
|  | 482 | .stats		= NULL, | 
|  | 483 | .irq_capable	= 1, | 
|  | 484 | .can_boost	= rcu_can_boost(), | 
|  | 485 | .name		= "rcu_expedited" | 
|  | 486 | }; | 
|  | 487 |  | 
|  | 488 | #ifndef CONFIG_PREEMPT_RT_FULL | 
|  | 489 | /* | 
|  | 490 | * Definitions for rcu_bh torture testing. | 
|  | 491 | */ | 
|  | 492 |  | 
|  | 493 | static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH) | 
|  | 494 | { | 
|  | 495 | rcu_read_lock_bh(); | 
|  | 496 | return 0; | 
|  | 497 | } | 
|  | 498 |  | 
|  | 499 | static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH) | 
|  | 500 | { | 
|  | 501 | rcu_read_unlock_bh(); | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | static int rcu_bh_torture_completed(void) | 
|  | 505 | { | 
|  | 506 | return rcu_batches_completed_bh(); | 
|  | 507 | } | 
|  | 508 |  | 
|  | 509 | static void rcu_bh_torture_deferred_free(struct rcu_torture *p) | 
|  | 510 | { | 
|  | 511 | call_rcu_bh(&p->rtort_rcu, rcu_torture_cb); | 
|  | 512 | } | 
|  | 513 |  | 
|  | 514 | static struct rcu_torture_ops rcu_bh_ops = { | 
|  | 515 | .init		= NULL, | 
|  | 516 | .cleanup	= NULL, | 
|  | 517 | .readlock	= rcu_bh_torture_read_lock, | 
|  | 518 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 519 | .readunlock	= rcu_bh_torture_read_unlock, | 
|  | 520 | .completed	= rcu_bh_torture_completed, | 
|  | 521 | .deferred_free	= rcu_bh_torture_deferred_free, | 
|  | 522 | .sync		= synchronize_rcu_bh, | 
|  | 523 | .cb_barrier	= rcu_barrier_bh, | 
|  | 524 | .fqs		= rcu_bh_force_quiescent_state, | 
|  | 525 | .stats		= NULL, | 
|  | 526 | .irq_capable	= 1, | 
|  | 527 | .name		= "rcu_bh" | 
|  | 528 | }; | 
|  | 529 |  | 
|  | 530 | static struct rcu_torture_ops rcu_bh_sync_ops = { | 
|  | 531 | .init		= rcu_sync_torture_init, | 
|  | 532 | .cleanup	= NULL, | 
|  | 533 | .readlock	= rcu_bh_torture_read_lock, | 
|  | 534 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 535 | .readunlock	= rcu_bh_torture_read_unlock, | 
|  | 536 | .completed	= rcu_bh_torture_completed, | 
|  | 537 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 538 | .sync		= synchronize_rcu_bh, | 
|  | 539 | .cb_barrier	= NULL, | 
|  | 540 | .fqs		= rcu_bh_force_quiescent_state, | 
|  | 541 | .stats		= NULL, | 
|  | 542 | .irq_capable	= 1, | 
|  | 543 | .name		= "rcu_bh_sync" | 
|  | 544 | }; | 
|  | 545 |  | 
|  | 546 | static struct rcu_torture_ops rcu_bh_expedited_ops = { | 
|  | 547 | .init		= rcu_sync_torture_init, | 
|  | 548 | .cleanup	= NULL, | 
|  | 549 | .readlock	= rcu_bh_torture_read_lock, | 
|  | 550 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 551 | .readunlock	= rcu_bh_torture_read_unlock, | 
|  | 552 | .completed	= rcu_bh_torture_completed, | 
|  | 553 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 554 | .sync		= synchronize_rcu_bh_expedited, | 
|  | 555 | .cb_barrier	= NULL, | 
|  | 556 | .fqs		= rcu_bh_force_quiescent_state, | 
|  | 557 | .stats		= NULL, | 
|  | 558 | .irq_capable	= 1, | 
|  | 559 | .name		= "rcu_bh_expedited" | 
|  | 560 | }; | 
|  | 561 |  | 
|  | 562 | #else | 
|  | 563 | static struct rcu_torture_ops rcu_bh_ops = { | 
|  | 564 | .ttype		= INVALID_RCU_FLAVOR, | 
|  | 565 | }; | 
|  | 566 | #endif | 
|  | 567 |  | 
|  | 568 | /* | 
|  | 569 | * Definitions for srcu torture testing. | 
|  | 570 | */ | 
|  | 571 |  | 
|  | 572 | static struct srcu_struct srcu_ctl; | 
|  | 573 |  | 
|  | 574 | static void srcu_torture_init(void) | 
|  | 575 | { | 
|  | 576 | init_srcu_struct(&srcu_ctl); | 
|  | 577 | rcu_sync_torture_init(); | 
|  | 578 | } | 
|  | 579 |  | 
|  | 580 | static void srcu_torture_cleanup(void) | 
|  | 581 | { | 
|  | 582 | synchronize_srcu(&srcu_ctl); | 
|  | 583 | cleanup_srcu_struct(&srcu_ctl); | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) | 
|  | 587 | { | 
|  | 588 | return srcu_read_lock(&srcu_ctl); | 
|  | 589 | } | 
|  | 590 |  | 
|  | 591 | static void srcu_read_delay(struct rcu_random_state *rrsp) | 
|  | 592 | { | 
|  | 593 | long delay; | 
|  | 594 | const long uspertick = 1000000 / HZ; | 
|  | 595 | const long longdelay = 10; | 
|  | 596 |  | 
|  | 597 | /* We want there to be long-running readers, but not all the time. */ | 
|  | 598 |  | 
|  | 599 | delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); | 
|  | 600 | if (!delay) | 
|  | 601 | schedule_timeout_interruptible(longdelay); | 
|  | 602 | else | 
|  | 603 | rcu_read_delay(rrsp); | 
|  | 604 | } | 
|  | 605 |  | 
|  | 606 | static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) | 
|  | 607 | { | 
|  | 608 | srcu_read_unlock(&srcu_ctl, idx); | 
|  | 609 | } | 
|  | 610 |  | 
|  | 611 | static int srcu_torture_completed(void) | 
|  | 612 | { | 
|  | 613 | return srcu_batches_completed(&srcu_ctl); | 
|  | 614 | } | 
|  | 615 |  | 
|  | 616 | static void srcu_torture_synchronize(void) | 
|  | 617 | { | 
|  | 618 | synchronize_srcu(&srcu_ctl); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | static int srcu_torture_stats(char *page) | 
|  | 622 | { | 
|  | 623 | int cnt = 0; | 
|  | 624 | int cpu; | 
|  | 625 | int idx = srcu_ctl.completed & 0x1; | 
|  | 626 |  | 
|  | 627 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | 
|  | 628 | torture_type, TORTURE_FLAG, idx); | 
|  | 629 | for_each_possible_cpu(cpu) { | 
|  | 630 | cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu, | 
|  | 631 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], | 
|  | 632 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | 
|  | 633 | } | 
|  | 634 | cnt += sprintf(&page[cnt], "\n"); | 
|  | 635 | return cnt; | 
|  | 636 | } | 
|  | 637 |  | 
|  | 638 | static struct rcu_torture_ops srcu_ops = { | 
|  | 639 | .init		= srcu_torture_init, | 
|  | 640 | .cleanup	= srcu_torture_cleanup, | 
|  | 641 | .readlock	= srcu_torture_read_lock, | 
|  | 642 | .read_delay	= srcu_read_delay, | 
|  | 643 | .readunlock	= srcu_torture_read_unlock, | 
|  | 644 | .completed	= srcu_torture_completed, | 
|  | 645 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 646 | .sync		= srcu_torture_synchronize, | 
|  | 647 | .cb_barrier	= NULL, | 
|  | 648 | .stats		= srcu_torture_stats, | 
|  | 649 | .name		= "srcu" | 
|  | 650 | }; | 
|  | 651 |  | 
|  | 652 | static int srcu_torture_read_lock_raw(void) __acquires(&srcu_ctl) | 
|  | 653 | { | 
|  | 654 | return srcu_read_lock_raw(&srcu_ctl); | 
|  | 655 | } | 
|  | 656 |  | 
|  | 657 | static void srcu_torture_read_unlock_raw(int idx) __releases(&srcu_ctl) | 
|  | 658 | { | 
|  | 659 | srcu_read_unlock_raw(&srcu_ctl, idx); | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 | static struct rcu_torture_ops srcu_raw_ops = { | 
|  | 663 | .init		= srcu_torture_init, | 
|  | 664 | .cleanup	= srcu_torture_cleanup, | 
|  | 665 | .readlock	= srcu_torture_read_lock_raw, | 
|  | 666 | .read_delay	= srcu_read_delay, | 
|  | 667 | .readunlock	= srcu_torture_read_unlock_raw, | 
|  | 668 | .completed	= srcu_torture_completed, | 
|  | 669 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 670 | .sync		= srcu_torture_synchronize, | 
|  | 671 | .cb_barrier	= NULL, | 
|  | 672 | .stats		= srcu_torture_stats, | 
|  | 673 | .name		= "srcu_raw" | 
|  | 674 | }; | 
|  | 675 |  | 
|  | 676 | static void srcu_torture_synchronize_expedited(void) | 
|  | 677 | { | 
|  | 678 | synchronize_srcu_expedited(&srcu_ctl); | 
|  | 679 | } | 
|  | 680 |  | 
|  | 681 | static struct rcu_torture_ops srcu_expedited_ops = { | 
|  | 682 | .init		= srcu_torture_init, | 
|  | 683 | .cleanup	= srcu_torture_cleanup, | 
|  | 684 | .readlock	= srcu_torture_read_lock, | 
|  | 685 | .read_delay	= srcu_read_delay, | 
|  | 686 | .readunlock	= srcu_torture_read_unlock, | 
|  | 687 | .completed	= srcu_torture_completed, | 
|  | 688 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 689 | .sync		= srcu_torture_synchronize_expedited, | 
|  | 690 | .cb_barrier	= NULL, | 
|  | 691 | .stats		= srcu_torture_stats, | 
|  | 692 | .name		= "srcu_expedited" | 
|  | 693 | }; | 
|  | 694 |  | 
|  | 695 | /* | 
|  | 696 | * Definitions for sched torture testing. | 
|  | 697 | */ | 
|  | 698 |  | 
|  | 699 | static int sched_torture_read_lock(void) | 
|  | 700 | { | 
|  | 701 | preempt_disable(); | 
|  | 702 | return 0; | 
|  | 703 | } | 
|  | 704 |  | 
|  | 705 | static void sched_torture_read_unlock(int idx) | 
|  | 706 | { | 
|  | 707 | preempt_enable(); | 
|  | 708 | } | 
|  | 709 |  | 
|  | 710 | static void rcu_sched_torture_deferred_free(struct rcu_torture *p) | 
|  | 711 | { | 
|  | 712 | call_rcu_sched(&p->rtort_rcu, rcu_torture_cb); | 
|  | 713 | } | 
|  | 714 |  | 
|  | 715 | static struct rcu_torture_ops sched_ops = { | 
|  | 716 | .init		= rcu_sync_torture_init, | 
|  | 717 | .cleanup	= NULL, | 
|  | 718 | .readlock	= sched_torture_read_lock, | 
|  | 719 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 720 | .readunlock	= sched_torture_read_unlock, | 
|  | 721 | .completed	= rcu_no_completed, | 
|  | 722 | .deferred_free	= rcu_sched_torture_deferred_free, | 
|  | 723 | .sync		= synchronize_sched, | 
|  | 724 | .cb_barrier	= rcu_barrier_sched, | 
|  | 725 | .fqs		= rcu_sched_force_quiescent_state, | 
|  | 726 | .stats		= NULL, | 
|  | 727 | .irq_capable	= 1, | 
|  | 728 | .name		= "sched" | 
|  | 729 | }; | 
|  | 730 |  | 
|  | 731 | static struct rcu_torture_ops sched_sync_ops = { | 
|  | 732 | .init		= rcu_sync_torture_init, | 
|  | 733 | .cleanup	= NULL, | 
|  | 734 | .readlock	= sched_torture_read_lock, | 
|  | 735 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 736 | .readunlock	= sched_torture_read_unlock, | 
|  | 737 | .completed	= rcu_no_completed, | 
|  | 738 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 739 | .sync		= synchronize_sched, | 
|  | 740 | .cb_barrier	= NULL, | 
|  | 741 | .fqs		= rcu_sched_force_quiescent_state, | 
|  | 742 | .stats		= NULL, | 
|  | 743 | .name		= "sched_sync" | 
|  | 744 | }; | 
|  | 745 |  | 
|  | 746 | static struct rcu_torture_ops sched_expedited_ops = { | 
|  | 747 | .init		= rcu_sync_torture_init, | 
|  | 748 | .cleanup	= NULL, | 
|  | 749 | .readlock	= sched_torture_read_lock, | 
|  | 750 | .read_delay	= rcu_read_delay,  /* just reuse rcu's version. */ | 
|  | 751 | .readunlock	= sched_torture_read_unlock, | 
|  | 752 | .completed	= rcu_no_completed, | 
|  | 753 | .deferred_free	= rcu_sync_torture_deferred_free, | 
|  | 754 | .sync		= synchronize_sched_expedited, | 
|  | 755 | .cb_barrier	= NULL, | 
|  | 756 | .fqs		= rcu_sched_force_quiescent_state, | 
|  | 757 | .stats		= NULL, | 
|  | 758 | .irq_capable	= 1, | 
|  | 759 | .name		= "sched_expedited" | 
|  | 760 | }; | 
|  | 761 |  | 
|  | 762 | /* | 
|  | 763 | * RCU torture priority-boost testing.  Runs one real-time thread per | 
|  | 764 | * CPU for moderate bursts, repeatedly registering RCU callbacks and | 
|  | 765 | * spinning waiting for them to be invoked.  If a given callback takes | 
|  | 766 | * too long to be invoked, we assume that priority inversion has occurred. | 
|  | 767 | */ | 
|  | 768 |  | 
|  | 769 | struct rcu_boost_inflight { | 
|  | 770 | struct rcu_head rcu; | 
|  | 771 | int inflight; | 
|  | 772 | }; | 
|  | 773 |  | 
|  | 774 | static void rcu_torture_boost_cb(struct rcu_head *head) | 
|  | 775 | { | 
|  | 776 | struct rcu_boost_inflight *rbip = | 
|  | 777 | container_of(head, struct rcu_boost_inflight, rcu); | 
|  | 778 |  | 
|  | 779 | smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ | 
|  | 780 | rbip->inflight = 0; | 
|  | 781 | } | 
|  | 782 |  | 
|  | 783 | static int rcu_torture_boost(void *arg) | 
|  | 784 | { | 
|  | 785 | unsigned long call_rcu_time; | 
|  | 786 | unsigned long endtime; | 
|  | 787 | unsigned long oldstarttime; | 
|  | 788 | struct rcu_boost_inflight rbi = { .inflight = 0 }; | 
|  | 789 | struct sched_param sp; | 
|  | 790 |  | 
|  | 791 | VERBOSE_PRINTK_STRING("rcu_torture_boost started"); | 
|  | 792 |  | 
|  | 793 | /* Set real-time priority. */ | 
|  | 794 | sp.sched_priority = 1; | 
|  | 795 | if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) { | 
|  | 796 | VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!"); | 
|  | 797 | n_rcu_torture_boost_rterror++; | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | init_rcu_head_on_stack(&rbi.rcu); | 
|  | 801 | /* Each pass through the following loop does one boost-test cycle. */ | 
|  | 802 | do { | 
|  | 803 | /* Wait for the next test interval. */ | 
|  | 804 | oldstarttime = boost_starttime; | 
|  | 805 | while (ULONG_CMP_LT(jiffies, oldstarttime)) { | 
|  | 806 | schedule_timeout_uninterruptible(1); | 
|  | 807 | rcu_stutter_wait("rcu_torture_boost"); | 
|  | 808 | if (kthread_should_stop() || | 
|  | 809 | fullstop != FULLSTOP_DONTSTOP) | 
|  | 810 | goto checkwait; | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | /* Do one boost-test interval. */ | 
|  | 814 | endtime = oldstarttime + test_boost_duration * HZ; | 
|  | 815 | call_rcu_time = jiffies; | 
|  | 816 | while (ULONG_CMP_LT(jiffies, endtime)) { | 
|  | 817 | /* If we don't have a callback in flight, post one. */ | 
|  | 818 | if (!rbi.inflight) { | 
|  | 819 | smp_mb(); /* RCU core before ->inflight = 1. */ | 
|  | 820 | rbi.inflight = 1; | 
|  | 821 | call_rcu(&rbi.rcu, rcu_torture_boost_cb); | 
|  | 822 | if (jiffies - call_rcu_time > | 
|  | 823 | test_boost_duration * HZ - HZ / 2) { | 
|  | 824 | VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed"); | 
|  | 825 | n_rcu_torture_boost_failure++; | 
|  | 826 | } | 
|  | 827 | call_rcu_time = jiffies; | 
|  | 828 | } | 
|  | 829 | cond_resched(); | 
|  | 830 | rcu_stutter_wait("rcu_torture_boost"); | 
|  | 831 | if (kthread_should_stop() || | 
|  | 832 | fullstop != FULLSTOP_DONTSTOP) | 
|  | 833 | goto checkwait; | 
|  | 834 | } | 
|  | 835 |  | 
|  | 836 | /* | 
|  | 837 | * Set the start time of the next test interval. | 
|  | 838 | * Yes, this is vulnerable to long delays, but such | 
|  | 839 | * delays simply cause a false negative for the next | 
|  | 840 | * interval.  Besides, we are running at RT priority, | 
|  | 841 | * so delays should be relatively rare. | 
|  | 842 | */ | 
|  | 843 | while (oldstarttime == boost_starttime && | 
|  | 844 | !kthread_should_stop()) { | 
|  | 845 | if (mutex_trylock(&boost_mutex)) { | 
|  | 846 | boost_starttime = jiffies + | 
|  | 847 | test_boost_interval * HZ; | 
|  | 848 | n_rcu_torture_boosts++; | 
|  | 849 | mutex_unlock(&boost_mutex); | 
|  | 850 | break; | 
|  | 851 | } | 
|  | 852 | schedule_timeout_uninterruptible(1); | 
|  | 853 | } | 
|  | 854 |  | 
|  | 855 | /* Go do the stutter. */ | 
|  | 856 | checkwait:	rcu_stutter_wait("rcu_torture_boost"); | 
|  | 857 | } while (!kthread_should_stop() && fullstop  == FULLSTOP_DONTSTOP); | 
|  | 858 |  | 
|  | 859 | /* Clean up and exit. */ | 
|  | 860 | VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping"); | 
|  | 861 | rcutorture_shutdown_absorb("rcu_torture_boost"); | 
|  | 862 | while (!kthread_should_stop() || rbi.inflight) | 
|  | 863 | schedule_timeout_uninterruptible(1); | 
|  | 864 | smp_mb(); /* order accesses to ->inflight before stack-frame death. */ | 
|  | 865 | destroy_rcu_head_on_stack(&rbi.rcu); | 
|  | 866 | return 0; | 
|  | 867 | } | 
|  | 868 |  | 
|  | 869 | /* | 
|  | 870 | * RCU torture force-quiescent-state kthread.  Repeatedly induces | 
|  | 871 | * bursts of calls to force_quiescent_state(), increasing the probability | 
|  | 872 | * of occurrence of some important types of race conditions. | 
|  | 873 | */ | 
|  | 874 | static int | 
|  | 875 | rcu_torture_fqs(void *arg) | 
|  | 876 | { | 
|  | 877 | unsigned long fqs_resume_time; | 
|  | 878 | int fqs_burst_remaining; | 
|  | 879 |  | 
|  | 880 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task started"); | 
|  | 881 | do { | 
|  | 882 | fqs_resume_time = jiffies + fqs_stutter * HZ; | 
|  | 883 | while (ULONG_CMP_LT(jiffies, fqs_resume_time) && | 
|  | 884 | !kthread_should_stop()) { | 
|  | 885 | schedule_timeout_interruptible(1); | 
|  | 886 | } | 
|  | 887 | fqs_burst_remaining = fqs_duration; | 
|  | 888 | while (fqs_burst_remaining > 0 && | 
|  | 889 | !kthread_should_stop()) { | 
|  | 890 | cur_ops->fqs(); | 
|  | 891 | udelay(fqs_holdoff); | 
|  | 892 | fqs_burst_remaining -= fqs_holdoff; | 
|  | 893 | } | 
|  | 894 | rcu_stutter_wait("rcu_torture_fqs"); | 
|  | 895 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 
|  | 896 | VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping"); | 
|  | 897 | rcutorture_shutdown_absorb("rcu_torture_fqs"); | 
|  | 898 | while (!kthread_should_stop()) | 
|  | 899 | schedule_timeout_uninterruptible(1); | 
|  | 900 | return 0; | 
|  | 901 | } | 
|  | 902 |  | 
|  | 903 | /* | 
|  | 904 | * RCU torture writer kthread.  Repeatedly substitutes a new structure | 
|  | 905 | * for that pointed to by rcu_torture_current, freeing the old structure | 
|  | 906 | * after a series of grace periods (the "pipeline"). | 
|  | 907 | */ | 
|  | 908 | static int | 
|  | 909 | rcu_torture_writer(void *arg) | 
|  | 910 | { | 
|  | 911 | int i; | 
|  | 912 | long oldbatch = rcu_batches_completed(); | 
|  | 913 | struct rcu_torture *rp; | 
|  | 914 | struct rcu_torture *old_rp; | 
|  | 915 | static DEFINE_RCU_RANDOM(rand); | 
|  | 916 |  | 
|  | 917 | VERBOSE_PRINTK_STRING("rcu_torture_writer task started"); | 
|  | 918 | set_user_nice(current, 19); | 
|  | 919 |  | 
|  | 920 | do { | 
|  | 921 | schedule_timeout_uninterruptible(1); | 
|  | 922 | rp = rcu_torture_alloc(); | 
|  | 923 | if (rp == NULL) | 
|  | 924 | continue; | 
|  | 925 | rp->rtort_pipe_count = 0; | 
|  | 926 | udelay(rcu_random(&rand) & 0x3ff); | 
|  | 927 | old_rp = rcu_dereference_check(rcu_torture_current, | 
|  | 928 | current == writer_task); | 
|  | 929 | rp->rtort_mbtest = 1; | 
|  | 930 | rcu_assign_pointer(rcu_torture_current, rp); | 
|  | 931 | smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */ | 
|  | 932 | if (old_rp) { | 
|  | 933 | i = old_rp->rtort_pipe_count; | 
|  | 934 | if (i > RCU_TORTURE_PIPE_LEN) | 
|  | 935 | i = RCU_TORTURE_PIPE_LEN; | 
|  | 936 | atomic_inc(&rcu_torture_wcount[i]); | 
|  | 937 | old_rp->rtort_pipe_count++; | 
|  | 938 | cur_ops->deferred_free(old_rp); | 
|  | 939 | } | 
|  | 940 | rcutorture_record_progress(++rcu_torture_current_version); | 
|  | 941 | oldbatch = cur_ops->completed(); | 
|  | 942 | rcu_stutter_wait("rcu_torture_writer"); | 
|  | 943 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 
|  | 944 | VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping"); | 
|  | 945 | rcutorture_shutdown_absorb("rcu_torture_writer"); | 
|  | 946 | while (!kthread_should_stop()) | 
|  | 947 | schedule_timeout_uninterruptible(1); | 
|  | 948 | return 0; | 
|  | 949 | } | 
|  | 950 |  | 
|  | 951 | /* | 
|  | 952 | * RCU torture fake writer kthread.  Repeatedly calls sync, with a random | 
|  | 953 | * delay between calls. | 
|  | 954 | */ | 
|  | 955 | static int | 
|  | 956 | rcu_torture_fakewriter(void *arg) | 
|  | 957 | { | 
|  | 958 | DEFINE_RCU_RANDOM(rand); | 
|  | 959 |  | 
|  | 960 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started"); | 
|  | 961 | set_user_nice(current, 19); | 
|  | 962 |  | 
|  | 963 | do { | 
|  | 964 | schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10); | 
|  | 965 | udelay(rcu_random(&rand) & 0x3ff); | 
|  | 966 | cur_ops->sync(); | 
|  | 967 | rcu_stutter_wait("rcu_torture_fakewriter"); | 
|  | 968 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 
|  | 969 |  | 
|  | 970 | VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping"); | 
|  | 971 | rcutorture_shutdown_absorb("rcu_torture_fakewriter"); | 
|  | 972 | while (!kthread_should_stop()) | 
|  | 973 | schedule_timeout_uninterruptible(1); | 
|  | 974 | return 0; | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 | void rcutorture_trace_dump(void) | 
|  | 978 | { | 
|  | 979 | static atomic_t beenhere = ATOMIC_INIT(0); | 
|  | 980 |  | 
|  | 981 | if (atomic_read(&beenhere)) | 
|  | 982 | return; | 
|  | 983 | if (atomic_xchg(&beenhere, 1) != 0) | 
|  | 984 | return; | 
|  | 985 | do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL); | 
|  | 986 | ftrace_dump(DUMP_ALL); | 
|  | 987 | } | 
|  | 988 |  | 
|  | 989 | /* | 
|  | 990 | * RCU torture reader from timer handler.  Dereferences rcu_torture_current, | 
|  | 991 | * incrementing the corresponding element of the pipeline array.  The | 
|  | 992 | * counter in the element should never be greater than 1, otherwise, the | 
|  | 993 | * RCU implementation is broken. | 
|  | 994 | */ | 
|  | 995 | static void rcu_torture_timer(unsigned long unused) | 
|  | 996 | { | 
|  | 997 | int idx; | 
|  | 998 | int completed; | 
|  | 999 | static DEFINE_RCU_RANDOM(rand); | 
|  | 1000 | static DEFINE_SPINLOCK(rand_lock); | 
|  | 1001 | struct rcu_torture *p; | 
|  | 1002 | int pipe_count; | 
|  | 1003 |  | 
|  | 1004 | idx = cur_ops->readlock(); | 
|  | 1005 | completed = cur_ops->completed(); | 
|  | 1006 | p = rcu_dereference_check(rcu_torture_current, | 
|  | 1007 | rcu_read_lock_bh_held() || | 
|  | 1008 | rcu_read_lock_sched_held() || | 
|  | 1009 | srcu_read_lock_held(&srcu_ctl)); | 
|  | 1010 | if (p == NULL) { | 
|  | 1011 | /* Leave because rcu_torture_writer is not yet underway */ | 
|  | 1012 | cur_ops->readunlock(idx); | 
|  | 1013 | return; | 
|  | 1014 | } | 
|  | 1015 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu); | 
|  | 1016 | if (p->rtort_mbtest == 0) | 
|  | 1017 | atomic_inc(&n_rcu_torture_mberror); | 
|  | 1018 | spin_lock(&rand_lock); | 
|  | 1019 | cur_ops->read_delay(&rand); | 
|  | 1020 | n_rcu_torture_timers++; | 
|  | 1021 | spin_unlock(&rand_lock); | 
|  | 1022 | preempt_disable(); | 
|  | 1023 | pipe_count = p->rtort_pipe_count; | 
|  | 1024 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | 
|  | 1025 | /* Should not happen, but... */ | 
|  | 1026 | pipe_count = RCU_TORTURE_PIPE_LEN; | 
|  | 1027 | } | 
|  | 1028 | if (pipe_count > 1) | 
|  | 1029 | rcutorture_trace_dump(); | 
|  | 1030 | __this_cpu_inc(rcu_torture_count[pipe_count]); | 
|  | 1031 | completed = cur_ops->completed() - completed; | 
|  | 1032 | if (completed > RCU_TORTURE_PIPE_LEN) { | 
|  | 1033 | /* Should not happen, but... */ | 
|  | 1034 | completed = RCU_TORTURE_PIPE_LEN; | 
|  | 1035 | } | 
|  | 1036 | __this_cpu_inc(rcu_torture_batch[completed]); | 
|  | 1037 | preempt_enable(); | 
|  | 1038 | cur_ops->readunlock(idx); | 
|  | 1039 | } | 
|  | 1040 |  | 
|  | 1041 | /* | 
|  | 1042 | * RCU torture reader kthread.  Repeatedly dereferences rcu_torture_current, | 
|  | 1043 | * incrementing the corresponding element of the pipeline array.  The | 
|  | 1044 | * counter in the element should never be greater than 1, otherwise, the | 
|  | 1045 | * RCU implementation is broken. | 
|  | 1046 | */ | 
|  | 1047 | static int | 
|  | 1048 | rcu_torture_reader(void *arg) | 
|  | 1049 | { | 
|  | 1050 | int completed; | 
|  | 1051 | int idx; | 
|  | 1052 | DEFINE_RCU_RANDOM(rand); | 
|  | 1053 | struct rcu_torture *p; | 
|  | 1054 | int pipe_count; | 
|  | 1055 | struct timer_list t; | 
|  | 1056 |  | 
|  | 1057 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | 
|  | 1058 | set_user_nice(current, 19); | 
|  | 1059 | if (irqreader && cur_ops->irq_capable) | 
|  | 1060 | setup_timer_on_stack(&t, rcu_torture_timer, 0); | 
|  | 1061 |  | 
|  | 1062 | do { | 
|  | 1063 | if (irqreader && cur_ops->irq_capable) { | 
|  | 1064 | if (!timer_pending(&t)) | 
|  | 1065 | mod_timer(&t, jiffies + 1); | 
|  | 1066 | } | 
|  | 1067 | idx = cur_ops->readlock(); | 
|  | 1068 | completed = cur_ops->completed(); | 
|  | 1069 | p = rcu_dereference_check(rcu_torture_current, | 
|  | 1070 | rcu_read_lock_bh_held() || | 
|  | 1071 | rcu_read_lock_sched_held() || | 
|  | 1072 | srcu_read_lock_held(&srcu_ctl)); | 
|  | 1073 | if (p == NULL) { | 
|  | 1074 | /* Wait for rcu_torture_writer to get underway */ | 
|  | 1075 | cur_ops->readunlock(idx); | 
|  | 1076 | schedule_timeout_interruptible(HZ); | 
|  | 1077 | continue; | 
|  | 1078 | } | 
|  | 1079 | do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu); | 
|  | 1080 | if (p->rtort_mbtest == 0) | 
|  | 1081 | atomic_inc(&n_rcu_torture_mberror); | 
|  | 1082 | cur_ops->read_delay(&rand); | 
|  | 1083 | preempt_disable(); | 
|  | 1084 | pipe_count = p->rtort_pipe_count; | 
|  | 1085 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | 
|  | 1086 | /* Should not happen, but... */ | 
|  | 1087 | pipe_count = RCU_TORTURE_PIPE_LEN; | 
|  | 1088 | } | 
|  | 1089 | if (pipe_count > 1) | 
|  | 1090 | rcutorture_trace_dump(); | 
|  | 1091 | __this_cpu_inc(rcu_torture_count[pipe_count]); | 
|  | 1092 | completed = cur_ops->completed() - completed; | 
|  | 1093 | if (completed > RCU_TORTURE_PIPE_LEN) { | 
|  | 1094 | /* Should not happen, but... */ | 
|  | 1095 | completed = RCU_TORTURE_PIPE_LEN; | 
|  | 1096 | } | 
|  | 1097 | __this_cpu_inc(rcu_torture_batch[completed]); | 
|  | 1098 | preempt_enable(); | 
|  | 1099 | cur_ops->readunlock(idx); | 
|  | 1100 | schedule(); | 
|  | 1101 | rcu_stutter_wait("rcu_torture_reader"); | 
|  | 1102 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 
|  | 1103 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); | 
|  | 1104 | rcutorture_shutdown_absorb("rcu_torture_reader"); | 
|  | 1105 | if (irqreader && cur_ops->irq_capable) | 
|  | 1106 | del_timer_sync(&t); | 
|  | 1107 | while (!kthread_should_stop()) | 
|  | 1108 | schedule_timeout_uninterruptible(1); | 
|  | 1109 | return 0; | 
|  | 1110 | } | 
|  | 1111 |  | 
|  | 1112 | /* | 
|  | 1113 | * Create an RCU-torture statistics message in the specified buffer. | 
|  | 1114 | */ | 
|  | 1115 | static int | 
|  | 1116 | rcu_torture_printk(char *page) | 
|  | 1117 | { | 
|  | 1118 | int cnt = 0; | 
|  | 1119 | int cpu; | 
|  | 1120 | int i; | 
|  | 1121 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | 
|  | 1122 | long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | 
|  | 1123 |  | 
|  | 1124 | for_each_possible_cpu(cpu) { | 
|  | 1125 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | 
|  | 1126 | pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i]; | 
|  | 1127 | batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i]; | 
|  | 1128 | } | 
|  | 1129 | } | 
|  | 1130 | for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) { | 
|  | 1131 | if (pipesummary[i] != 0) | 
|  | 1132 | break; | 
|  | 1133 | } | 
|  | 1134 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); | 
|  | 1135 | cnt += sprintf(&page[cnt], | 
|  | 1136 | "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d " | 
|  | 1137 | "rtmbe: %d rtbke: %ld rtbre: %ld " | 
|  | 1138 | "rtbf: %ld rtb: %ld nt: %ld " | 
|  | 1139 | "onoff: %ld/%ld:%ld/%ld", | 
|  | 1140 | rcu_torture_current, | 
|  | 1141 | rcu_torture_current_version, | 
|  | 1142 | list_empty(&rcu_torture_freelist), | 
|  | 1143 | atomic_read(&n_rcu_torture_alloc), | 
|  | 1144 | atomic_read(&n_rcu_torture_alloc_fail), | 
|  | 1145 | atomic_read(&n_rcu_torture_free), | 
|  | 1146 | atomic_read(&n_rcu_torture_mberror), | 
|  | 1147 | n_rcu_torture_boost_ktrerror, | 
|  | 1148 | n_rcu_torture_boost_rterror, | 
|  | 1149 | n_rcu_torture_boost_failure, | 
|  | 1150 | n_rcu_torture_boosts, | 
|  | 1151 | n_rcu_torture_timers, | 
|  | 1152 | n_online_successes, | 
|  | 1153 | n_online_attempts, | 
|  | 1154 | n_offline_successes, | 
|  | 1155 | n_offline_attempts); | 
|  | 1156 | if (atomic_read(&n_rcu_torture_mberror) != 0 || | 
|  | 1157 | n_rcu_torture_boost_ktrerror != 0 || | 
|  | 1158 | n_rcu_torture_boost_rterror != 0 || | 
|  | 1159 | n_rcu_torture_boost_failure != 0) | 
|  | 1160 | cnt += sprintf(&page[cnt], " !!!"); | 
|  | 1161 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 
|  | 1162 | if (i > 1) { | 
|  | 1163 | cnt += sprintf(&page[cnt], "!!! "); | 
|  | 1164 | atomic_inc(&n_rcu_torture_error); | 
|  | 1165 | WARN_ON_ONCE(1); | 
|  | 1166 | } | 
|  | 1167 | cnt += sprintf(&page[cnt], "Reader Pipe: "); | 
|  | 1168 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | 
|  | 1169 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | 
|  | 1170 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 
|  | 1171 | cnt += sprintf(&page[cnt], "Reader Batch: "); | 
|  | 1172 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | 
|  | 1173 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); | 
|  | 1174 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 
|  | 1175 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); | 
|  | 1176 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | 
|  | 1177 | cnt += sprintf(&page[cnt], " %d", | 
|  | 1178 | atomic_read(&rcu_torture_wcount[i])); | 
|  | 1179 | } | 
|  | 1180 | cnt += sprintf(&page[cnt], "\n"); | 
|  | 1181 | if (cur_ops->stats) | 
|  | 1182 | cnt += cur_ops->stats(&page[cnt]); | 
|  | 1183 | return cnt; | 
|  | 1184 | } | 
|  | 1185 |  | 
|  | 1186 | /* | 
|  | 1187 | * Print torture statistics.  Caller must ensure that there is only | 
|  | 1188 | * one call to this function at a given time!!!  This is normally | 
|  | 1189 | * accomplished by relying on the module system to only have one copy | 
|  | 1190 | * of the module loaded, and then by giving the rcu_torture_stats | 
|  | 1191 | * kthread full control (or the init/cleanup functions when rcu_torture_stats | 
|  | 1192 | * thread is not running). | 
|  | 1193 | */ | 
|  | 1194 | static void | 
|  | 1195 | rcu_torture_stats_print(void) | 
|  | 1196 | { | 
|  | 1197 | int cnt; | 
|  | 1198 |  | 
|  | 1199 | cnt = rcu_torture_printk(printk_buf); | 
|  | 1200 | printk(KERN_ALERT "%s", printk_buf); | 
|  | 1201 | } | 
|  | 1202 |  | 
|  | 1203 | /* | 
|  | 1204 | * Periodically prints torture statistics, if periodic statistics printing | 
|  | 1205 | * was specified via the stat_interval module parameter. | 
|  | 1206 | * | 
|  | 1207 | * No need to worry about fullstop here, since this one doesn't reference | 
|  | 1208 | * volatile state or register callbacks. | 
|  | 1209 | */ | 
|  | 1210 | static int | 
|  | 1211 | rcu_torture_stats(void *arg) | 
|  | 1212 | { | 
|  | 1213 | VERBOSE_PRINTK_STRING("rcu_torture_stats task started"); | 
|  | 1214 | do { | 
|  | 1215 | schedule_timeout_interruptible(stat_interval * HZ); | 
|  | 1216 | rcu_torture_stats_print(); | 
|  | 1217 | rcutorture_shutdown_absorb("rcu_torture_stats"); | 
|  | 1218 | } while (!kthread_should_stop()); | 
|  | 1219 | VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping"); | 
|  | 1220 | return 0; | 
|  | 1221 | } | 
|  | 1222 |  | 
|  | 1223 | static int rcu_idle_cpu;	/* Force all torture tasks off this CPU */ | 
|  | 1224 |  | 
|  | 1225 | /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case | 
|  | 1226 | * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs. | 
|  | 1227 | */ | 
|  | 1228 | static void rcu_torture_shuffle_tasks(void) | 
|  | 1229 | { | 
|  | 1230 | int i; | 
|  | 1231 |  | 
|  | 1232 | cpumask_setall(shuffle_tmp_mask); | 
|  | 1233 | get_online_cpus(); | 
|  | 1234 |  | 
|  | 1235 | /* No point in shuffling if there is only one online CPU (ex: UP) */ | 
|  | 1236 | if (num_online_cpus() == 1) { | 
|  | 1237 | put_online_cpus(); | 
|  | 1238 | return; | 
|  | 1239 | } | 
|  | 1240 |  | 
|  | 1241 | if (rcu_idle_cpu != -1) | 
|  | 1242 | cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask); | 
|  | 1243 |  | 
|  | 1244 | set_cpus_allowed_ptr(current, shuffle_tmp_mask); | 
|  | 1245 |  | 
|  | 1246 | if (reader_tasks) { | 
|  | 1247 | for (i = 0; i < nrealreaders; i++) | 
|  | 1248 | if (reader_tasks[i]) | 
|  | 1249 | set_cpus_allowed_ptr(reader_tasks[i], | 
|  | 1250 | shuffle_tmp_mask); | 
|  | 1251 | } | 
|  | 1252 |  | 
|  | 1253 | if (fakewriter_tasks) { | 
|  | 1254 | for (i = 0; i < nfakewriters; i++) | 
|  | 1255 | if (fakewriter_tasks[i]) | 
|  | 1256 | set_cpus_allowed_ptr(fakewriter_tasks[i], | 
|  | 1257 | shuffle_tmp_mask); | 
|  | 1258 | } | 
|  | 1259 |  | 
|  | 1260 | if (writer_task) | 
|  | 1261 | set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask); | 
|  | 1262 |  | 
|  | 1263 | if (stats_task) | 
|  | 1264 | set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask); | 
|  | 1265 |  | 
|  | 1266 | if (rcu_idle_cpu == -1) | 
|  | 1267 | rcu_idle_cpu = num_online_cpus() - 1; | 
|  | 1268 | else | 
|  | 1269 | rcu_idle_cpu--; | 
|  | 1270 |  | 
|  | 1271 | put_online_cpus(); | 
|  | 1272 | } | 
|  | 1273 |  | 
|  | 1274 | /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the | 
|  | 1275 | * system to become idle at a time and cut off its timer ticks. This is meant | 
|  | 1276 | * to test the support for such tickless idle CPU in RCU. | 
|  | 1277 | */ | 
|  | 1278 | static int | 
|  | 1279 | rcu_torture_shuffle(void *arg) | 
|  | 1280 | { | 
|  | 1281 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started"); | 
|  | 1282 | do { | 
|  | 1283 | schedule_timeout_interruptible(shuffle_interval * HZ); | 
|  | 1284 | rcu_torture_shuffle_tasks(); | 
|  | 1285 | rcutorture_shutdown_absorb("rcu_torture_shuffle"); | 
|  | 1286 | } while (!kthread_should_stop()); | 
|  | 1287 | VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping"); | 
|  | 1288 | return 0; | 
|  | 1289 | } | 
|  | 1290 |  | 
|  | 1291 | /* Cause the rcutorture test to "stutter", starting and stopping all | 
|  | 1292 | * threads periodically. | 
|  | 1293 | */ | 
|  | 1294 | static int | 
|  | 1295 | rcu_torture_stutter(void *arg) | 
|  | 1296 | { | 
|  | 1297 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task started"); | 
|  | 1298 | do { | 
|  | 1299 | schedule_timeout_interruptible(stutter * HZ); | 
|  | 1300 | stutter_pause_test = 1; | 
|  | 1301 | if (!kthread_should_stop()) | 
|  | 1302 | schedule_timeout_interruptible(stutter * HZ); | 
|  | 1303 | stutter_pause_test = 0; | 
|  | 1304 | rcutorture_shutdown_absorb("rcu_torture_stutter"); | 
|  | 1305 | } while (!kthread_should_stop()); | 
|  | 1306 | VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping"); | 
|  | 1307 | return 0; | 
|  | 1308 | } | 
|  | 1309 |  | 
|  | 1310 | static inline void | 
|  | 1311 | rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag) | 
|  | 1312 | { | 
|  | 1313 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1314 | "--- %s: nreaders=%d nfakewriters=%d " | 
|  | 1315 | "stat_interval=%d verbose=%d test_no_idle_hz=%d " | 
|  | 1316 | "shuffle_interval=%d stutter=%d irqreader=%d " | 
|  | 1317 | "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d " | 
|  | 1318 | "test_boost=%d/%d test_boost_interval=%d " | 
|  | 1319 | "test_boost_duration=%d shutdown_secs=%d " | 
|  | 1320 | "onoff_interval=%d onoff_holdoff=%d\n", | 
|  | 1321 | torture_type, tag, nrealreaders, nfakewriters, | 
|  | 1322 | stat_interval, verbose, test_no_idle_hz, shuffle_interval, | 
|  | 1323 | stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter, | 
|  | 1324 | test_boost, cur_ops->can_boost, | 
|  | 1325 | test_boost_interval, test_boost_duration, shutdown_secs, | 
|  | 1326 | onoff_interval, onoff_holdoff); | 
|  | 1327 | } | 
|  | 1328 |  | 
|  | 1329 | static struct notifier_block rcutorture_shutdown_nb = { | 
|  | 1330 | .notifier_call = rcutorture_shutdown_notify, | 
|  | 1331 | }; | 
|  | 1332 |  | 
|  | 1333 | static void rcutorture_booster_cleanup(int cpu) | 
|  | 1334 | { | 
|  | 1335 | struct task_struct *t; | 
|  | 1336 |  | 
|  | 1337 | if (boost_tasks[cpu] == NULL) | 
|  | 1338 | return; | 
|  | 1339 | mutex_lock(&boost_mutex); | 
|  | 1340 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task"); | 
|  | 1341 | t = boost_tasks[cpu]; | 
|  | 1342 | boost_tasks[cpu] = NULL; | 
|  | 1343 | mutex_unlock(&boost_mutex); | 
|  | 1344 |  | 
|  | 1345 | /* This must be outside of the mutex, otherwise deadlock! */ | 
|  | 1346 | kthread_stop(t); | 
|  | 1347 | } | 
|  | 1348 |  | 
|  | 1349 | static int rcutorture_booster_init(int cpu) | 
|  | 1350 | { | 
|  | 1351 | int retval; | 
|  | 1352 |  | 
|  | 1353 | if (boost_tasks[cpu] != NULL) | 
|  | 1354 | return 0;  /* Already created, nothing more to do. */ | 
|  | 1355 |  | 
|  | 1356 | /* Don't allow time recalculation while creating a new task. */ | 
|  | 1357 | mutex_lock(&boost_mutex); | 
|  | 1358 | VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task"); | 
|  | 1359 | boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL, | 
|  | 1360 | cpu_to_node(cpu), | 
|  | 1361 | "rcu_torture_boost"); | 
|  | 1362 | if (IS_ERR(boost_tasks[cpu])) { | 
|  | 1363 | retval = PTR_ERR(boost_tasks[cpu]); | 
|  | 1364 | VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed"); | 
|  | 1365 | n_rcu_torture_boost_ktrerror++; | 
|  | 1366 | boost_tasks[cpu] = NULL; | 
|  | 1367 | mutex_unlock(&boost_mutex); | 
|  | 1368 | return retval; | 
|  | 1369 | } | 
|  | 1370 | kthread_bind(boost_tasks[cpu], cpu); | 
|  | 1371 | wake_up_process(boost_tasks[cpu]); | 
|  | 1372 | mutex_unlock(&boost_mutex); | 
|  | 1373 | return 0; | 
|  | 1374 | } | 
|  | 1375 |  | 
|  | 1376 | /* | 
|  | 1377 | * Cause the rcutorture test to shutdown the system after the test has | 
|  | 1378 | * run for the time specified by the shutdown_secs module parameter. | 
|  | 1379 | */ | 
|  | 1380 | static int | 
|  | 1381 | rcu_torture_shutdown(void *arg) | 
|  | 1382 | { | 
|  | 1383 | long delta; | 
|  | 1384 | unsigned long jiffies_snap; | 
|  | 1385 |  | 
|  | 1386 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started"); | 
|  | 1387 | jiffies_snap = ACCESS_ONCE(jiffies); | 
|  | 1388 | while (ULONG_CMP_LT(jiffies_snap, shutdown_time) && | 
|  | 1389 | !kthread_should_stop()) { | 
|  | 1390 | delta = shutdown_time - jiffies_snap; | 
|  | 1391 | if (verbose) | 
|  | 1392 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1393 | "rcu_torture_shutdown task: %lu " | 
|  | 1394 | "jiffies remaining\n", | 
|  | 1395 | torture_type, delta); | 
|  | 1396 | schedule_timeout_interruptible(delta); | 
|  | 1397 | jiffies_snap = ACCESS_ONCE(jiffies); | 
|  | 1398 | } | 
|  | 1399 | if (kthread_should_stop()) { | 
|  | 1400 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping"); | 
|  | 1401 | return 0; | 
|  | 1402 | } | 
|  | 1403 |  | 
|  | 1404 | /* OK, shut down the system. */ | 
|  | 1405 |  | 
|  | 1406 | VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system"); | 
|  | 1407 | shutdown_task = NULL;	/* Avoid self-kill deadlock. */ | 
|  | 1408 | rcu_torture_cleanup();	/* Get the success/failure message. */ | 
|  | 1409 | kernel_power_off();	/* Shut down the system. */ | 
|  | 1410 | return 0; | 
|  | 1411 | } | 
|  | 1412 |  | 
|  | 1413 | #ifdef CONFIG_HOTPLUG_CPU | 
|  | 1414 |  | 
|  | 1415 | /* | 
|  | 1416 | * Execute random CPU-hotplug operations at the interval specified | 
|  | 1417 | * by the onoff_interval. | 
|  | 1418 | */ | 
|  | 1419 | static int __cpuinit | 
|  | 1420 | rcu_torture_onoff(void *arg) | 
|  | 1421 | { | 
|  | 1422 | int cpu; | 
|  | 1423 | int maxcpu = -1; | 
|  | 1424 | DEFINE_RCU_RANDOM(rand); | 
|  | 1425 |  | 
|  | 1426 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task started"); | 
|  | 1427 | for_each_online_cpu(cpu) | 
|  | 1428 | maxcpu = cpu; | 
|  | 1429 | WARN_ON(maxcpu < 0); | 
|  | 1430 | if (onoff_holdoff > 0) { | 
|  | 1431 | VERBOSE_PRINTK_STRING("rcu_torture_onoff begin holdoff"); | 
|  | 1432 | schedule_timeout_interruptible(onoff_holdoff * HZ); | 
|  | 1433 | VERBOSE_PRINTK_STRING("rcu_torture_onoff end holdoff"); | 
|  | 1434 | } | 
|  | 1435 | while (!kthread_should_stop()) { | 
|  | 1436 | cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1); | 
|  | 1437 | if (cpu_online(cpu) && cpu_is_hotpluggable(cpu)) { | 
|  | 1438 | if (verbose) | 
|  | 1439 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1440 | "rcu_torture_onoff task: offlining %d\n", | 
|  | 1441 | torture_type, cpu); | 
|  | 1442 | n_offline_attempts++; | 
|  | 1443 | if (cpu_down(cpu) == 0) { | 
|  | 1444 | if (verbose) | 
|  | 1445 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1446 | "rcu_torture_onoff task: " | 
|  | 1447 | "offlined %d\n", | 
|  | 1448 | torture_type, cpu); | 
|  | 1449 | n_offline_successes++; | 
|  | 1450 | } | 
|  | 1451 | } else if (cpu_is_hotpluggable(cpu)) { | 
|  | 1452 | if (verbose) | 
|  | 1453 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1454 | "rcu_torture_onoff task: onlining %d\n", | 
|  | 1455 | torture_type, cpu); | 
|  | 1456 | n_online_attempts++; | 
|  | 1457 | if (cpu_up(cpu) == 0) { | 
|  | 1458 | if (verbose) | 
|  | 1459 | printk(KERN_ALERT "%s" TORTURE_FLAG | 
|  | 1460 | "rcu_torture_onoff task: " | 
|  | 1461 | "onlined %d\n", | 
|  | 1462 | torture_type, cpu); | 
|  | 1463 | n_online_successes++; | 
|  | 1464 | } | 
|  | 1465 | } | 
|  | 1466 | schedule_timeout_interruptible(onoff_interval * HZ); | 
|  | 1467 | } | 
|  | 1468 | VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping"); | 
|  | 1469 | return 0; | 
|  | 1470 | } | 
|  | 1471 |  | 
|  | 1472 | static int __cpuinit | 
|  | 1473 | rcu_torture_onoff_init(void) | 
|  | 1474 | { | 
|  | 1475 | int ret; | 
|  | 1476 |  | 
|  | 1477 | if (onoff_interval <= 0) | 
|  | 1478 | return 0; | 
|  | 1479 | onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff"); | 
|  | 1480 | if (IS_ERR(onoff_task)) { | 
|  | 1481 | ret = PTR_ERR(onoff_task); | 
|  | 1482 | onoff_task = NULL; | 
|  | 1483 | return ret; | 
|  | 1484 | } | 
|  | 1485 | return 0; | 
|  | 1486 | } | 
|  | 1487 |  | 
|  | 1488 | static void rcu_torture_onoff_cleanup(void) | 
|  | 1489 | { | 
|  | 1490 | if (onoff_task == NULL) | 
|  | 1491 | return; | 
|  | 1492 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task"); | 
|  | 1493 | kthread_stop(onoff_task); | 
|  | 1494 | } | 
|  | 1495 |  | 
|  | 1496 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | 
|  | 1497 |  | 
|  | 1498 | static void | 
|  | 1499 | rcu_torture_onoff_init(void) | 
|  | 1500 | { | 
|  | 1501 | } | 
|  | 1502 |  | 
|  | 1503 | static void rcu_torture_onoff_cleanup(void) | 
|  | 1504 | { | 
|  | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | 
|  | 1508 |  | 
|  | 1509 | /* | 
|  | 1510 | * CPU-stall kthread.  It waits as specified by stall_cpu_holdoff, then | 
|  | 1511 | * induces a CPU stall for the time specified by stall_cpu. | 
|  | 1512 | */ | 
|  | 1513 | static int __cpuinit rcu_torture_stall(void *args) | 
|  | 1514 | { | 
|  | 1515 | unsigned long stop_at; | 
|  | 1516 |  | 
|  | 1517 | VERBOSE_PRINTK_STRING("rcu_torture_stall task started"); | 
|  | 1518 | if (stall_cpu_holdoff > 0) { | 
|  | 1519 | VERBOSE_PRINTK_STRING("rcu_torture_stall begin holdoff"); | 
|  | 1520 | schedule_timeout_interruptible(stall_cpu_holdoff * HZ); | 
|  | 1521 | VERBOSE_PRINTK_STRING("rcu_torture_stall end holdoff"); | 
|  | 1522 | } | 
|  | 1523 | if (!kthread_should_stop()) { | 
|  | 1524 | stop_at = get_seconds() + stall_cpu; | 
|  | 1525 | /* RCU CPU stall is expected behavior in following code. */ | 
|  | 1526 | printk(KERN_ALERT "rcu_torture_stall start.\n"); | 
|  | 1527 | rcu_read_lock(); | 
|  | 1528 | preempt_disable(); | 
|  | 1529 | while (ULONG_CMP_LT(get_seconds(), stop_at)) | 
|  | 1530 | continue;  /* Induce RCU CPU stall warning. */ | 
|  | 1531 | preempt_enable(); | 
|  | 1532 | rcu_read_unlock(); | 
|  | 1533 | printk(KERN_ALERT "rcu_torture_stall end.\n"); | 
|  | 1534 | } | 
|  | 1535 | rcutorture_shutdown_absorb("rcu_torture_stall"); | 
|  | 1536 | while (!kthread_should_stop()) | 
|  | 1537 | schedule_timeout_interruptible(10 * HZ); | 
|  | 1538 | return 0; | 
|  | 1539 | } | 
|  | 1540 |  | 
|  | 1541 | /* Spawn CPU-stall kthread, if stall_cpu specified. */ | 
|  | 1542 | static int __init rcu_torture_stall_init(void) | 
|  | 1543 | { | 
|  | 1544 | int ret; | 
|  | 1545 |  | 
|  | 1546 | if (stall_cpu <= 0) | 
|  | 1547 | return 0; | 
|  | 1548 | stall_task = kthread_run(rcu_torture_stall, NULL, "rcu_torture_stall"); | 
|  | 1549 | if (IS_ERR(stall_task)) { | 
|  | 1550 | ret = PTR_ERR(stall_task); | 
|  | 1551 | stall_task = NULL; | 
|  | 1552 | return ret; | 
|  | 1553 | } | 
|  | 1554 | return 0; | 
|  | 1555 | } | 
|  | 1556 |  | 
|  | 1557 | /* Clean up after the CPU-stall kthread, if one was spawned. */ | 
|  | 1558 | static void rcu_torture_stall_cleanup(void) | 
|  | 1559 | { | 
|  | 1560 | if (stall_task == NULL) | 
|  | 1561 | return; | 
|  | 1562 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stall_task."); | 
|  | 1563 | kthread_stop(stall_task); | 
|  | 1564 | } | 
|  | 1565 |  | 
|  | 1566 | static int rcutorture_cpu_notify(struct notifier_block *self, | 
|  | 1567 | unsigned long action, void *hcpu) | 
|  | 1568 | { | 
|  | 1569 | long cpu = (long)hcpu; | 
|  | 1570 |  | 
|  | 1571 | switch (action) { | 
|  | 1572 | case CPU_ONLINE: | 
|  | 1573 | case CPU_DOWN_FAILED: | 
|  | 1574 | (void)rcutorture_booster_init(cpu); | 
|  | 1575 | break; | 
|  | 1576 | case CPU_DOWN_PREPARE: | 
|  | 1577 | rcutorture_booster_cleanup(cpu); | 
|  | 1578 | break; | 
|  | 1579 | default: | 
|  | 1580 | break; | 
|  | 1581 | } | 
|  | 1582 | return NOTIFY_OK; | 
|  | 1583 | } | 
|  | 1584 |  | 
|  | 1585 | static struct notifier_block rcutorture_cpu_nb = { | 
|  | 1586 | .notifier_call = rcutorture_cpu_notify, | 
|  | 1587 | }; | 
|  | 1588 |  | 
|  | 1589 | static void | 
|  | 1590 | rcu_torture_cleanup(void) | 
|  | 1591 | { | 
|  | 1592 | int i; | 
|  | 1593 |  | 
|  | 1594 | mutex_lock(&fullstop_mutex); | 
|  | 1595 | rcutorture_record_test_transition(); | 
|  | 1596 | if (fullstop == FULLSTOP_SHUTDOWN) { | 
|  | 1597 | printk(KERN_WARNING /* but going down anyway, so... */ | 
|  | 1598 | "Concurrent 'rmmod rcutorture' and shutdown illegal!\n"); | 
|  | 1599 | mutex_unlock(&fullstop_mutex); | 
|  | 1600 | schedule_timeout_uninterruptible(10); | 
|  | 1601 | if (cur_ops->cb_barrier != NULL) | 
|  | 1602 | cur_ops->cb_barrier(); | 
|  | 1603 | return; | 
|  | 1604 | } | 
|  | 1605 | fullstop = FULLSTOP_RMMOD; | 
|  | 1606 | mutex_unlock(&fullstop_mutex); | 
|  | 1607 | unregister_reboot_notifier(&rcutorture_shutdown_nb); | 
|  | 1608 | rcu_torture_stall_cleanup(); | 
|  | 1609 | if (stutter_task) { | 
|  | 1610 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task"); | 
|  | 1611 | kthread_stop(stutter_task); | 
|  | 1612 | } | 
|  | 1613 | stutter_task = NULL; | 
|  | 1614 | if (shuffler_task) { | 
|  | 1615 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task"); | 
|  | 1616 | kthread_stop(shuffler_task); | 
|  | 1617 | free_cpumask_var(shuffle_tmp_mask); | 
|  | 1618 | } | 
|  | 1619 | shuffler_task = NULL; | 
|  | 1620 |  | 
|  | 1621 | if (writer_task) { | 
|  | 1622 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task"); | 
|  | 1623 | kthread_stop(writer_task); | 
|  | 1624 | } | 
|  | 1625 | writer_task = NULL; | 
|  | 1626 |  | 
|  | 1627 | if (reader_tasks) { | 
|  | 1628 | for (i = 0; i < nrealreaders; i++) { | 
|  | 1629 | if (reader_tasks[i]) { | 
|  | 1630 | VERBOSE_PRINTK_STRING( | 
|  | 1631 | "Stopping rcu_torture_reader task"); | 
|  | 1632 | kthread_stop(reader_tasks[i]); | 
|  | 1633 | } | 
|  | 1634 | reader_tasks[i] = NULL; | 
|  | 1635 | } | 
|  | 1636 | kfree(reader_tasks); | 
|  | 1637 | reader_tasks = NULL; | 
|  | 1638 | } | 
|  | 1639 | rcu_torture_current = NULL; | 
|  | 1640 |  | 
|  | 1641 | if (fakewriter_tasks) { | 
|  | 1642 | for (i = 0; i < nfakewriters; i++) { | 
|  | 1643 | if (fakewriter_tasks[i]) { | 
|  | 1644 | VERBOSE_PRINTK_STRING( | 
|  | 1645 | "Stopping rcu_torture_fakewriter task"); | 
|  | 1646 | kthread_stop(fakewriter_tasks[i]); | 
|  | 1647 | } | 
|  | 1648 | fakewriter_tasks[i] = NULL; | 
|  | 1649 | } | 
|  | 1650 | kfree(fakewriter_tasks); | 
|  | 1651 | fakewriter_tasks = NULL; | 
|  | 1652 | } | 
|  | 1653 |  | 
|  | 1654 | if (stats_task) { | 
|  | 1655 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task"); | 
|  | 1656 | kthread_stop(stats_task); | 
|  | 1657 | } | 
|  | 1658 | stats_task = NULL; | 
|  | 1659 |  | 
|  | 1660 | if (fqs_task) { | 
|  | 1661 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task"); | 
|  | 1662 | kthread_stop(fqs_task); | 
|  | 1663 | } | 
|  | 1664 | fqs_task = NULL; | 
|  | 1665 | if ((test_boost == 1 && cur_ops->can_boost) || | 
|  | 1666 | test_boost == 2) { | 
|  | 1667 | unregister_cpu_notifier(&rcutorture_cpu_nb); | 
|  | 1668 | for_each_possible_cpu(i) | 
|  | 1669 | rcutorture_booster_cleanup(i); | 
|  | 1670 | } | 
|  | 1671 | if (shutdown_task != NULL) { | 
|  | 1672 | VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task"); | 
|  | 1673 | kthread_stop(shutdown_task); | 
|  | 1674 | } | 
|  | 1675 | rcu_torture_onoff_cleanup(); | 
|  | 1676 |  | 
|  | 1677 | /* Wait for all RCU callbacks to fire.  */ | 
|  | 1678 |  | 
|  | 1679 | if (cur_ops->cb_barrier != NULL) | 
|  | 1680 | cur_ops->cb_barrier(); | 
|  | 1681 |  | 
|  | 1682 | rcu_torture_stats_print();  /* -After- the stats thread is stopped! */ | 
|  | 1683 |  | 
|  | 1684 | if (cur_ops->cleanup) | 
|  | 1685 | cur_ops->cleanup(); | 
|  | 1686 | if (atomic_read(&n_rcu_torture_error)) | 
|  | 1687 | rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE"); | 
|  | 1688 | else if (n_online_successes != n_online_attempts || | 
|  | 1689 | n_offline_successes != n_offline_attempts) | 
|  | 1690 | rcu_torture_print_module_parms(cur_ops, | 
|  | 1691 | "End of test: RCU_HOTPLUG"); | 
|  | 1692 | else | 
|  | 1693 | rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS"); | 
|  | 1694 | } | 
|  | 1695 |  | 
|  | 1696 | static int __init | 
|  | 1697 | rcu_torture_init(void) | 
|  | 1698 | { | 
|  | 1699 | int i; | 
|  | 1700 | int cpu; | 
|  | 1701 | int firsterr = 0; | 
|  | 1702 | static struct rcu_torture_ops *torture_ops[] = | 
|  | 1703 | { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops, | 
|  | 1704 | &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops, | 
|  | 1705 | &srcu_ops, &srcu_raw_ops, &srcu_expedited_ops, | 
|  | 1706 | &sched_ops, &sched_sync_ops, &sched_expedited_ops, }; | 
|  | 1707 |  | 
|  | 1708 | mutex_lock(&fullstop_mutex); | 
|  | 1709 |  | 
|  | 1710 | /* Process args and tell the world that the torturer is on the job. */ | 
|  | 1711 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) { | 
|  | 1712 | cur_ops = torture_ops[i]; | 
|  | 1713 | if (strcmp(torture_type, cur_ops->name) == 0) | 
|  | 1714 | break; | 
|  | 1715 | } | 
|  | 1716 | if (i == ARRAY_SIZE(torture_ops)) { | 
|  | 1717 | printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n", | 
|  | 1718 | torture_type); | 
|  | 1719 | printk(KERN_ALERT "rcu-torture types:"); | 
|  | 1720 | for (i = 0; i < ARRAY_SIZE(torture_ops); i++) | 
|  | 1721 | printk(KERN_ALERT " %s", torture_ops[i]->name); | 
|  | 1722 | printk(KERN_ALERT "\n"); | 
|  | 1723 | mutex_unlock(&fullstop_mutex); | 
|  | 1724 | return -EINVAL; | 
|  | 1725 | } | 
|  | 1726 | if (cur_ops->fqs == NULL && fqs_duration != 0) { | 
|  | 1727 | printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero " | 
|  | 1728 | "fqs_duration, fqs disabled.\n"); | 
|  | 1729 | fqs_duration = 0; | 
|  | 1730 | } | 
|  | 1731 | if (cur_ops->init) | 
|  | 1732 | cur_ops->init(); /* no "goto unwind" prior to this point!!! */ | 
|  | 1733 |  | 
|  | 1734 | if (nreaders >= 0) | 
|  | 1735 | nrealreaders = nreaders; | 
|  | 1736 | else | 
|  | 1737 | nrealreaders = 2 * num_online_cpus(); | 
|  | 1738 | rcu_torture_print_module_parms(cur_ops, "Start of test"); | 
|  | 1739 | fullstop = FULLSTOP_DONTSTOP; | 
|  | 1740 |  | 
|  | 1741 | /* Set up the freelist. */ | 
|  | 1742 |  | 
|  | 1743 | INIT_LIST_HEAD(&rcu_torture_freelist); | 
|  | 1744 | for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) { | 
|  | 1745 | rcu_tortures[i].rtort_mbtest = 0; | 
|  | 1746 | list_add_tail(&rcu_tortures[i].rtort_free, | 
|  | 1747 | &rcu_torture_freelist); | 
|  | 1748 | } | 
|  | 1749 |  | 
|  | 1750 | /* Initialize the statistics so that each run gets its own numbers. */ | 
|  | 1751 |  | 
|  | 1752 | rcu_torture_current = NULL; | 
|  | 1753 | rcu_torture_current_version = 0; | 
|  | 1754 | atomic_set(&n_rcu_torture_alloc, 0); | 
|  | 1755 | atomic_set(&n_rcu_torture_alloc_fail, 0); | 
|  | 1756 | atomic_set(&n_rcu_torture_free, 0); | 
|  | 1757 | atomic_set(&n_rcu_torture_mberror, 0); | 
|  | 1758 | atomic_set(&n_rcu_torture_error, 0); | 
|  | 1759 | n_rcu_torture_boost_ktrerror = 0; | 
|  | 1760 | n_rcu_torture_boost_rterror = 0; | 
|  | 1761 | n_rcu_torture_boost_failure = 0; | 
|  | 1762 | n_rcu_torture_boosts = 0; | 
|  | 1763 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | 
|  | 1764 | atomic_set(&rcu_torture_wcount[i], 0); | 
|  | 1765 | for_each_possible_cpu(cpu) { | 
|  | 1766 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | 
|  | 1767 | per_cpu(rcu_torture_count, cpu)[i] = 0; | 
|  | 1768 | per_cpu(rcu_torture_batch, cpu)[i] = 0; | 
|  | 1769 | } | 
|  | 1770 | } | 
|  | 1771 |  | 
|  | 1772 | /* Start up the kthreads. */ | 
|  | 1773 |  | 
|  | 1774 | VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); | 
|  | 1775 | writer_task = kthread_run(rcu_torture_writer, NULL, | 
|  | 1776 | "rcu_torture_writer"); | 
|  | 1777 | if (IS_ERR(writer_task)) { | 
|  | 1778 | firsterr = PTR_ERR(writer_task); | 
|  | 1779 | VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); | 
|  | 1780 | writer_task = NULL; | 
|  | 1781 | goto unwind; | 
|  | 1782 | } | 
|  | 1783 | fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), | 
|  | 1784 | GFP_KERNEL); | 
|  | 1785 | if (fakewriter_tasks == NULL) { | 
|  | 1786 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | 
|  | 1787 | firsterr = -ENOMEM; | 
|  | 1788 | goto unwind; | 
|  | 1789 | } | 
|  | 1790 | for (i = 0; i < nfakewriters; i++) { | 
|  | 1791 | VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task"); | 
|  | 1792 | fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL, | 
|  | 1793 | "rcu_torture_fakewriter"); | 
|  | 1794 | if (IS_ERR(fakewriter_tasks[i])) { | 
|  | 1795 | firsterr = PTR_ERR(fakewriter_tasks[i]); | 
|  | 1796 | VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter"); | 
|  | 1797 | fakewriter_tasks[i] = NULL; | 
|  | 1798 | goto unwind; | 
|  | 1799 | } | 
|  | 1800 | } | 
|  | 1801 | reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]), | 
|  | 1802 | GFP_KERNEL); | 
|  | 1803 | if (reader_tasks == NULL) { | 
|  | 1804 | VERBOSE_PRINTK_ERRSTRING("out of memory"); | 
|  | 1805 | firsterr = -ENOMEM; | 
|  | 1806 | goto unwind; | 
|  | 1807 | } | 
|  | 1808 | for (i = 0; i < nrealreaders; i++) { | 
|  | 1809 | VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task"); | 
|  | 1810 | reader_tasks[i] = kthread_run(rcu_torture_reader, NULL, | 
|  | 1811 | "rcu_torture_reader"); | 
|  | 1812 | if (IS_ERR(reader_tasks[i])) { | 
|  | 1813 | firsterr = PTR_ERR(reader_tasks[i]); | 
|  | 1814 | VERBOSE_PRINTK_ERRSTRING("Failed to create reader"); | 
|  | 1815 | reader_tasks[i] = NULL; | 
|  | 1816 | goto unwind; | 
|  | 1817 | } | 
|  | 1818 | } | 
|  | 1819 | if (stat_interval > 0) { | 
|  | 1820 | VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task"); | 
|  | 1821 | stats_task = kthread_run(rcu_torture_stats, NULL, | 
|  | 1822 | "rcu_torture_stats"); | 
|  | 1823 | if (IS_ERR(stats_task)) { | 
|  | 1824 | firsterr = PTR_ERR(stats_task); | 
|  | 1825 | VERBOSE_PRINTK_ERRSTRING("Failed to create stats"); | 
|  | 1826 | stats_task = NULL; | 
|  | 1827 | goto unwind; | 
|  | 1828 | } | 
|  | 1829 | } | 
|  | 1830 | if (test_no_idle_hz) { | 
|  | 1831 | rcu_idle_cpu = num_online_cpus() - 1; | 
|  | 1832 |  | 
|  | 1833 | if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) { | 
|  | 1834 | firsterr = -ENOMEM; | 
|  | 1835 | VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask"); | 
|  | 1836 | goto unwind; | 
|  | 1837 | } | 
|  | 1838 |  | 
|  | 1839 | /* Create the shuffler thread */ | 
|  | 1840 | shuffler_task = kthread_run(rcu_torture_shuffle, NULL, | 
|  | 1841 | "rcu_torture_shuffle"); | 
|  | 1842 | if (IS_ERR(shuffler_task)) { | 
|  | 1843 | free_cpumask_var(shuffle_tmp_mask); | 
|  | 1844 | firsterr = PTR_ERR(shuffler_task); | 
|  | 1845 | VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler"); | 
|  | 1846 | shuffler_task = NULL; | 
|  | 1847 | goto unwind; | 
|  | 1848 | } | 
|  | 1849 | } | 
|  | 1850 | if (stutter < 0) | 
|  | 1851 | stutter = 0; | 
|  | 1852 | if (stutter) { | 
|  | 1853 | /* Create the stutter thread */ | 
|  | 1854 | stutter_task = kthread_run(rcu_torture_stutter, NULL, | 
|  | 1855 | "rcu_torture_stutter"); | 
|  | 1856 | if (IS_ERR(stutter_task)) { | 
|  | 1857 | firsterr = PTR_ERR(stutter_task); | 
|  | 1858 | VERBOSE_PRINTK_ERRSTRING("Failed to create stutter"); | 
|  | 1859 | stutter_task = NULL; | 
|  | 1860 | goto unwind; | 
|  | 1861 | } | 
|  | 1862 | } | 
|  | 1863 | if (fqs_duration < 0) | 
|  | 1864 | fqs_duration = 0; | 
|  | 1865 | if (fqs_duration) { | 
|  | 1866 | /* Create the stutter thread */ | 
|  | 1867 | fqs_task = kthread_run(rcu_torture_fqs, NULL, | 
|  | 1868 | "rcu_torture_fqs"); | 
|  | 1869 | if (IS_ERR(fqs_task)) { | 
|  | 1870 | firsterr = PTR_ERR(fqs_task); | 
|  | 1871 | VERBOSE_PRINTK_ERRSTRING("Failed to create fqs"); | 
|  | 1872 | fqs_task = NULL; | 
|  | 1873 | goto unwind; | 
|  | 1874 | } | 
|  | 1875 | } | 
|  | 1876 | if (test_boost_interval < 1) | 
|  | 1877 | test_boost_interval = 1; | 
|  | 1878 | if (test_boost_duration < 2) | 
|  | 1879 | test_boost_duration = 2; | 
|  | 1880 | if ((test_boost == 1 && cur_ops->can_boost) || | 
|  | 1881 | test_boost == 2) { | 
|  | 1882 | int retval; | 
|  | 1883 |  | 
|  | 1884 | boost_starttime = jiffies + test_boost_interval * HZ; | 
|  | 1885 | register_cpu_notifier(&rcutorture_cpu_nb); | 
|  | 1886 | for_each_possible_cpu(i) { | 
|  | 1887 | if (cpu_is_offline(i)) | 
|  | 1888 | continue;  /* Heuristic: CPU can go offline. */ | 
|  | 1889 | retval = rcutorture_booster_init(i); | 
|  | 1890 | if (retval < 0) { | 
|  | 1891 | firsterr = retval; | 
|  | 1892 | goto unwind; | 
|  | 1893 | } | 
|  | 1894 | } | 
|  | 1895 | } | 
|  | 1896 | if (shutdown_secs > 0) { | 
|  | 1897 | shutdown_time = jiffies + shutdown_secs * HZ; | 
|  | 1898 | shutdown_task = kthread_run(rcu_torture_shutdown, NULL, | 
|  | 1899 | "rcu_torture_shutdown"); | 
|  | 1900 | if (IS_ERR(shutdown_task)) { | 
|  | 1901 | firsterr = PTR_ERR(shutdown_task); | 
|  | 1902 | VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown"); | 
|  | 1903 | shutdown_task = NULL; | 
|  | 1904 | goto unwind; | 
|  | 1905 | } | 
|  | 1906 | } | 
|  | 1907 | rcu_torture_onoff_init(); | 
|  | 1908 | register_reboot_notifier(&rcutorture_shutdown_nb); | 
|  | 1909 | rcu_torture_stall_init(); | 
|  | 1910 | rcutorture_record_test_transition(); | 
|  | 1911 | mutex_unlock(&fullstop_mutex); | 
|  | 1912 | return 0; | 
|  | 1913 |  | 
|  | 1914 | unwind: | 
|  | 1915 | mutex_unlock(&fullstop_mutex); | 
|  | 1916 | rcu_torture_cleanup(); | 
|  | 1917 | return firsterr; | 
|  | 1918 | } | 
|  | 1919 |  | 
|  | 1920 | module_init(rcu_torture_init); | 
|  | 1921 | module_exit(rcu_torture_cleanup); |