rcutorture.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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 <linux/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 int fqs_duration; /* Duration of bursts (us), 0 to disable. */
  63. static int fqs_holdoff; /* Hold time within burst (us). */
  64. static int fqs_stutter = 3; /* Wait time between bursts (s). */
  65. static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
  66. static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
  67. static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
  68. static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
  69. static int test_boost_duration = 4; /* Duration of each boost test, seconds. */
  70. static char *torture_type = "rcu"; /* What RCU implementation to torture. */
  71. module_param(nreaders, int, 0444);
  72. MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
  73. module_param(nfakewriters, int, 0444);
  74. MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
  75. module_param(stat_interval, int, 0644);
  76. MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
  77. module_param(verbose, bool, 0444);
  78. MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
  79. module_param(test_no_idle_hz, bool, 0444);
  80. MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
  81. module_param(shuffle_interval, int, 0444);
  82. MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
  83. module_param(stutter, int, 0444);
  84. MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
  85. module_param(irqreader, int, 0444);
  86. MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
  87. module_param(fqs_duration, int, 0444);
  88. MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
  89. module_param(fqs_holdoff, int, 0444);
  90. MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
  91. module_param(fqs_stutter, int, 0444);
  92. MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
  93. module_param(onoff_interval, int, 0444);
  94. MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
  95. module_param(shutdown_secs, int, 0444);
  96. MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
  97. module_param(test_boost, int, 0444);
  98. MODULE_PARM_DESC(test_boost, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
  99. module_param(test_boost_interval, int, 0444);
  100. MODULE_PARM_DESC(test_boost_interval, "Interval between boost tests, seconds.");
  101. module_param(test_boost_duration, int, 0444);
  102. MODULE_PARM_DESC(test_boost_duration, "Duration of each boost test, seconds.");
  103. module_param(torture_type, charp, 0444);
  104. MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
  105. #define TORTURE_FLAG "-torture:"
  106. #define PRINTK_STRING(s) \
  107. do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  108. #define VERBOSE_PRINTK_STRING(s) \
  109. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  110. #define VERBOSE_PRINTK_ERRSTRING(s) \
  111. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
  112. static char printk_buf[4096];
  113. static int nrealreaders;
  114. static struct task_struct *writer_task;
  115. static struct task_struct **fakewriter_tasks;
  116. static struct task_struct **reader_tasks;
  117. static struct task_struct *stats_task;
  118. static struct task_struct *shuffler_task;
  119. static struct task_struct *stutter_task;
  120. static struct task_struct *fqs_task;
  121. static struct task_struct *boost_tasks[NR_CPUS];
  122. static struct task_struct *shutdown_task;
  123. #ifdef CONFIG_HOTPLUG_CPU
  124. static struct task_struct *onoff_task;
  125. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  126. #define RCU_TORTURE_PIPE_LEN 10
  127. struct rcu_torture {
  128. struct rcu_head rtort_rcu;
  129. int rtort_pipe_count;
  130. struct list_head rtort_free;
  131. int rtort_mbtest;
  132. };
  133. static LIST_HEAD(rcu_torture_freelist);
  134. static struct rcu_torture __rcu *rcu_torture_current;
  135. static unsigned long rcu_torture_current_version;
  136. static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
  137. static DEFINE_SPINLOCK(rcu_torture_lock);
  138. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
  139. { 0 };
  140. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
  141. { 0 };
  142. static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  143. static atomic_t n_rcu_torture_alloc;
  144. static atomic_t n_rcu_torture_alloc_fail;
  145. static atomic_t n_rcu_torture_free;
  146. static atomic_t n_rcu_torture_mberror;
  147. static atomic_t n_rcu_torture_error;
  148. static long n_rcu_torture_boost_ktrerror;
  149. static long n_rcu_torture_boost_rterror;
  150. static long n_rcu_torture_boost_failure;
  151. static long n_rcu_torture_boosts;
  152. static long n_rcu_torture_timers;
  153. static long n_offline_attempts;
  154. static long n_offline_successes;
  155. static long n_online_attempts;
  156. static long n_online_successes;
  157. static struct list_head rcu_torture_removed;
  158. static cpumask_var_t shuffle_tmp_mask;
  159. static int stutter_pause_test;
  160. #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
  161. #define RCUTORTURE_RUNNABLE_INIT 1
  162. #else
  163. #define RCUTORTURE_RUNNABLE_INIT 0
  164. #endif
  165. int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
  166. module_param(rcutorture_runnable, int, 0444);
  167. MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
  168. #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
  169. #define rcu_can_boost() 1
  170. #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  171. #define rcu_can_boost() 0
  172. #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  173. static unsigned long shutdown_time; /* jiffies to system shutdown. */
  174. static unsigned long boost_starttime; /* jiffies of next boost test start. */
  175. DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
  176. /* and boost task create/destroy. */
  177. /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
  178. #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
  179. #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
  180. #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
  181. static int fullstop = FULLSTOP_RMMOD;
  182. /*
  183. * Protect fullstop transitions and spawning of kthreads.
  184. */
  185. static DEFINE_MUTEX(fullstop_mutex);
  186. /* Forward reference. */
  187. static void rcu_torture_cleanup(void);
  188. /*
  189. * Detect and respond to a system shutdown.
  190. */
  191. static int
  192. rcutorture_shutdown_notify(struct notifier_block *unused1,
  193. unsigned long unused2, void *unused3)
  194. {
  195. mutex_lock(&fullstop_mutex);
  196. if (fullstop == FULLSTOP_DONTSTOP)
  197. fullstop = FULLSTOP_SHUTDOWN;
  198. else
  199. printk(KERN_WARNING /* but going down anyway, so... */
  200. "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
  201. mutex_unlock(&fullstop_mutex);
  202. return NOTIFY_DONE;
  203. }
  204. /*
  205. * Absorb kthreads into a kernel function that won't return, so that
  206. * they won't ever access module text or data again.
  207. */
  208. static void rcutorture_shutdown_absorb(char *title)
  209. {
  210. if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
  211. printk(KERN_NOTICE
  212. "rcutorture thread %s parking due to system shutdown\n",
  213. title);
  214. schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
  215. }
  216. }
  217. /*
  218. * Allocate an element from the rcu_tortures pool.
  219. */
  220. static struct rcu_torture *
  221. rcu_torture_alloc(void)
  222. {
  223. struct list_head *p;
  224. spin_lock_bh(&rcu_torture_lock);
  225. if (list_empty(&rcu_torture_freelist)) {
  226. atomic_inc(&n_rcu_torture_alloc_fail);
  227. spin_unlock_bh(&rcu_torture_lock);
  228. return NULL;
  229. }
  230. atomic_inc(&n_rcu_torture_alloc);
  231. p = rcu_torture_freelist.next;
  232. list_del_init(p);
  233. spin_unlock_bh(&rcu_torture_lock);
  234. return container_of(p, struct rcu_torture, rtort_free);
  235. }
  236. /*
  237. * Free an element to the rcu_tortures pool.
  238. */
  239. static void
  240. rcu_torture_free(struct rcu_torture *p)
  241. {
  242. atomic_inc(&n_rcu_torture_free);
  243. spin_lock_bh(&rcu_torture_lock);
  244. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  245. spin_unlock_bh(&rcu_torture_lock);
  246. }
  247. struct rcu_random_state {
  248. unsigned long rrs_state;
  249. long rrs_count;
  250. };
  251. #define RCU_RANDOM_MULT 39916801 /* prime */
  252. #define RCU_RANDOM_ADD 479001701 /* prime */
  253. #define RCU_RANDOM_REFRESH 10000
  254. #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
  255. /*
  256. * Crude but fast random-number generator. Uses a linear congruential
  257. * generator, with occasional help from cpu_clock().
  258. */
  259. static unsigned long
  260. rcu_random(struct rcu_random_state *rrsp)
  261. {
  262. if (--rrsp->rrs_count < 0) {
  263. rrsp->rrs_state += (unsigned long)local_clock();
  264. rrsp->rrs_count = RCU_RANDOM_REFRESH;
  265. }
  266. rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
  267. return swahw32(rrsp->rrs_state);
  268. }
  269. static void
  270. rcu_stutter_wait(char *title)
  271. {
  272. while (stutter_pause_test || !rcutorture_runnable) {
  273. if (rcutorture_runnable)
  274. schedule_timeout_interruptible(1);
  275. else
  276. schedule_timeout_interruptible(round_jiffies_relative(HZ));
  277. rcutorture_shutdown_absorb(title);
  278. }
  279. }
  280. /*
  281. * Operations vector for selecting different types of tests.
  282. */
  283. struct rcu_torture_ops {
  284. void (*init)(void);
  285. void (*cleanup)(void);
  286. int (*readlock)(void);
  287. void (*read_delay)(struct rcu_random_state *rrsp);
  288. void (*readunlock)(int idx);
  289. int (*completed)(void);
  290. void (*deferred_free)(struct rcu_torture *p);
  291. void (*sync)(void);
  292. void (*cb_barrier)(void);
  293. void (*fqs)(void);
  294. int (*stats)(char *page);
  295. int irq_capable;
  296. int can_boost;
  297. char *name;
  298. };
  299. static struct rcu_torture_ops *cur_ops;
  300. /*
  301. * Definitions for rcu torture testing.
  302. */
  303. static int rcu_torture_read_lock(void) __acquires(RCU)
  304. {
  305. rcu_read_lock();
  306. return 0;
  307. }
  308. static void rcu_read_delay(struct rcu_random_state *rrsp)
  309. {
  310. const unsigned long shortdelay_us = 200;
  311. const unsigned long longdelay_ms = 50;
  312. /* We want a short delay sometimes to make a reader delay the grace
  313. * period, and we want a long delay occasionally to trigger
  314. * force_quiescent_state. */
  315. if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
  316. mdelay(longdelay_ms);
  317. if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
  318. udelay(shortdelay_us);
  319. #ifdef CONFIG_PREEMPT
  320. if (!preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
  321. preempt_schedule(); /* No QS if preempt_disable() in effect */
  322. #endif
  323. }
  324. static void rcu_torture_read_unlock(int idx) __releases(RCU)
  325. {
  326. rcu_read_unlock();
  327. }
  328. static int rcu_torture_completed(void)
  329. {
  330. return rcu_batches_completed();
  331. }
  332. static void
  333. rcu_torture_cb(struct rcu_head *p)
  334. {
  335. int i;
  336. struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
  337. if (fullstop != FULLSTOP_DONTSTOP) {
  338. /* Test is ending, just drop callbacks on the floor. */
  339. /* The next initialization will pick up the pieces. */
  340. return;
  341. }
  342. i = rp->rtort_pipe_count;
  343. if (i > RCU_TORTURE_PIPE_LEN)
  344. i = RCU_TORTURE_PIPE_LEN;
  345. atomic_inc(&rcu_torture_wcount[i]);
  346. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  347. rp->rtort_mbtest = 0;
  348. rcu_torture_free(rp);
  349. } else
  350. cur_ops->deferred_free(rp);
  351. }
  352. static int rcu_no_completed(void)
  353. {
  354. return 0;
  355. }
  356. static void rcu_torture_deferred_free(struct rcu_torture *p)
  357. {
  358. call_rcu(&p->rtort_rcu, rcu_torture_cb);
  359. }
  360. static struct rcu_torture_ops rcu_ops = {
  361. .init = NULL,
  362. .cleanup = NULL,
  363. .readlock = rcu_torture_read_lock,
  364. .read_delay = rcu_read_delay,
  365. .readunlock = rcu_torture_read_unlock,
  366. .completed = rcu_torture_completed,
  367. .deferred_free = rcu_torture_deferred_free,
  368. .sync = synchronize_rcu,
  369. .cb_barrier = rcu_barrier,
  370. .fqs = rcu_force_quiescent_state,
  371. .stats = NULL,
  372. .irq_capable = 1,
  373. .can_boost = rcu_can_boost(),
  374. .name = "rcu"
  375. };
  376. static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
  377. {
  378. int i;
  379. struct rcu_torture *rp;
  380. struct rcu_torture *rp1;
  381. cur_ops->sync();
  382. list_add(&p->rtort_free, &rcu_torture_removed);
  383. list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
  384. i = rp->rtort_pipe_count;
  385. if (i > RCU_TORTURE_PIPE_LEN)
  386. i = RCU_TORTURE_PIPE_LEN;
  387. atomic_inc(&rcu_torture_wcount[i]);
  388. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  389. rp->rtort_mbtest = 0;
  390. list_del(&rp->rtort_free);
  391. rcu_torture_free(rp);
  392. }
  393. }
  394. }
  395. static void rcu_sync_torture_init(void)
  396. {
  397. INIT_LIST_HEAD(&rcu_torture_removed);
  398. }
  399. static struct rcu_torture_ops rcu_sync_ops = {
  400. .init = rcu_sync_torture_init,
  401. .cleanup = NULL,
  402. .readlock = rcu_torture_read_lock,
  403. .read_delay = rcu_read_delay,
  404. .readunlock = rcu_torture_read_unlock,
  405. .completed = rcu_torture_completed,
  406. .deferred_free = rcu_sync_torture_deferred_free,
  407. .sync = synchronize_rcu,
  408. .cb_barrier = NULL,
  409. .fqs = rcu_force_quiescent_state,
  410. .stats = NULL,
  411. .irq_capable = 1,
  412. .can_boost = rcu_can_boost(),
  413. .name = "rcu_sync"
  414. };
  415. static struct rcu_torture_ops rcu_expedited_ops = {
  416. .init = rcu_sync_torture_init,
  417. .cleanup = NULL,
  418. .readlock = rcu_torture_read_lock,
  419. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  420. .readunlock = rcu_torture_read_unlock,
  421. .completed = rcu_no_completed,
  422. .deferred_free = rcu_sync_torture_deferred_free,
  423. .sync = synchronize_rcu_expedited,
  424. .cb_barrier = NULL,
  425. .fqs = rcu_force_quiescent_state,
  426. .stats = NULL,
  427. .irq_capable = 1,
  428. .can_boost = rcu_can_boost(),
  429. .name = "rcu_expedited"
  430. };
  431. /*
  432. * Definitions for rcu_bh torture testing.
  433. */
  434. static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
  435. {
  436. rcu_read_lock_bh();
  437. return 0;
  438. }
  439. static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
  440. {
  441. rcu_read_unlock_bh();
  442. }
  443. static int rcu_bh_torture_completed(void)
  444. {
  445. return rcu_batches_completed_bh();
  446. }
  447. static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
  448. {
  449. call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
  450. }
  451. static struct rcu_torture_ops rcu_bh_ops = {
  452. .init = NULL,
  453. .cleanup = NULL,
  454. .readlock = rcu_bh_torture_read_lock,
  455. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  456. .readunlock = rcu_bh_torture_read_unlock,
  457. .completed = rcu_bh_torture_completed,
  458. .deferred_free = rcu_bh_torture_deferred_free,
  459. .sync = synchronize_rcu_bh,
  460. .cb_barrier = rcu_barrier_bh,
  461. .fqs = rcu_bh_force_quiescent_state,
  462. .stats = NULL,
  463. .irq_capable = 1,
  464. .name = "rcu_bh"
  465. };
  466. static struct rcu_torture_ops rcu_bh_sync_ops = {
  467. .init = rcu_sync_torture_init,
  468. .cleanup = NULL,
  469. .readlock = rcu_bh_torture_read_lock,
  470. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  471. .readunlock = rcu_bh_torture_read_unlock,
  472. .completed = rcu_bh_torture_completed,
  473. .deferred_free = rcu_sync_torture_deferred_free,
  474. .sync = synchronize_rcu_bh,
  475. .cb_barrier = NULL,
  476. .fqs = rcu_bh_force_quiescent_state,
  477. .stats = NULL,
  478. .irq_capable = 1,
  479. .name = "rcu_bh_sync"
  480. };
  481. static struct rcu_torture_ops rcu_bh_expedited_ops = {
  482. .init = rcu_sync_torture_init,
  483. .cleanup = NULL,
  484. .readlock = rcu_bh_torture_read_lock,
  485. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  486. .readunlock = rcu_bh_torture_read_unlock,
  487. .completed = rcu_bh_torture_completed,
  488. .deferred_free = rcu_sync_torture_deferred_free,
  489. .sync = synchronize_rcu_bh_expedited,
  490. .cb_barrier = NULL,
  491. .fqs = rcu_bh_force_quiescent_state,
  492. .stats = NULL,
  493. .irq_capable = 1,
  494. .name = "rcu_bh_expedited"
  495. };
  496. /*
  497. * Definitions for srcu torture testing.
  498. */
  499. static struct srcu_struct srcu_ctl;
  500. static void srcu_torture_init(void)
  501. {
  502. init_srcu_struct(&srcu_ctl);
  503. rcu_sync_torture_init();
  504. }
  505. static void srcu_torture_cleanup(void)
  506. {
  507. synchronize_srcu(&srcu_ctl);
  508. cleanup_srcu_struct(&srcu_ctl);
  509. }
  510. static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
  511. {
  512. return srcu_read_lock(&srcu_ctl);
  513. }
  514. static void srcu_read_delay(struct rcu_random_state *rrsp)
  515. {
  516. long delay;
  517. const long uspertick = 1000000 / HZ;
  518. const long longdelay = 10;
  519. /* We want there to be long-running readers, but not all the time. */
  520. delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
  521. if (!delay)
  522. schedule_timeout_interruptible(longdelay);
  523. else
  524. rcu_read_delay(rrsp);
  525. }
  526. static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
  527. {
  528. srcu_read_unlock(&srcu_ctl, idx);
  529. }
  530. static int srcu_torture_completed(void)
  531. {
  532. return srcu_batches_completed(&srcu_ctl);
  533. }
  534. static void srcu_torture_synchronize(void)
  535. {
  536. synchronize_srcu(&srcu_ctl);
  537. }
  538. static int srcu_torture_stats(char *page)
  539. {
  540. int cnt = 0;
  541. int cpu;
  542. int idx = srcu_ctl.completed & 0x1;
  543. cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
  544. torture_type, TORTURE_FLAG, idx);
  545. for_each_possible_cpu(cpu) {
  546. cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
  547. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
  548. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
  549. }
  550. cnt += sprintf(&page[cnt], "\n");
  551. return cnt;
  552. }
  553. static struct rcu_torture_ops srcu_ops = {
  554. .init = srcu_torture_init,
  555. .cleanup = srcu_torture_cleanup,
  556. .readlock = srcu_torture_read_lock,
  557. .read_delay = srcu_read_delay,
  558. .readunlock = srcu_torture_read_unlock,
  559. .completed = srcu_torture_completed,
  560. .deferred_free = rcu_sync_torture_deferred_free,
  561. .sync = srcu_torture_synchronize,
  562. .cb_barrier = NULL,
  563. .stats = srcu_torture_stats,
  564. .name = "srcu"
  565. };
  566. static void srcu_torture_synchronize_expedited(void)
  567. {
  568. synchronize_srcu_expedited(&srcu_ctl);
  569. }
  570. static struct rcu_torture_ops srcu_expedited_ops = {
  571. .init = srcu_torture_init,
  572. .cleanup = srcu_torture_cleanup,
  573. .readlock = srcu_torture_read_lock,
  574. .read_delay = srcu_read_delay,
  575. .readunlock = srcu_torture_read_unlock,
  576. .completed = srcu_torture_completed,
  577. .deferred_free = rcu_sync_torture_deferred_free,
  578. .sync = srcu_torture_synchronize_expedited,
  579. .cb_barrier = NULL,
  580. .stats = srcu_torture_stats,
  581. .name = "srcu_expedited"
  582. };
  583. /*
  584. * Definitions for sched torture testing.
  585. */
  586. static int sched_torture_read_lock(void)
  587. {
  588. preempt_disable();
  589. return 0;
  590. }
  591. static void sched_torture_read_unlock(int idx)
  592. {
  593. preempt_enable();
  594. }
  595. static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
  596. {
  597. call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
  598. }
  599. static struct rcu_torture_ops sched_ops = {
  600. .init = rcu_sync_torture_init,
  601. .cleanup = NULL,
  602. .readlock = sched_torture_read_lock,
  603. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  604. .readunlock = sched_torture_read_unlock,
  605. .completed = rcu_no_completed,
  606. .deferred_free = rcu_sched_torture_deferred_free,
  607. .sync = synchronize_sched,
  608. .cb_barrier = rcu_barrier_sched,
  609. .fqs = rcu_sched_force_quiescent_state,
  610. .stats = NULL,
  611. .irq_capable = 1,
  612. .name = "sched"
  613. };
  614. static struct rcu_torture_ops sched_sync_ops = {
  615. .init = rcu_sync_torture_init,
  616. .cleanup = NULL,
  617. .readlock = sched_torture_read_lock,
  618. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  619. .readunlock = sched_torture_read_unlock,
  620. .completed = rcu_no_completed,
  621. .deferred_free = rcu_sync_torture_deferred_free,
  622. .sync = synchronize_sched,
  623. .cb_barrier = NULL,
  624. .fqs = rcu_sched_force_quiescent_state,
  625. .stats = NULL,
  626. .name = "sched_sync"
  627. };
  628. static struct rcu_torture_ops sched_expedited_ops = {
  629. .init = rcu_sync_torture_init,
  630. .cleanup = NULL,
  631. .readlock = sched_torture_read_lock,
  632. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  633. .readunlock = sched_torture_read_unlock,
  634. .completed = rcu_no_completed,
  635. .deferred_free = rcu_sync_torture_deferred_free,
  636. .sync = synchronize_sched_expedited,
  637. .cb_barrier = NULL,
  638. .fqs = rcu_sched_force_quiescent_state,
  639. .stats = NULL,
  640. .irq_capable = 1,
  641. .name = "sched_expedited"
  642. };
  643. /*
  644. * RCU torture priority-boost testing. Runs one real-time thread per
  645. * CPU for moderate bursts, repeatedly registering RCU callbacks and
  646. * spinning waiting for them to be invoked. If a given callback takes
  647. * too long to be invoked, we assume that priority inversion has occurred.
  648. */
  649. struct rcu_boost_inflight {
  650. struct rcu_head rcu;
  651. int inflight;
  652. };
  653. static void rcu_torture_boost_cb(struct rcu_head *head)
  654. {
  655. struct rcu_boost_inflight *rbip =
  656. container_of(head, struct rcu_boost_inflight, rcu);
  657. smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
  658. rbip->inflight = 0;
  659. }
  660. static int rcu_torture_boost(void *arg)
  661. {
  662. unsigned long call_rcu_time;
  663. unsigned long endtime;
  664. unsigned long oldstarttime;
  665. struct rcu_boost_inflight rbi = { .inflight = 0 };
  666. struct sched_param sp;
  667. VERBOSE_PRINTK_STRING("rcu_torture_boost started");
  668. /* Set real-time priority. */
  669. sp.sched_priority = 1;
  670. if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
  671. VERBOSE_PRINTK_STRING("rcu_torture_boost RT prio failed!");
  672. n_rcu_torture_boost_rterror++;
  673. }
  674. init_rcu_head_on_stack(&rbi.rcu);
  675. /* Each pass through the following loop does one boost-test cycle. */
  676. do {
  677. /* Wait for the next test interval. */
  678. oldstarttime = boost_starttime;
  679. while (ULONG_CMP_LT(jiffies, oldstarttime)) {
  680. schedule_timeout_uninterruptible(1);
  681. rcu_stutter_wait("rcu_torture_boost");
  682. if (kthread_should_stop() ||
  683. fullstop != FULLSTOP_DONTSTOP)
  684. goto checkwait;
  685. }
  686. /* Do one boost-test interval. */
  687. endtime = oldstarttime + test_boost_duration * HZ;
  688. call_rcu_time = jiffies;
  689. while (ULONG_CMP_LT(jiffies, endtime)) {
  690. /* If we don't have a callback in flight, post one. */
  691. if (!rbi.inflight) {
  692. smp_mb(); /* RCU core before ->inflight = 1. */
  693. rbi.inflight = 1;
  694. call_rcu(&rbi.rcu, rcu_torture_boost_cb);
  695. if (jiffies - call_rcu_time >
  696. test_boost_duration * HZ - HZ / 2) {
  697. VERBOSE_PRINTK_STRING("rcu_torture_boost boosting failed");
  698. n_rcu_torture_boost_failure++;
  699. }
  700. call_rcu_time = jiffies;
  701. }
  702. cond_resched();
  703. rcu_stutter_wait("rcu_torture_boost");
  704. if (kthread_should_stop() ||
  705. fullstop != FULLSTOP_DONTSTOP)
  706. goto checkwait;
  707. }
  708. /*
  709. * Set the start time of the next test interval.
  710. * Yes, this is vulnerable to long delays, but such
  711. * delays simply cause a false negative for the next
  712. * interval. Besides, we are running at RT priority,
  713. * so delays should be relatively rare.
  714. */
  715. while (oldstarttime == boost_starttime &&
  716. !kthread_should_stop()) {
  717. if (mutex_trylock(&boost_mutex)) {
  718. boost_starttime = jiffies +
  719. test_boost_interval * HZ;
  720. n_rcu_torture_boosts++;
  721. mutex_unlock(&boost_mutex);
  722. break;
  723. }
  724. schedule_timeout_uninterruptible(1);
  725. }
  726. /* Go do the stutter. */
  727. checkwait: rcu_stutter_wait("rcu_torture_boost");
  728. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  729. /* Clean up and exit. */
  730. VERBOSE_PRINTK_STRING("rcu_torture_boost task stopping");
  731. rcutorture_shutdown_absorb("rcu_torture_boost");
  732. while (!kthread_should_stop() || rbi.inflight)
  733. schedule_timeout_uninterruptible(1);
  734. smp_mb(); /* order accesses to ->inflight before stack-frame death. */
  735. destroy_rcu_head_on_stack(&rbi.rcu);
  736. return 0;
  737. }
  738. /*
  739. * RCU torture force-quiescent-state kthread. Repeatedly induces
  740. * bursts of calls to force_quiescent_state(), increasing the probability
  741. * of occurrence of some important types of race conditions.
  742. */
  743. static int
  744. rcu_torture_fqs(void *arg)
  745. {
  746. unsigned long fqs_resume_time;
  747. int fqs_burst_remaining;
  748. VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
  749. do {
  750. fqs_resume_time = jiffies + fqs_stutter * HZ;
  751. while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
  752. !kthread_should_stop()) {
  753. schedule_timeout_interruptible(1);
  754. }
  755. fqs_burst_remaining = fqs_duration;
  756. while (fqs_burst_remaining > 0 &&
  757. !kthread_should_stop()) {
  758. cur_ops->fqs();
  759. udelay(fqs_holdoff);
  760. fqs_burst_remaining -= fqs_holdoff;
  761. }
  762. rcu_stutter_wait("rcu_torture_fqs");
  763. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  764. VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
  765. rcutorture_shutdown_absorb("rcu_torture_fqs");
  766. while (!kthread_should_stop())
  767. schedule_timeout_uninterruptible(1);
  768. return 0;
  769. }
  770. /*
  771. * RCU torture writer kthread. Repeatedly substitutes a new structure
  772. * for that pointed to by rcu_torture_current, freeing the old structure
  773. * after a series of grace periods (the "pipeline").
  774. */
  775. static int
  776. rcu_torture_writer(void *arg)
  777. {
  778. int i;
  779. long oldbatch = rcu_batches_completed();
  780. struct rcu_torture *rp;
  781. struct rcu_torture *old_rp;
  782. static DEFINE_RCU_RANDOM(rand);
  783. VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
  784. set_user_nice(current, 19);
  785. do {
  786. schedule_timeout_uninterruptible(1);
  787. rp = rcu_torture_alloc();
  788. if (rp == NULL)
  789. continue;
  790. rp->rtort_pipe_count = 0;
  791. udelay(rcu_random(&rand) & 0x3ff);
  792. old_rp = rcu_dereference_check(rcu_torture_current,
  793. current == writer_task);
  794. rp->rtort_mbtest = 1;
  795. rcu_assign_pointer(rcu_torture_current, rp);
  796. smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
  797. if (old_rp) {
  798. i = old_rp->rtort_pipe_count;
  799. if (i > RCU_TORTURE_PIPE_LEN)
  800. i = RCU_TORTURE_PIPE_LEN;
  801. atomic_inc(&rcu_torture_wcount[i]);
  802. old_rp->rtort_pipe_count++;
  803. cur_ops->deferred_free(old_rp);
  804. }
  805. rcutorture_record_progress(++rcu_torture_current_version);
  806. oldbatch = cur_ops->completed();
  807. rcu_stutter_wait("rcu_torture_writer");
  808. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  809. VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
  810. rcutorture_shutdown_absorb("rcu_torture_writer");
  811. while (!kthread_should_stop())
  812. schedule_timeout_uninterruptible(1);
  813. return 0;
  814. }
  815. /*
  816. * RCU torture fake writer kthread. Repeatedly calls sync, with a random
  817. * delay between calls.
  818. */
  819. static int
  820. rcu_torture_fakewriter(void *arg)
  821. {
  822. DEFINE_RCU_RANDOM(rand);
  823. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
  824. set_user_nice(current, 19);
  825. do {
  826. schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
  827. udelay(rcu_random(&rand) & 0x3ff);
  828. cur_ops->sync();
  829. rcu_stutter_wait("rcu_torture_fakewriter");
  830. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  831. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
  832. rcutorture_shutdown_absorb("rcu_torture_fakewriter");
  833. while (!kthread_should_stop())
  834. schedule_timeout_uninterruptible(1);
  835. return 0;
  836. }
  837. void rcutorture_trace_dump(void)
  838. {
  839. static atomic_t beenhere = ATOMIC_INIT(0);
  840. if (atomic_read(&beenhere))
  841. return;
  842. if (atomic_xchg(&beenhere, 1) != 0)
  843. return;
  844. do_trace_rcu_torture_read(cur_ops->name, (struct rcu_head *)~0UL);
  845. ftrace_dump(DUMP_ALL);
  846. }
  847. /*
  848. * RCU torture reader from timer handler. Dereferences rcu_torture_current,
  849. * incrementing the corresponding element of the pipeline array. The
  850. * counter in the element should never be greater than 1, otherwise, the
  851. * RCU implementation is broken.
  852. */
  853. static void rcu_torture_timer(unsigned long unused)
  854. {
  855. int idx;
  856. int completed;
  857. static DEFINE_RCU_RANDOM(rand);
  858. static DEFINE_SPINLOCK(rand_lock);
  859. struct rcu_torture *p;
  860. int pipe_count;
  861. idx = cur_ops->readlock();
  862. completed = cur_ops->completed();
  863. p = rcu_dereference_check(rcu_torture_current,
  864. rcu_read_lock_bh_held() ||
  865. rcu_read_lock_sched_held() ||
  866. srcu_read_lock_held(&srcu_ctl));
  867. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
  868. if (p == NULL) {
  869. /* Leave because rcu_torture_writer is not yet underway */
  870. cur_ops->readunlock(idx);
  871. return;
  872. }
  873. if (p->rtort_mbtest == 0)
  874. atomic_inc(&n_rcu_torture_mberror);
  875. spin_lock(&rand_lock);
  876. cur_ops->read_delay(&rand);
  877. n_rcu_torture_timers++;
  878. spin_unlock(&rand_lock);
  879. preempt_disable();
  880. pipe_count = p->rtort_pipe_count;
  881. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  882. /* Should not happen, but... */
  883. pipe_count = RCU_TORTURE_PIPE_LEN;
  884. }
  885. if (pipe_count > 1)
  886. rcutorture_trace_dump();
  887. __this_cpu_inc(rcu_torture_count[pipe_count]);
  888. completed = cur_ops->completed() - completed;
  889. if (completed > RCU_TORTURE_PIPE_LEN) {
  890. /* Should not happen, but... */
  891. completed = RCU_TORTURE_PIPE_LEN;
  892. }
  893. __this_cpu_inc(rcu_torture_batch[completed]);
  894. preempt_enable();
  895. cur_ops->readunlock(idx);
  896. }
  897. /*
  898. * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
  899. * incrementing the corresponding element of the pipeline array. The
  900. * counter in the element should never be greater than 1, otherwise, the
  901. * RCU implementation is broken.
  902. */
  903. static int
  904. rcu_torture_reader(void *arg)
  905. {
  906. int completed;
  907. int idx;
  908. DEFINE_RCU_RANDOM(rand);
  909. struct rcu_torture *p;
  910. int pipe_count;
  911. struct timer_list t;
  912. VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
  913. set_user_nice(current, 19);
  914. if (irqreader && cur_ops->irq_capable)
  915. setup_timer_on_stack(&t, rcu_torture_timer, 0);
  916. do {
  917. if (irqreader && cur_ops->irq_capable) {
  918. if (!timer_pending(&t))
  919. mod_timer(&t, jiffies + 1);
  920. }
  921. idx = cur_ops->readlock();
  922. completed = cur_ops->completed();
  923. p = rcu_dereference_check(rcu_torture_current,
  924. rcu_read_lock_bh_held() ||
  925. rcu_read_lock_sched_held() ||
  926. srcu_read_lock_held(&srcu_ctl));
  927. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
  928. if (p == NULL) {
  929. /* Wait for rcu_torture_writer to get underway */
  930. cur_ops->readunlock(idx);
  931. schedule_timeout_interruptible(HZ);
  932. continue;
  933. }
  934. if (p->rtort_mbtest == 0)
  935. atomic_inc(&n_rcu_torture_mberror);
  936. cur_ops->read_delay(&rand);
  937. preempt_disable();
  938. pipe_count = p->rtort_pipe_count;
  939. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  940. /* Should not happen, but... */
  941. pipe_count = RCU_TORTURE_PIPE_LEN;
  942. }
  943. if (pipe_count > 1)
  944. rcutorture_trace_dump();
  945. __this_cpu_inc(rcu_torture_count[pipe_count]);
  946. completed = cur_ops->completed() - completed;
  947. if (completed > RCU_TORTURE_PIPE_LEN) {
  948. /* Should not happen, but... */
  949. completed = RCU_TORTURE_PIPE_LEN;
  950. }
  951. __this_cpu_inc(rcu_torture_batch[completed]);
  952. preempt_enable();
  953. cur_ops->readunlock(idx);
  954. schedule();
  955. rcu_stutter_wait("rcu_torture_reader");
  956. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  957. VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
  958. rcutorture_shutdown_absorb("rcu_torture_reader");
  959. if (irqreader && cur_ops->irq_capable)
  960. del_timer_sync(&t);
  961. while (!kthread_should_stop())
  962. schedule_timeout_uninterruptible(1);
  963. return 0;
  964. }
  965. /*
  966. * Create an RCU-torture statistics message in the specified buffer.
  967. */
  968. static int
  969. rcu_torture_printk(char *page)
  970. {
  971. int cnt = 0;
  972. int cpu;
  973. int i;
  974. long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  975. long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  976. for_each_possible_cpu(cpu) {
  977. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  978. pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
  979. batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
  980. }
  981. }
  982. for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
  983. if (pipesummary[i] != 0)
  984. break;
  985. }
  986. cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
  987. cnt += sprintf(&page[cnt],
  988. "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
  989. "rtmbe: %d rtbke: %ld rtbre: %ld "
  990. "rtbf: %ld rtb: %ld nt: %ld "
  991. "onoff: %ld/%ld:%ld/%ld",
  992. rcu_torture_current,
  993. rcu_torture_current_version,
  994. list_empty(&rcu_torture_freelist),
  995. atomic_read(&n_rcu_torture_alloc),
  996. atomic_read(&n_rcu_torture_alloc_fail),
  997. atomic_read(&n_rcu_torture_free),
  998. atomic_read(&n_rcu_torture_mberror),
  999. n_rcu_torture_boost_ktrerror,
  1000. n_rcu_torture_boost_rterror,
  1001. n_rcu_torture_boost_failure,
  1002. n_rcu_torture_boosts,
  1003. n_rcu_torture_timers,
  1004. n_online_successes,
  1005. n_online_attempts,
  1006. n_offline_successes,
  1007. n_offline_attempts);
  1008. if (atomic_read(&n_rcu_torture_mberror) != 0 ||
  1009. n_rcu_torture_boost_ktrerror != 0 ||
  1010. n_rcu_torture_boost_rterror != 0 ||
  1011. n_rcu_torture_boost_failure != 0)
  1012. cnt += sprintf(&page[cnt], " !!!");
  1013. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  1014. if (i > 1) {
  1015. cnt += sprintf(&page[cnt], "!!! ");
  1016. atomic_inc(&n_rcu_torture_error);
  1017. WARN_ON_ONCE(1);
  1018. }
  1019. cnt += sprintf(&page[cnt], "Reader Pipe: ");
  1020. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1021. cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
  1022. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  1023. cnt += sprintf(&page[cnt], "Reader Batch: ");
  1024. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1025. cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
  1026. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  1027. cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
  1028. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1029. cnt += sprintf(&page[cnt], " %d",
  1030. atomic_read(&rcu_torture_wcount[i]));
  1031. }
  1032. cnt += sprintf(&page[cnt], "\n");
  1033. if (cur_ops->stats)
  1034. cnt += cur_ops->stats(&page[cnt]);
  1035. return cnt;
  1036. }
  1037. /*
  1038. * Print torture statistics. Caller must ensure that there is only
  1039. * one call to this function at a given time!!! This is normally
  1040. * accomplished by relying on the module system to only have one copy
  1041. * of the module loaded, and then by giving the rcu_torture_stats
  1042. * kthread full control (or the init/cleanup functions when rcu_torture_stats
  1043. * thread is not running).
  1044. */
  1045. static void
  1046. rcu_torture_stats_print(void)
  1047. {
  1048. int cnt;
  1049. cnt = rcu_torture_printk(printk_buf);
  1050. printk(KERN_ALERT "%s", printk_buf);
  1051. }
  1052. /*
  1053. * Periodically prints torture statistics, if periodic statistics printing
  1054. * was specified via the stat_interval module parameter.
  1055. *
  1056. * No need to worry about fullstop here, since this one doesn't reference
  1057. * volatile state or register callbacks.
  1058. */
  1059. static int
  1060. rcu_torture_stats(void *arg)
  1061. {
  1062. VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
  1063. do {
  1064. schedule_timeout_interruptible(stat_interval * HZ);
  1065. rcu_torture_stats_print();
  1066. rcutorture_shutdown_absorb("rcu_torture_stats");
  1067. } while (!kthread_should_stop());
  1068. VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
  1069. return 0;
  1070. }
  1071. static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
  1072. /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
  1073. * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
  1074. */
  1075. static void rcu_torture_shuffle_tasks(void)
  1076. {
  1077. int i;
  1078. cpumask_setall(shuffle_tmp_mask);
  1079. get_online_cpus();
  1080. /* No point in shuffling if there is only one online CPU (ex: UP) */
  1081. if (num_online_cpus() == 1) {
  1082. put_online_cpus();
  1083. return;
  1084. }
  1085. if (rcu_idle_cpu != -1)
  1086. cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
  1087. set_cpus_allowed_ptr(current, shuffle_tmp_mask);
  1088. if (reader_tasks) {
  1089. for (i = 0; i < nrealreaders; i++)
  1090. if (reader_tasks[i])
  1091. set_cpus_allowed_ptr(reader_tasks[i],
  1092. shuffle_tmp_mask);
  1093. }
  1094. if (fakewriter_tasks) {
  1095. for (i = 0; i < nfakewriters; i++)
  1096. if (fakewriter_tasks[i])
  1097. set_cpus_allowed_ptr(fakewriter_tasks[i],
  1098. shuffle_tmp_mask);
  1099. }
  1100. if (writer_task)
  1101. set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
  1102. if (stats_task)
  1103. set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
  1104. if (rcu_idle_cpu == -1)
  1105. rcu_idle_cpu = num_online_cpus() - 1;
  1106. else
  1107. rcu_idle_cpu--;
  1108. put_online_cpus();
  1109. }
  1110. /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
  1111. * system to become idle at a time and cut off its timer ticks. This is meant
  1112. * to test the support for such tickless idle CPU in RCU.
  1113. */
  1114. static int
  1115. rcu_torture_shuffle(void *arg)
  1116. {
  1117. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
  1118. do {
  1119. schedule_timeout_interruptible(shuffle_interval * HZ);
  1120. rcu_torture_shuffle_tasks();
  1121. rcutorture_shutdown_absorb("rcu_torture_shuffle");
  1122. } while (!kthread_should_stop());
  1123. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
  1124. return 0;
  1125. }
  1126. /* Cause the rcutorture test to "stutter", starting and stopping all
  1127. * threads periodically.
  1128. */
  1129. static int
  1130. rcu_torture_stutter(void *arg)
  1131. {
  1132. VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
  1133. do {
  1134. schedule_timeout_interruptible(stutter * HZ);
  1135. stutter_pause_test = 1;
  1136. if (!kthread_should_stop())
  1137. schedule_timeout_interruptible(stutter * HZ);
  1138. stutter_pause_test = 0;
  1139. rcutorture_shutdown_absorb("rcu_torture_stutter");
  1140. } while (!kthread_should_stop());
  1141. VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
  1142. return 0;
  1143. }
  1144. static inline void
  1145. rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
  1146. {
  1147. printk(KERN_ALERT "%s" TORTURE_FLAG
  1148. "--- %s: nreaders=%d nfakewriters=%d "
  1149. "stat_interval=%d verbose=%d test_no_idle_hz=%d "
  1150. "shuffle_interval=%d stutter=%d irqreader=%d "
  1151. "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
  1152. "test_boost=%d/%d test_boost_interval=%d "
  1153. "test_boost_duration=%d shutdown_secs=%d "
  1154. "onoff_interval=%d\n",
  1155. torture_type, tag, nrealreaders, nfakewriters,
  1156. stat_interval, verbose, test_no_idle_hz, shuffle_interval,
  1157. stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
  1158. test_boost, cur_ops->can_boost,
  1159. test_boost_interval, test_boost_duration, shutdown_secs,
  1160. onoff_interval);
  1161. }
  1162. static struct notifier_block rcutorture_shutdown_nb = {
  1163. .notifier_call = rcutorture_shutdown_notify,
  1164. };
  1165. static void rcutorture_booster_cleanup(int cpu)
  1166. {
  1167. struct task_struct *t;
  1168. if (boost_tasks[cpu] == NULL)
  1169. return;
  1170. mutex_lock(&boost_mutex);
  1171. VERBOSE_PRINTK_STRING("Stopping rcu_torture_boost task");
  1172. t = boost_tasks[cpu];
  1173. boost_tasks[cpu] = NULL;
  1174. mutex_unlock(&boost_mutex);
  1175. /* This must be outside of the mutex, otherwise deadlock! */
  1176. kthread_stop(t);
  1177. }
  1178. static int rcutorture_booster_init(int cpu)
  1179. {
  1180. int retval;
  1181. if (boost_tasks[cpu] != NULL)
  1182. return 0; /* Already created, nothing more to do. */
  1183. /* Don't allow time recalculation while creating a new task. */
  1184. mutex_lock(&boost_mutex);
  1185. VERBOSE_PRINTK_STRING("Creating rcu_torture_boost task");
  1186. boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
  1187. cpu_to_node(cpu),
  1188. "rcu_torture_boost");
  1189. if (IS_ERR(boost_tasks[cpu])) {
  1190. retval = PTR_ERR(boost_tasks[cpu]);
  1191. VERBOSE_PRINTK_STRING("rcu_torture_boost task create failed");
  1192. n_rcu_torture_boost_ktrerror++;
  1193. boost_tasks[cpu] = NULL;
  1194. mutex_unlock(&boost_mutex);
  1195. return retval;
  1196. }
  1197. kthread_bind(boost_tasks[cpu], cpu);
  1198. wake_up_process(boost_tasks[cpu]);
  1199. mutex_unlock(&boost_mutex);
  1200. return 0;
  1201. }
  1202. /*
  1203. * Cause the rcutorture test to shutdown the system after the test has
  1204. * run for the time specified by the shutdown_secs module parameter.
  1205. */
  1206. static int
  1207. rcu_torture_shutdown(void *arg)
  1208. {
  1209. long delta;
  1210. unsigned long jiffies_snap;
  1211. VERBOSE_PRINTK_STRING("rcu_torture_shutdown task started");
  1212. jiffies_snap = ACCESS_ONCE(jiffies);
  1213. while (ULONG_CMP_LT(jiffies_snap, shutdown_time) &&
  1214. !kthread_should_stop()) {
  1215. delta = shutdown_time - jiffies_snap;
  1216. if (verbose)
  1217. printk(KERN_ALERT "%s" TORTURE_FLAG
  1218. "rcu_torture_shutdown task: %lu "
  1219. "jiffies remaining\n",
  1220. torture_type, delta);
  1221. schedule_timeout_interruptible(delta);
  1222. jiffies_snap = ACCESS_ONCE(jiffies);
  1223. }
  1224. if (kthread_should_stop()) {
  1225. VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
  1226. return 0;
  1227. }
  1228. /* OK, shut down the system. */
  1229. VERBOSE_PRINTK_STRING("rcu_torture_shutdown task shutting down system");
  1230. shutdown_task = NULL; /* Avoid self-kill deadlock. */
  1231. rcu_torture_cleanup(); /* Get the success/failure message. */
  1232. kernel_power_off(); /* Shut down the system. */
  1233. return 0;
  1234. }
  1235. #ifdef CONFIG_HOTPLUG_CPU
  1236. /*
  1237. * Execute random CPU-hotplug operations at the interval specified
  1238. * by the onoff_interval.
  1239. */
  1240. static int
  1241. rcu_torture_onoff(void *arg)
  1242. {
  1243. int cpu;
  1244. int maxcpu = -1;
  1245. DEFINE_RCU_RANDOM(rand);
  1246. VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
  1247. for_each_online_cpu(cpu)
  1248. maxcpu = cpu;
  1249. WARN_ON(maxcpu < 0);
  1250. while (!kthread_should_stop()) {
  1251. cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
  1252. if (cpu_online(cpu)) {
  1253. if (verbose)
  1254. printk(KERN_ALERT "%s" TORTURE_FLAG
  1255. "rcu_torture_onoff task: offlining %d\n",
  1256. torture_type, cpu);
  1257. n_offline_attempts++;
  1258. if (cpu_down(cpu) == 0) {
  1259. if (verbose)
  1260. printk(KERN_ALERT "%s" TORTURE_FLAG
  1261. "rcu_torture_onoff task: "
  1262. "offlined %d\n",
  1263. torture_type, cpu);
  1264. n_offline_successes++;
  1265. }
  1266. } else {
  1267. if (verbose)
  1268. printk(KERN_ALERT "%s" TORTURE_FLAG
  1269. "rcu_torture_onoff task: onlining %d\n",
  1270. torture_type, cpu);
  1271. n_online_attempts++;
  1272. if (cpu_up(cpu) == 0) {
  1273. if (verbose)
  1274. printk(KERN_ALERT "%s" TORTURE_FLAG
  1275. "rcu_torture_onoff task: "
  1276. "onlined %d\n",
  1277. torture_type, cpu);
  1278. n_online_successes++;
  1279. }
  1280. }
  1281. schedule_timeout_interruptible(onoff_interval * HZ);
  1282. }
  1283. VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
  1284. return 0;
  1285. }
  1286. static int
  1287. rcu_torture_onoff_init(void)
  1288. {
  1289. if (onoff_interval <= 0)
  1290. return 0;
  1291. onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
  1292. if (IS_ERR(onoff_task)) {
  1293. onoff_task = NULL;
  1294. return PTR_ERR(onoff_task);
  1295. }
  1296. return 0;
  1297. }
  1298. static void rcu_torture_onoff_cleanup(void)
  1299. {
  1300. if (onoff_task == NULL)
  1301. return;
  1302. VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
  1303. kthread_stop(onoff_task);
  1304. }
  1305. #else /* #ifdef CONFIG_HOTPLUG_CPU */
  1306. static void
  1307. rcu_torture_onoff_init(void)
  1308. {
  1309. }
  1310. static void rcu_torture_onoff_cleanup(void)
  1311. {
  1312. }
  1313. #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
  1314. static int rcutorture_cpu_notify(struct notifier_block *self,
  1315. unsigned long action, void *hcpu)
  1316. {
  1317. long cpu = (long)hcpu;
  1318. switch (action) {
  1319. case CPU_ONLINE:
  1320. case CPU_DOWN_FAILED:
  1321. (void)rcutorture_booster_init(cpu);
  1322. break;
  1323. case CPU_DOWN_PREPARE:
  1324. rcutorture_booster_cleanup(cpu);
  1325. break;
  1326. default:
  1327. break;
  1328. }
  1329. return NOTIFY_OK;
  1330. }
  1331. static struct notifier_block rcutorture_cpu_nb = {
  1332. .notifier_call = rcutorture_cpu_notify,
  1333. };
  1334. static void
  1335. rcu_torture_cleanup(void)
  1336. {
  1337. int i;
  1338. mutex_lock(&fullstop_mutex);
  1339. rcutorture_record_test_transition();
  1340. if (fullstop == FULLSTOP_SHUTDOWN) {
  1341. printk(KERN_WARNING /* but going down anyway, so... */
  1342. "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
  1343. mutex_unlock(&fullstop_mutex);
  1344. schedule_timeout_uninterruptible(10);
  1345. if (cur_ops->cb_barrier != NULL)
  1346. cur_ops->cb_barrier();
  1347. return;
  1348. }
  1349. fullstop = FULLSTOP_RMMOD;
  1350. mutex_unlock(&fullstop_mutex);
  1351. unregister_reboot_notifier(&rcutorture_shutdown_nb);
  1352. if (stutter_task) {
  1353. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
  1354. kthread_stop(stutter_task);
  1355. }
  1356. stutter_task = NULL;
  1357. if (shuffler_task) {
  1358. VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
  1359. kthread_stop(shuffler_task);
  1360. free_cpumask_var(shuffle_tmp_mask);
  1361. }
  1362. shuffler_task = NULL;
  1363. if (writer_task) {
  1364. VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
  1365. kthread_stop(writer_task);
  1366. }
  1367. writer_task = NULL;
  1368. if (reader_tasks) {
  1369. for (i = 0; i < nrealreaders; i++) {
  1370. if (reader_tasks[i]) {
  1371. VERBOSE_PRINTK_STRING(
  1372. "Stopping rcu_torture_reader task");
  1373. kthread_stop(reader_tasks[i]);
  1374. }
  1375. reader_tasks[i] = NULL;
  1376. }
  1377. kfree(reader_tasks);
  1378. reader_tasks = NULL;
  1379. }
  1380. rcu_torture_current = NULL;
  1381. if (fakewriter_tasks) {
  1382. for (i = 0; i < nfakewriters; i++) {
  1383. if (fakewriter_tasks[i]) {
  1384. VERBOSE_PRINTK_STRING(
  1385. "Stopping rcu_torture_fakewriter task");
  1386. kthread_stop(fakewriter_tasks[i]);
  1387. }
  1388. fakewriter_tasks[i] = NULL;
  1389. }
  1390. kfree(fakewriter_tasks);
  1391. fakewriter_tasks = NULL;
  1392. }
  1393. if (stats_task) {
  1394. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
  1395. kthread_stop(stats_task);
  1396. }
  1397. stats_task = NULL;
  1398. if (fqs_task) {
  1399. VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
  1400. kthread_stop(fqs_task);
  1401. }
  1402. fqs_task = NULL;
  1403. if ((test_boost == 1 && cur_ops->can_boost) ||
  1404. test_boost == 2) {
  1405. unregister_cpu_notifier(&rcutorture_cpu_nb);
  1406. for_each_possible_cpu(i)
  1407. rcutorture_booster_cleanup(i);
  1408. }
  1409. if (shutdown_task != NULL) {
  1410. VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
  1411. kthread_stop(shutdown_task);
  1412. }
  1413. rcu_torture_onoff_cleanup();
  1414. /* Wait for all RCU callbacks to fire. */
  1415. if (cur_ops->cb_barrier != NULL)
  1416. cur_ops->cb_barrier();
  1417. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  1418. if (cur_ops->cleanup)
  1419. cur_ops->cleanup();
  1420. if (atomic_read(&n_rcu_torture_error))
  1421. rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
  1422. else
  1423. rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
  1424. }
  1425. static int __init
  1426. rcu_torture_init(void)
  1427. {
  1428. int i;
  1429. int cpu;
  1430. int firsterr = 0;
  1431. static struct rcu_torture_ops *torture_ops[] =
  1432. { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
  1433. &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
  1434. &srcu_ops, &srcu_expedited_ops,
  1435. &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
  1436. mutex_lock(&fullstop_mutex);
  1437. /* Process args and tell the world that the torturer is on the job. */
  1438. for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
  1439. cur_ops = torture_ops[i];
  1440. if (strcmp(torture_type, cur_ops->name) == 0)
  1441. break;
  1442. }
  1443. if (i == ARRAY_SIZE(torture_ops)) {
  1444. printk(KERN_ALERT "rcu-torture: invalid torture type: \"%s\"\n",
  1445. torture_type);
  1446. printk(KERN_ALERT "rcu-torture types:");
  1447. for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
  1448. printk(KERN_ALERT " %s", torture_ops[i]->name);
  1449. printk(KERN_ALERT "\n");
  1450. mutex_unlock(&fullstop_mutex);
  1451. return -EINVAL;
  1452. }
  1453. if (cur_ops->fqs == NULL && fqs_duration != 0) {
  1454. printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
  1455. "fqs_duration, fqs disabled.\n");
  1456. fqs_duration = 0;
  1457. }
  1458. if (cur_ops->init)
  1459. cur_ops->init(); /* no "goto unwind" prior to this point!!! */
  1460. if (nreaders >= 0)
  1461. nrealreaders = nreaders;
  1462. else
  1463. nrealreaders = 2 * num_online_cpus();
  1464. rcu_torture_print_module_parms(cur_ops, "Start of test");
  1465. fullstop = FULLSTOP_DONTSTOP;
  1466. /* Set up the freelist. */
  1467. INIT_LIST_HEAD(&rcu_torture_freelist);
  1468. for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
  1469. rcu_tortures[i].rtort_mbtest = 0;
  1470. list_add_tail(&rcu_tortures[i].rtort_free,
  1471. &rcu_torture_freelist);
  1472. }
  1473. /* Initialize the statistics so that each run gets its own numbers. */
  1474. rcu_torture_current = NULL;
  1475. rcu_torture_current_version = 0;
  1476. atomic_set(&n_rcu_torture_alloc, 0);
  1477. atomic_set(&n_rcu_torture_alloc_fail, 0);
  1478. atomic_set(&n_rcu_torture_free, 0);
  1479. atomic_set(&n_rcu_torture_mberror, 0);
  1480. atomic_set(&n_rcu_torture_error, 0);
  1481. n_rcu_torture_boost_ktrerror = 0;
  1482. n_rcu_torture_boost_rterror = 0;
  1483. n_rcu_torture_boost_failure = 0;
  1484. n_rcu_torture_boosts = 0;
  1485. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1486. atomic_set(&rcu_torture_wcount[i], 0);
  1487. for_each_possible_cpu(cpu) {
  1488. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1489. per_cpu(rcu_torture_count, cpu)[i] = 0;
  1490. per_cpu(rcu_torture_batch, cpu)[i] = 0;
  1491. }
  1492. }
  1493. /* Start up the kthreads. */
  1494. VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
  1495. writer_task = kthread_run(rcu_torture_writer, NULL,
  1496. "rcu_torture_writer");
  1497. if (IS_ERR(writer_task)) {
  1498. firsterr = PTR_ERR(writer_task);
  1499. VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
  1500. writer_task = NULL;
  1501. goto unwind;
  1502. }
  1503. fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
  1504. GFP_KERNEL);
  1505. if (fakewriter_tasks == NULL) {
  1506. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1507. firsterr = -ENOMEM;
  1508. goto unwind;
  1509. }
  1510. for (i = 0; i < nfakewriters; i++) {
  1511. VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
  1512. fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
  1513. "rcu_torture_fakewriter");
  1514. if (IS_ERR(fakewriter_tasks[i])) {
  1515. firsterr = PTR_ERR(fakewriter_tasks[i]);
  1516. VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
  1517. fakewriter_tasks[i] = NULL;
  1518. goto unwind;
  1519. }
  1520. }
  1521. reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
  1522. GFP_KERNEL);
  1523. if (reader_tasks == NULL) {
  1524. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1525. firsterr = -ENOMEM;
  1526. goto unwind;
  1527. }
  1528. for (i = 0; i < nrealreaders; i++) {
  1529. VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
  1530. reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
  1531. "rcu_torture_reader");
  1532. if (IS_ERR(reader_tasks[i])) {
  1533. firsterr = PTR_ERR(reader_tasks[i]);
  1534. VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
  1535. reader_tasks[i] = NULL;
  1536. goto unwind;
  1537. }
  1538. }
  1539. if (stat_interval > 0) {
  1540. VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
  1541. stats_task = kthread_run(rcu_torture_stats, NULL,
  1542. "rcu_torture_stats");
  1543. if (IS_ERR(stats_task)) {
  1544. firsterr = PTR_ERR(stats_task);
  1545. VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
  1546. stats_task = NULL;
  1547. goto unwind;
  1548. }
  1549. }
  1550. if (test_no_idle_hz) {
  1551. rcu_idle_cpu = num_online_cpus() - 1;
  1552. if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
  1553. firsterr = -ENOMEM;
  1554. VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
  1555. goto unwind;
  1556. }
  1557. /* Create the shuffler thread */
  1558. shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
  1559. "rcu_torture_shuffle");
  1560. if (IS_ERR(shuffler_task)) {
  1561. free_cpumask_var(shuffle_tmp_mask);
  1562. firsterr = PTR_ERR(shuffler_task);
  1563. VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
  1564. shuffler_task = NULL;
  1565. goto unwind;
  1566. }
  1567. }
  1568. if (stutter < 0)
  1569. stutter = 0;
  1570. if (stutter) {
  1571. /* Create the stutter thread */
  1572. stutter_task = kthread_run(rcu_torture_stutter, NULL,
  1573. "rcu_torture_stutter");
  1574. if (IS_ERR(stutter_task)) {
  1575. firsterr = PTR_ERR(stutter_task);
  1576. VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
  1577. stutter_task = NULL;
  1578. goto unwind;
  1579. }
  1580. }
  1581. if (fqs_duration < 0)
  1582. fqs_duration = 0;
  1583. if (fqs_duration) {
  1584. /* Create the stutter thread */
  1585. fqs_task = kthread_run(rcu_torture_fqs, NULL,
  1586. "rcu_torture_fqs");
  1587. if (IS_ERR(fqs_task)) {
  1588. firsterr = PTR_ERR(fqs_task);
  1589. VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
  1590. fqs_task = NULL;
  1591. goto unwind;
  1592. }
  1593. }
  1594. if (test_boost_interval < 1)
  1595. test_boost_interval = 1;
  1596. if (test_boost_duration < 2)
  1597. test_boost_duration = 2;
  1598. if ((test_boost == 1 && cur_ops->can_boost) ||
  1599. test_boost == 2) {
  1600. int retval;
  1601. boost_starttime = jiffies + test_boost_interval * HZ;
  1602. register_cpu_notifier(&rcutorture_cpu_nb);
  1603. for_each_possible_cpu(i) {
  1604. if (cpu_is_offline(i))
  1605. continue; /* Heuristic: CPU can go offline. */
  1606. retval = rcutorture_booster_init(i);
  1607. if (retval < 0) {
  1608. firsterr = retval;
  1609. goto unwind;
  1610. }
  1611. }
  1612. }
  1613. if (shutdown_secs > 0) {
  1614. shutdown_time = jiffies + shutdown_secs * HZ;
  1615. shutdown_task = kthread_run(rcu_torture_shutdown, NULL,
  1616. "rcu_torture_shutdown");
  1617. if (IS_ERR(shutdown_task)) {
  1618. firsterr = PTR_ERR(shutdown_task);
  1619. VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown");
  1620. shutdown_task = NULL;
  1621. goto unwind;
  1622. }
  1623. }
  1624. rcu_torture_onoff_init();
  1625. register_reboot_notifier(&rcutorture_shutdown_nb);
  1626. rcutorture_record_test_transition();
  1627. mutex_unlock(&fullstop_mutex);
  1628. return 0;
  1629. unwind:
  1630. mutex_unlock(&fullstop_mutex);
  1631. rcu_torture_cleanup();
  1632. return firsterr;
  1633. }
  1634. module_init(rcu_torture_init);
  1635. module_exit(rcu_torture_cleanup);