rcutorture.c 63 KB

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