rcutorture.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  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 <asm/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. MODULE_LICENSE("GPL");
  51. MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and "
  52. "Josh Triplett <josh@freedesktop.org>");
  53. static int nreaders = -1; /* # reader threads, defaults to 2*ncpus */
  54. static int nfakewriters = 4; /* # fake writer threads */
  55. static int stat_interval; /* Interval between stats, in seconds. */
  56. /* Defaults to "only at end of test". */
  57. static int verbose; /* Print more debug info. */
  58. static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */
  59. static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
  60. static int stutter = 5; /* Start/stop testing interval (in sec) */
  61. static int irqreader = 1; /* RCU readers from irq (timers). */
  62. static char *torture_type = "rcu"; /* What RCU implementation to torture. */
  63. module_param(nreaders, int, 0444);
  64. MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
  65. module_param(nfakewriters, int, 0444);
  66. MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
  67. module_param(stat_interval, int, 0444);
  68. MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
  69. module_param(verbose, bool, 0444);
  70. MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
  71. module_param(test_no_idle_hz, bool, 0444);
  72. MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
  73. module_param(shuffle_interval, int, 0444);
  74. MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
  75. module_param(stutter, int, 0444);
  76. MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
  77. module_param(irqreader, int, 0444);
  78. MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
  79. module_param(torture_type, charp, 0444);
  80. MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
  81. #define TORTURE_FLAG "-torture:"
  82. #define PRINTK_STRING(s) \
  83. do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  84. #define VERBOSE_PRINTK_STRING(s) \
  85. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  86. #define VERBOSE_PRINTK_ERRSTRING(s) \
  87. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
  88. static char printk_buf[4096];
  89. static int nrealreaders;
  90. static struct task_struct *writer_task;
  91. static struct task_struct **fakewriter_tasks;
  92. static struct task_struct **reader_tasks;
  93. static struct task_struct *stats_task;
  94. static struct task_struct *shuffler_task;
  95. static struct task_struct *stutter_task;
  96. #define RCU_TORTURE_PIPE_LEN 10
  97. struct rcu_torture {
  98. struct rcu_head rtort_rcu;
  99. int rtort_pipe_count;
  100. struct list_head rtort_free;
  101. int rtort_mbtest;
  102. };
  103. static LIST_HEAD(rcu_torture_freelist);
  104. static struct rcu_torture *rcu_torture_current = NULL;
  105. static long rcu_torture_current_version = 0;
  106. static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
  107. static DEFINE_SPINLOCK(rcu_torture_lock);
  108. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
  109. { 0 };
  110. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
  111. { 0 };
  112. static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  113. static atomic_t n_rcu_torture_alloc;
  114. static atomic_t n_rcu_torture_alloc_fail;
  115. static atomic_t n_rcu_torture_free;
  116. static atomic_t n_rcu_torture_mberror;
  117. static atomic_t n_rcu_torture_error;
  118. static long n_rcu_torture_timers = 0;
  119. static struct list_head rcu_torture_removed;
  120. static int stutter_pause_test = 0;
  121. #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
  122. #define RCUTORTURE_RUNNABLE_INIT 1
  123. #else
  124. #define RCUTORTURE_RUNNABLE_INIT 0
  125. #endif
  126. int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
  127. #define FULLSTOP_SIGNALED 1 /* Bail due to signal. */
  128. #define FULLSTOP_CLEANUP 2 /* Orderly shutdown. */
  129. static int fullstop; /* stop generating callbacks at test end. */
  130. DEFINE_MUTEX(fullstop_mutex); /* protect fullstop transitions and */
  131. /* spawning of kthreads. */
  132. /*
  133. * Detect and respond to a signal-based shutdown.
  134. */
  135. static int
  136. rcutorture_shutdown_notify(struct notifier_block *unused1,
  137. unsigned long unused2, void *unused3)
  138. {
  139. if (fullstop)
  140. return NOTIFY_DONE;
  141. if (signal_pending(current)) {
  142. mutex_lock(&fullstop_mutex);
  143. if (!ACCESS_ONCE(fullstop))
  144. fullstop = FULLSTOP_SIGNALED;
  145. mutex_unlock(&fullstop_mutex);
  146. }
  147. return NOTIFY_DONE;
  148. }
  149. /*
  150. * Allocate an element from the rcu_tortures pool.
  151. */
  152. static struct rcu_torture *
  153. rcu_torture_alloc(void)
  154. {
  155. struct list_head *p;
  156. spin_lock_bh(&rcu_torture_lock);
  157. if (list_empty(&rcu_torture_freelist)) {
  158. atomic_inc(&n_rcu_torture_alloc_fail);
  159. spin_unlock_bh(&rcu_torture_lock);
  160. return NULL;
  161. }
  162. atomic_inc(&n_rcu_torture_alloc);
  163. p = rcu_torture_freelist.next;
  164. list_del_init(p);
  165. spin_unlock_bh(&rcu_torture_lock);
  166. return container_of(p, struct rcu_torture, rtort_free);
  167. }
  168. /*
  169. * Free an element to the rcu_tortures pool.
  170. */
  171. static void
  172. rcu_torture_free(struct rcu_torture *p)
  173. {
  174. atomic_inc(&n_rcu_torture_free);
  175. spin_lock_bh(&rcu_torture_lock);
  176. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  177. spin_unlock_bh(&rcu_torture_lock);
  178. }
  179. struct rcu_random_state {
  180. unsigned long rrs_state;
  181. long rrs_count;
  182. };
  183. #define RCU_RANDOM_MULT 39916801 /* prime */
  184. #define RCU_RANDOM_ADD 479001701 /* prime */
  185. #define RCU_RANDOM_REFRESH 10000
  186. #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
  187. /*
  188. * Crude but fast random-number generator. Uses a linear congruential
  189. * generator, with occasional help from cpu_clock().
  190. */
  191. static unsigned long
  192. rcu_random(struct rcu_random_state *rrsp)
  193. {
  194. if (--rrsp->rrs_count < 0) {
  195. rrsp->rrs_state +=
  196. (unsigned long)cpu_clock(raw_smp_processor_id());
  197. rrsp->rrs_count = RCU_RANDOM_REFRESH;
  198. }
  199. rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
  200. return swahw32(rrsp->rrs_state);
  201. }
  202. static void
  203. rcu_stutter_wait(void)
  204. {
  205. while ((stutter_pause_test || !rcutorture_runnable) && !fullstop) {
  206. if (rcutorture_runnable)
  207. schedule_timeout_interruptible(1);
  208. else
  209. schedule_timeout_interruptible(round_jiffies_relative(HZ));
  210. }
  211. }
  212. /*
  213. * Operations vector for selecting different types of tests.
  214. */
  215. struct rcu_torture_ops {
  216. void (*init)(void);
  217. void (*cleanup)(void);
  218. int (*readlock)(void);
  219. void (*readdelay)(struct rcu_random_state *rrsp);
  220. void (*readunlock)(int idx);
  221. int (*completed)(void);
  222. void (*deferredfree)(struct rcu_torture *p);
  223. void (*sync)(void);
  224. void (*cb_barrier)(void);
  225. int (*stats)(char *page);
  226. int irqcapable;
  227. char *name;
  228. };
  229. static struct rcu_torture_ops *cur_ops = NULL;
  230. /*
  231. * Definitions for rcu torture testing.
  232. */
  233. static int rcu_torture_read_lock(void) __acquires(RCU)
  234. {
  235. rcu_read_lock();
  236. return 0;
  237. }
  238. static void rcu_read_delay(struct rcu_random_state *rrsp)
  239. {
  240. long delay;
  241. const long longdelay = 200;
  242. /* We want there to be long-running readers, but not all the time. */
  243. delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay);
  244. if (!delay)
  245. udelay(longdelay);
  246. }
  247. static void rcu_torture_read_unlock(int idx) __releases(RCU)
  248. {
  249. rcu_read_unlock();
  250. }
  251. static int rcu_torture_completed(void)
  252. {
  253. return rcu_batches_completed();
  254. }
  255. static void
  256. rcu_torture_cb(struct rcu_head *p)
  257. {
  258. int i;
  259. struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
  260. if (fullstop) {
  261. /* Test is ending, just drop callbacks on the floor. */
  262. /* The next initialization will pick up the pieces. */
  263. return;
  264. }
  265. i = rp->rtort_pipe_count;
  266. if (i > RCU_TORTURE_PIPE_LEN)
  267. i = RCU_TORTURE_PIPE_LEN;
  268. atomic_inc(&rcu_torture_wcount[i]);
  269. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  270. rp->rtort_mbtest = 0;
  271. rcu_torture_free(rp);
  272. } else
  273. cur_ops->deferredfree(rp);
  274. }
  275. static void rcu_torture_deferred_free(struct rcu_torture *p)
  276. {
  277. call_rcu(&p->rtort_rcu, rcu_torture_cb);
  278. }
  279. static struct rcu_torture_ops rcu_ops = {
  280. .init = NULL,
  281. .cleanup = NULL,
  282. .readlock = rcu_torture_read_lock,
  283. .readdelay = rcu_read_delay,
  284. .readunlock = rcu_torture_read_unlock,
  285. .completed = rcu_torture_completed,
  286. .deferredfree = rcu_torture_deferred_free,
  287. .sync = synchronize_rcu,
  288. .cb_barrier = rcu_barrier,
  289. .stats = NULL,
  290. .irqcapable = 1,
  291. .name = "rcu"
  292. };
  293. static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
  294. {
  295. int i;
  296. struct rcu_torture *rp;
  297. struct rcu_torture *rp1;
  298. cur_ops->sync();
  299. list_add(&p->rtort_free, &rcu_torture_removed);
  300. list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
  301. i = rp->rtort_pipe_count;
  302. if (i > RCU_TORTURE_PIPE_LEN)
  303. i = RCU_TORTURE_PIPE_LEN;
  304. atomic_inc(&rcu_torture_wcount[i]);
  305. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  306. rp->rtort_mbtest = 0;
  307. list_del(&rp->rtort_free);
  308. rcu_torture_free(rp);
  309. }
  310. }
  311. }
  312. static void rcu_sync_torture_init(void)
  313. {
  314. INIT_LIST_HEAD(&rcu_torture_removed);
  315. }
  316. static struct rcu_torture_ops rcu_sync_ops = {
  317. .init = rcu_sync_torture_init,
  318. .cleanup = NULL,
  319. .readlock = rcu_torture_read_lock,
  320. .readdelay = rcu_read_delay,
  321. .readunlock = rcu_torture_read_unlock,
  322. .completed = rcu_torture_completed,
  323. .deferredfree = rcu_sync_torture_deferred_free,
  324. .sync = synchronize_rcu,
  325. .cb_barrier = NULL,
  326. .stats = NULL,
  327. .irqcapable = 1,
  328. .name = "rcu_sync"
  329. };
  330. /*
  331. * Definitions for rcu_bh torture testing.
  332. */
  333. static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
  334. {
  335. rcu_read_lock_bh();
  336. return 0;
  337. }
  338. static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
  339. {
  340. rcu_read_unlock_bh();
  341. }
  342. static int rcu_bh_torture_completed(void)
  343. {
  344. return rcu_batches_completed_bh();
  345. }
  346. static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
  347. {
  348. call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
  349. }
  350. struct rcu_bh_torture_synchronize {
  351. struct rcu_head head;
  352. struct completion completion;
  353. };
  354. static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
  355. {
  356. struct rcu_bh_torture_synchronize *rcu;
  357. rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
  358. complete(&rcu->completion);
  359. }
  360. static void rcu_bh_torture_synchronize(void)
  361. {
  362. struct rcu_bh_torture_synchronize rcu;
  363. init_completion(&rcu.completion);
  364. call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
  365. wait_for_completion(&rcu.completion);
  366. }
  367. static struct rcu_torture_ops rcu_bh_ops = {
  368. .init = NULL,
  369. .cleanup = NULL,
  370. .readlock = rcu_bh_torture_read_lock,
  371. .readdelay = rcu_read_delay, /* just reuse rcu's version. */
  372. .readunlock = rcu_bh_torture_read_unlock,
  373. .completed = rcu_bh_torture_completed,
  374. .deferredfree = rcu_bh_torture_deferred_free,
  375. .sync = rcu_bh_torture_synchronize,
  376. .cb_barrier = rcu_barrier_bh,
  377. .stats = NULL,
  378. .irqcapable = 1,
  379. .name = "rcu_bh"
  380. };
  381. static struct rcu_torture_ops rcu_bh_sync_ops = {
  382. .init = rcu_sync_torture_init,
  383. .cleanup = NULL,
  384. .readlock = rcu_bh_torture_read_lock,
  385. .readdelay = rcu_read_delay, /* just reuse rcu's version. */
  386. .readunlock = rcu_bh_torture_read_unlock,
  387. .completed = rcu_bh_torture_completed,
  388. .deferredfree = rcu_sync_torture_deferred_free,
  389. .sync = rcu_bh_torture_synchronize,
  390. .cb_barrier = NULL,
  391. .stats = NULL,
  392. .irqcapable = 1,
  393. .name = "rcu_bh_sync"
  394. };
  395. /*
  396. * Definitions for srcu torture testing.
  397. */
  398. static struct srcu_struct srcu_ctl;
  399. static void srcu_torture_init(void)
  400. {
  401. init_srcu_struct(&srcu_ctl);
  402. rcu_sync_torture_init();
  403. }
  404. static void srcu_torture_cleanup(void)
  405. {
  406. synchronize_srcu(&srcu_ctl);
  407. cleanup_srcu_struct(&srcu_ctl);
  408. }
  409. static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
  410. {
  411. return srcu_read_lock(&srcu_ctl);
  412. }
  413. static void srcu_read_delay(struct rcu_random_state *rrsp)
  414. {
  415. long delay;
  416. const long uspertick = 1000000 / HZ;
  417. const long longdelay = 10;
  418. /* We want there to be long-running readers, but not all the time. */
  419. delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
  420. if (!delay)
  421. schedule_timeout_interruptible(longdelay);
  422. }
  423. static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
  424. {
  425. srcu_read_unlock(&srcu_ctl, idx);
  426. }
  427. static int srcu_torture_completed(void)
  428. {
  429. return srcu_batches_completed(&srcu_ctl);
  430. }
  431. static void srcu_torture_synchronize(void)
  432. {
  433. synchronize_srcu(&srcu_ctl);
  434. }
  435. static int srcu_torture_stats(char *page)
  436. {
  437. int cnt = 0;
  438. int cpu;
  439. int idx = srcu_ctl.completed & 0x1;
  440. cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
  441. torture_type, TORTURE_FLAG, idx);
  442. for_each_possible_cpu(cpu) {
  443. cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
  444. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
  445. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
  446. }
  447. cnt += sprintf(&page[cnt], "\n");
  448. return cnt;
  449. }
  450. static struct rcu_torture_ops srcu_ops = {
  451. .init = srcu_torture_init,
  452. .cleanup = srcu_torture_cleanup,
  453. .readlock = srcu_torture_read_lock,
  454. .readdelay = srcu_read_delay,
  455. .readunlock = srcu_torture_read_unlock,
  456. .completed = srcu_torture_completed,
  457. .deferredfree = rcu_sync_torture_deferred_free,
  458. .sync = srcu_torture_synchronize,
  459. .cb_barrier = NULL,
  460. .stats = srcu_torture_stats,
  461. .name = "srcu"
  462. };
  463. /*
  464. * Definitions for sched torture testing.
  465. */
  466. static int sched_torture_read_lock(void)
  467. {
  468. preempt_disable();
  469. return 0;
  470. }
  471. static void sched_torture_read_unlock(int idx)
  472. {
  473. preempt_enable();
  474. }
  475. static int sched_torture_completed(void)
  476. {
  477. return 0;
  478. }
  479. static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
  480. {
  481. call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
  482. }
  483. static void sched_torture_synchronize(void)
  484. {
  485. synchronize_sched();
  486. }
  487. static struct rcu_torture_ops sched_ops = {
  488. .init = rcu_sync_torture_init,
  489. .cleanup = NULL,
  490. .readlock = sched_torture_read_lock,
  491. .readdelay = rcu_read_delay, /* just reuse rcu's version. */
  492. .readunlock = sched_torture_read_unlock,
  493. .completed = sched_torture_completed,
  494. .deferredfree = rcu_sched_torture_deferred_free,
  495. .sync = sched_torture_synchronize,
  496. .cb_barrier = rcu_barrier_sched,
  497. .stats = NULL,
  498. .irqcapable = 1,
  499. .name = "sched"
  500. };
  501. static struct rcu_torture_ops sched_ops_sync = {
  502. .init = rcu_sync_torture_init,
  503. .cleanup = NULL,
  504. .readlock = sched_torture_read_lock,
  505. .readdelay = rcu_read_delay, /* just reuse rcu's version. */
  506. .readunlock = sched_torture_read_unlock,
  507. .completed = sched_torture_completed,
  508. .deferredfree = rcu_sync_torture_deferred_free,
  509. .sync = sched_torture_synchronize,
  510. .cb_barrier = NULL,
  511. .stats = NULL,
  512. .name = "sched_sync"
  513. };
  514. /*
  515. * RCU torture writer kthread. Repeatedly substitutes a new structure
  516. * for that pointed to by rcu_torture_current, freeing the old structure
  517. * after a series of grace periods (the "pipeline").
  518. */
  519. static int
  520. rcu_torture_writer(void *arg)
  521. {
  522. int i;
  523. long oldbatch = rcu_batches_completed();
  524. struct rcu_torture *rp;
  525. struct rcu_torture *old_rp;
  526. static DEFINE_RCU_RANDOM(rand);
  527. VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
  528. set_user_nice(current, 19);
  529. do {
  530. schedule_timeout_uninterruptible(1);
  531. if ((rp = rcu_torture_alloc()) == NULL)
  532. continue;
  533. rp->rtort_pipe_count = 0;
  534. udelay(rcu_random(&rand) & 0x3ff);
  535. old_rp = rcu_torture_current;
  536. rp->rtort_mbtest = 1;
  537. rcu_assign_pointer(rcu_torture_current, rp);
  538. smp_wmb();
  539. if (old_rp) {
  540. i = old_rp->rtort_pipe_count;
  541. if (i > RCU_TORTURE_PIPE_LEN)
  542. i = RCU_TORTURE_PIPE_LEN;
  543. atomic_inc(&rcu_torture_wcount[i]);
  544. old_rp->rtort_pipe_count++;
  545. cur_ops->deferredfree(old_rp);
  546. }
  547. rcu_torture_current_version++;
  548. oldbatch = cur_ops->completed();
  549. rcu_stutter_wait();
  550. } while (!kthread_should_stop() && !fullstop);
  551. VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
  552. while (!kthread_should_stop() && fullstop != FULLSTOP_SIGNALED)
  553. schedule_timeout_uninterruptible(1);
  554. return 0;
  555. }
  556. /*
  557. * RCU torture fake writer kthread. Repeatedly calls sync, with a random
  558. * delay between calls.
  559. */
  560. static int
  561. rcu_torture_fakewriter(void *arg)
  562. {
  563. DEFINE_RCU_RANDOM(rand);
  564. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
  565. set_user_nice(current, 19);
  566. do {
  567. schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
  568. udelay(rcu_random(&rand) & 0x3ff);
  569. cur_ops->sync();
  570. rcu_stutter_wait();
  571. } while (!kthread_should_stop() && !fullstop);
  572. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
  573. while (!kthread_should_stop() && fullstop != FULLSTOP_SIGNALED)
  574. schedule_timeout_uninterruptible(1);
  575. return 0;
  576. }
  577. /*
  578. * RCU torture reader from timer handler. Dereferences rcu_torture_current,
  579. * incrementing the corresponding element of the pipeline array. The
  580. * counter in the element should never be greater than 1, otherwise, the
  581. * RCU implementation is broken.
  582. */
  583. static void rcu_torture_timer(unsigned long unused)
  584. {
  585. int idx;
  586. int completed;
  587. static DEFINE_RCU_RANDOM(rand);
  588. static DEFINE_SPINLOCK(rand_lock);
  589. struct rcu_torture *p;
  590. int pipe_count;
  591. idx = cur_ops->readlock();
  592. completed = cur_ops->completed();
  593. p = rcu_dereference(rcu_torture_current);
  594. if (p == NULL) {
  595. /* Leave because rcu_torture_writer is not yet underway */
  596. cur_ops->readunlock(idx);
  597. return;
  598. }
  599. if (p->rtort_mbtest == 0)
  600. atomic_inc(&n_rcu_torture_mberror);
  601. spin_lock(&rand_lock);
  602. cur_ops->readdelay(&rand);
  603. n_rcu_torture_timers++;
  604. spin_unlock(&rand_lock);
  605. preempt_disable();
  606. pipe_count = p->rtort_pipe_count;
  607. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  608. /* Should not happen, but... */
  609. pipe_count = RCU_TORTURE_PIPE_LEN;
  610. }
  611. ++__get_cpu_var(rcu_torture_count)[pipe_count];
  612. completed = cur_ops->completed() - completed;
  613. if (completed > RCU_TORTURE_PIPE_LEN) {
  614. /* Should not happen, but... */
  615. completed = RCU_TORTURE_PIPE_LEN;
  616. }
  617. ++__get_cpu_var(rcu_torture_batch)[completed];
  618. preempt_enable();
  619. cur_ops->readunlock(idx);
  620. }
  621. /*
  622. * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
  623. * incrementing the corresponding element of the pipeline array. The
  624. * counter in the element should never be greater than 1, otherwise, the
  625. * RCU implementation is broken.
  626. */
  627. static int
  628. rcu_torture_reader(void *arg)
  629. {
  630. int completed;
  631. int idx;
  632. DEFINE_RCU_RANDOM(rand);
  633. struct rcu_torture *p;
  634. int pipe_count;
  635. struct timer_list t;
  636. VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
  637. set_user_nice(current, 19);
  638. if (irqreader && cur_ops->irqcapable)
  639. setup_timer_on_stack(&t, rcu_torture_timer, 0);
  640. do {
  641. if (irqreader && cur_ops->irqcapable) {
  642. if (!timer_pending(&t))
  643. mod_timer(&t, 1);
  644. }
  645. idx = cur_ops->readlock();
  646. completed = cur_ops->completed();
  647. p = rcu_dereference(rcu_torture_current);
  648. if (p == NULL) {
  649. /* Wait for rcu_torture_writer to get underway */
  650. cur_ops->readunlock(idx);
  651. schedule_timeout_interruptible(HZ);
  652. continue;
  653. }
  654. if (p->rtort_mbtest == 0)
  655. atomic_inc(&n_rcu_torture_mberror);
  656. cur_ops->readdelay(&rand);
  657. preempt_disable();
  658. pipe_count = p->rtort_pipe_count;
  659. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  660. /* Should not happen, but... */
  661. pipe_count = RCU_TORTURE_PIPE_LEN;
  662. }
  663. ++__get_cpu_var(rcu_torture_count)[pipe_count];
  664. completed = cur_ops->completed() - completed;
  665. if (completed > RCU_TORTURE_PIPE_LEN) {
  666. /* Should not happen, but... */
  667. completed = RCU_TORTURE_PIPE_LEN;
  668. }
  669. ++__get_cpu_var(rcu_torture_batch)[completed];
  670. preempt_enable();
  671. cur_ops->readunlock(idx);
  672. schedule();
  673. rcu_stutter_wait();
  674. } while (!kthread_should_stop() && !fullstop);
  675. VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
  676. if (irqreader && cur_ops->irqcapable)
  677. del_timer_sync(&t);
  678. while (!kthread_should_stop() && fullstop != FULLSTOP_SIGNALED)
  679. schedule_timeout_uninterruptible(1);
  680. return 0;
  681. }
  682. /*
  683. * Create an RCU-torture statistics message in the specified buffer.
  684. */
  685. static int
  686. rcu_torture_printk(char *page)
  687. {
  688. int cnt = 0;
  689. int cpu;
  690. int i;
  691. long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  692. long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  693. for_each_possible_cpu(cpu) {
  694. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  695. pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
  696. batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
  697. }
  698. }
  699. for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
  700. if (pipesummary[i] != 0)
  701. break;
  702. }
  703. cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
  704. cnt += sprintf(&page[cnt],
  705. "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
  706. "rtmbe: %d nt: %ld",
  707. rcu_torture_current,
  708. rcu_torture_current_version,
  709. list_empty(&rcu_torture_freelist),
  710. atomic_read(&n_rcu_torture_alloc),
  711. atomic_read(&n_rcu_torture_alloc_fail),
  712. atomic_read(&n_rcu_torture_free),
  713. atomic_read(&n_rcu_torture_mberror),
  714. n_rcu_torture_timers);
  715. if (atomic_read(&n_rcu_torture_mberror) != 0)
  716. cnt += sprintf(&page[cnt], " !!!");
  717. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  718. if (i > 1) {
  719. cnt += sprintf(&page[cnt], "!!! ");
  720. atomic_inc(&n_rcu_torture_error);
  721. WARN_ON_ONCE(1);
  722. }
  723. cnt += sprintf(&page[cnt], "Reader Pipe: ");
  724. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  725. cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
  726. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  727. cnt += sprintf(&page[cnt], "Reader Batch: ");
  728. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  729. cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
  730. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  731. cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
  732. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  733. cnt += sprintf(&page[cnt], " %d",
  734. atomic_read(&rcu_torture_wcount[i]));
  735. }
  736. cnt += sprintf(&page[cnt], "\n");
  737. if (cur_ops->stats)
  738. cnt += cur_ops->stats(&page[cnt]);
  739. return cnt;
  740. }
  741. /*
  742. * Print torture statistics. Caller must ensure that there is only
  743. * one call to this function at a given time!!! This is normally
  744. * accomplished by relying on the module system to only have one copy
  745. * of the module loaded, and then by giving the rcu_torture_stats
  746. * kthread full control (or the init/cleanup functions when rcu_torture_stats
  747. * thread is not running).
  748. */
  749. static void
  750. rcu_torture_stats_print(void)
  751. {
  752. int cnt;
  753. cnt = rcu_torture_printk(printk_buf);
  754. printk(KERN_ALERT "%s", printk_buf);
  755. }
  756. /*
  757. * Periodically prints torture statistics, if periodic statistics printing
  758. * was specified via the stat_interval module parameter.
  759. *
  760. * No need to worry about fullstop here, since this one doesn't reference
  761. * volatile state or register callbacks.
  762. */
  763. static int
  764. rcu_torture_stats(void *arg)
  765. {
  766. VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
  767. do {
  768. schedule_timeout_interruptible(stat_interval * HZ);
  769. rcu_torture_stats_print();
  770. } while (!kthread_should_stop() && !fullstop);
  771. VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
  772. return 0;
  773. }
  774. static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
  775. /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
  776. * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
  777. */
  778. static void rcu_torture_shuffle_tasks(void)
  779. {
  780. cpumask_var_t tmp_mask;
  781. int i;
  782. if (!alloc_cpumask_var(&tmp_mask, GFP_KERNEL))
  783. BUG();
  784. cpumask_setall(tmp_mask);
  785. get_online_cpus();
  786. /* No point in shuffling if there is only one online CPU (ex: UP) */
  787. if (num_online_cpus() == 1)
  788. goto out;
  789. if (rcu_idle_cpu != -1)
  790. cpumask_clear_cpu(rcu_idle_cpu, tmp_mask);
  791. set_cpus_allowed_ptr(current, tmp_mask);
  792. if (reader_tasks) {
  793. for (i = 0; i < nrealreaders; i++)
  794. if (reader_tasks[i])
  795. set_cpus_allowed_ptr(reader_tasks[i],
  796. tmp_mask);
  797. }
  798. if (fakewriter_tasks) {
  799. for (i = 0; i < nfakewriters; i++)
  800. if (fakewriter_tasks[i])
  801. set_cpus_allowed_ptr(fakewriter_tasks[i],
  802. tmp_mask);
  803. }
  804. if (writer_task)
  805. set_cpus_allowed_ptr(writer_task, tmp_mask);
  806. if (stats_task)
  807. set_cpus_allowed_ptr(stats_task, tmp_mask);
  808. if (rcu_idle_cpu == -1)
  809. rcu_idle_cpu = num_online_cpus() - 1;
  810. else
  811. rcu_idle_cpu--;
  812. out:
  813. put_online_cpus();
  814. free_cpumask_var(tmp_mask);
  815. }
  816. /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
  817. * system to become idle at a time and cut off its timer ticks. This is meant
  818. * to test the support for such tickless idle CPU in RCU.
  819. */
  820. static int
  821. rcu_torture_shuffle(void *arg)
  822. {
  823. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
  824. do {
  825. schedule_timeout_interruptible(shuffle_interval * HZ);
  826. rcu_torture_shuffle_tasks();
  827. } while (!kthread_should_stop() && !fullstop);
  828. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
  829. return 0;
  830. }
  831. /* Cause the rcutorture test to "stutter", starting and stopping all
  832. * threads periodically.
  833. */
  834. static int
  835. rcu_torture_stutter(void *arg)
  836. {
  837. VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
  838. do {
  839. schedule_timeout_interruptible(stutter * HZ);
  840. stutter_pause_test = 1;
  841. if (!kthread_should_stop() && !fullstop)
  842. schedule_timeout_interruptible(stutter * HZ);
  843. stutter_pause_test = 0;
  844. } while (!kthread_should_stop() && !fullstop);
  845. VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
  846. return 0;
  847. }
  848. static inline void
  849. rcu_torture_print_module_parms(char *tag)
  850. {
  851. printk(KERN_ALERT "%s" TORTURE_FLAG
  852. "--- %s: nreaders=%d nfakewriters=%d "
  853. "stat_interval=%d verbose=%d test_no_idle_hz=%d "
  854. "shuffle_interval=%d stutter=%d irqreader=%d\n",
  855. torture_type, tag, nrealreaders, nfakewriters,
  856. stat_interval, verbose, test_no_idle_hz, shuffle_interval,
  857. stutter, irqreader);
  858. }
  859. static struct notifier_block rcutorture_nb = {
  860. .notifier_call = rcutorture_shutdown_notify,
  861. };
  862. static void
  863. rcu_torture_cleanup(void)
  864. {
  865. int i;
  866. mutex_lock(&fullstop_mutex);
  867. if (!fullstop) {
  868. /* If being signaled, let it happen, then exit. */
  869. mutex_unlock(&fullstop_mutex);
  870. schedule_timeout_interruptible(10 * HZ);
  871. if (cur_ops->cb_barrier != NULL)
  872. cur_ops->cb_barrier();
  873. return;
  874. }
  875. fullstop = FULLSTOP_CLEANUP;
  876. mutex_unlock(&fullstop_mutex);
  877. unregister_reboot_notifier(&rcutorture_nb);
  878. if (stutter_task) {
  879. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
  880. kthread_stop(stutter_task);
  881. }
  882. stutter_task = NULL;
  883. if (shuffler_task) {
  884. VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
  885. kthread_stop(shuffler_task);
  886. }
  887. shuffler_task = NULL;
  888. if (writer_task) {
  889. VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
  890. kthread_stop(writer_task);
  891. }
  892. writer_task = NULL;
  893. if (reader_tasks) {
  894. for (i = 0; i < nrealreaders; i++) {
  895. if (reader_tasks[i]) {
  896. VERBOSE_PRINTK_STRING(
  897. "Stopping rcu_torture_reader task");
  898. kthread_stop(reader_tasks[i]);
  899. }
  900. reader_tasks[i] = NULL;
  901. }
  902. kfree(reader_tasks);
  903. reader_tasks = NULL;
  904. }
  905. rcu_torture_current = NULL;
  906. if (fakewriter_tasks) {
  907. for (i = 0; i < nfakewriters; i++) {
  908. if (fakewriter_tasks[i]) {
  909. VERBOSE_PRINTK_STRING(
  910. "Stopping rcu_torture_fakewriter task");
  911. kthread_stop(fakewriter_tasks[i]);
  912. }
  913. fakewriter_tasks[i] = NULL;
  914. }
  915. kfree(fakewriter_tasks);
  916. fakewriter_tasks = NULL;
  917. }
  918. if (stats_task) {
  919. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
  920. kthread_stop(stats_task);
  921. }
  922. stats_task = NULL;
  923. /* Wait for all RCU callbacks to fire. */
  924. if (cur_ops->cb_barrier != NULL)
  925. cur_ops->cb_barrier();
  926. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  927. if (cur_ops->cleanup)
  928. cur_ops->cleanup();
  929. if (atomic_read(&n_rcu_torture_error))
  930. rcu_torture_print_module_parms("End of test: FAILURE");
  931. else
  932. rcu_torture_print_module_parms("End of test: SUCCESS");
  933. }
  934. static int __init
  935. rcu_torture_init(void)
  936. {
  937. int i;
  938. int cpu;
  939. int firsterr = 0;
  940. static struct rcu_torture_ops *torture_ops[] =
  941. { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
  942. &srcu_ops, &sched_ops, &sched_ops_sync, };
  943. mutex_lock(&fullstop_mutex);
  944. /* Process args and tell the world that the torturer is on the job. */
  945. for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
  946. cur_ops = torture_ops[i];
  947. if (strcmp(torture_type, cur_ops->name) == 0)
  948. break;
  949. }
  950. if (i == ARRAY_SIZE(torture_ops)) {
  951. printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
  952. torture_type);
  953. mutex_unlock(&fullstop_mutex);
  954. return (-EINVAL);
  955. }
  956. if (cur_ops->init)
  957. cur_ops->init(); /* no "goto unwind" prior to this point!!! */
  958. if (nreaders >= 0)
  959. nrealreaders = nreaders;
  960. else
  961. nrealreaders = 2 * num_online_cpus();
  962. rcu_torture_print_module_parms("Start of test");
  963. fullstop = 0;
  964. /* Set up the freelist. */
  965. INIT_LIST_HEAD(&rcu_torture_freelist);
  966. for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
  967. rcu_tortures[i].rtort_mbtest = 0;
  968. list_add_tail(&rcu_tortures[i].rtort_free,
  969. &rcu_torture_freelist);
  970. }
  971. /* Initialize the statistics so that each run gets its own numbers. */
  972. rcu_torture_current = NULL;
  973. rcu_torture_current_version = 0;
  974. atomic_set(&n_rcu_torture_alloc, 0);
  975. atomic_set(&n_rcu_torture_alloc_fail, 0);
  976. atomic_set(&n_rcu_torture_free, 0);
  977. atomic_set(&n_rcu_torture_mberror, 0);
  978. atomic_set(&n_rcu_torture_error, 0);
  979. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  980. atomic_set(&rcu_torture_wcount[i], 0);
  981. for_each_possible_cpu(cpu) {
  982. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  983. per_cpu(rcu_torture_count, cpu)[i] = 0;
  984. per_cpu(rcu_torture_batch, cpu)[i] = 0;
  985. }
  986. }
  987. /* Start up the kthreads. */
  988. VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
  989. writer_task = kthread_run(rcu_torture_writer, NULL,
  990. "rcu_torture_writer");
  991. if (IS_ERR(writer_task)) {
  992. firsterr = PTR_ERR(writer_task);
  993. VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
  994. writer_task = NULL;
  995. goto unwind;
  996. }
  997. fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
  998. GFP_KERNEL);
  999. if (fakewriter_tasks == NULL) {
  1000. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1001. firsterr = -ENOMEM;
  1002. goto unwind;
  1003. }
  1004. for (i = 0; i < nfakewriters; i++) {
  1005. VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
  1006. fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
  1007. "rcu_torture_fakewriter");
  1008. if (IS_ERR(fakewriter_tasks[i])) {
  1009. firsterr = PTR_ERR(fakewriter_tasks[i]);
  1010. VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
  1011. fakewriter_tasks[i] = NULL;
  1012. goto unwind;
  1013. }
  1014. }
  1015. reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
  1016. GFP_KERNEL);
  1017. if (reader_tasks == NULL) {
  1018. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1019. firsterr = -ENOMEM;
  1020. goto unwind;
  1021. }
  1022. for (i = 0; i < nrealreaders; i++) {
  1023. VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
  1024. reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
  1025. "rcu_torture_reader");
  1026. if (IS_ERR(reader_tasks[i])) {
  1027. firsterr = PTR_ERR(reader_tasks[i]);
  1028. VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
  1029. reader_tasks[i] = NULL;
  1030. goto unwind;
  1031. }
  1032. }
  1033. if (stat_interval > 0) {
  1034. VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
  1035. stats_task = kthread_run(rcu_torture_stats, NULL,
  1036. "rcu_torture_stats");
  1037. if (IS_ERR(stats_task)) {
  1038. firsterr = PTR_ERR(stats_task);
  1039. VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
  1040. stats_task = NULL;
  1041. goto unwind;
  1042. }
  1043. }
  1044. if (test_no_idle_hz) {
  1045. rcu_idle_cpu = num_online_cpus() - 1;
  1046. /* Create the shuffler thread */
  1047. shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
  1048. "rcu_torture_shuffle");
  1049. if (IS_ERR(shuffler_task)) {
  1050. firsterr = PTR_ERR(shuffler_task);
  1051. VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
  1052. shuffler_task = NULL;
  1053. goto unwind;
  1054. }
  1055. }
  1056. if (stutter < 0)
  1057. stutter = 0;
  1058. if (stutter) {
  1059. /* Create the stutter thread */
  1060. stutter_task = kthread_run(rcu_torture_stutter, NULL,
  1061. "rcu_torture_stutter");
  1062. if (IS_ERR(stutter_task)) {
  1063. firsterr = PTR_ERR(stutter_task);
  1064. VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
  1065. stutter_task = NULL;
  1066. goto unwind;
  1067. }
  1068. }
  1069. register_reboot_notifier(&rcutorture_nb);
  1070. mutex_unlock(&fullstop_mutex);
  1071. return 0;
  1072. unwind:
  1073. mutex_unlock(&fullstop_mutex);
  1074. rcu_torture_cleanup();
  1075. return firsterr;
  1076. }
  1077. module_init(rcu_torture_init);
  1078. module_exit(rcu_torture_cleanup);