Skip to content

Commit b58bdcc

Browse files
Paul E. McKenneypaulmck
authored andcommitted
rcu: Add rcutorture CPU-hotplug capability
Running CPU-hotplug operations concurrently with rcutorture has historically been a good way to find bugs in both RCU and CPU hotplug. This commit therefore adds an rcutorture module parameter called "onoff_interval" that causes a randomly selected CPU-hotplug operation to be executed at the specified interval, in seconds. The default value of "onoff_interval" is zero, which disables rcutorture-instigated CPU-hotplug operations. Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent a95f881 commit b58bdcc

2 files changed

Lines changed: 120 additions & 5 deletions

File tree

‎Documentation/RCU/torture.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ nreaders This is the number of RCU reading threads supported.
6161
To properly exercise RCU implementations with preemptible
6262
read-side critical sections.
6363

64+
onoff_interval
65+
The number of seconds between each attempt to execute a
66+
randomly selected CPU-hotplug operation. Defaults to
67+
zero, which disables CPU hotplugging. In HOTPLUG_CPU=n
68+
kernels, rcutorture will silently refuse to do any
69+
CPU-hotplug operations regardless of what value is
70+
specified for onoff_interval.
71+
6472
shuffle_interval
6573
The number of seconds to keep the test threads affinitied
6674
to a particular subset of the CPUs, defaults to 3 seconds.

‎kernel/rcutorture.c‎

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static int irqreader = 1; /* RCU readers from irq (timers). */
6464
static int fqs_duration; /* Duration of bursts (us), 0 to disable. */
6565
static int fqs_holdoff; /* Hold time within burst (us). */
6666
static int fqs_stutter = 3; /* Wait time between bursts (s). */
67+
static int onoff_interval; /* Wait time between CPU hotplugs, 0=disable. */
6768
static int shutdown_secs; /* Shutdown time (s). <=0 for no shutdown. */
6869
static int test_boost = 1; /* Test RCU prio boost: 0=no, 1=maybe, 2=yes. */
6970
static int test_boost_interval = 7; /* Interval between boost tests, seconds. */
@@ -92,6 +93,8 @@ module_param(fqs_holdoff, int, 0444);
9293
MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
9394
module_param(fqs_stutter, int, 0444);
9495
MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
96+
module_param(onoff_interval, int, 0444);
97+
MODULE_PARM_DESC(onoff_interval, "Time between CPU hotplugs (s), 0=disable");
9598
module_param(shutdown_secs, int, 0444);
9699
MODULE_PARM_DESC(shutdown_secs, "Shutdown time (s), zero to disable.");
97100
module_param(test_boost, int, 0444);
@@ -123,6 +126,9 @@ static struct task_struct *stutter_task;
123126
static struct task_struct *fqs_task;
124127
static struct task_struct *boost_tasks[NR_CPUS];
125128
static struct task_struct *shutdown_task;
129+
#ifdef CONFIG_HOTPLUG_CPU
130+
static struct task_struct *onoff_task;
131+
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
126132

127133
#define RCU_TORTURE_PIPE_LEN 10
128134

@@ -153,6 +159,10 @@ static long n_rcu_torture_boost_rterror;
153159
static long n_rcu_torture_boost_failure;
154160
static long n_rcu_torture_boosts;
155161
static long n_rcu_torture_timers;
162+
static long n_offline_attempts;
163+
static long n_offline_successes;
164+
static long n_online_attempts;
165+
static long n_online_successes;
156166
static struct list_head rcu_torture_removed;
157167
static cpumask_var_t shuffle_tmp_mask;
158168

@@ -1084,7 +1094,8 @@ rcu_torture_printk(char *page)
10841094
cnt += sprintf(&page[cnt],
10851095
"rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d "
10861096
"rtmbe: %d rtbke: %ld rtbre: %ld "
1087-
"rtbf: %ld rtb: %ld nt: %ld",
1097+
"rtbf: %ld rtb: %ld nt: %ld "
1098+
"onoff: %ld/%ld:%ld/%ld",
10881099
rcu_torture_current,
10891100
rcu_torture_current_version,
10901101
list_empty(&rcu_torture_freelist),
@@ -1096,7 +1107,11 @@ rcu_torture_printk(char *page)
10961107
n_rcu_torture_boost_rterror,
10971108
n_rcu_torture_boost_failure,
10981109
n_rcu_torture_boosts,
1099-
n_rcu_torture_timers);
1110+
n_rcu_torture_timers,
1111+
n_online_successes,
1112+
n_online_attempts,
1113+
n_offline_successes,
1114+
n_offline_attempts);
11001115
if (atomic_read(&n_rcu_torture_mberror) != 0 ||
11011116
n_rcu_torture_boost_ktrerror != 0 ||
11021117
n_rcu_torture_boost_rterror != 0 ||
@@ -1260,12 +1275,14 @@ rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, char *tag)
12601275
"shuffle_interval=%d stutter=%d irqreader=%d "
12611276
"fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d "
12621277
"test_boost=%d/%d test_boost_interval=%d "
1263-
"test_boost_duration=%d shutdown_secs=%d\n",
1278+
"test_boost_duration=%d shutdown_secs=%d "
1279+
"onoff_interval=%d\n",
12641280
torture_type, tag, nrealreaders, nfakewriters,
12651281
stat_interval, verbose, test_no_idle_hz, shuffle_interval,
12661282
stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
12671283
test_boost, cur_ops->can_boost,
1268-
test_boost_interval, test_boost_duration, shutdown_secs);
1284+
test_boost_interval, test_boost_duration, shutdown_secs,
1285+
onoff_interval);
12691286
}
12701287

12711288
static struct notifier_block rcutorture_shutdown_nb = {
@@ -1338,7 +1355,7 @@ rcu_torture_shutdown(void *arg)
13381355
schedule_timeout_interruptible(delta);
13391356
jiffies_snap = ACCESS_ONCE(jiffies);
13401357
}
1341-
if (ULONG_CMP_LT(jiffies, shutdown_time)) {
1358+
if (kthread_should_stop()) {
13421359
VERBOSE_PRINTK_STRING("rcu_torture_shutdown task stopping");
13431360
return 0;
13441361
}
@@ -1352,6 +1369,94 @@ rcu_torture_shutdown(void *arg)
13521369
return 0;
13531370
}
13541371

1372+
#ifdef CONFIG_HOTPLUG_CPU
1373+
1374+
/*
1375+
* Execute random CPU-hotplug operations at the interval specified
1376+
* by the onoff_interval.
1377+
*/
1378+
static int
1379+
rcu_torture_onoff(void *arg)
1380+
{
1381+
int cpu;
1382+
int maxcpu = -1;
1383+
DEFINE_RCU_RANDOM(rand);
1384+
1385+
VERBOSE_PRINTK_STRING("rcu_torture_onoff task started");
1386+
for_each_online_cpu(cpu)
1387+
maxcpu = cpu;
1388+
WARN_ON(maxcpu < 0);
1389+
while (!kthread_should_stop()) {
1390+
cpu = (rcu_random(&rand) >> 4) % (maxcpu + 1);
1391+
if (cpu_online(cpu)) {
1392+
if (verbose)
1393+
printk(KERN_ALERT "%s" TORTURE_FLAG
1394+
"rcu_torture_onoff task: offlining %d\n",
1395+
torture_type, cpu);
1396+
n_offline_attempts++;
1397+
if (cpu_down(cpu) == 0) {
1398+
if (verbose)
1399+
printk(KERN_ALERT "%s" TORTURE_FLAG
1400+
"rcu_torture_onoff task: "
1401+
"offlined %d\n",
1402+
torture_type, cpu);
1403+
n_offline_successes++;
1404+
}
1405+
} else {
1406+
if (verbose)
1407+
printk(KERN_ALERT "%s" TORTURE_FLAG
1408+
"rcu_torture_onoff task: onlining %d\n",
1409+
torture_type, cpu);
1410+
n_online_attempts++;
1411+
if (cpu_up(cpu) == 0) {
1412+
if (verbose)
1413+
printk(KERN_ALERT "%s" TORTURE_FLAG
1414+
"rcu_torture_onoff task: "
1415+
"onlined %d\n",
1416+
torture_type, cpu);
1417+
n_online_successes++;
1418+
}
1419+
}
1420+
schedule_timeout_interruptible(onoff_interval * HZ);
1421+
}
1422+
VERBOSE_PRINTK_STRING("rcu_torture_onoff task stopping");
1423+
return 0;
1424+
}
1425+
1426+
static int
1427+
rcu_torture_onoff_init(void)
1428+
{
1429+
if (onoff_interval <= 0)
1430+
return 0;
1431+
onoff_task = kthread_run(rcu_torture_onoff, NULL, "rcu_torture_onoff");
1432+
if (IS_ERR(onoff_task)) {
1433+
onoff_task = NULL;
1434+
return PTR_ERR(onoff_task);
1435+
}
1436+
return 0;
1437+
}
1438+
1439+
static void rcu_torture_onoff_cleanup(void)
1440+
{
1441+
if (onoff_task == NULL)
1442+
return;
1443+
VERBOSE_PRINTK_STRING("Stopping rcu_torture_onoff task");
1444+
kthread_stop(onoff_task);
1445+
}
1446+
1447+
#else /* #ifdef CONFIG_HOTPLUG_CPU */
1448+
1449+
static void
1450+
rcu_torture_onoff_init(void)
1451+
{
1452+
}
1453+
1454+
static void rcu_torture_onoff_cleanup(void)
1455+
{
1456+
}
1457+
1458+
#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
1459+
13551460
static int rcutorture_cpu_notify(struct notifier_block *self,
13561461
unsigned long action, void *hcpu)
13571462
{
@@ -1460,6 +1565,7 @@ rcu_torture_cleanup(void)
14601565
VERBOSE_PRINTK_STRING("Stopping rcu_torture_shutdown task");
14611566
kthread_stop(shutdown_task);
14621567
}
1568+
rcu_torture_onoff_cleanup();
14631569

14641570
/* Wait for all RCU callbacks to fire. */
14651571

@@ -1687,6 +1793,7 @@ rcu_torture_init(void)
16871793
goto unwind;
16881794
}
16891795
}
1796+
rcu_torture_onoff_init();
16901797
register_reboot_notifier(&rcutorture_shutdown_nb);
16911798
rcutorture_record_test_transition();
16921799
mutex_unlock(&fullstop_mutex);

0 commit comments

Comments
 (0)