rcu: Improve comments for RCU_FANOUT and RCU_FANOUT_LEAF
PATCH 1/1 rcu: Improve comments for RCU_FANOUT and RCU_FANOUT_LEAF
From: Kunwu Chan <[email protected]>
The original comments introduced in commit 05c5df31afd1 ("rcu: Make RCU able to tolerate undefined CONFIG_RCU_FANOUT"), contained confusing annotations.
Specifically, the #else and #endif comments did not clearly reflect their corresponding condition blocks, hampering readability.
Fixes condition branch comments. And adds explicit explanations of the overall purpose:
defining middle/leaf fan-out parameters, their relation to Kconfig, and how they shape the RCU hierarchy based on CPU count.
Make the hierarchical configuration logic of the RCU easier to understand.
--- include/linux/rcu_node_tree.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
include/linux/rcu_node_tree.h +12 -4
@@ -25,26 +25,34 @@/* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and * CONFIG_RCU_FANOUT_LEAF. +* - RCU_FANOUT: Controls fan-out of middle levels in the RCU hierarchy. +* - RCU_FANOUT_LEAF: Controls fan-out of the leaf level (directly managing CPUs). +* +* These parameters are determined by Kconfig options if configured; otherwise, +* they use sensible defaults based on system architecture (for RCU_FANOUT) +* or a fixed default (for RCU_FANOUT_LEAF). * In theory, it should be possible to add more levels straightforwardly. * In practice, this did work well going from three levels to four. * Of course, your mileage may vary. */ +/* Define RCU_FANOUT: middle-level fan-out parameter */ #ifdef CONFIG_RCU_FANOUT #define RCU_FANOUT CONFIG_RCU_FANOUT -#else /* #ifdef CONFIG_RCU_FANOUT */ +#else /* #ifndef CONFIG_RCU_FANOUT */ # ifdef CONFIG_64BIT # define RCU_FANOUT 64# else # define RCU_FANOUT 32# endif -#endif /* #else #ifdef CONFIG_RCU_FANOUT */ +#endif +/* Define RCU_FANOUT_LEAF: leaf-level fan-out parameter (manages CPUs directly) */ #ifdef CONFIG_RCU_FANOUT_LEAF #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF -#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */ +#else /* #ifndef CONFIG_RCU_FANOUT_LEAF */ #define RCU_FANOUT_LEAF 16 -#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */ +#endif #define RCU_FANOUT_1 (RCU_FANOUT_LEAF)#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
Signature · 1 line
2.25.1
Paul E. McKenney
maintainerQuoted 9 lines · Kunwu Chan
From: Kunwu Chan <[email protected]>
The original comments introduced in commit
05c5df31afd1("rcu: Make RCU able to tolerate undefinedCONFIG_RCU_FANOUT"), contained confusing annotations.Specifically, the #else and #endif comments did not clearly reflect their corresponding condition blocks, hampering readability.
Quoted 8 lines
Fixes condition branch comments. And adds explicit explanations of the overall purpose:
defining middle/leaf fan-out parameters, their relation toKconfig, and how they shape the RCU hierarchy based on CPU count.Make the hierarchical configuration logic of the RCU easier to understand.
Signed-off-by Kunwu Chan <[email protected]>
Thank you for posting this! Please see below for some comments.
Thanx, Paul
Quoted 9 lines
--- include/linux/rcu_node_tree.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)include/linux/rcu_node_tree.h +0
-0
include/linux/rcu_node_tree.h line 33
Quoted 9 lines
include/linux/rcu_node_tree.h +6
-0@@ -25,26 +25,34 @@/* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and * CONFIG_RCU_FANOUT_LEAF. +* - RCU_FANOUT: Controls fan-out of middle levels in the RCU hierarchy. +* - RCU_FANOUT_LEAF: Controls fan-out of the leaf level (directly managing CPUs). +* +* These parameters are determined by Kconfig options if configured; otherwise, +* they use sensible defaults based on system architecture (for RCU_FANOUT) +* or a fixed default (for RCU_FANOUT_LEAF).
I have no objections to this change if at least one of my fellow maintainers is willing to speak up for it and none of the others object to it.
Quoted 16 lines
include/linux/rcu_node_tree.h +2
-2* In theory, it should be possible to add more levels straightforwardly. * In practice, this did work well going from three levels to four. * Of course, your mileage may vary. */ +/* Define RCU_FANOUT: middle-level fan-out parameter */ #ifdef CONFIG_RCU_FANOUT #define RCU_FANOUT CONFIG_RCU_FANOUT -#else /* #ifdef CONFIG_RCU_FANOUT */ +#else /* #ifndef CONFIG_RCU_FANOUT */ # ifdef CONFIG_64BIT # define RCU_FANOUT 64# else # define RCU_FANOUT 32# endif -#endif /* #else #ifdef CONFIG_RCU_FANOUT */
include/linux/rcu_node_tree.h line 55
Quoted 10 lines
include/linux/rcu_node_tree.h +4
-2+#endif +/* Define RCU_FANOUT_LEAF: leaf-level fan-out parameter (manages CPUs directly) */ #ifdef CONFIG_RCU_FANOUT_LEAF #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF -#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */ +#else /* #ifndef CONFIG_RCU_FANOUT_LEAF */ #define RCU_FANOUT_LEAF 16 -#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */ +#endif
But these much stay as they are. The #else echos the "#if" condition, and the #endif contains "#else" followed by the "#if" condition. This means that you can tell where you are without having to find the matching "#if" and without having to figure out whether there is an intervening "#else".
Quoted 5 lines
include/linux/rcu_node_tree.h +0
-0#define RCU_FANOUT_1 (RCU_FANOUT_LEAF)#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)Signature · 1 line
2.25.1
Quoted 62 lines · Paul E. McKenney
Quoted 9 lines · Kunwu Chan
From: Kunwu Chan <[email protected]>
The original comments introduced in commit
05c5df31afd1("rcu: Make RCU able to tolerate undefinedCONFIG_RCU_FANOUT"), contained confusing annotations.Specifically, the #else and #endif comments did not clearly reflect their corresponding condition blocks, hampering readability.
Quoted 8 lines
Fixes condition branch comments. And adds explicit explanations of the overall purpose:
defining middle/leaf fan-out parameters, their relation toKconfig, and how they shape the RCU hierarchy based on CPU count.Make the hierarchical configuration logic of the RCU easier to understand.
Signed-off-by Kunwu Chan <[email protected]>Thank you for posting this! Please see below for some comments.
Thanx, Paul
Quoted 9 lines
--- include/linux/rcu_node_tree.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)include/linux/rcu_node_tree.h +0
-0include/linux/rcu_node_tree.h line 33
Quoted 9 lines
include/linux/rcu_node_tree.h +6
-0@@ -25,26 +25,34 @@/* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and * CONFIG_RCU_FANOUT_LEAF. +* - RCU_FANOUT: Controls fan-out of middle levels in the RCU hierarchy. +* - RCU_FANOUT_LEAF: Controls fan-out of the leaf level (directly managing CPUs). +* +* These parameters are determined by Kconfig options if configured; otherwise, +* they use sensible defaults based on system architecture (for RCU_FANOUT) +* or a fixed default (for RCU_FANOUT_LEAF). I have no objections to this change if at least one of my fellow maintainers is willing to speak up for it and none of the others object to it.
Quoted 18 lines
include/linux/rcu_node_tree.h +3
-2* In theory, it should be possible to add more levels straightforwardly. * In practice, this did work well going from three levels to four. * Of course, your mileage may vary. */ +/* Define RCU_FANOUT: middle-level fan-out parameter */ #ifdef CONFIG_RCU_FANOUT #define RCU_FANOUT CONFIG_RCU_FANOUT -#else /* #ifdef CONFIG_RCU_FANOUT */ +#else /* #ifndef CONFIG_RCU_FANOUT */ # ifdef CONFIG_64BIT # define RCU_FANOUT 64# else # define RCU_FANOUT 32# endif -#endif /* #else #ifdef CONFIG_RCU_FANOUT */ +#endif
Quoted 12 lines
include/linux/rcu_node_tree.h line 55
Quoted 8 lines
include/linux/rcu_node_tree.h +3
-2+/* Define RCU_FANOUT_LEAF: leaf-level fan-out parameter (manages CPUs directly) */ #ifdef CONFIG_RCU_FANOUT_LEAF #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF -#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */ +#else /* #ifndef CONFIG_RCU_FANOUT_LEAF */ #define RCU_FANOUT_LEAF 16 -#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */ +#endif But these much stay as they are. The #else echos the "#if" condition, and the #endif contains "#else" followed by the "#if" condition. This means that you can tell where you are without having to find the matching "#if" and without having to figure out whether there is an intervening "#else".
Hi Paul,
Thank you for the feedback! I reviewed Documentation/process/coding-style.rst and found the guidance on #endif comments (section 19), but I didn't find explicit guidance on the #else comment format. I wasn't aware of the specific convention used in the RCU codebase for #else and #endif directives. I understand now that this format helps readers quickly identify which conditional branch they're in without having to search backwards for the matching #if.
I'll prepare a V2 patch that restores the original #else and #endif comment format while keeping the new explanatory comments about RCU_FANOUT and RCU_FANOUT_LEAF.
Quoted 6 lines
Quoted 6 lines
include/linux/rcu_node_tree.h +0
-0#define RCU_FANOUT_1 (RCU_FANOUT_LEAF)#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)Signature · 1 line
2.25.1
Signature · 2 lines
Thanks,
Kunwu Chan.PATCH v2 1/1 rcu: Improve comments for RCU_FANOUT and RCU_FANOUT_LEAF
In reply to Paul E. McKenneyFrom: Kunwu Chan <[email protected]>
Add explicit explanations of the overall purpose of RCU_FANOUT and RCU_FANOUT_LEAF parameters: defining middle/leaf fan-out parameters, their relation to Kconfig, and how they shape the RCU hierarchy based on CPU count.
This makes the hierarchical configuration logic of the RCU easier to understand.
---
Changes in v2:
- Restores the original #else #endif comment format
- Reword commit msg
--- include/linux/rcu_node_tree.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/rcu_node_tree.h +8 -0
@@ -25,11 +25,18 @@/* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and * CONFIG_RCU_FANOUT_LEAF. +* - RCU_FANOUT: Controls fan-out of middle levels in the RCU hierarchy. +* - RCU_FANOUT_LEAF: Controls fan-out of the leaf level (directly managing CPUs). +* +* These parameters are determined by Kconfig options if configured; otherwise, +* they use sensible defaults based on system architecture (for RCU_FANOUT) +* or a fixed default (for RCU_FANOUT_LEAF). * In theory, it should be possible to add more levels straightforwardly. * In practice, this did work well going from three levels to four. * Of course, your mileage may vary. */ +/* Define RCU_FANOUT: middle-level fan-out parameter */ #ifdef CONFIG_RCU_FANOUT #define RCU_FANOUT CONFIG_RCU_FANOUT#else /* #ifdef CONFIG_RCU_FANOUT */
@@ -40,6 +47,7 @@# endif #endif /* #else #ifdef CONFIG_RCU_FANOUT */ +/* Define RCU_FANOUT_LEAF: leaf-level fan-out parameter (manages CPUs directly) */ #ifdef CONFIG_RCU_FANOUT_LEAF #define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
Signature · 1 line
2.25.1