rcutorture.c 35 KB

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