Skip to content

Commit 8d7dc92

Browse files
committed
rcu: Control grace-period delays directly from value
In a misguided attempt to avoid an #ifdef, the use of the gp_init_delay module parameter was conditioned on the corresponding RCU_TORTURE_TEST_SLOW_INIT Kconfig variable, using IS_ENABLED() at the point of use in the code. This meant that the compiler always saw the delay, which meant that RCU_TORTURE_TEST_SLOW_INIT_DELAY had to be unconditionally defined. This in turn caused "make oldconfig" to ask pointless questions about the value of RCU_TORTURE_TEST_SLOW_INIT_DELAY in cases where it was not even used. This commit avoids these pointless questions by defining gp_init_delay under #ifdef. In one branch, gp_init_delay is initialized to RCU_TORTURE_TEST_SLOW_INIT_DELAY and is also a module parameter (thus allowing boot-time modification), and in the other branch gp_init_delay is a const variable initialized by default to zero. This approach also simplifies the code at the delay point by eliminating the IS_DEFINED(). Because gp_init_delay is constant zero in the no-delay case intended for production use, the "gp_init_delay > 0" check causes the delay to become dead code, as desired in this case. In addition, this commit replaces magic constant "10" with the preprocessor variable PER_RCU_NODE_PERIOD, which controls the number of grace periods that are allowed to elapse at full speed before a delay is inserted. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 590ee7d commit 8d7dc92

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

kernel/rcu/tree.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,14 @@ static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
162162
static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO;
163163
module_param(kthread_prio, int, 0644);
164164

165-
/* Delay in jiffies for grace-period initialization delays. */
166-
static int gp_init_delay = IS_ENABLED(CONFIG_RCU_TORTURE_TEST_SLOW_INIT)
167-
? CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY
168-
: 0;
165+
/* Delay in jiffies for grace-period initialization delays, debug only. */
166+
#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT
167+
static int gp_init_delay = CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY;
169168
module_param(gp_init_delay, int, 0644);
169+
#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
170+
static const int gp_init_delay;
171+
#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
172+
#define PER_RCU_NODE_PERIOD 10 /* Number of grace periods between delays. */
170173

171174
/*
172175
* Track the rcutorture test sequence number and the update version
@@ -1843,9 +1846,8 @@ static int rcu_gp_init(struct rcu_state *rsp)
18431846
raw_spin_unlock_irq(&rnp->lock);
18441847
cond_resched_rcu_qs();
18451848
ACCESS_ONCE(rsp->gp_activity) = jiffies;
1846-
if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_SLOW_INIT) &&
1847-
gp_init_delay > 0 &&
1848-
!(rsp->gpnum % (rcu_num_nodes * 10)))
1849+
if (gp_init_delay > 0 &&
1850+
!(rsp->gpnum % (rcu_num_nodes * PER_RCU_NODE_PERIOD)))
18491851
schedule_timeout_uninterruptible(gp_init_delay);
18501852
}
18511853

lib/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ config RCU_TORTURE_TEST_SLOW_INIT_DELAY
12681268
int "How much to slow down RCU grace-period initialization"
12691269
range 0 5
12701270
default 3
1271+
depends on RCU_TORTURE_TEST_SLOW_INIT
12711272
help
12721273
This option specifies the number of jiffies to wait between
12731274
each rcu_node structure initialization.

0 commit comments

Comments
 (0)