rcutorture.c 62 KB

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