rcutorture.c 62 KB

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