[RFC PATCH v2 16/20] rcu: Make RCU dynticks counter size configurable

Valentin Schneider
2023-07-20T16:40:23Z

CONTEXT_TRACKING_WORK reduces the size of the dynticks counter to free up
some bits for work deferral. Paul suggested making the actual counter size
configurable for rcutorture to poke at, so do that.

Make it only configurable under RCU_EXPERT. Previous commits have added
build-time checks that ensure a kernel with problematic dynticks counter
width can't be built.

Link: http://lore.kernel.org/r/4c2cb573-168f-4806-b1d9-164e8276e66a@paulmck-laptop
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
include/linux/context_tracking.h | 3 ++-
include/linux/context_tracking_state.h | 3 +--
kernel/rcu/Kconfig | 33 ++++++++++++++++++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 8aee086d0a25f..9c0c622bc27bb 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -12,7 +12,8 @@

#ifdef CONFIG_CONTEXT_TRACKING_WORK
static_assert(CONTEXT_WORK_MAX_OFFSET <= CONTEXT_WORK_END + 1 - CONTEXT_WORK_START,
- "Not enough bits for CONTEXT_WORK");
+ "Not enough bits for CONTEXT_WORK, "
+ "CONFIG_RCU_DYNTICKS_BITS might be too high");
#endif

#ifdef CONFIG_CONTEXT_TRACKING_USER
diff --git a/include/linux/context_tracking_state.h b/include/linux/context_tracking_state.h
index 828fcdb801f73..292a0b7c06948 100644
--- a/include/linux/context_tracking_state.h
+++ b/include/linux/context_tracking_state.h
@@ -58,8 +58,7 @@ enum ctx_state {
#define CONTEXT_STATE_START 0
#define CONTEXT_STATE_END (bits_per(CONTEXT_MAX - 1) - 1)

-#define RCU_DYNTICKS_BITS (IS_ENABLED(CONFIG_CONTEXT_TRACKING_WORK) ? 16 : 31)
-#define RCU_DYNTICKS_START (CT_STATE_SIZE - RCU_DYNTICKS_BITS)
+#define RCU_DYNTICKS_START (CT_STATE_SIZE - CONFIG_RCU_DYNTICKS_BITS)
#define RCU_DYNTICKS_END (CT_STATE_SIZE - 1)
#define RCU_DYNTICKS_IDX BIT(RCU_DYNTICKS_START)

diff --git a/kernel/rcu/Kconfig b/kernel/rcu/Kconfig
index bdd7eadb33d8f..1ff2aab24e964 100644
--- a/kernel/rcu/Kconfig
+++ b/kernel/rcu/Kconfig
@@ -332,4 +332,37 @@ config RCU_DOUBLE_CHECK_CB_TIME
Say Y here if you need tighter callback-limit enforcement.
Say N here if you are unsure.

+config RCU_DYNTICKS_RANGE_BEGIN
+ int
+ depends on !RCU_EXPERT
+ default 31 if !CONTEXT_TRACKING_WORK
+ default 16 if CONTEXT_TRACKING_WORK
+
+config RCU_DYNTICKS_RANGE_BEGIN
+ int
+ depends on RCU_EXPERT
+ default 2
+
+config RCU_DYNTICKS_RANGE_END
+ int
+ default 31 if !CONTEXT_TRACKING_WORK
+ default 16 if CONTEXT_TRACKING_WORK
+
+config RCU_DYNTICKS_BITS_DEFAULT
+ int
+ default 31 if !CONTEXT_TRACKING_WORK
+ default 16 if CONTEXT_TRACKING_WORK
+
+config RCU_DYNTICKS_BITS
+ int "Dynticks counter width" if CONTEXT_TRACKING_WORK
+ range RCU_DYNTICKS_RANGE_BEGIN RCU_DYNTICKS_RANGE_END
+ default RCU_DYNTICKS_BITS_DEFAULT
+ help
+ This option controls the width of the dynticks counter.
+
+ Lower values will make overflows more frequent, which will increase
+ the likelihood of extending grace-periods.
+
+ Don't touch this unless you are running some tests.
+
endmenu # "RCU Subsystem"
--
2.31.1