rcutorture.c 62 KB

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