rcutorture.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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 <asm/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 "
  52. "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; /* Interval between stats, in seconds. */
  56. /* Defaults to "only at end of test". */
  57. static int verbose; /* Print more debug info. */
  58. static int test_no_idle_hz; /* Test RCU's 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 char *torture_type = "rcu"; /* What RCU implementation to torture. */
  63. module_param(nreaders, int, 0444);
  64. MODULE_PARM_DESC(nreaders, "Number of RCU reader threads");
  65. module_param(nfakewriters, int, 0444);
  66. MODULE_PARM_DESC(nfakewriters, "Number of RCU fake writer threads");
  67. module_param(stat_interval, int, 0444);
  68. MODULE_PARM_DESC(stat_interval, "Number of seconds between stats printk()s");
  69. module_param(verbose, bool, 0444);
  70. MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s");
  71. module_param(test_no_idle_hz, bool, 0444);
  72. MODULE_PARM_DESC(test_no_idle_hz, "Test support for tickless idle CPUs");
  73. module_param(shuffle_interval, int, 0444);
  74. MODULE_PARM_DESC(shuffle_interval, "Number of seconds between shuffles");
  75. module_param(stutter, int, 0444);
  76. MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
  77. module_param(irqreader, int, 0444);
  78. MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
  79. module_param(torture_type, charp, 0444);
  80. MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
  81. #define TORTURE_FLAG "-torture:"
  82. #define PRINTK_STRING(s) \
  83. do { printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  84. #define VERBOSE_PRINTK_STRING(s) \
  85. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG s "\n", torture_type); } while (0)
  86. #define VERBOSE_PRINTK_ERRSTRING(s) \
  87. do { if (verbose) printk(KERN_ALERT "%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
  88. static char printk_buf[4096];
  89. static int nrealreaders;
  90. static struct task_struct *writer_task;
  91. static struct task_struct **fakewriter_tasks;
  92. static struct task_struct **reader_tasks;
  93. static struct task_struct *stats_task;
  94. static struct task_struct *shuffler_task;
  95. static struct task_struct *stutter_task;
  96. #define RCU_TORTURE_PIPE_LEN 10
  97. struct rcu_torture {
  98. struct rcu_head rtort_rcu;
  99. int rtort_pipe_count;
  100. struct list_head rtort_free;
  101. int rtort_mbtest;
  102. };
  103. static LIST_HEAD(rcu_torture_freelist);
  104. static struct rcu_torture *rcu_torture_current;
  105. static long rcu_torture_current_version;
  106. static struct rcu_torture rcu_tortures[10 * RCU_TORTURE_PIPE_LEN];
  107. static DEFINE_SPINLOCK(rcu_torture_lock);
  108. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
  109. { 0 };
  110. static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
  111. { 0 };
  112. static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
  113. static atomic_t n_rcu_torture_alloc;
  114. static atomic_t n_rcu_torture_alloc_fail;
  115. static atomic_t n_rcu_torture_free;
  116. static atomic_t n_rcu_torture_mberror;
  117. static atomic_t n_rcu_torture_error;
  118. static long n_rcu_torture_timers;
  119. static struct list_head rcu_torture_removed;
  120. static cpumask_var_t shuffle_tmp_mask;
  121. static int stutter_pause_test;
  122. #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
  123. #define RCUTORTURE_RUNNABLE_INIT 1
  124. #else
  125. #define RCUTORTURE_RUNNABLE_INIT 0
  126. #endif
  127. int rcutorture_runnable = RCUTORTURE_RUNNABLE_INIT;
  128. /* Mediate rmmod and system shutdown. Concurrent rmmod & shutdown illegal! */
  129. #define FULLSTOP_DONTSTOP 0 /* Normal operation. */
  130. #define FULLSTOP_SHUTDOWN 1 /* System shutdown with rcutorture running. */
  131. #define FULLSTOP_RMMOD 2 /* Normal rmmod of rcutorture. */
  132. static int fullstop = FULLSTOP_RMMOD;
  133. DEFINE_MUTEX(fullstop_mutex); /* Protect fullstop transitions and spawning */
  134. /* of kthreads. */
  135. /*
  136. * Detect and respond to a system shutdown.
  137. */
  138. static int
  139. rcutorture_shutdown_notify(struct notifier_block *unused1,
  140. unsigned long unused2, void *unused3)
  141. {
  142. mutex_lock(&fullstop_mutex);
  143. if (fullstop == FULLSTOP_DONTSTOP)
  144. fullstop = FULLSTOP_SHUTDOWN;
  145. else
  146. printk(KERN_WARNING /* but going down anyway, so... */
  147. "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
  148. mutex_unlock(&fullstop_mutex);
  149. return NOTIFY_DONE;
  150. }
  151. /*
  152. * Absorb kthreads into a kernel function that won't return, so that
  153. * they won't ever access module text or data again.
  154. */
  155. static void rcutorture_shutdown_absorb(char *title)
  156. {
  157. if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
  158. printk(KERN_NOTICE
  159. "rcutorture thread %s parking due to system shutdown\n",
  160. title);
  161. schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
  162. }
  163. }
  164. /*
  165. * Allocate an element from the rcu_tortures pool.
  166. */
  167. static struct rcu_torture *
  168. rcu_torture_alloc(void)
  169. {
  170. struct list_head *p;
  171. spin_lock_bh(&rcu_torture_lock);
  172. if (list_empty(&rcu_torture_freelist)) {
  173. atomic_inc(&n_rcu_torture_alloc_fail);
  174. spin_unlock_bh(&rcu_torture_lock);
  175. return NULL;
  176. }
  177. atomic_inc(&n_rcu_torture_alloc);
  178. p = rcu_torture_freelist.next;
  179. list_del_init(p);
  180. spin_unlock_bh(&rcu_torture_lock);
  181. return container_of(p, struct rcu_torture, rtort_free);
  182. }
  183. /*
  184. * Free an element to the rcu_tortures pool.
  185. */
  186. static void
  187. rcu_torture_free(struct rcu_torture *p)
  188. {
  189. atomic_inc(&n_rcu_torture_free);
  190. spin_lock_bh(&rcu_torture_lock);
  191. list_add_tail(&p->rtort_free, &rcu_torture_freelist);
  192. spin_unlock_bh(&rcu_torture_lock);
  193. }
  194. struct rcu_random_state {
  195. unsigned long rrs_state;
  196. long rrs_count;
  197. };
  198. #define RCU_RANDOM_MULT 39916801 /* prime */
  199. #define RCU_RANDOM_ADD 479001701 /* prime */
  200. #define RCU_RANDOM_REFRESH 10000
  201. #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
  202. /*
  203. * Crude but fast random-number generator. Uses a linear congruential
  204. * generator, with occasional help from cpu_clock().
  205. */
  206. static unsigned long
  207. rcu_random(struct rcu_random_state *rrsp)
  208. {
  209. if (--rrsp->rrs_count < 0) {
  210. rrsp->rrs_state +=
  211. (unsigned long)cpu_clock(raw_smp_processor_id());
  212. rrsp->rrs_count = RCU_RANDOM_REFRESH;
  213. }
  214. rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;
  215. return swahw32(rrsp->rrs_state);
  216. }
  217. static void
  218. rcu_stutter_wait(char *title)
  219. {
  220. while (stutter_pause_test || !rcutorture_runnable) {
  221. if (rcutorture_runnable)
  222. schedule_timeout_interruptible(1);
  223. else
  224. schedule_timeout_interruptible(round_jiffies_relative(HZ));
  225. rcutorture_shutdown_absorb(title);
  226. }
  227. }
  228. /*
  229. * Operations vector for selecting different types of tests.
  230. */
  231. struct rcu_torture_ops {
  232. void (*init)(void);
  233. void (*cleanup)(void);
  234. int (*readlock)(void);
  235. void (*read_delay)(struct rcu_random_state *rrsp);
  236. void (*readunlock)(int idx);
  237. int (*completed)(void);
  238. void (*deferred_free)(struct rcu_torture *p);
  239. void (*sync)(void);
  240. void (*cb_barrier)(void);
  241. int (*stats)(char *page);
  242. int irq_capable;
  243. char *name;
  244. };
  245. static struct rcu_torture_ops *cur_ops;
  246. /*
  247. * Definitions for rcu torture testing.
  248. */
  249. static int rcu_torture_read_lock(void) __acquires(RCU)
  250. {
  251. rcu_read_lock();
  252. return 0;
  253. }
  254. static void rcu_read_delay(struct rcu_random_state *rrsp)
  255. {
  256. const unsigned long shortdelay_us = 200;
  257. const unsigned long longdelay_ms = 50;
  258. /* We want a short delay sometimes to make a reader delay the grace
  259. * period, and we want a long delay occasionally to trigger
  260. * force_quiescent_state. */
  261. if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
  262. mdelay(longdelay_ms);
  263. if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
  264. udelay(shortdelay_us);
  265. }
  266. static void rcu_torture_read_unlock(int idx) __releases(RCU)
  267. {
  268. rcu_read_unlock();
  269. }
  270. static int rcu_torture_completed(void)
  271. {
  272. return rcu_batches_completed();
  273. }
  274. static void
  275. rcu_torture_cb(struct rcu_head *p)
  276. {
  277. int i;
  278. struct rcu_torture *rp = container_of(p, struct rcu_torture, rtort_rcu);
  279. if (fullstop != FULLSTOP_DONTSTOP) {
  280. /* Test is ending, just drop callbacks on the floor. */
  281. /* The next initialization will pick up the pieces. */
  282. return;
  283. }
  284. i = rp->rtort_pipe_count;
  285. if (i > RCU_TORTURE_PIPE_LEN)
  286. i = RCU_TORTURE_PIPE_LEN;
  287. atomic_inc(&rcu_torture_wcount[i]);
  288. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  289. rp->rtort_mbtest = 0;
  290. rcu_torture_free(rp);
  291. } else
  292. cur_ops->deferred_free(rp);
  293. }
  294. static void rcu_torture_deferred_free(struct rcu_torture *p)
  295. {
  296. call_rcu(&p->rtort_rcu, rcu_torture_cb);
  297. }
  298. static struct rcu_torture_ops rcu_ops = {
  299. .init = NULL,
  300. .cleanup = NULL,
  301. .readlock = rcu_torture_read_lock,
  302. .read_delay = rcu_read_delay,
  303. .readunlock = rcu_torture_read_unlock,
  304. .completed = rcu_torture_completed,
  305. .deferred_free = rcu_torture_deferred_free,
  306. .sync = synchronize_rcu,
  307. .cb_barrier = rcu_barrier,
  308. .stats = NULL,
  309. .irq_capable = 1,
  310. .name = "rcu"
  311. };
  312. static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
  313. {
  314. int i;
  315. struct rcu_torture *rp;
  316. struct rcu_torture *rp1;
  317. cur_ops->sync();
  318. list_add(&p->rtort_free, &rcu_torture_removed);
  319. list_for_each_entry_safe(rp, rp1, &rcu_torture_removed, rtort_free) {
  320. i = rp->rtort_pipe_count;
  321. if (i > RCU_TORTURE_PIPE_LEN)
  322. i = RCU_TORTURE_PIPE_LEN;
  323. atomic_inc(&rcu_torture_wcount[i]);
  324. if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
  325. rp->rtort_mbtest = 0;
  326. list_del(&rp->rtort_free);
  327. rcu_torture_free(rp);
  328. }
  329. }
  330. }
  331. static void rcu_sync_torture_init(void)
  332. {
  333. INIT_LIST_HEAD(&rcu_torture_removed);
  334. }
  335. static struct rcu_torture_ops rcu_sync_ops = {
  336. .init = rcu_sync_torture_init,
  337. .cleanup = NULL,
  338. .readlock = rcu_torture_read_lock,
  339. .read_delay = rcu_read_delay,
  340. .readunlock = rcu_torture_read_unlock,
  341. .completed = rcu_torture_completed,
  342. .deferred_free = rcu_sync_torture_deferred_free,
  343. .sync = synchronize_rcu,
  344. .cb_barrier = NULL,
  345. .stats = NULL,
  346. .irq_capable = 1,
  347. .name = "rcu_sync"
  348. };
  349. /*
  350. * Definitions for rcu_bh torture testing.
  351. */
  352. static int rcu_bh_torture_read_lock(void) __acquires(RCU_BH)
  353. {
  354. rcu_read_lock_bh();
  355. return 0;
  356. }
  357. static void rcu_bh_torture_read_unlock(int idx) __releases(RCU_BH)
  358. {
  359. rcu_read_unlock_bh();
  360. }
  361. static int rcu_bh_torture_completed(void)
  362. {
  363. return rcu_batches_completed_bh();
  364. }
  365. static void rcu_bh_torture_deferred_free(struct rcu_torture *p)
  366. {
  367. call_rcu_bh(&p->rtort_rcu, rcu_torture_cb);
  368. }
  369. struct rcu_bh_torture_synchronize {
  370. struct rcu_head head;
  371. struct completion completion;
  372. };
  373. static void rcu_bh_torture_wakeme_after_cb(struct rcu_head *head)
  374. {
  375. struct rcu_bh_torture_synchronize *rcu;
  376. rcu = container_of(head, struct rcu_bh_torture_synchronize, head);
  377. complete(&rcu->completion);
  378. }
  379. static void rcu_bh_torture_synchronize(void)
  380. {
  381. struct rcu_bh_torture_synchronize rcu;
  382. init_completion(&rcu.completion);
  383. call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
  384. wait_for_completion(&rcu.completion);
  385. }
  386. static struct rcu_torture_ops rcu_bh_ops = {
  387. .init = NULL,
  388. .cleanup = NULL,
  389. .readlock = rcu_bh_torture_read_lock,
  390. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  391. .readunlock = rcu_bh_torture_read_unlock,
  392. .completed = rcu_bh_torture_completed,
  393. .deferred_free = rcu_bh_torture_deferred_free,
  394. .sync = rcu_bh_torture_synchronize,
  395. .cb_barrier = rcu_barrier_bh,
  396. .stats = NULL,
  397. .irq_capable = 1,
  398. .name = "rcu_bh"
  399. };
  400. static struct rcu_torture_ops rcu_bh_sync_ops = {
  401. .init = rcu_sync_torture_init,
  402. .cleanup = NULL,
  403. .readlock = rcu_bh_torture_read_lock,
  404. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  405. .readunlock = rcu_bh_torture_read_unlock,
  406. .completed = rcu_bh_torture_completed,
  407. .deferred_free = rcu_sync_torture_deferred_free,
  408. .sync = rcu_bh_torture_synchronize,
  409. .cb_barrier = NULL,
  410. .stats = NULL,
  411. .irq_capable = 1,
  412. .name = "rcu_bh_sync"
  413. };
  414. /*
  415. * Definitions for srcu torture testing.
  416. */
  417. static struct srcu_struct srcu_ctl;
  418. static void srcu_torture_init(void)
  419. {
  420. init_srcu_struct(&srcu_ctl);
  421. rcu_sync_torture_init();
  422. }
  423. static void srcu_torture_cleanup(void)
  424. {
  425. synchronize_srcu(&srcu_ctl);
  426. cleanup_srcu_struct(&srcu_ctl);
  427. }
  428. static int srcu_torture_read_lock(void) __acquires(&srcu_ctl)
  429. {
  430. return srcu_read_lock(&srcu_ctl);
  431. }
  432. static void srcu_read_delay(struct rcu_random_state *rrsp)
  433. {
  434. long delay;
  435. const long uspertick = 1000000 / HZ;
  436. const long longdelay = 10;
  437. /* We want there to be long-running readers, but not all the time. */
  438. delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
  439. if (!delay)
  440. schedule_timeout_interruptible(longdelay);
  441. }
  442. static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl)
  443. {
  444. srcu_read_unlock(&srcu_ctl, idx);
  445. }
  446. static int srcu_torture_completed(void)
  447. {
  448. return srcu_batches_completed(&srcu_ctl);
  449. }
  450. static void srcu_torture_synchronize(void)
  451. {
  452. synchronize_srcu(&srcu_ctl);
  453. }
  454. static int srcu_torture_stats(char *page)
  455. {
  456. int cnt = 0;
  457. int cpu;
  458. int idx = srcu_ctl.completed & 0x1;
  459. cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):",
  460. torture_type, TORTURE_FLAG, idx);
  461. for_each_possible_cpu(cpu) {
  462. cnt += sprintf(&page[cnt], " %d(%d,%d)", cpu,
  463. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx],
  464. per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]);
  465. }
  466. cnt += sprintf(&page[cnt], "\n");
  467. return cnt;
  468. }
  469. static struct rcu_torture_ops srcu_ops = {
  470. .init = srcu_torture_init,
  471. .cleanup = srcu_torture_cleanup,
  472. .readlock = srcu_torture_read_lock,
  473. .read_delay = srcu_read_delay,
  474. .readunlock = srcu_torture_read_unlock,
  475. .completed = srcu_torture_completed,
  476. .deferred_free = rcu_sync_torture_deferred_free,
  477. .sync = srcu_torture_synchronize,
  478. .cb_barrier = NULL,
  479. .stats = srcu_torture_stats,
  480. .name = "srcu"
  481. };
  482. /*
  483. * Definitions for sched torture testing.
  484. */
  485. static int sched_torture_read_lock(void)
  486. {
  487. preempt_disable();
  488. return 0;
  489. }
  490. static void sched_torture_read_unlock(int idx)
  491. {
  492. preempt_enable();
  493. }
  494. static int sched_torture_completed(void)
  495. {
  496. return 0;
  497. }
  498. static void rcu_sched_torture_deferred_free(struct rcu_torture *p)
  499. {
  500. call_rcu_sched(&p->rtort_rcu, rcu_torture_cb);
  501. }
  502. static void sched_torture_synchronize(void)
  503. {
  504. synchronize_sched();
  505. }
  506. static struct rcu_torture_ops sched_ops = {
  507. .init = rcu_sync_torture_init,
  508. .cleanup = NULL,
  509. .readlock = sched_torture_read_lock,
  510. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  511. .readunlock = sched_torture_read_unlock,
  512. .completed = sched_torture_completed,
  513. .deferred_free = rcu_sched_torture_deferred_free,
  514. .sync = sched_torture_synchronize,
  515. .cb_barrier = rcu_barrier_sched,
  516. .stats = NULL,
  517. .irq_capable = 1,
  518. .name = "sched"
  519. };
  520. static struct rcu_torture_ops sched_ops_sync = {
  521. .init = rcu_sync_torture_init,
  522. .cleanup = NULL,
  523. .readlock = sched_torture_read_lock,
  524. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  525. .readunlock = sched_torture_read_unlock,
  526. .completed = sched_torture_completed,
  527. .deferred_free = rcu_sync_torture_deferred_free,
  528. .sync = sched_torture_synchronize,
  529. .cb_barrier = NULL,
  530. .stats = NULL,
  531. .name = "sched_sync"
  532. };
  533. extern int rcu_expedited_torture_stats(char *page);
  534. static struct rcu_torture_ops sched_expedited_ops = {
  535. .init = rcu_sync_torture_init,
  536. .cleanup = NULL,
  537. .readlock = sched_torture_read_lock,
  538. .read_delay = rcu_read_delay, /* just reuse rcu's version. */
  539. .readunlock = sched_torture_read_unlock,
  540. .completed = sched_torture_completed,
  541. .deferred_free = rcu_sync_torture_deferred_free,
  542. .sync = synchronize_sched_expedited,
  543. .cb_barrier = NULL,
  544. .stats = rcu_expedited_torture_stats,
  545. .irq_capable = 1,
  546. .name = "sched_expedited"
  547. };
  548. /*
  549. * RCU torture writer kthread. Repeatedly substitutes a new structure
  550. * for that pointed to by rcu_torture_current, freeing the old structure
  551. * after a series of grace periods (the "pipeline").
  552. */
  553. static int
  554. rcu_torture_writer(void *arg)
  555. {
  556. int i;
  557. long oldbatch = rcu_batches_completed();
  558. struct rcu_torture *rp;
  559. struct rcu_torture *old_rp;
  560. static DEFINE_RCU_RANDOM(rand);
  561. VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
  562. set_user_nice(current, 19);
  563. do {
  564. schedule_timeout_uninterruptible(1);
  565. rp = rcu_torture_alloc();
  566. if (rp == NULL)
  567. continue;
  568. rp->rtort_pipe_count = 0;
  569. udelay(rcu_random(&rand) & 0x3ff);
  570. old_rp = rcu_torture_current;
  571. rp->rtort_mbtest = 1;
  572. rcu_assign_pointer(rcu_torture_current, rp);
  573. smp_wmb();
  574. if (old_rp) {
  575. i = old_rp->rtort_pipe_count;
  576. if (i > RCU_TORTURE_PIPE_LEN)
  577. i = RCU_TORTURE_PIPE_LEN;
  578. atomic_inc(&rcu_torture_wcount[i]);
  579. old_rp->rtort_pipe_count++;
  580. cur_ops->deferred_free(old_rp);
  581. }
  582. rcu_torture_current_version++;
  583. oldbatch = cur_ops->completed();
  584. rcu_stutter_wait("rcu_torture_writer");
  585. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  586. VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
  587. rcutorture_shutdown_absorb("rcu_torture_writer");
  588. while (!kthread_should_stop())
  589. schedule_timeout_uninterruptible(1);
  590. return 0;
  591. }
  592. /*
  593. * RCU torture fake writer kthread. Repeatedly calls sync, with a random
  594. * delay between calls.
  595. */
  596. static int
  597. rcu_torture_fakewriter(void *arg)
  598. {
  599. DEFINE_RCU_RANDOM(rand);
  600. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
  601. set_user_nice(current, 19);
  602. do {
  603. schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
  604. udelay(rcu_random(&rand) & 0x3ff);
  605. cur_ops->sync();
  606. rcu_stutter_wait("rcu_torture_fakewriter");
  607. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  608. VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task stopping");
  609. rcutorture_shutdown_absorb("rcu_torture_fakewriter");
  610. while (!kthread_should_stop())
  611. schedule_timeout_uninterruptible(1);
  612. return 0;
  613. }
  614. /*
  615. * RCU torture reader from timer handler. Dereferences rcu_torture_current,
  616. * incrementing the corresponding element of the pipeline array. The
  617. * counter in the element should never be greater than 1, otherwise, the
  618. * RCU implementation is broken.
  619. */
  620. static void rcu_torture_timer(unsigned long unused)
  621. {
  622. int idx;
  623. int completed;
  624. static DEFINE_RCU_RANDOM(rand);
  625. static DEFINE_SPINLOCK(rand_lock);
  626. struct rcu_torture *p;
  627. int pipe_count;
  628. idx = cur_ops->readlock();
  629. completed = cur_ops->completed();
  630. p = rcu_dereference(rcu_torture_current);
  631. if (p == NULL) {
  632. /* Leave because rcu_torture_writer is not yet underway */
  633. cur_ops->readunlock(idx);
  634. return;
  635. }
  636. if (p->rtort_mbtest == 0)
  637. atomic_inc(&n_rcu_torture_mberror);
  638. spin_lock(&rand_lock);
  639. cur_ops->read_delay(&rand);
  640. n_rcu_torture_timers++;
  641. spin_unlock(&rand_lock);
  642. preempt_disable();
  643. pipe_count = p->rtort_pipe_count;
  644. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  645. /* Should not happen, but... */
  646. pipe_count = RCU_TORTURE_PIPE_LEN;
  647. }
  648. ++__get_cpu_var(rcu_torture_count)[pipe_count];
  649. completed = cur_ops->completed() - completed;
  650. if (completed > RCU_TORTURE_PIPE_LEN) {
  651. /* Should not happen, but... */
  652. completed = RCU_TORTURE_PIPE_LEN;
  653. }
  654. ++__get_cpu_var(rcu_torture_batch)[completed];
  655. preempt_enable();
  656. cur_ops->readunlock(idx);
  657. }
  658. /*
  659. * RCU torture reader kthread. Repeatedly dereferences rcu_torture_current,
  660. * incrementing the corresponding element of the pipeline array. The
  661. * counter in the element should never be greater than 1, otherwise, the
  662. * RCU implementation is broken.
  663. */
  664. static int
  665. rcu_torture_reader(void *arg)
  666. {
  667. int completed;
  668. int idx;
  669. DEFINE_RCU_RANDOM(rand);
  670. struct rcu_torture *p;
  671. int pipe_count;
  672. struct timer_list t;
  673. VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
  674. set_user_nice(current, 19);
  675. if (irqreader && cur_ops->irq_capable)
  676. setup_timer_on_stack(&t, rcu_torture_timer, 0);
  677. do {
  678. if (irqreader && cur_ops->irq_capable) {
  679. if (!timer_pending(&t))
  680. mod_timer(&t, 1);
  681. }
  682. idx = cur_ops->readlock();
  683. completed = cur_ops->completed();
  684. p = rcu_dereference(rcu_torture_current);
  685. if (p == NULL) {
  686. /* Wait for rcu_torture_writer to get underway */
  687. cur_ops->readunlock(idx);
  688. schedule_timeout_interruptible(HZ);
  689. continue;
  690. }
  691. if (p->rtort_mbtest == 0)
  692. atomic_inc(&n_rcu_torture_mberror);
  693. cur_ops->read_delay(&rand);
  694. preempt_disable();
  695. pipe_count = p->rtort_pipe_count;
  696. if (pipe_count > RCU_TORTURE_PIPE_LEN) {
  697. /* Should not happen, but... */
  698. pipe_count = RCU_TORTURE_PIPE_LEN;
  699. }
  700. ++__get_cpu_var(rcu_torture_count)[pipe_count];
  701. completed = cur_ops->completed() - completed;
  702. if (completed > RCU_TORTURE_PIPE_LEN) {
  703. /* Should not happen, but... */
  704. completed = RCU_TORTURE_PIPE_LEN;
  705. }
  706. ++__get_cpu_var(rcu_torture_batch)[completed];
  707. preempt_enable();
  708. cur_ops->readunlock(idx);
  709. schedule();
  710. rcu_stutter_wait("rcu_torture_reader");
  711. } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
  712. VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping");
  713. rcutorture_shutdown_absorb("rcu_torture_reader");
  714. if (irqreader && cur_ops->irq_capable)
  715. del_timer_sync(&t);
  716. while (!kthread_should_stop())
  717. schedule_timeout_uninterruptible(1);
  718. return 0;
  719. }
  720. /*
  721. * Create an RCU-torture statistics message in the specified buffer.
  722. */
  723. static int
  724. rcu_torture_printk(char *page)
  725. {
  726. int cnt = 0;
  727. int cpu;
  728. int i;
  729. long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  730. long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
  731. for_each_possible_cpu(cpu) {
  732. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  733. pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
  734. batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
  735. }
  736. }
  737. for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
  738. if (pipesummary[i] != 0)
  739. break;
  740. }
  741. cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG);
  742. cnt += sprintf(&page[cnt],
  743. "rtc: %p ver: %ld tfle: %d rta: %d rtaf: %d rtf: %d "
  744. "rtmbe: %d nt: %ld",
  745. rcu_torture_current,
  746. rcu_torture_current_version,
  747. list_empty(&rcu_torture_freelist),
  748. atomic_read(&n_rcu_torture_alloc),
  749. atomic_read(&n_rcu_torture_alloc_fail),
  750. atomic_read(&n_rcu_torture_free),
  751. atomic_read(&n_rcu_torture_mberror),
  752. n_rcu_torture_timers);
  753. if (atomic_read(&n_rcu_torture_mberror) != 0)
  754. cnt += sprintf(&page[cnt], " !!!");
  755. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  756. if (i > 1) {
  757. cnt += sprintf(&page[cnt], "!!! ");
  758. atomic_inc(&n_rcu_torture_error);
  759. WARN_ON_ONCE(1);
  760. }
  761. cnt += sprintf(&page[cnt], "Reader Pipe: ");
  762. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  763. cnt += sprintf(&page[cnt], " %ld", pipesummary[i]);
  764. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  765. cnt += sprintf(&page[cnt], "Reader Batch: ");
  766. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  767. cnt += sprintf(&page[cnt], " %ld", batchsummary[i]);
  768. cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
  769. cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
  770. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  771. cnt += sprintf(&page[cnt], " %d",
  772. atomic_read(&rcu_torture_wcount[i]));
  773. }
  774. cnt += sprintf(&page[cnt], "\n");
  775. if (cur_ops->stats)
  776. cnt += cur_ops->stats(&page[cnt]);
  777. return cnt;
  778. }
  779. /*
  780. * Print torture statistics. Caller must ensure that there is only
  781. * one call to this function at a given time!!! This is normally
  782. * accomplished by relying on the module system to only have one copy
  783. * of the module loaded, and then by giving the rcu_torture_stats
  784. * kthread full control (or the init/cleanup functions when rcu_torture_stats
  785. * thread is not running).
  786. */
  787. static void
  788. rcu_torture_stats_print(void)
  789. {
  790. int cnt;
  791. cnt = rcu_torture_printk(printk_buf);
  792. printk(KERN_ALERT "%s", printk_buf);
  793. }
  794. /*
  795. * Periodically prints torture statistics, if periodic statistics printing
  796. * was specified via the stat_interval module parameter.
  797. *
  798. * No need to worry about fullstop here, since this one doesn't reference
  799. * volatile state or register callbacks.
  800. */
  801. static int
  802. rcu_torture_stats(void *arg)
  803. {
  804. VERBOSE_PRINTK_STRING("rcu_torture_stats task started");
  805. do {
  806. schedule_timeout_interruptible(stat_interval * HZ);
  807. rcu_torture_stats_print();
  808. rcutorture_shutdown_absorb("rcu_torture_stats");
  809. } while (!kthread_should_stop());
  810. VERBOSE_PRINTK_STRING("rcu_torture_stats task stopping");
  811. return 0;
  812. }
  813. static int rcu_idle_cpu; /* Force all torture tasks off this CPU */
  814. /* Shuffle tasks such that we allow @rcu_idle_cpu to become idle. A special case
  815. * is when @rcu_idle_cpu = -1, when we allow the tasks to run on all CPUs.
  816. */
  817. static void rcu_torture_shuffle_tasks(void)
  818. {
  819. int i;
  820. cpumask_setall(shuffle_tmp_mask);
  821. get_online_cpus();
  822. /* No point in shuffling if there is only one online CPU (ex: UP) */
  823. if (num_online_cpus() == 1) {
  824. put_online_cpus();
  825. return;
  826. }
  827. if (rcu_idle_cpu != -1)
  828. cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
  829. set_cpus_allowed_ptr(current, shuffle_tmp_mask);
  830. if (reader_tasks) {
  831. for (i = 0; i < nrealreaders; i++)
  832. if (reader_tasks[i])
  833. set_cpus_allowed_ptr(reader_tasks[i],
  834. shuffle_tmp_mask);
  835. }
  836. if (fakewriter_tasks) {
  837. for (i = 0; i < nfakewriters; i++)
  838. if (fakewriter_tasks[i])
  839. set_cpus_allowed_ptr(fakewriter_tasks[i],
  840. shuffle_tmp_mask);
  841. }
  842. if (writer_task)
  843. set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
  844. if (stats_task)
  845. set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
  846. if (rcu_idle_cpu == -1)
  847. rcu_idle_cpu = num_online_cpus() - 1;
  848. else
  849. rcu_idle_cpu--;
  850. put_online_cpus();
  851. }
  852. /* Shuffle tasks across CPUs, with the intent of allowing each CPU in the
  853. * system to become idle at a time and cut off its timer ticks. This is meant
  854. * to test the support for such tickless idle CPU in RCU.
  855. */
  856. static int
  857. rcu_torture_shuffle(void *arg)
  858. {
  859. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task started");
  860. do {
  861. schedule_timeout_interruptible(shuffle_interval * HZ);
  862. rcu_torture_shuffle_tasks();
  863. rcutorture_shutdown_absorb("rcu_torture_shuffle");
  864. } while (!kthread_should_stop());
  865. VERBOSE_PRINTK_STRING("rcu_torture_shuffle task stopping");
  866. return 0;
  867. }
  868. /* Cause the rcutorture test to "stutter", starting and stopping all
  869. * threads periodically.
  870. */
  871. static int
  872. rcu_torture_stutter(void *arg)
  873. {
  874. VERBOSE_PRINTK_STRING("rcu_torture_stutter task started");
  875. do {
  876. schedule_timeout_interruptible(stutter * HZ);
  877. stutter_pause_test = 1;
  878. if (!kthread_should_stop())
  879. schedule_timeout_interruptible(stutter * HZ);
  880. stutter_pause_test = 0;
  881. rcutorture_shutdown_absorb("rcu_torture_stutter");
  882. } while (!kthread_should_stop());
  883. VERBOSE_PRINTK_STRING("rcu_torture_stutter task stopping");
  884. return 0;
  885. }
  886. static inline void
  887. rcu_torture_print_module_parms(char *tag)
  888. {
  889. printk(KERN_ALERT "%s" TORTURE_FLAG
  890. "--- %s: nreaders=%d nfakewriters=%d "
  891. "stat_interval=%d verbose=%d test_no_idle_hz=%d "
  892. "shuffle_interval=%d stutter=%d irqreader=%d\n",
  893. torture_type, tag, nrealreaders, nfakewriters,
  894. stat_interval, verbose, test_no_idle_hz, shuffle_interval,
  895. stutter, irqreader);
  896. }
  897. static struct notifier_block rcutorture_nb = {
  898. .notifier_call = rcutorture_shutdown_notify,
  899. };
  900. static void
  901. rcu_torture_cleanup(void)
  902. {
  903. int i;
  904. mutex_lock(&fullstop_mutex);
  905. if (fullstop == FULLSTOP_SHUTDOWN) {
  906. printk(KERN_WARNING /* but going down anyway, so... */
  907. "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
  908. mutex_unlock(&fullstop_mutex);
  909. schedule_timeout_uninterruptible(10);
  910. if (cur_ops->cb_barrier != NULL)
  911. cur_ops->cb_barrier();
  912. return;
  913. }
  914. fullstop = FULLSTOP_RMMOD;
  915. mutex_unlock(&fullstop_mutex);
  916. unregister_reboot_notifier(&rcutorture_nb);
  917. if (stutter_task) {
  918. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stutter task");
  919. kthread_stop(stutter_task);
  920. }
  921. stutter_task = NULL;
  922. if (shuffler_task) {
  923. VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
  924. kthread_stop(shuffler_task);
  925. free_cpumask_var(shuffle_tmp_mask);
  926. }
  927. shuffler_task = NULL;
  928. if (writer_task) {
  929. VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
  930. kthread_stop(writer_task);
  931. }
  932. writer_task = NULL;
  933. if (reader_tasks) {
  934. for (i = 0; i < nrealreaders; i++) {
  935. if (reader_tasks[i]) {
  936. VERBOSE_PRINTK_STRING(
  937. "Stopping rcu_torture_reader task");
  938. kthread_stop(reader_tasks[i]);
  939. }
  940. reader_tasks[i] = NULL;
  941. }
  942. kfree(reader_tasks);
  943. reader_tasks = NULL;
  944. }
  945. rcu_torture_current = NULL;
  946. if (fakewriter_tasks) {
  947. for (i = 0; i < nfakewriters; i++) {
  948. if (fakewriter_tasks[i]) {
  949. VERBOSE_PRINTK_STRING(
  950. "Stopping rcu_torture_fakewriter task");
  951. kthread_stop(fakewriter_tasks[i]);
  952. }
  953. fakewriter_tasks[i] = NULL;
  954. }
  955. kfree(fakewriter_tasks);
  956. fakewriter_tasks = NULL;
  957. }
  958. if (stats_task) {
  959. VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
  960. kthread_stop(stats_task);
  961. }
  962. stats_task = NULL;
  963. /* Wait for all RCU callbacks to fire. */
  964. if (cur_ops->cb_barrier != NULL)
  965. cur_ops->cb_barrier();
  966. rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
  967. if (cur_ops->cleanup)
  968. cur_ops->cleanup();
  969. if (atomic_read(&n_rcu_torture_error))
  970. rcu_torture_print_module_parms("End of test: FAILURE");
  971. else
  972. rcu_torture_print_module_parms("End of test: SUCCESS");
  973. }
  974. static int __init
  975. rcu_torture_init(void)
  976. {
  977. int i;
  978. int cpu;
  979. int firsterr = 0;
  980. static struct rcu_torture_ops *torture_ops[] =
  981. { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops,
  982. &sched_expedited_ops,
  983. &srcu_ops, &sched_ops, &sched_ops_sync, };
  984. mutex_lock(&fullstop_mutex);
  985. /* Process args and tell the world that the torturer is on the job. */
  986. for (i = 0; i < ARRAY_SIZE(torture_ops); i++) {
  987. cur_ops = torture_ops[i];
  988. if (strcmp(torture_type, cur_ops->name) == 0)
  989. break;
  990. }
  991. if (i == ARRAY_SIZE(torture_ops)) {
  992. printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
  993. torture_type);
  994. mutex_unlock(&fullstop_mutex);
  995. return -EINVAL;
  996. }
  997. if (cur_ops->init)
  998. cur_ops->init(); /* no "goto unwind" prior to this point!!! */
  999. if (nreaders >= 0)
  1000. nrealreaders = nreaders;
  1001. else
  1002. nrealreaders = 2 * num_online_cpus();
  1003. rcu_torture_print_module_parms("Start of test");
  1004. fullstop = FULLSTOP_DONTSTOP;
  1005. /* Set up the freelist. */
  1006. INIT_LIST_HEAD(&rcu_torture_freelist);
  1007. for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
  1008. rcu_tortures[i].rtort_mbtest = 0;
  1009. list_add_tail(&rcu_tortures[i].rtort_free,
  1010. &rcu_torture_freelist);
  1011. }
  1012. /* Initialize the statistics so that each run gets its own numbers. */
  1013. rcu_torture_current = NULL;
  1014. rcu_torture_current_version = 0;
  1015. atomic_set(&n_rcu_torture_alloc, 0);
  1016. atomic_set(&n_rcu_torture_alloc_fail, 0);
  1017. atomic_set(&n_rcu_torture_free, 0);
  1018. atomic_set(&n_rcu_torture_mberror, 0);
  1019. atomic_set(&n_rcu_torture_error, 0);
  1020. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
  1021. atomic_set(&rcu_torture_wcount[i], 0);
  1022. for_each_possible_cpu(cpu) {
  1023. for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
  1024. per_cpu(rcu_torture_count, cpu)[i] = 0;
  1025. per_cpu(rcu_torture_batch, cpu)[i] = 0;
  1026. }
  1027. }
  1028. /* Start up the kthreads. */
  1029. VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task");
  1030. writer_task = kthread_run(rcu_torture_writer, NULL,
  1031. "rcu_torture_writer");
  1032. if (IS_ERR(writer_task)) {
  1033. firsterr = PTR_ERR(writer_task);
  1034. VERBOSE_PRINTK_ERRSTRING("Failed to create writer");
  1035. writer_task = NULL;
  1036. goto unwind;
  1037. }
  1038. fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]),
  1039. GFP_KERNEL);
  1040. if (fakewriter_tasks == NULL) {
  1041. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1042. firsterr = -ENOMEM;
  1043. goto unwind;
  1044. }
  1045. for (i = 0; i < nfakewriters; i++) {
  1046. VERBOSE_PRINTK_STRING("Creating rcu_torture_fakewriter task");
  1047. fakewriter_tasks[i] = kthread_run(rcu_torture_fakewriter, NULL,
  1048. "rcu_torture_fakewriter");
  1049. if (IS_ERR(fakewriter_tasks[i])) {
  1050. firsterr = PTR_ERR(fakewriter_tasks[i]);
  1051. VERBOSE_PRINTK_ERRSTRING("Failed to create fakewriter");
  1052. fakewriter_tasks[i] = NULL;
  1053. goto unwind;
  1054. }
  1055. }
  1056. reader_tasks = kzalloc(nrealreaders * sizeof(reader_tasks[0]),
  1057. GFP_KERNEL);
  1058. if (reader_tasks == NULL) {
  1059. VERBOSE_PRINTK_ERRSTRING("out of memory");
  1060. firsterr = -ENOMEM;
  1061. goto unwind;
  1062. }
  1063. for (i = 0; i < nrealreaders; i++) {
  1064. VERBOSE_PRINTK_STRING("Creating rcu_torture_reader task");
  1065. reader_tasks[i] = kthread_run(rcu_torture_reader, NULL,
  1066. "rcu_torture_reader");
  1067. if (IS_ERR(reader_tasks[i])) {
  1068. firsterr = PTR_ERR(reader_tasks[i]);
  1069. VERBOSE_PRINTK_ERRSTRING("Failed to create reader");
  1070. reader_tasks[i] = NULL;
  1071. goto unwind;
  1072. }
  1073. }
  1074. if (stat_interval > 0) {
  1075. VERBOSE_PRINTK_STRING("Creating rcu_torture_stats task");
  1076. stats_task = kthread_run(rcu_torture_stats, NULL,
  1077. "rcu_torture_stats");
  1078. if (IS_ERR(stats_task)) {
  1079. firsterr = PTR_ERR(stats_task);
  1080. VERBOSE_PRINTK_ERRSTRING("Failed to create stats");
  1081. stats_task = NULL;
  1082. goto unwind;
  1083. }
  1084. }
  1085. if (test_no_idle_hz) {
  1086. rcu_idle_cpu = num_online_cpus() - 1;
  1087. if (!alloc_cpumask_var(&shuffle_tmp_mask, GFP_KERNEL)) {
  1088. firsterr = -ENOMEM;
  1089. VERBOSE_PRINTK_ERRSTRING("Failed to alloc mask");
  1090. goto unwind;
  1091. }
  1092. /* Create the shuffler thread */
  1093. shuffler_task = kthread_run(rcu_torture_shuffle, NULL,
  1094. "rcu_torture_shuffle");
  1095. if (IS_ERR(shuffler_task)) {
  1096. free_cpumask_var(shuffle_tmp_mask);
  1097. firsterr = PTR_ERR(shuffler_task);
  1098. VERBOSE_PRINTK_ERRSTRING("Failed to create shuffler");
  1099. shuffler_task = NULL;
  1100. goto unwind;
  1101. }
  1102. }
  1103. if (stutter < 0)
  1104. stutter = 0;
  1105. if (stutter) {
  1106. /* Create the stutter thread */
  1107. stutter_task = kthread_run(rcu_torture_stutter, NULL,
  1108. "rcu_torture_stutter");
  1109. if (IS_ERR(stutter_task)) {
  1110. firsterr = PTR_ERR(stutter_task);
  1111. VERBOSE_PRINTK_ERRSTRING("Failed to create stutter");
  1112. stutter_task = NULL;
  1113. goto unwind;
  1114. }
  1115. }
  1116. register_reboot_notifier(&rcutorture_nb);
  1117. mutex_unlock(&fullstop_mutex);
  1118. return 0;
  1119. unwind:
  1120. mutex_unlock(&fullstop_mutex);
  1121. rcu_torture_cleanup();
  1122. return firsterr;
  1123. }
  1124. module_init(rcu_torture_init);
  1125. module_exit(rcu_torture_cleanup);