rcutorture.c 33 KB

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