rcutorture.c 63 KB

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