Skip to content

Commit 8d67c15

Browse files
urezkifbq
authored andcommitted
rcutorture: Allow a negative value for nfakewriters
Currently "nfakewriters" parameter can be set to any value but there is no possibility to adjust it automatically based on how many CPUs a system has where a test is run on. To address this, if the "nfakewriters" is set to negative it will be adjusted to num_online_cpus() during torture initialization. Reviewed-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Link: https://lore.kernel.org/r/20250227131613.52683-1-urezki@gmail.com Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent 6ea9a17 commit 8d67c15

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

kernel/rcu/rcutorture.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, srcu, ...)");
147147

148148
static int nrealnocbers;
149149
static int nrealreaders;
150+
static int nrealfakewriters;
150151
static struct task_struct *writer_task;
151152
static struct task_struct **fakewriter_tasks;
152153
static struct task_struct **reader_tasks;
@@ -1728,7 +1729,7 @@ rcu_torture_fakewriter(void *arg)
17281729
do {
17291730
torture_hrtimeout_jiffies(torture_random(&rand) % 10, &rand);
17301731
if (cur_ops->cb_barrier != NULL &&
1731-
torture_random(&rand) % (nfakewriters * 8) == 0) {
1732+
torture_random(&rand) % (nrealfakewriters * 8) == 0) {
17321733
cur_ops->cb_barrier();
17331734
} else {
17341735
switch (synctype[torture_random(&rand) % nsynctypes]) {
@@ -2522,7 +2523,7 @@ rcu_torture_print_module_parms(struct rcu_torture_ops *cur_ops, const char *tag)
25222523
"nocbs_nthreads=%d nocbs_toggle=%d "
25232524
"test_nmis=%d "
25242525
"preempt_duration=%d preempt_interval=%d\n",
2525-
torture_type, tag, nrealreaders, nfakewriters,
2526+
torture_type, tag, nrealreaders, nrealfakewriters,
25262527
stat_interval, verbose, test_no_idle_hz, shuffle_interval,
25272528
stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter,
25282529
test_boost, cur_ops->can_boost,
@@ -3597,7 +3598,7 @@ rcu_torture_cleanup(void)
35973598
rcu_torture_reader_mbchk = NULL;
35983599

35993600
if (fakewriter_tasks) {
3600-
for (i = 0; i < nfakewriters; i++)
3601+
for (i = 0; i < nrealfakewriters; i++)
36013602
torture_stop_kthread(rcu_torture_fakewriter,
36023603
fakewriter_tasks[i]);
36033604
kfree(fakewriter_tasks);
@@ -3994,6 +3995,14 @@ rcu_torture_init(void)
39943995

39953996
rcu_torture_init_srcu_lockdep();
39963997

3998+
if (nfakewriters >= 0) {
3999+
nrealfakewriters = nfakewriters;
4000+
} else {
4001+
nrealfakewriters = num_online_cpus() - 2 - nfakewriters;
4002+
if (nrealfakewriters <= 0)
4003+
nrealfakewriters = 1;
4004+
}
4005+
39974006
if (nreaders >= 0) {
39984007
nrealreaders = nreaders;
39994008
} else {
@@ -4050,8 +4059,9 @@ rcu_torture_init(void)
40504059
writer_task);
40514060
if (torture_init_error(firsterr))
40524061
goto unwind;
4053-
if (nfakewriters > 0) {
4054-
fakewriter_tasks = kcalloc(nfakewriters,
4062+
4063+
if (nrealfakewriters > 0) {
4064+
fakewriter_tasks = kcalloc(nrealfakewriters,
40554065
sizeof(fakewriter_tasks[0]),
40564066
GFP_KERNEL);
40574067
if (fakewriter_tasks == NULL) {
@@ -4060,7 +4070,7 @@ rcu_torture_init(void)
40604070
goto unwind;
40614071
}
40624072
}
4063-
for (i = 0; i < nfakewriters; i++) {
4073+
for (i = 0; i < nrealfakewriters; i++) {
40644074
firsterr = torture_create_kthread(rcu_torture_fakewriter,
40654075
NULL, fakewriter_tasks[i]);
40664076
if (torture_init_error(firsterr))

0 commit comments

Comments
 (0)