rcutorture.c 63 KB

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