rcutorture.c 36 KB

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