rcutorture.c 34 KB

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