25 #include <linux/types.h>
26 #include <linux/kernel.h>
28 #include <linux/module.h>
35 #include <linux/sched.h>
37 #include <linux/bitops.h>
42 #include <linux/reboot.h>
46 #include <linux/stat.h>
48 #include <linux/slab.h>
49 #include <asm/byteorder.h>
54 static int nreaders = -1;
55 static int nfakewriters = 4;
56 static int stat_interval = 60;
59 static bool test_no_idle_hz =
true;
61 static int shuffle_interval = 3;
62 static int stutter = 5;
63 static int irqreader = 1;
64 static int fqs_duration;
65 static int fqs_holdoff;
66 static int fqs_stutter = 3;
67 static int n_barrier_cbs;
68 static int onoff_interval;
69 static int onoff_holdoff;
70 static int shutdown_secs;
72 static int stall_cpu_holdoff = 10;
73 static int test_boost = 1;
74 static int test_boost_interval = 7;
75 static int test_boost_duration = 4;
76 static char *torture_type =
"rcu";
83 MODULE_PARM_DESC(stat_interval,
"Number of seconds between stats printk()s");
101 MODULE_PARM_DESC(n_barrier_cbs,
"# of callbacks/kthreads for barrier testing");
103 MODULE_PARM_DESC(onoff_interval,
"Time between CPU hotplugs (s), 0=disable");
111 MODULE_PARM_DESC(stall_cpu_holdoff,
"Time to wait before starting stall (s).");
115 MODULE_PARM_DESC(test_boost_interval,
"Interval between boost tests, seconds.");
117 MODULE_PARM_DESC(test_boost_duration,
"Duration of each boost test, seconds.");
119 MODULE_PARM_DESC(torture_type,
"Type of RCU to torture (rcu, rcu_bh, srcu)");
121 #define TORTURE_FLAG "-torture:"
122 #define PRINTK_STRING(s) \
123 do { pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
124 #define VERBOSE_PRINTK_STRING(s) \
125 do { if (verbose) pr_alert("%s" TORTURE_FLAG s "\n", torture_type); } while (0)
126 #define VERBOSE_PRINTK_ERRSTRING(s) \
127 do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0)
129 static char printk_buf[4096];
131 static int nrealreaders;
141 #ifdef CONFIG_HOTPLUG_CPU
148 #define RCU_TORTURE_PIPE_LEN 10
159 static unsigned long rcu_torture_current_version;
167 static atomic_t n_rcu_torture_alloc;
168 static atomic_t n_rcu_torture_alloc_fail;
170 static atomic_t n_rcu_torture_mberror;
171 static atomic_t n_rcu_torture_error;
172 static long n_rcu_torture_barrier_error;
173 static long n_rcu_torture_boost_ktrerror;
174 static long n_rcu_torture_boost_rterror;
175 static long n_rcu_torture_boost_failure;
176 static long n_rcu_torture_boosts;
177 static long n_rcu_torture_timers;
178 static long n_offline_attempts;
179 static long n_offline_successes;
180 static unsigned long sum_offline;
181 static int min_offline = -1;
182 static int max_offline;
183 static long n_online_attempts;
184 static long n_online_successes;
185 static unsigned long sum_online;
186 static int min_online = -1;
187 static int max_online;
188 static long n_barrier_attempts;
189 static long n_barrier_successes;
190 static struct list_head rcu_torture_removed;
193 static int stutter_pause_test;
195 #if defined(MODULE) || defined(CONFIG_RCU_TORTURE_TEST_RUNNABLE)
196 #define RCUTORTURE_RUNNABLE_INIT 1
198 #define RCUTORTURE_RUNNABLE_INIT 0
204 #if defined(CONFIG_RCU_BOOST) && !defined(CONFIG_HOTPLUG_CPU)
205 #define rcu_can_boost() 1
207 #define rcu_can_boost() 0
210 static unsigned long shutdown_time;
211 static unsigned long boost_starttime;
215 static bool barrier_phase;
216 static atomic_t barrier_cbs_invoked;
222 #define FULLSTOP_DONTSTOP 0
223 #define FULLSTOP_SHUTDOWN 1
224 #define FULLSTOP_RMMOD 2
232 static void rcu_torture_cleanup(
void);
246 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
255 static void rcutorture_shutdown_absorb(
char *title)
259 "rcutorture thread %s parking due to system shutdown\n",
269 rcu_torture_alloc(
void)
273 spin_lock_bh(&rcu_torture_lock);
274 if (list_empty(&rcu_torture_freelist)) {
276 spin_unlock_bh(&rcu_torture_lock);
280 p = rcu_torture_freelist.
next;
282 spin_unlock_bh(&rcu_torture_lock);
293 spin_lock_bh(&rcu_torture_lock);
295 spin_unlock_bh(&rcu_torture_lock);
303 #define RCU_RANDOM_MULT 39916801
304 #define RCU_RANDOM_ADD 479001701
305 #define RCU_RANDOM_REFRESH 10000
307 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
325 rcu_stutter_wait(
char *title)
332 rcutorture_shutdown_absorb(title);
364 static int rcu_torture_read_lock(
void)
__acquires(RCU)
372 const unsigned long shortdelay_us = 200;
373 const unsigned long longdelay_ms = 50;
379 if (!(rcu_random(rrsp) % (nrealreaders * 2000 * longdelay_ms)))
381 if (!(rcu_random(rrsp) % (nrealreaders * 2 * shortdelay_us)))
383 #ifdef CONFIG_PREEMPT
384 if (!
preempt_count() && !(rcu_random(rrsp) % (nrealreaders * 20000)))
394 static int rcu_torture_completed(
void)
416 rcu_torture_free(rp);
422 static int rcu_no_completed(
void)
427 static void rcu_torture_deferred_free(
struct rcu_torture *p)
435 .readlock = rcu_torture_read_lock,
436 .read_delay = rcu_read_delay,
437 .readunlock = rcu_torture_read_unlock,
438 .completed = rcu_torture_completed,
439 .deferred_free = rcu_torture_deferred_free,
440 .sync = synchronize_rcu,
450 static void rcu_sync_torture_deferred_free(
struct rcu_torture *p)
457 list_add(&p->
rtort_free, &rcu_torture_removed);
466 rcu_torture_free(rp);
471 static void rcu_sync_torture_init(
void)
473 INIT_LIST_HEAD(&rcu_torture_removed);
477 .init = rcu_sync_torture_init,
479 .readlock = rcu_torture_read_lock,
480 .read_delay = rcu_read_delay,
481 .readunlock = rcu_torture_read_unlock,
482 .completed = rcu_torture_completed,
483 .deferred_free = rcu_sync_torture_deferred_free,
484 .sync = synchronize_rcu,
495 .init = rcu_sync_torture_init,
497 .readlock = rcu_torture_read_lock,
498 .read_delay = rcu_read_delay,
499 .readunlock = rcu_torture_read_unlock,
500 .completed = rcu_no_completed,
501 .deferred_free = rcu_sync_torture_deferred_free,
509 .name =
"rcu_expedited"
516 static int rcu_bh_torture_read_lock(
void)
__acquires(RCU_BH)
522 static void rcu_bh_torture_read_unlock(
int idx)
__releases(RCU_BH)
524 rcu_read_unlock_bh();
527 static int rcu_bh_torture_completed(
void)
532 static void rcu_bh_torture_deferred_free(
struct rcu_torture *p)
540 .readlock = rcu_bh_torture_read_lock,
541 .read_delay = rcu_read_delay,
542 .readunlock = rcu_bh_torture_read_unlock,
543 .completed = rcu_bh_torture_completed,
544 .deferred_free = rcu_bh_torture_deferred_free,
555 .init = rcu_sync_torture_init,
557 .readlock = rcu_bh_torture_read_lock,
558 .read_delay = rcu_read_delay,
559 .readunlock = rcu_bh_torture_read_unlock,
560 .completed = rcu_bh_torture_completed,
561 .deferred_free = rcu_sync_torture_deferred_free,
568 .name =
"rcu_bh_sync"
572 .init = rcu_sync_torture_init,
574 .readlock = rcu_bh_torture_read_lock,
575 .read_delay = rcu_read_delay,
576 .readunlock = rcu_bh_torture_read_unlock,
577 .completed = rcu_bh_torture_completed,
578 .deferred_free = rcu_sync_torture_deferred_free,
579 .sync = synchronize_rcu_bh_expedited,
585 .name =
"rcu_bh_expedited"
594 static void srcu_torture_init(
void)
597 rcu_sync_torture_init();
600 static void srcu_torture_cleanup(
void)
606 static int srcu_torture_read_lock(
void)
__acquires(&srcu_ctl)
608 return srcu_read_lock(&srcu_ctl);
614 const long uspertick = 1000000 /
HZ;
615 const long longdelay = 10;
619 delay = rcu_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick);
623 rcu_read_delay(rrsp);
626 static void srcu_torture_read_unlock(
int idx)
__releases(&srcu_ctl)
628 srcu_read_unlock(&srcu_ctl,
idx);
631 static int srcu_torture_completed(
void)
636 static void srcu_torture_deferred_free(
struct rcu_torture *rp)
641 static void srcu_torture_synchronize(
void)
652 static void srcu_torture_barrier(
void)
657 static int srcu_torture_stats(
char *
page)
661 int idx = srcu_ctl.completed & 0x1;
663 cnt +=
sprintf(&page[cnt],
"%s%s per-CPU(idx=%d):",
666 cnt +=
sprintf(&page[cnt],
" %d(%lu,%lu)", cpu,
670 cnt +=
sprintf(&page[cnt],
"\n");
675 .init = srcu_torture_init,
676 .cleanup = srcu_torture_cleanup,
677 .readlock = srcu_torture_read_lock,
678 .read_delay = srcu_read_delay,
679 .readunlock = srcu_torture_read_unlock,
680 .completed = srcu_torture_completed,
681 .deferred_free = srcu_torture_deferred_free,
682 .sync = srcu_torture_synchronize,
683 .call = srcu_torture_call,
684 .cb_barrier = srcu_torture_barrier,
685 .stats = srcu_torture_stats,
690 .init = srcu_torture_init,
691 .cleanup = srcu_torture_cleanup,
692 .readlock = srcu_torture_read_lock,
693 .read_delay = srcu_read_delay,
694 .readunlock = srcu_torture_read_unlock,
695 .completed = srcu_torture_completed,
696 .deferred_free = rcu_sync_torture_deferred_free,
697 .sync = srcu_torture_synchronize,
700 .stats = srcu_torture_stats,
704 static int srcu_torture_read_lock_raw(
void)
__acquires(&srcu_ctl)
706 return srcu_read_lock_raw(&srcu_ctl);
709 static void srcu_torture_read_unlock_raw(
int idx)
__releases(&srcu_ctl)
711 srcu_read_unlock_raw(&srcu_ctl, idx);
715 .init = srcu_torture_init,
716 .cleanup = srcu_torture_cleanup,
717 .readlock = srcu_torture_read_lock_raw,
718 .read_delay = srcu_read_delay,
719 .readunlock = srcu_torture_read_unlock_raw,
720 .completed = srcu_torture_completed,
721 .deferred_free = srcu_torture_deferred_free,
722 .sync = srcu_torture_synchronize,
725 .stats = srcu_torture_stats,
730 .init = srcu_torture_init,
731 .cleanup = srcu_torture_cleanup,
732 .readlock = srcu_torture_read_lock_raw,
733 .read_delay = srcu_read_delay,
734 .readunlock = srcu_torture_read_unlock_raw,
735 .completed = srcu_torture_completed,
736 .deferred_free = rcu_sync_torture_deferred_free,
737 .sync = srcu_torture_synchronize,
740 .stats = srcu_torture_stats,
741 .name =
"srcu_raw_sync"
744 static void srcu_torture_synchronize_expedited(
void)
750 .init = srcu_torture_init,
751 .cleanup = srcu_torture_cleanup,
752 .readlock = srcu_torture_read_lock,
753 .read_delay = srcu_read_delay,
754 .readunlock = srcu_torture_read_unlock,
755 .completed = srcu_torture_completed,
756 .deferred_free = rcu_sync_torture_deferred_free,
757 .sync = srcu_torture_synchronize_expedited,
760 .stats = srcu_torture_stats,
761 .name =
"srcu_expedited"
768 static int sched_torture_read_lock(
void)
774 static void sched_torture_read_unlock(
int idx)
779 static void rcu_sched_torture_deferred_free(
struct rcu_torture *p)
785 .init = rcu_sync_torture_init,
787 .readlock = sched_torture_read_lock,
788 .read_delay = rcu_read_delay,
789 .readunlock = sched_torture_read_unlock,
790 .completed = rcu_no_completed,
791 .deferred_free = rcu_sched_torture_deferred_free,
801 .init = rcu_sync_torture_init,
803 .readlock = sched_torture_read_lock,
804 .read_delay = rcu_read_delay,
805 .readunlock = sched_torture_read_unlock,
806 .completed = rcu_no_completed,
807 .deferred_free = rcu_sync_torture_deferred_free,
816 .init = rcu_sync_torture_init,
818 .readlock = sched_torture_read_lock,
819 .read_delay = rcu_read_delay,
820 .readunlock = sched_torture_read_unlock,
821 .completed = rcu_no_completed,
822 .deferred_free = rcu_sync_torture_deferred_free,
828 .name =
"sched_expedited"
843 static void rcu_torture_boost_cb(
struct rcu_head *head)
852 static int rcu_torture_boost(
void *
arg)
854 unsigned long call_rcu_time;
855 unsigned long endtime;
856 unsigned long oldstarttime;
863 sp.sched_priority = 1;
866 n_rcu_torture_boost_rterror++;
869 init_rcu_head_on_stack(&rbi.
rcu);
873 oldstarttime = boost_starttime;
876 rcu_stutter_wait(
"rcu_torture_boost");
883 endtime = oldstarttime + test_boost_duration *
HZ;
891 if (jiffies - call_rcu_time >
892 test_boost_duration * HZ - HZ / 2) {
894 n_rcu_torture_boost_failure++;
899 rcu_stutter_wait(
"rcu_torture_boost");
912 while (oldstarttime == boost_starttime &&
916 test_boost_interval *
HZ;
917 n_rcu_torture_boosts++;
925 checkwait: rcu_stutter_wait(
"rcu_torture_boost");
930 rcutorture_shutdown_absorb(
"rcu_torture_boost");
934 destroy_rcu_head_on_stack(&rbi.
rcu);
944 rcu_torture_fqs(
void *arg)
946 unsigned long fqs_resume_time;
947 int fqs_burst_remaining;
951 fqs_resume_time =
jiffies + fqs_stutter *
HZ;
956 fqs_burst_remaining = fqs_duration;
957 while (fqs_burst_remaining > 0 &&
961 fqs_burst_remaining -= fqs_holdoff;
963 rcu_stutter_wait(
"rcu_torture_fqs");
966 rcutorture_shutdown_absorb(
"rcu_torture_fqs");
978 rcu_torture_writer(
void *arg)
991 rp = rcu_torture_alloc();
995 udelay(rcu_random(&rand) & 0x3ff);
1011 rcu_stutter_wait(
"rcu_torture_writer");
1014 rcutorture_shutdown_absorb(
"rcu_torture_writer");
1025 rcu_torture_fakewriter(
void *arg)
1034 udelay(rcu_random(&rand) & 0x3ff);
1036 rcu_random(&rand) % (nfakewriters * 8) == 0)
1040 rcu_stutter_wait(
"rcu_torture_fakewriter");
1044 rcutorture_shutdown_absorb(
"rcu_torture_fakewriter");
1068 static void rcu_torture_timer(
unsigned long unused)
1080 rcu_read_lock_bh_held() ||
1081 rcu_read_lock_sched_held() ||
1082 srcu_read_lock_held(&srcu_ctl));
1091 spin_lock(&rand_lock);
1093 n_rcu_torture_timers++;
1094 spin_unlock(&rand_lock);
1121 rcu_torture_reader(
void *arg)
1137 if (!timer_pending(&
t))
1143 rcu_read_lock_bh_held() ||
1144 rcu_read_lock_sched_held() ||
1145 srcu_read_lock_held(&srcu_ctl));
1174 rcu_stutter_wait(
"rcu_torture_reader");
1177 rcutorture_shutdown_absorb(
"rcu_torture_reader");
1189 rcu_torture_printk(
char *page)
1199 pipesummary[
i] +=
per_cpu(rcu_torture_count, cpu)[
i];
1200 batchsummary[
i] +=
per_cpu(rcu_torture_batch, cpu)[
i];
1204 if (pipesummary[i] != 0)
1209 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1210 rcu_torture_current,
1211 rcu_torture_current_version,
1212 list_empty(&rcu_torture_freelist),
1216 cnt +=
sprintf(&page[cnt],
"rtmbe: %d rtbke: %ld rtbre: %ld ",
1218 n_rcu_torture_boost_ktrerror,
1219 n_rcu_torture_boost_rterror);
1220 cnt +=
sprintf(&page[cnt],
"rtbf: %ld rtb: %ld nt: %ld ",
1221 n_rcu_torture_boost_failure,
1222 n_rcu_torture_boosts,
1223 n_rcu_torture_timers);
1225 "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ",
1226 n_online_successes, n_online_attempts,
1227 n_offline_successes, n_offline_attempts,
1228 min_online, max_online,
1229 min_offline, max_offline,
1230 sum_online, sum_offline, HZ);
1231 cnt +=
sprintf(&page[cnt],
"barrier: %ld/%ld:%ld",
1232 n_barrier_successes,
1234 n_rcu_torture_barrier_error);
1237 n_rcu_torture_barrier_error != 0 ||
1238 n_rcu_torture_boost_ktrerror != 0 ||
1239 n_rcu_torture_boost_rterror != 0 ||
1240 n_rcu_torture_boost_failure != 0 ||
1242 cnt +=
sprintf(&page[cnt],
"!!! ");
1246 cnt +=
sprintf(&page[cnt],
"Reader Pipe: ");
1248 cnt +=
sprintf(&page[cnt],
" %ld", pipesummary[i]);
1250 cnt +=
sprintf(&page[cnt],
"Reader Batch: ");
1251 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1252 cnt +=
sprintf(&page[cnt],
" %ld", batchsummary[i]);
1254 cnt +=
sprintf(&page[cnt],
"Free-Block Circulation: ");
1255 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1256 cnt +=
sprintf(&page[cnt],
" %d",
1259 cnt +=
sprintf(&page[cnt],
"\n");
1261 cnt += cur_ops->
stats(&page[cnt]);
1274 rcu_torture_stats_print(
void)
1278 cnt = rcu_torture_printk(printk_buf);
1290 rcu_torture_stats(
void *arg)
1295 rcu_torture_stats_print();
1296 rcutorture_shutdown_absorb(
"rcu_torture_stats");
1302 static int rcu_idle_cpu;
1307 static void rcu_torture_shuffle_tasks(
void)
1311 cpumask_setall(shuffle_tmp_mask);
1320 if (rcu_idle_cpu != -1)
1321 cpumask_clear_cpu(rcu_idle_cpu, shuffle_tmp_mask);
1323 set_cpus_allowed_ptr(
current, shuffle_tmp_mask);
1326 for (i = 0; i < nrealreaders; i++)
1327 if (reader_tasks[i])
1328 set_cpus_allowed_ptr(reader_tasks[i],
1332 if (fakewriter_tasks) {
1333 for (i = 0; i < nfakewriters; i++)
1334 if (fakewriter_tasks[i])
1335 set_cpus_allowed_ptr(fakewriter_tasks[i],
1340 set_cpus_allowed_ptr(writer_task, shuffle_tmp_mask);
1343 set_cpus_allowed_ptr(stats_task, shuffle_tmp_mask);
1345 if (rcu_idle_cpu == -1)
1358 rcu_torture_shuffle(
void *arg)
1363 rcu_torture_shuffle_tasks();
1364 rcutorture_shutdown_absorb(
"rcu_torture_shuffle");
1374 rcu_torture_stutter(
void *arg)
1379 stutter_pause_test = 1;
1382 stutter_pause_test = 0;
1383 rcutorture_shutdown_absorb(
"rcu_torture_stutter");
1393 "--- %s: nreaders=%d nfakewriters=%d "
1394 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1395 "shuffle_interval=%d stutter=%d irqreader=%d "
1396 "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
1397 "test_boost=%d/%d test_boost_interval=%d "
1398 "test_boost_duration=%d shutdown_secs=%d "
1399 "onoff_interval=%d onoff_holdoff=%d\n",
1400 torture_type, tag, nrealreaders, nfakewriters,
1401 stat_interval,
verbose, test_no_idle_hz, shuffle_interval,
1402 stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
1404 test_boost_interval, test_boost_duration, shutdown_secs,
1405 onoff_interval, onoff_holdoff);
1409 .notifier_call = rcutorture_shutdown_notify,
1412 static void rcutorture_booster_cleanup(
int cpu)
1416 if (boost_tasks[cpu] ==
NULL)
1420 t = boost_tasks[
cpu];
1429 static int rcutorture_booster_init(
int cpu)
1433 if (boost_tasks[cpu] !=
NULL)
1441 "rcu_torture_boost");
1442 if (IS_ERR(boost_tasks[cpu])) {
1443 retval = PTR_ERR(boost_tasks[cpu]);
1445 n_rcu_torture_boost_ktrerror++;
1461 rcu_torture_shutdown(
void *arg)
1464 unsigned long jiffies_snap;
1470 delta = shutdown_time - jiffies_snap;
1473 "rcu_torture_shutdown task: %lu jiffies remaining\n",
1474 torture_type, delta);
1486 shutdown_task =
NULL;
1487 rcu_torture_cleanup();
1492 #ifdef CONFIG_HOTPLUG_CPU
1499 rcu_torture_onoff(
void *arg)
1502 unsigned long delta;
1505 unsigned long starttime;
1511 if (onoff_holdoff > 0) {
1517 cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1521 "rcu_torture_onoff task: offlining %d\n",
1524 n_offline_attempts++;
1525 if (cpu_down(cpu) == 0) {
1528 "rcu_torture_onoff task: offlined %d\n",
1530 n_offline_successes++;
1532 sum_offline +=
delta;
1533 if (min_offline < 0) {
1534 min_offline =
delta;
1535 max_offline =
delta;
1537 if (min_offline > delta)
1538 min_offline =
delta;
1539 if (max_offline < delta)
1540 max_offline =
delta;
1545 "rcu_torture_onoff task: onlining %d\n",
1548 n_online_attempts++;
1549 if (cpu_up(cpu) == 0) {
1552 "rcu_torture_onoff task: onlined %d\n",
1554 n_online_successes++;
1556 sum_online +=
delta;
1557 if (min_online < 0) {
1561 if (min_online > delta)
1563 if (max_online < delta)
1574 rcu_torture_onoff_init(
void)
1578 if (onoff_interval <= 0)
1580 onoff_task =
kthread_run(rcu_torture_onoff,
NULL,
"rcu_torture_onoff");
1581 if (IS_ERR(onoff_task)) {
1582 ret = PTR_ERR(onoff_task);
1589 static void rcu_torture_onoff_cleanup(
void)
1591 if (onoff_task ==
NULL)
1601 rcu_torture_onoff_init(
void)
1606 static void rcu_torture_onoff_cleanup(
void)
1616 static int __cpuinit rcu_torture_stall(
void *args)
1618 unsigned long stop_at;
1621 if (stall_cpu_holdoff > 0) {
1629 pr_alert(
"rcu_torture_stall start.\n");
1636 pr_alert(
"rcu_torture_stall end.\n");
1638 rcutorture_shutdown_absorb(
"rcu_torture_stall");
1645 static int __init rcu_torture_stall_init(
void)
1651 stall_task =
kthread_run(rcu_torture_stall,
NULL,
"rcu_torture_stall");
1652 if (IS_ERR(stall_task)) {
1653 ret = PTR_ERR(stall_task);
1661 static void rcu_torture_stall_cleanup(
void)
1663 if (stall_task ==
NULL)
1677 static int rcu_torture_barrier_cbs(
void *arg)
1679 long myid = (
long)arg;
1683 init_rcu_head_on_stack(&rcu);
1688 barrier_phase != lastphase ||
1691 lastphase = barrier_phase;
1700 rcutorture_shutdown_absorb(
"rcu_torture_barrier_cbs");
1704 destroy_rcu_head_on_stack(&rcu);
1709 static int rcu_torture_barrier(
void *arg)
1716 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1718 barrier_phase = !barrier_phase;
1719 for (i = 0; i < n_barrier_cbs; i++)
1727 n_barrier_attempts++;
1729 if (
atomic_read(&barrier_cbs_invoked) != n_barrier_cbs) {
1730 n_rcu_torture_barrier_error++;
1733 n_barrier_successes++;
1737 rcutorture_shutdown_absorb(
"rcu_torture_barrier");
1744 static int rcu_torture_barrier_init(
void)
1749 if (n_barrier_cbs == 0)
1753 " Call or barrier ops missing for %s,\n",
1754 torture_type, cur_ops->
name);
1756 " RCU barrier testing omitted from run.\n",
1763 kzalloc(n_barrier_cbs *
sizeof(barrier_cbs_tasks[0]),
1766 kzalloc(n_barrier_cbs *
sizeof(barrier_cbs_wq[0]),
1768 if (barrier_cbs_tasks ==
NULL || barrier_cbs_wq == 0)
1770 for (i = 0; i < n_barrier_cbs; i++) {
1772 barrier_cbs_tasks[
i] =
kthread_run(rcu_torture_barrier_cbs,
1774 "rcu_torture_barrier_cbs");
1775 if (IS_ERR(barrier_cbs_tasks[i])) {
1776 ret = PTR_ERR(barrier_cbs_tasks[i]);
1778 barrier_cbs_tasks[
i] =
NULL;
1783 "rcu_torture_barrier");
1784 if (IS_ERR(barrier_task)) {
1785 ret = PTR_ERR(barrier_task);
1787 barrier_task =
NULL;
1793 static void rcu_torture_barrier_cleanup(
void)
1797 if (barrier_task !=
NULL) {
1800 barrier_task =
NULL;
1802 if (barrier_cbs_tasks !=
NULL) {
1803 for (i = 0; i < n_barrier_cbs; i++) {
1804 if (barrier_cbs_tasks[i] !=
NULL) {
1807 barrier_cbs_tasks[
i] =
NULL;
1810 kfree(barrier_cbs_tasks);
1811 barrier_cbs_tasks =
NULL;
1813 if (barrier_cbs_wq !=
NULL) {
1814 kfree(barrier_cbs_wq);
1815 barrier_cbs_wq =
NULL;
1820 unsigned long action,
void *hcpu)
1822 long cpu = (
long)hcpu;
1827 (
void)rcutorture_booster_init(cpu);
1830 rcutorture_booster_cleanup(cpu);
1839 .notifier_call = rcutorture_cpu_notify,
1843 rcu_torture_cleanup(
void)
1851 "Concurrent 'rmmod rcutorture' and shutdown illegal!\n");
1861 rcu_torture_barrier_cleanup();
1862 rcu_torture_stall_cleanup();
1867 stutter_task =
NULL;
1868 if (shuffler_task) {
1871 free_cpumask_var(shuffle_tmp_mask);
1873 shuffler_task =
NULL;
1882 for (i = 0; i < nrealreaders; i++) {
1883 if (reader_tasks[i]) {
1885 "Stopping rcu_torture_reader task");
1888 reader_tasks[
i] =
NULL;
1890 kfree(reader_tasks);
1891 reader_tasks =
NULL;
1893 rcu_torture_current =
NULL;
1895 if (fakewriter_tasks) {
1896 for (i = 0; i < nfakewriters; i++) {
1897 if (fakewriter_tasks[i]) {
1899 "Stopping rcu_torture_fakewriter task");
1902 fakewriter_tasks[
i] =
NULL;
1904 kfree(fakewriter_tasks);
1905 fakewriter_tasks =
NULL;
1919 if ((test_boost == 1 && cur_ops->
can_boost) ||
1921 unregister_cpu_notifier(&rcutorture_cpu_nb);
1923 rcutorture_booster_cleanup(i);
1925 if (shutdown_task !=
NULL) {
1929 shutdown_task =
NULL;
1930 rcu_torture_onoff_cleanup();
1937 rcu_torture_stats_print();
1941 if (
atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
1942 rcu_torture_print_module_parms(cur_ops,
"End of test: FAILURE");
1943 else if (n_online_successes != n_online_attempts ||
1944 n_offline_successes != n_offline_attempts)
1945 rcu_torture_print_module_parms(cur_ops,
1946 "End of test: RCU_HOTPLUG");
1948 rcu_torture_print_module_parms(cur_ops,
"End of test: SUCCESS");
1952 rcu_torture_init(
void)
1959 { &rcu_ops, &rcu_sync_ops, &rcu_expedited_ops,
1960 &rcu_bh_ops, &rcu_bh_sync_ops, &rcu_bh_expedited_ops,
1961 &srcu_ops, &srcu_sync_ops, &srcu_expedited_ops,
1962 &srcu_raw_ops, &srcu_raw_sync_ops,
1963 &sched_ops, &sched_sync_ops, &sched_expedited_ops, };
1968 for (i = 0; i <
ARRAY_SIZE(torture_ops); i++) {
1969 cur_ops = torture_ops[
i];
1970 if (
strcmp(torture_type, cur_ops->
name) == 0)
1974 pr_alert(
"rcu-torture: invalid torture type: \"%s\"\n",
1977 for (i = 0; i <
ARRAY_SIZE(torture_ops); i++)
1983 if (cur_ops->
fqs ==
NULL && fqs_duration != 0) {
1984 pr_alert(
"rcu-torture: ->fqs NULL and non-zero fqs_duration, fqs disabled.\n");
1991 nrealreaders = nreaders;
1994 rcu_torture_print_module_parms(cur_ops,
"Start of test");
1999 INIT_LIST_HEAD(&rcu_torture_freelist);
2000 for (i = 0; i <
ARRAY_SIZE(rcu_tortures); i++) {
2001 rcu_tortures[
i].rtort_mbtest = 0;
2003 &rcu_torture_freelist);
2008 rcu_torture_current =
NULL;
2009 rcu_torture_current_version = 0;
2015 n_rcu_torture_barrier_error = 0;
2016 n_rcu_torture_boost_ktrerror = 0;
2017 n_rcu_torture_boost_rterror = 0;
2018 n_rcu_torture_boost_failure = 0;
2019 n_rcu_torture_boosts = 0;
2020 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
2023 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
2024 per_cpu(rcu_torture_count, cpu)[
i] = 0;
2025 per_cpu(rcu_torture_batch, cpu)[
i] = 0;
2033 "rcu_torture_writer");
2034 if (IS_ERR(writer_task)) {
2035 firsterr = PTR_ERR(writer_task);
2041 fakewriter_tasks = kzalloc(nfakewriters *
sizeof(fakewriter_tasks[0]),
2043 if (fakewriter_tasks ==
NULL) {
2048 for (i = 0; i < nfakewriters; i++) {
2051 "rcu_torture_fakewriter");
2052 if (IS_ERR(fakewriter_tasks[i])) {
2053 firsterr = PTR_ERR(fakewriter_tasks[i]);
2055 fakewriter_tasks[
i] =
NULL;
2059 reader_tasks = kzalloc(nrealreaders *
sizeof(reader_tasks[0]),
2061 if (reader_tasks ==
NULL) {
2066 for (i = 0; i < nrealreaders; i++) {
2069 "rcu_torture_reader");
2070 if (IS_ERR(reader_tasks[i])) {
2071 firsterr = PTR_ERR(reader_tasks[i]);
2073 reader_tasks[
i] =
NULL;
2077 if (stat_interval > 0) {
2080 "rcu_torture_stats");
2081 if (IS_ERR(stats_task)) {
2082 firsterr = PTR_ERR(stats_task);
2088 if (test_no_idle_hz) {
2091 if (!alloc_cpumask_var(&shuffle_tmp_mask,
GFP_KERNEL)) {
2099 "rcu_torture_shuffle");
2100 if (IS_ERR(shuffler_task)) {
2101 free_cpumask_var(shuffle_tmp_mask);
2102 firsterr = PTR_ERR(shuffler_task);
2104 shuffler_task =
NULL;
2113 "rcu_torture_stutter");
2114 if (IS_ERR(stutter_task)) {
2115 firsterr = PTR_ERR(stutter_task);
2117 stutter_task =
NULL;
2121 if (fqs_duration < 0)
2127 if (IS_ERR(fqs_task)) {
2128 firsterr = PTR_ERR(fqs_task);
2134 if (test_boost_interval < 1)
2135 test_boost_interval = 1;
2136 if (test_boost_duration < 2)
2137 test_boost_duration = 2;
2138 if ((test_boost == 1 && cur_ops->
can_boost) ||
2141 boost_starttime =
jiffies + test_boost_interval *
HZ;
2142 register_cpu_notifier(&rcutorture_cpu_nb);
2146 retval = rcutorture_booster_init(i);
2153 if (shutdown_secs > 0) {
2154 shutdown_time =
jiffies + shutdown_secs *
HZ;
2156 "rcu_torture_shutdown");
2157 if (IS_ERR(shutdown_task)) {
2158 firsterr = PTR_ERR(shutdown_task);
2160 shutdown_task =
NULL;
2165 i = rcu_torture_onoff_init();
2171 i = rcu_torture_stall_init();
2176 retval = rcu_torture_barrier_init();
2187 rcu_torture_cleanup();