rcutorture.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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, you can access it online at
  16. * http://www.gnu.org/licenses/gpl-2.0.html.
  17. *
  18. * Copyright (C) IBM Corporation, 2005, 2006
  19. *
  20. * Authors: Paul E. McKenney <paulmck@us.ibm.com>
  21. * Josh Triplett <josh@joshtriplett.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 <linux/trace_clock.h>
  50. #include <asm/byteorder.h>
  51. #include <linux/torture.h>
  52. MODULE_LICENSE("GPL");
  53. MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>");
  54. torture_param(int, fqs_duration, 0,
  55. "Duration of fqs bursts (us), 0 to disable");
  56. torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
  57. torture_param(int, fqs_stutter, 3, "Wait time between fqs bursts (s)");
  58. torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives");
  59. torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
  60. torture_param(bool, gp_normal, false,
  61. "Use normal (non-expedited) GP wait primitives");
  62. torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
  63. torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
  64. torture_param(int, n_barrier_cbs, 0,
  65. "# of callbacks/kthreads for barrier testing");
  66. torture_param(int, nfakewriters, 4, "Number of RCU fake writer threads");
  67. torture_param(int, nreaders, -1, "Number of RCU reader threads");
  68. torture_param(int, object_debug, 0,
  69. "Enable debug-object double call_rcu() testing");
  70. torture_param(int, onoff_holdoff, 0, "Time after boot before CPU hotplugs (s)");
  71. torture_param(int, onoff_interval, 0,
  72. "Time between CPU hotplugs (s), 0=disable");
  73. torture_param(int, shuffle_interval, 3, "Number of seconds between shuffles");
  74. torture_param(int, shutdown_secs, 0, "Shutdown time (s), <= zero to disable.");
  75. torture_param(int, stall_cpu, 0, "Stall duration (s), zero to disable.");
  76. torture_param(int, stall_cpu_holdoff, 10,
  77. "Time to wait before starting stall (s).");
  78. torture_param(int, stat_interval, 60,
  79. "Number of seconds between stats printk()s");
  80. torture_param(int, stutter, 5, "Number of seconds to run/halt test");
  81. torture_param(int, test_boost, 1, "Test RCU prio boost: 0=no, 1=maybe, 2=yes.");
  82. torture_param(int, test_boost_duration, 4,
  83. "Duration of each boost test, seconds.");
  84. torture_param(int, test_boost_interval, 7,
  85. "Interval between boost tests, seconds.");
  86. torture_param(bool, test_no_idle_hz, true,
  87. "Test support for tickless idle CPUs");
  88. torture_param(bool, verbose, true,
  89. "Enable verbose debugging printk()s");
  90. static char *torture_type = "rcu";
  91. module_param(torture_type, charp, 0444);
  92. MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
  93. static int nrealreaders;
  94. static struct task_struct *writer_task;
  95. static struct task_struct **fakewriter_tasks;
  96. static struct task_struct **reader_tasks;
  97. static struct task_struct *stats_task;
  98. static struct task_struct *fqs_task;
  99. static struct task_struct *boost_tasks[NR_CPUS];
  100. static struct task_struct *stall_task;
  101. static struct task_struct **barrier_cbs_tasks;
  102. static struct task_struct *barrier_task;
  103. #define RCU_TORTURE_PIPE_LEN 10
  104. struct rcu_torture {
  105. struct rcu_head rtort_rcu;
  106. int rtort_pipe_count;
  107. struct list_head rtort_free;
  108. int rtort_mbtest;
  109. };
  110. static LIST_HEAD(rcu_torture_freelist);
  111. static struct rcu_torture __rcu *rcu_torture_current;
  112. static unsigned long rcu_torture_current_version;
  113. static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
  114. static DEFINE_SPINLOCK(rcu_torture_lock);
  115. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
  116. rcu_torture_count) = { 0 };
  117. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
  118. rcu_torture_batch) = { 0 };
  119. static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  120. static atomic_t n_rcu_torture_alloc;
  121. static atomic_t n_rcu_torture_alloc_fail;
  122. static atomic_t n_rcu_torture_free;
  123. static atomic_t n_rcu_torture_mberror;
  124. static atomic_t n_rcu_torture_error;
  125. static long n_rcu_torture_barrier_error;
  126. static long n_rcu_torture_boost_ktrerror;
  127. static long n_rcu_torture_boost_rterror;
  128. static long n_rcu_torture_boost_failure;
  129. static long n_rcu_torture_boosts;
  130. static long n_rcu_torture_timers;
  131. static long n_barrier_attempts;
  132. static long n_barrier_successes;
  133. static struct list_head rcu_torture_removed;
  134. static int rcu_torture_writer_state;
  135. #define RTWS_FIXED_DELAY 0
  136. #define RTWS_DELAY 1
  137. #define RTWS_REPLACE 2
  138. #define RTWS_DEF_FREE 3
  139. #define RTWS_EXP_SYNC 4
  140. #define RTWS_COND_GET 5
  141. #define RTWS_COND_SYNC 6
  142. #define RTWS_SYNC 7
  143. #define RTWS_STUTTER 8
  144. #define RTWS_STOPPING 9
  145. #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
  146. #define RCUTORTURE_RUNNABLE_INIT 1
  147. #else
  148. #define RCUTORTURE_RUNNABLE_INIT 0
  149. #endif
  150. int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
  151. module_param(rcutorture_runnable, int, 0444);
  152. MODULE_PARM_DESC(rcutorture_runnable, "Start rcutorture at boot");
  153. #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
  154. #define rcu_can_boost() 1
  155. #else /* #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  156. #define rcu_can_boost() 0
  157. #endif /* #else #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU) */
  158. #ifdef CONFIG_RCU_TRACE
  159. static u64 notrace rcu_trace_clock_local(void)
  160. {
  161. u64 ts = trace_clock_local();
  162. unsigned long __maybe_unused ts_rem = do_div(ts, NSEC_PER_USEC);
  163. return ts;
  164. }
  165. #else /* #ifdef CONFIG_RCU_TRACE */
  166. static u64 notrace rcu_trace_clock_local(void)
  167. {
  168. return 0ULL;
  169. }
  170. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  171. static unsigned long boost_starttime; /* jiffies of next boost test start. */
  172. DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
  173. /* and boost task create/destroy. */
  174. static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
  175. static bool barrier_phase; /* Test phase. */
  176. static atomic_t barrier_cbs_invoked; /* Barrier callbacks invoked. */
  177. static wait_queue_head_t *barrier_cbs_wq; /* Coordinate barrier testing. */
  178. static DECLARE_WAIT_QUEUE_HEAD(barrier_wq);
  179. /*
  180. * Allocate an element from the rcu_tortures pool.
  181. */
  182. static struct rcu_torture *
  183. rcu_torture_alloc(void)
  184. {
  185. struct list_head *p;
  186. spin_lock_bh(&rcu_torture_lock);
  187. if (list_empty(&rcu_torture_freelist)) {
  188. atomic_inc(&n_rcu_torture_alloc_fail);
  189. spin_unlock_bh(&rcu_torture_lock);
  190. return NULL;
  191. }
  192. atomic_inc(&n_rcu_torture_alloc);
  193. p = rcu_torture_freelist.next;
  194. list_del_init(p);
  195. spin_unlock_bh(&rcu_torture_lock);
  196. return container_of(p, struct rcu_torture, rtort_free);
  197. }
  198. /*
  199. * Free an element to the rcu_tortures pool.
  200. */
  201. static void
  202. rcu_torture_free(struct rcu_torture *p)
  203. {
  204. atomic_inc(&n_rcu_torture_free);
  205. spin_lock_bh(&rcu_torture_lock);
  206. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  207. spin_unlock_bh(&rcu_torture_lock);
  208. }
  209. /*
  210. * Operations vector for selecting different types of tests.
  211. */
  212. struct rcu_torture_ops {
  213. int ttype;
  214. void (*init)(void);
  215. int (*readlock)(void);
  216. void (*read_delay)(struct torture_random_state *rrsp);
  217. void (*readunlock)(int idx);
  218. int (*completed)(void);
  219. void (*deferred_free)(struct rcu_torture *p);
  220. void (*sync)(void);
  221. void (*exp_sync)(void);
  222. unsigned long (*get_state)(void);
  223. void (*cond_sync)(unsigned long oldstate);
  224. void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
  225. void (*cb_barrier)(void);
  226. void (*fqs)(void);
  227. void (*stats)(char *page);
  228. int irq_capable;
  229. int can_boost;
  230. const char *name;
  231. };
  232. static struct rcu_torture_ops *cur_ops;
  233. /*
  234. * Definitions for rcu torture testing.
  235. */
  236. static int rcu_torture_read_lock(void) __acquires(RCU)
  237. {
  238. rcu_read_lock();
  239. return 0;
  240. }
  241. static void rcu_read_delay(struct torture_random_state *rrsp)
  242. {
  243. const unsigned long shortdelay_us = 200;
  244. const unsigned long longdelay_ms = 50;
  245. /* We want a short delay sometimes to make a reader delay the grace
  246. * period, and we want a long delay occasionally to trigger
  247. * force_quiescent_state. */
  248. if (!(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
  249. mdelay(longdelay_ms);
  250. if (!(torture_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
  251. udelay(shortdelay_us);
  252. #ifdef CONFIG_PREEMPT
  253. if (!preempt_count() &&
  254. !(torture_random(rrsp) % (nrealreaders * 20000)))
  255. preempt_schedule(); /* No QS if preempt_disable() in effect */
  256. #endif
  257. }
  258. static void rcu_torture_read_unlock(int idx) __releases(RCU)
  259. {
  260. rcu_read_unlock();
  261. }
  262. static int rcu_torture_completed(void)
  263. {
  264. return rcu_batches_completed();
  265. }
  266. /*
  267. * Update callback in the pipe. This should be invoked after a grace period.
  268. */
  269. static bool
  270. rcu_torture_pipe_update_one(struct rcu_torture *rp)
  271. {
  272. int i;
  273. i = rp->rtort_pipe_count;
  274. if (i > RCU_TORTURE_PIPE_LEN)
  275. i = RCU_TORTURE_PIPE_LEN;
  276. atomic_inc(&rcu_torture_wcount[i]);
  277. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  278. rp->rtort_mbtest = 0;
  279. return true;
  280. }
  281. return false;
  282. }
  283. /*
  284. * Update all callbacks in the pipe. Suitable for synchronous grace-period
  285. * primitives.
  286. */
  287. static void
  288. rcu_torture_pipe_update(struct rcu_torture *old_rp)
  289. {
  290. struct rcu_torture *rp;
  291. struct rcu_torture *rp1;
  292. if (old_rp)
  293. list_add(&old_rp->rtort_free, &rcu_torture_removed);
  294. list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
  295. if (rcu_torture_pipe_update_one(rp)) {
  296. list_del(&rp->rtort_free);
  297. rcu_torture_free(rp);
  298. }
  299. }
  300. }
  301. static void
  302. rcu_torture_cb(struct rcu_head *p)
  303. {
  304. struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
  305. if (torture_must_stop_irq()) {
  306. /* Test is ending, just drop callbacks on the floor. */
  307. /* The next initialization will pick up the pieces. */
  308. return;
  309. }
  310. if (rcu_torture_pipe_update_one(rp))
  311. rcu_torture_free(rp);
  312. else
  313. cur_ops->deferred_free(rp);
  314. }
  315. static int rcu_no_completed(void)
  316. {
  317. return 0;
  318. }
  319. static void rcu_torture_deferred_free(struct rcu_torture *p)
  320. {
  321. call_rcu(&p->rtort_rcu, rcu_torture_cb);
  322. }
  323. static void rcu_sync_torture_init(void)
  324. {
  325. INIT_LIST_HEAD(&rcu_torture_removed);
  326. }
  327. static struct rcu_torture_ops rcu_ops = {
  328. .ttype = RCU_FLAVOR,
  329. .init = rcu_sync_torture_init,
  330. .readlock = rcu_torture_read_lock,
  331. .read_delay = rcu_read_delay,
  332. .readunlock = rcu_torture_read_unlock,
  333. .completed = rcu_torture_completed,
  334. .deferred_free = rcu_torture_deferred_free,
  335. .sync = synchronize_rcu,
  336. .exp_sync = synchronize_rcu_expedited,
  337. .get_state = get_state_synchronize_rcu,
  338. .cond_sync = cond_synchronize_rcu,
  339. .call = call_rcu,
  340. .cb_barrier = rcu_barrier,
  341. .fqs = rcu_force_quiescent_state,
  342. .stats = NULL,
  343. .irq_capable = 1,
  344. .can_boost = rcu_can_boost(),
  345. .name = "rcu"
  346. };
  347. /*
  348. * Definitions for rcu_bh torture testing.
  349. */
  350. static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
  351. {
  352. rcu_read_lock_bh();
  353. return 0;
  354. }
  355. static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
  356. {
  357. rcu_read_unlock_bh();
  358. }
  359. static int rcu_bh_torture_completed(void)
  360. {
  361. return rcu_batches_completed_bh();
  362. }
  363. static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
  364. {
  365. call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
  366. }
  367. static struct rcu_torture_ops rcu_bh_ops = {
  368. .ttype = RCU_BH_FLAVOR,
  369. .init = rcu_sync_torture_init,
  370. .readlock = rcu_bh_torture_read_lock,
  371. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  372. .readunlock = rcu_bh_torture_read_unlock,
  373. .completed = rcu_bh_torture_completed,
  374. .deferred_free = rcu_bh_torture_deferred_free,
  375. .sync = synchronize_rcu_bh,
  376. .exp_sync = synchronize_rcu_bh_expedited,
  377. .call = call_rcu_bh,
  378. .cb_barrier = rcu_barrier_bh,
  379. .fqs = rcu_bh_force_quiescent_state,
  380. .stats = NULL,
  381. .irq_capable = 1,
  382. .name = "rcu_bh"
  383. };
  384. /*
  385. * Don't even think about trying any of these in real life!!!
  386. * The names includes "busted", and they really means it!
  387. * The only purpose of these functions is to provide a buggy RCU
  388. * implementation to make sure that rcutorture correctly emits
  389. * buggy-RCU error messages.
  390. */
  391. static void rcu_busted_torture_deferred_free(struct rcu_torture *p)
  392. {
  393. /* This is a deliberate bug for testing purposes only! */
  394. rcu_torture_cb(&p->rtort_rcu);
  395. }
  396. static void synchronize_rcu_busted(void)
  397. {
  398. /* This is a deliberate bug for testing purposes only! */
  399. }
  400. static void
  401. call_rcu_busted(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  402. {
  403. /* This is a deliberate bug for testing purposes only! */
  404. func(head);
  405. }
  406. static struct rcu_torture_ops rcu_busted_ops = {
  407. .ttype = INVALID_RCU_FLAVOR,
  408. .init = rcu_sync_torture_init,
  409. .readlock = rcu_torture_read_lock,
  410. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  411. .readunlock = rcu_torture_read_unlock,
  412. .completed = rcu_no_completed,
  413. .deferred_free = rcu_busted_torture_deferred_free,
  414. .sync = synchronize_rcu_busted,
  415. .exp_sync = synchronize_rcu_busted,
  416. .call = call_rcu_busted,
  417. .cb_barrier = NULL,
  418. .fqs = NULL,
  419. .stats = NULL,
  420. .irq_capable = 1,
  421. .name = "rcu_busted"
  422. };
  423. /*
  424. * Definitions for srcu torture testing.
  425. */
  426. DEFINE_STATIC_SRCU(srcu_ctl);
  427. static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
  428. {
  429. return srcu_read_lock(&srcu_ctl);
  430. }
  431. static void srcu_read_delay(struct torture_random_state *rrsp)
  432. {
  433. long delay;
  434. const long uspertick = 1000000 / HZ;
  435. const long longdelay = 10;
  436. /* We want there to be long-running readers, but not all the time. */
  437. delay = torture_random(rrsp) %
  438. (nrealreaders * 2 * longdelay * uspertick);
  439. if (!delay)
  440. schedule_timeout_interruptible(longdelay);
  441. else
  442. rcu_read_delay(rrsp);
  443. }
  444. static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
  445. {
  446. srcu_read_unlock(&srcu_ctl, idx);
  447. }
  448. static int srcu_torture_completed(void)
  449. {
  450. return srcu_batches_completed(&srcu_ctl);
  451. }
  452. static void srcu_torture_deferred_free(struct rcu_torture *rp)
  453. {
  454. call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb);
  455. }
  456. static void srcu_torture_synchronize(void)
  457. {
  458. synchronize_srcu(&srcu_ctl);
  459. }
  460. static void srcu_torture_call(struct rcu_head *head,
  461. void (*func)(struct rcu_head *head))
  462. {
  463. call_srcu(&srcu_ctl, head, func);
  464. }
  465. static void srcu_torture_barrier(void)
  466. {
  467. srcu_barrier(&srcu_ctl);
  468. }
  469. static void srcu_torture_stats(char *page)
  470. {
  471. int cpu;
  472. int idx = srcu_ctl.completed & 0x1;
  473. page += sprintf(page, "%s%s per-CPU(idx=%d):",
  474. torture_type, TORTURE_FLAG, idx);
  475. for_each_possible_cpu(cpu) {
  476. long c0, c1;
  477. c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx];
  478. c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx];
  479. page += sprintf(page, " %d(%ld,%ld)", cpu, c0, c1);
  480. }
  481. sprintf(page, "\n");
  482. }
  483. static void srcu_torture_synchronize_expedited(void)
  484. {
  485. synchronize_srcu_expedited(&srcu_ctl);
  486. }
  487. static struct rcu_torture_ops srcu_ops = {
  488. .ttype = SRCU_FLAVOR,
  489. .init = rcu_sync_torture_init,
  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 = srcu_torture_deferred_free,
  495. .sync = srcu_torture_synchronize,
  496. .exp_sync = srcu_torture_synchronize_expedited,
  497. .call = srcu_torture_call,
  498. .cb_barrier = srcu_torture_barrier,
  499. .stats = srcu_torture_stats,
  500. .name = "srcu"
  501. };
  502. /*
  503. * Definitions for sched torture testing.
  504. */
  505. static int sched_torture_read_lock(void)
  506. {
  507. preempt_disable();
  508. return 0;
  509. }
  510. static void sched_torture_read_unlock(int idx)
  511. {
  512. preempt_enable();
  513. }
  514. static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
  515. {
  516. call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
  517. }
  518. static struct rcu_torture_ops sched_ops = {
  519. .ttype = RCU_SCHED_FLAVOR,
  520. .init = rcu_sync_torture_init,
  521. .readlock = sched_torture_read_lock,
  522. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  523. .readunlock = sched_torture_read_unlock,
  524. .completed = rcu_no_completed,
  525. .deferred_free = rcu_sched_torture_deferred_free,
  526. .sync = synchronize_sched,
  527. .exp_sync = synchronize_sched_expedited,
  528. .call = call_rcu_sched,
  529. .cb_barrier = rcu_barrier_sched,
  530. .fqs = rcu_sched_force_quiescent_state,
  531. .stats = NULL,
  532. .irq_capable = 1,
  533. .name = "sched"
  534. };
  535. /*
  536. * RCU torture priority-boost testing. Runs one real-time thread per
  537. * CPU for moderate bursts, repeatedly registering RCU callbacks and
  538. * spinning waiting for them to be invoked. If a given callback takes
  539. * too long to be invoked, we assume that priority inversion has occurred.
  540. */
  541. struct rcu_boost_inflight {
  542. struct rcu_head rcu;
  543. int inflight;
  544. };
  545. static void rcu_torture_boost_cb(struct rcu_head *head)
  546. {
  547. struct rcu_boost_inflight *rbip =
  548. container_of(head, struct rcu_boost_inflight, rcu);
  549. smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */
  550. rbip->inflight = 0;
  551. }
  552. static int rcu_torture_boost(void *arg)
  553. {
  554. unsigned long call_rcu_time;
  555. unsigned long endtime;
  556. unsigned long oldstarttime;
  557. struct rcu_boost_inflight rbi = { .inflight = 0 };
  558. struct sched_param sp;
  559. VERBOSE_TOROUT_STRING("rcu_torture_boost started");
  560. /* Set real-time priority. */
  561. sp.sched_priority = 1;
  562. if (sched_setscheduler(current, SCHED_FIFO, &sp) < 0) {
  563. VERBOSE_TOROUT_STRING("rcu_torture_boost RT prio failed!");
  564. n_rcu_torture_boost_rterror++;
  565. }
  566. init_rcu_head_on_stack(&rbi.rcu);
  567. /* Each pass through the following loop does one boost-test cycle. */
  568. do {
  569. /* Wait for the next test interval. */
  570. oldstarttime = boost_starttime;
  571. while (ULONG_CMP_LT(jiffies, oldstarttime)) {
  572. schedule_timeout_interruptible(oldstarttime - jiffies);
  573. stutter_wait("rcu_torture_boost");
  574. if (torture_must_stop())
  575. goto checkwait;
  576. }
  577. /* Do one boost-test interval. */
  578. endtime = oldstarttime + test_boost_duration * HZ;
  579. call_rcu_time = jiffies;
  580. while (ULONG_CMP_LT(jiffies, endtime)) {
  581. /* If we don't have a callback in flight, post one. */
  582. if (!rbi.inflight) {
  583. smp_mb(); /* RCU core before ->inflight = 1. */
  584. rbi.inflight = 1;
  585. call_rcu(&rbi.rcu, rcu_torture_boost_cb);
  586. if (jiffies - call_rcu_time >
  587. test_boost_duration * HZ - HZ / 2) {
  588. VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
  589. n_rcu_torture_boost_failure++;
  590. }
  591. call_rcu_time = jiffies;
  592. }
  593. cond_resched();
  594. stutter_wait("rcu_torture_boost");
  595. if (torture_must_stop())
  596. goto checkwait;
  597. }
  598. /*
  599. * Set the start time of the next test interval.
  600. * Yes, this is vulnerable to long delays, but such
  601. * delays simply cause a false negative for the next
  602. * interval. Besides, we are running at RT priority,
  603. * so delays should be relatively rare.
  604. */
  605. while (oldstarttime == boost_starttime &&
  606. !kthread_should_stop()) {
  607. if (mutex_trylock(&boost_mutex)) {
  608. boost_starttime = jiffies +
  609. test_boost_interval * HZ;
  610. n_rcu_torture_boosts++;
  611. mutex_unlock(&boost_mutex);
  612. break;
  613. }
  614. schedule_timeout_uninterruptible(1);
  615. }
  616. /* Go do the stutter. */
  617. checkwait: stutter_wait("rcu_torture_boost");
  618. } while (!torture_must_stop());
  619. /* Clean up and exit. */
  620. while (!kthread_should_stop() || rbi.inflight) {
  621. torture_shutdown_absorb("rcu_torture_boost");
  622. schedule_timeout_uninterruptible(1);
  623. }
  624. smp_mb(); /* order accesses to ->inflight before stack-frame death. */
  625. destroy_rcu_head_on_stack(&rbi.rcu);
  626. torture_kthread_stopping("rcu_torture_boost");
  627. return 0;
  628. }
  629. /*
  630. * RCU torture force-quiescent-state kthread. Repeatedly induces
  631. * bursts of calls to force_quiescent_state(), increasing the probability
  632. * of occurrence of some important types of race conditions.
  633. */
  634. static int
  635. rcu_torture_fqs(void *arg)
  636. {
  637. unsigned long fqs_resume_time;
  638. int fqs_burst_remaining;
  639. VERBOSE_TOROUT_STRING("rcu_torture_fqs task started");
  640. do {
  641. fqs_resume_time = jiffies + fqs_stutter * HZ;
  642. while (ULONG_CMP_LT(jiffies, fqs_resume_time) &&
  643. !kthread_should_stop()) {
  644. schedule_timeout_interruptible(1);
  645. }
  646. fqs_burst_remaining = fqs_duration;
  647. while (fqs_burst_remaining > 0 &&
  648. !kthread_should_stop()) {
  649. cur_ops->fqs();
  650. udelay(fqs_holdoff);
  651. fqs_burst_remaining -= fqs_holdoff;
  652. }
  653. stutter_wait("rcu_torture_fqs");
  654. } while (!torture_must_stop());
  655. torture_kthread_stopping("rcu_torture_fqs");
  656. return 0;
  657. }
  658. /*
  659. * RCU torture writer kthread. Repeatedly substitutes a new structure
  660. * for that pointed to by rcu_torture_current, freeing the old structure
  661. * after a series of grace periods (the "pipeline").
  662. */
  663. static int
  664. rcu_torture_writer(void *arg)
  665. {
  666. unsigned long gp_snap;
  667. bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
  668. bool gp_sync1 = gp_sync;
  669. int i;
  670. struct rcu_torture *rp;
  671. struct rcu_torture *old_rp;
  672. static DEFINE_TORTURE_RANDOM(rand);
  673. int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
  674. RTWS_COND_GET, RTWS_SYNC };
  675. int nsynctypes = 0;
  676. VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
  677. /* Initialize synctype[] array. If none set, take default. */
  678. if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync)
  679. gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
  680. if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync)
  681. synctype[nsynctypes++] = RTWS_COND_GET;
  682. else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync))
  683. pr_alert("rcu_torture_writer: gp_cond without primitives.\n");
  684. if (gp_exp1 && cur_ops->exp_sync)
  685. synctype[nsynctypes++] = RTWS_EXP_SYNC;
  686. else if (gp_exp && !cur_ops->exp_sync)
  687. pr_alert("rcu_torture_writer: gp_exp without primitives.\n");
  688. if (gp_normal1 && cur_ops->deferred_free)
  689. synctype[nsynctypes++] = RTWS_DEF_FREE;
  690. else if (gp_normal && !cur_ops->deferred_free)
  691. pr_alert("rcu_torture_writer: gp_normal without primitives.\n");
  692. if (gp_sync1 && cur_ops->sync)
  693. synctype[nsynctypes++] = RTWS_SYNC;
  694. else if (gp_sync && !cur_ops->sync)
  695. pr_alert("rcu_torture_writer: gp_sync without primitives.\n");
  696. if (WARN_ONCE(nsynctypes == 0,
  697. "rcu_torture_writer: No update-side primitives.\n")) {
  698. /*
  699. * No updates primitives, so don't try updating.
  700. * The resulting test won't be testing much, hence the
  701. * above WARN_ONCE().
  702. */
  703. rcu_torture_writer_state = RTWS_STOPPING;
  704. torture_kthread_stopping("rcu_torture_writer");
  705. }
  706. do {
  707. rcu_torture_writer_state = RTWS_FIXED_DELAY;
  708. schedule_timeout_uninterruptible(1);
  709. rp = rcu_torture_alloc();
  710. if (rp == NULL)
  711. continue;
  712. rp->rtort_pipe_count = 0;
  713. rcu_torture_writer_state = RTWS_DELAY;
  714. udelay(torture_random(&rand) & 0x3ff);
  715. rcu_torture_writer_state = RTWS_REPLACE;
  716. old_rp = rcu_dereference_check(rcu_torture_current,
  717. current == writer_task);
  718. rp->rtort_mbtest = 1;
  719. rcu_assign_pointer(rcu_torture_current, rp);
  720. smp_wmb(); /* Mods to old_rp must follow rcu_assign_pointer() */
  721. if (old_rp) {
  722. i = old_rp->rtort_pipe_count;
  723. if (i > RCU_TORTURE_PIPE_LEN)
  724. i = RCU_TORTURE_PIPE_LEN;
  725. atomic_inc(&rcu_torture_wcount[i]);
  726. old_rp->rtort_pipe_count++;
  727. switch (synctype[torture_random(&rand) % nsynctypes]) {
  728. case RTWS_DEF_FREE:
  729. rcu_torture_writer_state = RTWS_DEF_FREE;
  730. cur_ops->deferred_free(old_rp);
  731. break;
  732. case RTWS_EXP_SYNC:
  733. rcu_torture_writer_state = RTWS_EXP_SYNC;
  734. cur_ops->exp_sync();
  735. rcu_torture_pipe_update(old_rp);
  736. break;
  737. case RTWS_COND_GET:
  738. rcu_torture_writer_state = RTWS_COND_GET;
  739. gp_snap = cur_ops->get_state();
  740. i = torture_random(&rand) % 16;
  741. if (i != 0)
  742. schedule_timeout_interruptible(i);
  743. udelay(torture_random(&rand) % 1000);
  744. rcu_torture_writer_state = RTWS_COND_SYNC;
  745. cur_ops->cond_sync(gp_snap);
  746. rcu_torture_pipe_update(old_rp);
  747. break;
  748. case RTWS_SYNC:
  749. rcu_torture_writer_state = RTWS_SYNC;
  750. cur_ops->sync();
  751. rcu_torture_pipe_update(old_rp);
  752. break;
  753. default:
  754. WARN_ON_ONCE(1);
  755. break;
  756. }
  757. }
  758. rcutorture_record_progress(++rcu_torture_current_version);
  759. rcu_torture_writer_state = RTWS_STUTTER;
  760. stutter_wait("rcu_torture_writer");
  761. } while (!torture_must_stop());
  762. rcu_torture_writer_state = RTWS_STOPPING;
  763. torture_kthread_stopping("rcu_torture_writer");
  764. return 0;
  765. }
  766. /*
  767. * RCU torture fake writer kthread. Repeatedly calls sync, with a random
  768. * delay between calls.
  769. */
  770. static int
  771. rcu_torture_fakewriter(void *arg)
  772. {
  773. DEFINE_TORTURE_RANDOM(rand);
  774. VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
  775. set_user_nice(current, MAX_NICE);
  776. do {
  777. schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
  778. udelay(torture_random(&rand) & 0x3ff);
  779. if (cur_ops->cb_barrier != NULL &&
  780. torture_random(&rand) % (nfakewriters * 8) == 0) {
  781. cur_ops->cb_barrier();
  782. } else if (gp_normal == gp_exp) {
  783. if (torture_random(&rand) & 0x80)
  784. cur_ops->sync();
  785. else
  786. cur_ops->exp_sync();
  787. } else if (gp_normal) {
  788. cur_ops->sync();
  789. } else {
  790. cur_ops->exp_sync();
  791. }
  792. stutter_wait("rcu_torture_fakewriter");
  793. } while (!torture_must_stop());
  794. torture_kthread_stopping("rcu_torture_fakewriter");
  795. return 0;
  796. }
  797. static void rcutorture_trace_dump(void)
  798. {
  799. static atomic_t beenhere = ATOMIC_INIT(0);
  800. if (atomic_read(&beenhere))
  801. return;
  802. if (atomic_xchg(&beenhere, 1) != 0)
  803. return;
  804. ftrace_dump(DUMP_ALL);
  805. }
  806. /*
  807. * RCU torture reader from timer handler. Dereferences rcu_torture_current,
  808. * incrementing the corresponding element of the pipeline array. The
  809. * counter in the element should never be greater than 1, otherwise, the
  810. * RCU implementation is broken.
  811. */
  812. static void rcu_torture_timer(unsigned long unused)
  813. {
  814. int idx;
  815. int completed;
  816. int completed_end;
  817. static DEFINE_TORTURE_RANDOM(rand);
  818. static DEFINE_SPINLOCK(rand_lock);
  819. struct rcu_torture *p;
  820. int pipe_count;
  821. unsigned long long ts;
  822. idx = cur_ops->readlock();
  823. completed = cur_ops->completed();
  824. ts = rcu_trace_clock_local();
  825. p = rcu_dereference_check(rcu_torture_current,
  826. rcu_read_lock_bh_held() ||
  827. rcu_read_lock_sched_held() ||
  828. srcu_read_lock_held(&srcu_ctl));
  829. if (p == NULL) {
  830. /* Leave because rcu_torture_writer is not yet underway */
  831. cur_ops->readunlock(idx);
  832. return;
  833. }
  834. if (p->rtort_mbtest == 0)
  835. atomic_inc(&n_rcu_torture_mberror);
  836. spin_lock(&rand_lock);
  837. cur_ops->read_delay(&rand);
  838. n_rcu_torture_timers++;
  839. spin_unlock(&rand_lock);
  840. preempt_disable();
  841. pipe_count = p->rtort_pipe_count;
  842. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  843. /* Should not happen, but... */
  844. pipe_count = RCU_TORTURE_PIPE_LEN;
  845. }
  846. completed_end = cur_ops->completed();
  847. if (pipe_count > 1) {
  848. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu, ts,
  849. completed, completed_end);
  850. rcutorture_trace_dump();
  851. }
  852. __this_cpu_inc(rcu_torture_count[pipe_count]);
  853. completed = completed_end - completed;
  854. if (completed > RCU_TORTURE_PIPE_LEN) {
  855. /* Should not happen, but... */
  856. completed = RCU_TORTURE_PIPE_LEN;
  857. }
  858. __this_cpu_inc(rcu_torture_batch[completed]);
  859. preempt_enable();
  860. cur_ops->readunlock(idx);
  861. }
  862. /*
  863. * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
  864. * incrementing the corresponding element of the pipeline array. The
  865. * counter in the element should never be greater than 1, otherwise, the
  866. * RCU implementation is broken.
  867. */
  868. static int
  869. rcu_torture_reader(void *arg)
  870. {
  871. int completed;
  872. int completed_end;
  873. int idx;
  874. DEFINE_TORTURE_RANDOM(rand);
  875. struct rcu_torture *p;
  876. int pipe_count;
  877. struct timer_list t;
  878. unsigned long long ts;
  879. VERBOSE_TOROUT_STRING("rcu_torture_reader task started");
  880. set_user_nice(current, MAX_NICE);
  881. if (irqreader && cur_ops->irq_capable)
  882. setup_timer_on_stack(&t, rcu_torture_timer, 0);
  883. do {
  884. if (irqreader && cur_ops->irq_capable) {
  885. if (!timer_pending(&t))
  886. mod_timer(&t, jiffies + 1);
  887. }
  888. idx = cur_ops->readlock();
  889. completed = cur_ops->completed();
  890. ts = rcu_trace_clock_local();
  891. p = rcu_dereference_check(rcu_torture_current,
  892. rcu_read_lock_bh_held() ||
  893. rcu_read_lock_sched_held() ||
  894. srcu_read_lock_held(&srcu_ctl));
  895. if (p == NULL) {
  896. /* Wait for rcu_torture_writer to get underway */
  897. cur_ops->readunlock(idx);
  898. schedule_timeout_interruptible(HZ);
  899. continue;
  900. }
  901. if (p->rtort_mbtest == 0)
  902. atomic_inc(&n_rcu_torture_mberror);
  903. cur_ops->read_delay(&rand);
  904. preempt_disable();
  905. pipe_count = p->rtort_pipe_count;
  906. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  907. /* Should not happen, but... */
  908. pipe_count = RCU_TORTURE_PIPE_LEN;
  909. }
  910. completed_end = cur_ops->completed();
  911. if (pipe_count > 1) {
  912. do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu,
  913. ts, completed, completed_end);
  914. rcutorture_trace_dump();
  915. }
  916. __this_cpu_inc(rcu_torture_count[pipe_count]);
  917. completed = completed_end - completed;
  918. if (completed > RCU_TORTURE_PIPE_LEN) {
  919. /* Should not happen, but... */
  920. completed = RCU_TORTURE_PIPE_LEN;
  921. }
  922. __this_cpu_inc(rcu_torture_batch[completed]);
  923. preempt_enable();
  924. cur_ops->readunlock(idx);
  925. cond_resched();
  926. stutter_wait("rcu_torture_reader");
  927. } while (!torture_must_stop());
  928. if (irqreader && cur_ops->irq_capable) {
  929. del_timer_sync(&t);
  930. destroy_timer_on_stack(&t);
  931. }
  932. torture_kthread_stopping("rcu_torture_reader");
  933. return 0;
  934. }
  935. /*
  936. * Create an RCU-torture statistics message in the specified buffer.
  937. */
  938. static void
  939. rcu_torture_printk(char *page)
  940. {
  941. int cpu;
  942. int i;
  943. long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  944. long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  945. static unsigned long rtcv_snap = ULONG_MAX;
  946. for_each_possible_cpu(cpu) {
  947. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  948. pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
  949. batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
  950. }
  951. }
  952. for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
  953. if (pipesummary[i] != 0)
  954. break;
  955. }
  956. page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
  957. page += sprintf(page,
  958. "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
  959. rcu_torture_current,
  960. rcu_torture_current_version,
  961. list_empty(&rcu_torture_freelist),
  962. atomic_read(&n_rcu_torture_alloc),
  963. atomic_read(&n_rcu_torture_alloc_fail),
  964. atomic_read(&n_rcu_torture_free));
  965. page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
  966. atomic_read(&n_rcu_torture_mberror),
  967. n_rcu_torture_boost_ktrerror,
  968. n_rcu_torture_boost_rterror);
  969. page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
  970. n_rcu_torture_boost_failure,
  971. n_rcu_torture_boosts,
  972. n_rcu_torture_timers);
  973. page = torture_onoff_stats(page);
  974. page += sprintf(page, "barrier: %ld/%ld:%ld",
  975. n_barrier_successes,
  976. n_barrier_attempts,
  977. n_rcu_torture_barrier_error);
  978. page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
  979. if (atomic_read(&n_rcu_torture_mberror) != 0 ||
  980. n_rcu_torture_barrier_error != 0 ||
  981. n_rcu_torture_boost_ktrerror != 0 ||
  982. n_rcu_torture_boost_rterror != 0 ||
  983. n_rcu_torture_boost_failure != 0 ||
  984. i > 1) {
  985. page += sprintf(page, "!!! ");
  986. atomic_inc(&n_rcu_torture_error);
  987. WARN_ON_ONCE(1);
  988. }
  989. page += sprintf(page, "Reader Pipe: ");
  990. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  991. page += sprintf(page, " %ld", pipesummary[i]);
  992. page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
  993. page += sprintf(page, "Reader Batch: ");
  994. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  995. page += sprintf(page, " %ld", batchsummary[i]);
  996. page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
  997. page += sprintf(page, "Free-Block Circulation: ");
  998. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  999. page += sprintf(page, " %d",
  1000. atomic_read(&rcu_torture_wcount[i]));
  1001. }
  1002. page += sprintf(page, "\n");
  1003. if (cur_ops->stats)
  1004. cur_ops->stats(page);
  1005. if (rtcv_snap == rcu_torture_current_version &&
  1006. rcu_torture_current != NULL) {
  1007. int __maybe_unused flags;
  1008. unsigned long __maybe_unused gpnum;
  1009. unsigned long __maybe_unused completed;
  1010. rcutorture_get_gp_data(cur_ops->ttype,
  1011. &flags, &gpnum, &completed);
  1012. page += sprintf(page,
  1013. "??? Writer stall state %d g%lu c%lu f%#x\n",
  1014. rcu_torture_writer_state,
  1015. gpnum, completed, flags);
  1016. show_rcu_gp_kthreads();
  1017. rcutorture_trace_dump();
  1018. }
  1019. rtcv_snap = rcu_torture_current_version;
  1020. }
  1021. /*
  1022. * Print torture statistics. Caller must ensure that there is only
  1023. * one call to this function at a given time!!! This is normally
  1024. * accomplished by relying on the module system to only have one copy
  1025. * of the module loaded, and then by giving the rcu_torture_stats
  1026. * kthread full control (or the init/cleanup functions when rcu_torture_stats
  1027. * thread is not running).
  1028. */
  1029. static void
  1030. rcu_torture_stats_print(void)
  1031. {
  1032. int size = nr_cpu_ids * 200 + 8192;
  1033. char *buf;
  1034. buf = kmalloc(size, GFP_KERNEL);
  1035. if (!buf) {
  1036. pr_err("rcu-torture: Out of memory, need: %d", size);
  1037. return;
  1038. }
  1039. rcu_torture_printk(buf);
  1040. pr_alert("%s", buf);
  1041. kfree(buf);
  1042. }
  1043. /*
  1044. * Periodically prints torture statistics, if periodic statistics printing
  1045. * was specified via the stat_interval module parameter.
  1046. */
  1047. static int
  1048. rcu_torture_stats(void *arg)
  1049. {
  1050. VERBOSE_TOROUT_STRING("rcu_torture_stats task started");
  1051. do {
  1052. schedule_timeout_interruptible(stat_interval * HZ);
  1053. rcu_torture_stats_print();
  1054. torture_shutdown_absorb("rcu_torture_stats");
  1055. } while (!torture_must_stop());
  1056. torture_kthread_stopping("rcu_torture_stats");
  1057. return 0;
  1058. }
  1059. static inline void
  1060. rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
  1061. {
  1062. pr_alert("%s" TORTURE_FLAG
  1063. "--- %s: nreaders=%d nfakewriters=%d "
  1064. "stat_interval=%d verbose=%d test_no_idle_hz=%d "
  1065. "shuffle_interval=%d stutter=%d irqreader=%d "
  1066. "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
  1067. "test_boost=%d/%d test_boost_interval=%d "
  1068. "test_boost_duration=%d shutdown_secs=%d "
  1069. "stall_cpu=%d stall_cpu_holdoff=%d "
  1070. "n_barrier_cbs=%d "
  1071. "onoff_interval=%d onoff_holdoff=%d\n",
  1072. torture_type, tag, nrealreaders, nfakewriters,
  1073. stat_interval, verbose, test_no_idle_hz, shuffle_interval,
  1074. stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
  1075. test_boost, cur_ops->can_boost,
  1076. test_boost_interval, test_boost_duration, shutdown_secs,
  1077. stall_cpu, stall_cpu_holdoff,
  1078. n_barrier_cbs,
  1079. onoff_interval, onoff_holdoff);
  1080. }
  1081. static void rcutorture_booster_cleanup(int cpu)
  1082. {
  1083. struct task_struct *t;
  1084. if (boost_tasks[cpu] == NULL)
  1085. return;
  1086. mutex_lock(&boost_mutex);
  1087. t = boost_tasks[cpu];
  1088. boost_tasks[cpu] = NULL;
  1089. mutex_unlock(&boost_mutex);
  1090. /* This must be outside of the mutex, otherwise deadlock! */
  1091. torture_stop_kthread(rcu_torture_boost, t);
  1092. }
  1093. static int rcutorture_booster_init(int cpu)
  1094. {
  1095. int retval;
  1096. if (boost_tasks[cpu] != NULL)
  1097. return 0; /* Already created, nothing more to do. */
  1098. /* Don't allow time recalculation while creating a new task. */
  1099. mutex_lock(&boost_mutex);
  1100. VERBOSE_TOROUT_STRING("Creating rcu_torture_boost task");
  1101. boost_tasks[cpu] = kthread_create_on_node(rcu_torture_boost, NULL,
  1102. cpu_to_node(cpu),
  1103. "rcu_torture_boost");
  1104. if (IS_ERR(boost_tasks[cpu])) {
  1105. retval = PTR_ERR(boost_tasks[cpu]);
  1106. VERBOSE_TOROUT_STRING("rcu_torture_boost task create failed");
  1107. n_rcu_torture_boost_ktrerror++;
  1108. boost_tasks[cpu] = NULL;
  1109. mutex_unlock(&boost_mutex);
  1110. return retval;
  1111. }
  1112. kthread_bind(boost_tasks[cpu], cpu);
  1113. wake_up_process(boost_tasks[cpu]);
  1114. mutex_unlock(&boost_mutex);
  1115. return 0;
  1116. }
  1117. /*
  1118. * CPU-stall kthread. It waits as specified by stall_cpu_holdoff, then
  1119. * induces a CPU stall for the time specified by stall_cpu.
  1120. */
  1121. static int rcu_torture_stall(void *args)
  1122. {
  1123. unsigned long stop_at;
  1124. VERBOSE_TOROUT_STRING("rcu_torture_stall task started");
  1125. if (stall_cpu_holdoff > 0) {
  1126. VERBOSE_TOROUT_STRING("rcu_torture_stall begin holdoff");
  1127. schedule_timeout_interruptible(stall_cpu_holdoff * HZ);
  1128. VERBOSE_TOROUT_STRING("rcu_torture_stall end holdoff");
  1129. }
  1130. if (!kthread_should_stop()) {
  1131. stop_at = get_seconds() + stall_cpu;
  1132. /* RCU CPU stall is expected behavior in following code. */
  1133. pr_alert("rcu_torture_stall start.\n");
  1134. rcu_read_lock();
  1135. preempt_disable();
  1136. while (ULONG_CMP_LT(get_seconds(), stop_at))
  1137. continue; /* Induce RCU CPU stall warning. */
  1138. preempt_enable();
  1139. rcu_read_unlock();
  1140. pr_alert("rcu_torture_stall end.\n");
  1141. }
  1142. torture_shutdown_absorb("rcu_torture_stall");
  1143. while (!kthread_should_stop())
  1144. schedule_timeout_interruptible(10 * HZ);
  1145. return 0;
  1146. }
  1147. /* Spawn CPU-stall kthread, if stall_cpu specified. */
  1148. static int __init rcu_torture_stall_init(void)
  1149. {
  1150. if (stall_cpu <= 0)
  1151. return 0;
  1152. return torture_create_kthread(rcu_torture_stall, NULL, stall_task);
  1153. }
  1154. /* Callback function for RCU barrier testing. */
  1155. static void rcu_torture_barrier_cbf(struct rcu_head *rcu)
  1156. {
  1157. atomic_inc(&barrier_cbs_invoked);
  1158. }
  1159. /* kthread function to register callbacks used to test RCU barriers. */
  1160. static int rcu_torture_barrier_cbs(void *arg)
  1161. {
  1162. long myid = (long)arg;
  1163. bool lastphase = 0;
  1164. bool newphase;
  1165. struct rcu_head rcu;
  1166. init_rcu_head_on_stack(&rcu);
  1167. VERBOSE_TOROUT_STRING("rcu_torture_barrier_cbs task started");
  1168. set_user_nice(current, MAX_NICE);
  1169. do {
  1170. wait_event(barrier_cbs_wq[myid],
  1171. (newphase =
  1172. ACCESS_ONCE(barrier_phase)) != lastphase ||
  1173. torture_must_stop());
  1174. lastphase = newphase;
  1175. smp_mb(); /* ensure barrier_phase load before ->call(). */
  1176. if (torture_must_stop())
  1177. break;
  1178. cur_ops->call(&rcu, rcu_torture_barrier_cbf);
  1179. if (atomic_dec_and_test(&barrier_cbs_count))
  1180. wake_up(&barrier_wq);
  1181. } while (!torture_must_stop());
  1182. cur_ops->cb_barrier();
  1183. destroy_rcu_head_on_stack(&rcu);
  1184. torture_kthread_stopping("rcu_torture_barrier_cbs");
  1185. return 0;
  1186. }
  1187. /* kthread function to drive and coordinate RCU barrier testing. */
  1188. static int rcu_torture_barrier(void *arg)
  1189. {
  1190. int i;
  1191. VERBOSE_TOROUT_STRING("rcu_torture_barrier task starting");
  1192. do {
  1193. atomic_set(&barrier_cbs_invoked, 0);
  1194. atomic_set(&barrier_cbs_count, n_barrier_cbs);
  1195. smp_mb(); /* Ensure barrier_phase after prior assignments. */
  1196. barrier_phase = !barrier_phase;
  1197. for (i = 0; i < n_barrier_cbs; i++)
  1198. wake_up(&barrier_cbs_wq[i]);
  1199. wait_event(barrier_wq,
  1200. atomic_read(&barrier_cbs_count) == 0 ||
  1201. torture_must_stop());
  1202. if (torture_must_stop())
  1203. break;
  1204. n_barrier_attempts++;
  1205. cur_ops->cb_barrier(); /* Implies smp_mb() for wait_event(). */
  1206. if (atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
  1207. n_rcu_torture_barrier_error++;
  1208. WARN_ON_ONCE(1);
  1209. }
  1210. n_barrier_successes++;
  1211. schedule_timeout_interruptible(HZ / 10);
  1212. } while (!torture_must_stop());
  1213. torture_kthread_stopping("rcu_torture_barrier");
  1214. return 0;
  1215. }
  1216. /* Initialize RCU barrier testing. */
  1217. static int rcu_torture_barrier_init(void)
  1218. {
  1219. int i;
  1220. int ret;
  1221. if (n_barrier_cbs == 0)
  1222. return 0;
  1223. if (cur_ops->call == NULL || cur_ops->cb_barrier == NULL) {
  1224. pr_alert("%s" TORTURE_FLAG
  1225. " Call or barrier ops missing for %s,\n",
  1226. torture_type, cur_ops->name);
  1227. pr_alert("%s" TORTURE_FLAG
  1228. " RCU barrier testing omitted from run.\n",
  1229. torture_type);
  1230. return 0;
  1231. }
  1232. atomic_set(&barrier_cbs_count, 0);
  1233. atomic_set(&barrier_cbs_invoked, 0);
  1234. barrier_cbs_tasks =
  1235. kzalloc(n_barrier_cbs * sizeof(barrier_cbs_tasks[0]),
  1236. GFP_KERNEL);
  1237. barrier_cbs_wq =
  1238. kzalloc(n_barrier_cbs * sizeof(barrier_cbs_wq[0]),
  1239. GFP_KERNEL);
  1240. if (barrier_cbs_tasks == NULL || !barrier_cbs_wq)
  1241. return -ENOMEM;
  1242. for (i = 0; i < n_barrier_cbs; i++) {
  1243. init_waitqueue_head(&barrier_cbs_wq[i]);
  1244. ret = torture_create_kthread(rcu_torture_barrier_cbs,
  1245. (void *)(long)i,
  1246. barrier_cbs_tasks[i]);
  1247. if (ret)
  1248. return ret;
  1249. }
  1250. return torture_create_kthread(rcu_torture_barrier, NULL, barrier_task);
  1251. }
  1252. /* Clean up after RCU barrier testing. */
  1253. static void rcu_torture_barrier_cleanup(void)
  1254. {
  1255. int i;
  1256. torture_stop_kthread(rcu_torture_barrier, barrier_task);
  1257. if (barrier_cbs_tasks != NULL) {
  1258. for (i = 0; i < n_barrier_cbs; i++)
  1259. torture_stop_kthread(rcu_torture_barrier_cbs,
  1260. barrier_cbs_tasks[i]);
  1261. kfree(barrier_cbs_tasks);
  1262. barrier_cbs_tasks = NULL;
  1263. }
  1264. if (barrier_cbs_wq != NULL) {
  1265. kfree(barrier_cbs_wq);
  1266. barrier_cbs_wq = NULL;
  1267. }
  1268. }
  1269. static int rcutorture_cpu_notify(struct notifier_block *self,
  1270. unsigned long action, void *hcpu)
  1271. {
  1272. long cpu = (long)hcpu;
  1273. switch (action) {
  1274. case CPU_ONLINE:
  1275. case CPU_DOWN_FAILED:
  1276. (void)rcutorture_booster_init(cpu);
  1277. break;
  1278. case CPU_DOWN_PREPARE:
  1279. rcutorture_booster_cleanup(cpu);
  1280. break;
  1281. default:
  1282. break;
  1283. }
  1284. return NOTIFY_OK;
  1285. }
  1286. static struct notifier_block rcutorture_cpu_nb = {
  1287. .notifier_call = rcutorture_cpu_notify,
  1288. };
  1289. static void
  1290. rcu_torture_cleanup(void)
  1291. {
  1292. int i;
  1293. rcutorture_record_test_transition();
  1294. if (torture_cleanup()) {
  1295. if (cur_ops->cb_barrier != NULL)
  1296. cur_ops->cb_barrier();
  1297. return;
  1298. }
  1299. rcu_torture_barrier_cleanup();
  1300. torture_stop_kthread(rcu_torture_stall, stall_task);
  1301. torture_stop_kthread(rcu_torture_writer, writer_task);
  1302. if (reader_tasks) {
  1303. for (i = 0; i < nrealreaders; i++)
  1304. torture_stop_kthread(rcu_torture_reader,
  1305. reader_tasks[i]);
  1306. kfree(reader_tasks);
  1307. }
  1308. rcu_torture_current = NULL;
  1309. if (fakewriter_tasks) {
  1310. for (i = 0; i < nfakewriters; i++) {
  1311. torture_stop_kthread(rcu_torture_fakewriter,
  1312. fakewriter_tasks[i]);
  1313. }
  1314. kfree(fakewriter_tasks);
  1315. fakewriter_tasks = NULL;
  1316. }
  1317. torture_stop_kthread(rcu_torture_stats, stats_task);
  1318. torture_stop_kthread(rcu_torture_fqs, fqs_task);
  1319. if ((test_boost == 1 && cur_ops->can_boost) ||
  1320. test_boost == 2) {
  1321. unregister_cpu_notifier(&rcutorture_cpu_nb);
  1322. for_each_possible_cpu(i)
  1323. rcutorture_booster_cleanup(i);
  1324. }
  1325. /* Wait for all RCU callbacks to fire. */
  1326. if (cur_ops->cb_barrier != NULL)
  1327. cur_ops->cb_barrier();
  1328. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  1329. if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
  1330. rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
  1331. else if (torture_onoff_failures())
  1332. rcu_torture_print_module_parms(cur_ops,
  1333. "End of test: RCU_HOTPLUG");
  1334. else
  1335. rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
  1336. }
  1337. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  1338. static void rcu_torture_leak_cb(struct rcu_head *rhp)
  1339. {
  1340. }
  1341. static void rcu_torture_err_cb(struct rcu_head *rhp)
  1342. {
  1343. /*
  1344. * This -might- happen due to race conditions, but is unlikely.
  1345. * The scenario that leads to this happening is that the
  1346. * first of the pair of duplicate callbacks is queued,
  1347. * someone else starts a grace period that includes that
  1348. * callback, then the second of the pair must wait for the
  1349. * next grace period. Unlikely, but can happen. If it
  1350. * does happen, the debug-objects subsystem won't have splatted.
  1351. */
  1352. pr_alert("rcutorture: duplicated callback was invoked.\n");
  1353. }
  1354. #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1355. /*
  1356. * Verify that double-free causes debug-objects to complain, but only
  1357. * if CONFIG_DEBUG_OBJECTS_RCU_HEAD=y. Otherwise, say that the test
  1358. * cannot be carried out.
  1359. */
  1360. static void rcu_test_debug_objects(void)
  1361. {
  1362. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  1363. struct rcu_head rh1;
  1364. struct rcu_head rh2;
  1365. init_rcu_head_on_stack(&rh1);
  1366. init_rcu_head_on_stack(&rh2);
  1367. pr_alert("rcutorture: WARN: Duplicate call_rcu() test starting.\n");
  1368. /* Try to queue the rh2 pair of callbacks for the same grace period. */
  1369. preempt_disable(); /* Prevent preemption from interrupting test. */
  1370. rcu_read_lock(); /* Make it impossible to finish a grace period. */
  1371. call_rcu(&rh1, rcu_torture_leak_cb); /* Start grace period. */
  1372. local_irq_disable(); /* Make it harder to start a new grace period. */
  1373. call_rcu(&rh2, rcu_torture_leak_cb);
  1374. call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
  1375. local_irq_enable();
  1376. rcu_read_unlock();
  1377. preempt_enable();
  1378. /* Wait for them all to get done so we can safely return. */
  1379. rcu_barrier();
  1380. pr_alert("rcutorture: WARN: Duplicate call_rcu() test complete.\n");
  1381. destroy_rcu_head_on_stack(&rh1);
  1382. destroy_rcu_head_on_stack(&rh2);
  1383. #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1384. pr_alert("rcutorture: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n");
  1385. #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  1386. }
  1387. static int __init
  1388. rcu_torture_init(void)
  1389. {
  1390. int i;
  1391. int cpu;
  1392. int firsterr = 0;
  1393. static struct rcu_torture_ops *torture_ops[] = {
  1394. &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops,
  1395. };
  1396. if (!torture_init_begin(torture_type, verbose, &rcutorture_runnable))
  1397. return -EBUSY;
  1398. /* Process args and tell the world that the torturer is on the job. */
  1399. for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
  1400. cur_ops = torture_ops[i];
  1401. if (strcmp(torture_type, cur_ops->name) == 0)
  1402. break;
  1403. }
  1404. if (i == ARRAY_SIZE(torture_ops)) {
  1405. pr_alert("rcu-torture: invalid torture type: \"%s\"\n",
  1406. torture_type);
  1407. pr_alert("rcu-torture types:");
  1408. for (i = 0; i < ARRAY_SIZE(torture_ops); i++)
  1409. pr_alert(" %s", torture_ops[i]->name);
  1410. pr_alert("\n");
  1411. torture_init_end();
  1412. return -EINVAL;
  1413. }
  1414. if (cur_ops->fqs == NULL && fqs_duration != 0) {
  1415. pr_alert("rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
  1416. fqs_duration = 0;
  1417. }
  1418. if (cur_ops->init)
  1419. cur_ops->init(); /* no "goto unwind" prior to this point!!! */
  1420. if (nreaders >= 0) {
  1421. nrealreaders = nreaders;
  1422. } else {
  1423. nrealreaders = num_online_cpus() - 1;
  1424. if (nrealreaders <= 0)
  1425. nrealreaders = 1;
  1426. }
  1427. rcu_torture_print_module_parms(cur_ops, "Start of test");
  1428. /* Set up the freelist. */
  1429. INIT_LIST_HEAD(&rcu_torture_freelist);
  1430. for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
  1431. rcu_tortures[i].rtort_mbtest = 0;
  1432. list_add_tail(&rcu_tortures[i].rtort_free,
  1433. &rcu_torture_freelist);
  1434. }
  1435. /* Initialize the statistics so that each run gets its own numbers. */
  1436. rcu_torture_current = NULL;
  1437. rcu_torture_current_version = 0;
  1438. atomic_set(&n_rcu_torture_alloc, 0);
  1439. atomic_set(&n_rcu_torture_alloc_fail, 0);
  1440. atomic_set(&n_rcu_torture_free, 0);
  1441. atomic_set(&n_rcu_torture_mberror, 0);
  1442. atomic_set(&n_rcu_torture_error, 0);
  1443. n_rcu_torture_barrier_error = 0;
  1444. n_rcu_torture_boost_ktrerror = 0;
  1445. n_rcu_torture_boost_rterror = 0;
  1446. n_rcu_torture_boost_failure = 0;
  1447. n_rcu_torture_boosts = 0;
  1448. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1449. atomic_set(&rcu_torture_wcount[i], 0);
  1450. for_each_possible_cpu(cpu) {
  1451. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1452. per_cpu(rcu_torture_count, cpu)[i] = 0;
  1453. per_cpu(rcu_torture_batch, cpu)[i] = 0;
  1454. }
  1455. }
  1456. /* Start up the kthreads. */
  1457. firsterr = torture_create_kthread(rcu_torture_writer, NULL,
  1458. writer_task);
  1459. if (firsterr)
  1460. goto unwind;
  1461. fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
  1462. GFP_KERNEL);
  1463. if (fakewriter_tasks == NULL) {
  1464. VERBOSE_TOROUT_ERRSTRING("out of memory");
  1465. firsterr = -ENOMEM;
  1466. goto unwind;
  1467. }
  1468. for (i = 0; i < nfakewriters; i++) {
  1469. firsterr = torture_create_kthread(rcu_torture_fakewriter,
  1470. NULL, fakewriter_tasks[i]);
  1471. if (firsterr)
  1472. goto unwind;
  1473. }
  1474. reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
  1475. GFP_KERNEL);
  1476. if (reader_tasks == NULL) {
  1477. VERBOSE_TOROUT_ERRSTRING("out of memory");
  1478. firsterr = -ENOMEM;
  1479. goto unwind;
  1480. }
  1481. for (i = 0; i < nrealreaders; i++) {
  1482. firsterr = torture_create_kthread(rcu_torture_reader, NULL,
  1483. reader_tasks[i]);
  1484. if (firsterr)
  1485. goto unwind;
  1486. }
  1487. if (stat_interval > 0) {
  1488. firsterr = torture_create_kthread(rcu_torture_stats, NULL,
  1489. stats_task);
  1490. if (firsterr)
  1491. goto unwind;
  1492. }
  1493. if (test_no_idle_hz) {
  1494. firsterr = torture_shuffle_init(shuffle_interval * HZ);
  1495. if (firsterr)
  1496. goto unwind;
  1497. }
  1498. if (stutter < 0)
  1499. stutter = 0;
  1500. if (stutter) {
  1501. firsterr = torture_stutter_init(stutter * HZ);
  1502. if (firsterr)
  1503. goto unwind;
  1504. }
  1505. if (fqs_duration < 0)
  1506. fqs_duration = 0;
  1507. if (fqs_duration) {
  1508. /* Create the fqs thread */
  1509. firsterr = torture_create_kthread(rcu_torture_fqs, NULL,
  1510. fqs_task);
  1511. if (firsterr)
  1512. goto unwind;
  1513. }
  1514. if (test_boost_interval < 1)
  1515. test_boost_interval = 1;
  1516. if (test_boost_duration < 2)
  1517. test_boost_duration = 2;
  1518. if ((test_boost == 1 && cur_ops->can_boost) ||
  1519. test_boost == 2) {
  1520. boost_starttime = jiffies + test_boost_interval * HZ;
  1521. register_cpu_notifier(&rcutorture_cpu_nb);
  1522. for_each_possible_cpu(i) {
  1523. if (cpu_is_offline(i))
  1524. continue; /* Heuristic: CPU can go offline. */
  1525. firsterr = rcutorture_booster_init(i);
  1526. if (firsterr)
  1527. goto unwind;
  1528. }
  1529. }
  1530. firsterr = torture_shutdown_init(shutdown_secs, rcu_torture_cleanup);
  1531. if (firsterr)
  1532. goto unwind;
  1533. firsterr = torture_onoff_init(onoff_holdoff * HZ, onoff_interval * HZ);
  1534. if (firsterr)
  1535. goto unwind;
  1536. firsterr = rcu_torture_stall_init();
  1537. if (firsterr)
  1538. goto unwind;
  1539. firsterr = rcu_torture_barrier_init();
  1540. if (firsterr)
  1541. goto unwind;
  1542. if (object_debug)
  1543. rcu_test_debug_objects();
  1544. rcutorture_record_test_transition();
  1545. torture_init_end();
  1546. return 0;
  1547. unwind:
  1548. torture_init_end();
  1549. rcu_torture_cleanup();
  1550. return firsterr;
  1551. }
  1552. module_init(rcu_torture_init);
  1553. module_exit(rcu_torture_cleanup);