rcutorture.c 33 KB

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