rcutorture.c 63 KB

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