rcutorture.c 62 KB

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