rcutorture.c 49 KB

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