rcu/nocb: Delete local variable 'need_rcu_nocb_mask' in rcu_init_nohz()
v5 cover rcu/nocb: Delete local variable 'need_rcu_nocb_mask' in rcu_init_nohz()
v4 --> v5:
1. Cancel eliminate rcu_state.nocb_is_setup. It is useful for case 1) below.
Test cases and test results as below:
----------------------------------------------------------------------
| CONFIG_NO_HZ_FULL | CONFIG_RCU_NOCB_CPU_DEFAULT_ALL | cmdline |
----------------------------------------------------------------------
1) N | N | none | 2) N | N | rcu_nocbs=1-2 | 3) Y | N | nohz_full=1-2 | 4) Y | Y | none |
----------------------------------------------------------------------
1)
[ 1018.082417] rcu-torture:--- End of test: SUCCESS (default) root@genericarmv8:~# dmesg | grep "Offload RCU callbacks"
root@genericarmv8:~# zcat /proc/config.gz | grep NOCB CONFIG_RCU_NOCB_CPU=y # CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL # CONFIG_NO_HZ_FULL is not set root@genericarmv8:~# cat /proc/cmdline console=ttyS0 earlyprintk=serial root=/dev/sda rw
2) 3) 4)
The same to v4.
v3 --> v4:
Fix a build warning.
- struct cpumask *cpumask = NULL;
+ const struct cpumask *cpumask = NULL;
v2 --> v3:
1. Eliminate rcu_state.nocb_is_setup
2. Update the code based on the above patch and commit b37a667c6242 ("rcu/nocb: Add an option to offload all CPUs on boot").
Test cases and test results as below:
----------------------------------------------------------------------
| CONFIG_NO_HZ_FULL | CONFIG_RCU_NOCB_CPU_DEFAULT_ALL | cmdline |
----------------------------------------------------------------------
1) N | N | none | 2) N | N | rcu_nocbs=1-2 | 3) Y | N | nohz_full=1-2 | 4) Y | Y | none |
----------------------------------------------------------------------
1)
[ 1085.691770] rcu-torture:--- End of test: SUCCESS: (default) root@genericarmv8:~# dmesg | grep "Offload RCU callbacks" [ 0.000000] rcu: Offload RCU callbacks from CPUs: (none). root@genericarmv8:~# zcat /proc/config.gz | grep NOCB CONFIG_RCU_NOCB_CPU=y # CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL # CONFIG_NO_HZ_FULL is not set root@genericarmv8:~# cat /proc/cmdline console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000
2)
[ 1022.532198] rcu-torture:--- End of test: SUCCESS: (default) root@genericarmv8:~# dmesg | grep "Offload RCU callbacks" [ 0.000000] rcu: Offload RCU callbacks from CPUs: 1-2. root@genericarmv8:~# zcat /proc/config.gz | grep NOCB CONFIG_RCU_NOCB_CPU=y # CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL # CONFIG_NO_HZ_FULL is not set root@genericarmv8:~# cat /proc/cmdline console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000 rcu_nocbs=1-2
3)
[ 1011.714712] rcu-torture:--- End of test: SUCCESS: (default) root@genericarmv8:~# dmesg | grep "Offload RCU callbacks" [ 0.000000] rcu: Offload RCU callbacks from CPUs: 1-2. root@genericarmv8:~# zcat /proc/config.gz | grep NOCB CONFIG_RCU_NOCB_CPU=y # CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL CONFIG_NO_HZ_FULL=y root@genericarmv8:~# cat /proc/cmdline console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000 nohz_full=1-2
4)
[ 1031.047094] rcu-torture:--- End of test: SUCCESS: (default) root@genericarmv8:~# dmesg | grep "Offload RCU callbacks" [ 0.000000] rcu: Offload RCU callbacks from CPUs: 0-3. root@genericarmv8:~# zcat /proc/config.gz | grep NOCB CONFIG_RCU_NOCB_CPU=y CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y root@genericarmv8:~# zcat /proc/config.gz | grep NO_HZ_FULL CONFIG_NO_HZ_FULL=y root@genericarmv8:~# cat /proc/cmdline console=ttyAMA0 root=/dev/vda2 crashkernel=256M@ee000000
v1 --> v2:
Update commit message.
Zhen Lei (1):
rcu: Simplify the code logic of rcu_init_nohz()
kernel/rcu/tree_nocb.h | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-)
Signature · 1 line
2.25.1
PATCH v5 1/1 rcu: Simplify the code logic of rcu_init_nohz()
When CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.
--- kernel/rcu/tree_nocb.h | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-)
kernel/rcu/tree_nocb.h +9 -23
@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Signature · 1 line
2.25.1
Paul E. McKenney
maintainerRe: [PATCH v5 1/1] rcu: Simplify the code logic of rcu_init_nohz()
Quoted 8 lines · Zhen Lei
When
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.Signed-off-by Zhen Lei <[email protected]>
Much nicer, thank you!
As usual, I could not resist the urge to wordsmith. Could you please check to make sure that I did not mess anything up?
Thanx, Paul
------------------------------------------------------------------------
commit 4ac3b3d1a19943b1522c0b1d0895aefbb80ec294
Author: Zhen Lei <[email protected]> Date: Thu Aug 25 17:23:11 2022 +0800
rcu: Simplify rcu_init_nohz() cpumask handling
In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocb_mask= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state.
But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function.
kernel/rcu/tree_nocb.h +9 -23
@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Joel Fernandes
Reviewed-byRe: [PATCH v5 1/1] rcu: Simplify the code logic of rcu_init_nohz()
Quoted 32 lines · Paul E. McKenney
Quoted 8 lines · Zhen Lei
When
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.Signed-off-by Zhen Lei <[email protected]>Much nicer, thank you!
As usual, I could not resist the urge to wordsmith. Could you please check to make sure that I did not mess anything up?
Thanx, Paul
------------------------------------------------------------------------
commit
4ac3b3d1a19943b1522c0b1d0895aefbb80ec294Author: Zhen Lei <[email protected]> Date: Thu Aug 25 17:23:11 2022 +0800rcu: Simplify
rcu_init_nohz()cpumask handlingIn kernels built with either
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs must be added torcu_nocb_mask. Except that kernels booted without the rcu_nocb_mask= will not have allocatedrcu_nocb_mask. And the currentrcu_init_nohz()function uses itsneed_rcu_nocb_maskandoffload_alllocal variables to track thercu_nocbandnohz_fullstate.
Quoted 7 lines
But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using
cpumask_available()to check thercu_nocb_maskstate. This commit takes this approach, thereby simplifying and shortening thercu_init_nohz()function.Signed-off-by Zhen Lei <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>
thanks,
- Joel
Quoted 60 lines
kernel/rcu/tree_nocb.h +9
-23@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Paul E. McKenney
maintainerRe: [PATCH v5 1/1] rcu: Simplify the code logic of rcu_init_nohz()
Quoted 38 lines · Joel Fernandes
Quoted 37 lines · Paul E. McKenney
Quoted 8 lines · Zhen Lei
When
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.Signed-off-by Zhen Lei <[email protected]>Much nicer, thank you!
As usual, I could not resist the urge to wordsmith. Could you please check to make sure that I did not mess anything up?
Thanx, Paul
------------------------------------------------------------------------
commit
4ac3b3d1a19943b1522c0b1d0895aefbb80ec294Author: Zhen Lei <[email protected]> Date: Thu Aug 25 17:23:11 2022 +0800rcu: Simplify
rcu_init_nohz()cpumask handlingIn kernels built with either
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs must be added torcu_nocb_mask. Except that kernels booted without the rcu_nocb_mask= will not have allocatedrcu_nocb_mask. And the currentrcu_init_nohz()function uses itsneed_rcu_nocb_maskandoffload_alllocal variables to track thercu_nocbandnohz_fullstate.But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using
cpumask_available()to check thercu_nocb_maskstate. This commit takes this approach, thereby simplifying and shortening thercu_init_nohz()function.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Zhen Lei <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>Reviewed-by Joel Fernandes (Google) <[email protected]>
Thank you, and I will apply this on the next rebase.
Thanx, Paul
Quoted 65 lines
thanks,
- Joel
Quoted 60 lines
kernel/rcu/tree_nocb.h +9
-23@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,
Re: [PATCH v5 1/1] rcu: Simplify the code logic of rcu_init_nohz()
In reply to Paul E. McKenneyQuoted 8 lines · Paul E. McKenney
Quoted 7 lines · Zhen Lei
When
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.
Quoted 6 lines
Quoted 1 line
Signed-off-by Zhen Lei <[email protected]>Much nicer, thank you!
As usual, I could not resist the urge to wordsmith. Could you please check to make sure that I did not mess anything up?
Okay, thank you very much. The boot option name "rcu_nocb_mask=" is incorrect, should be "rcu_nocbs=".
Quoted 6 lines
Thanx, Paul
------------------------------------------------------------------------
commit
4ac3b3d1a19943b1522c0b1d0895aefbb80ec294
Quoted 8 lines
Author: Zhen Lei <[email protected]> Date: Thu Aug 25 17:23:11 2022 +0800rcu: Simplify
rcu_init_nohz()cpumask handlingIn kernels built with either
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs must be added torcu_nocb_mask. Except that kernels booted without the rcu_nocb_mask= will not have
rcu_nocb_mask= ----> rcu_nocbs=
Quoted 73 lines
allocated
rcu_nocb_mask. And the currentrcu_init_nohz()function uses itsneed_rcu_nocb_maskandoffload_alllocal variables to track thercu_nocbandnohz_fullstate.But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using
cpumask_available()to check thercu_nocb_maskstate. This commit takes this approach, thereby simplifying and shortening thercu_init_nohz()function.Signed-off-by Zhen Lei <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>kernel/rcu/tree_nocb.h +9
-23@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,.
Signature · 2 lines
Regards, Zhen Lei
Paul E. McKenney
maintainerRe: [PATCH v5 1/1] rcu: Simplify the code logic of rcu_init_nohz()
Quoted 13 lines · Leizhen (ThunderTown)
Quoted 10 lines · Paul E. McKenney
Quoted 8 lines · Zhen Lei
When
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs need to be added to 'rcu_nocb_mask'. But 'rcu_nocb_mask' may be not available now, due to 'rcu_nocbs' is not specified. Check and initialize 'rcu_nocb_mask' before using it. This code simplification strictly follows this logic, compared with old implementations, unnecessary crossovers are avoided and easy to understand.Signed-off-by Zhen Lei <[email protected]>
Quoted 7 lines
Quoted 4 lines
Much nicer, thank you!
As usual, I could not resist the urge to wordsmith. Could you please check to make sure that I did not mess anything up?
Okay, thank you very much. The boot option name "rcu_nocb_mask=" is incorrect, should be "rcu_nocbs=".
Good eyes, thank you! I will fix this on the next rebase.
Thanx, Paul
Quoted 91 lines
Quoted 11 lines
------------------------------------------------------------------------
commit
4ac3b3d1a19943b1522c0b1d0895aefbb80ec294Author: Zhen Lei <[email protected]> Date: Thu Aug 25 17:23:11 2022 +0800rcu: Simplify
rcu_init_nohz()cpumask handlingIn kernels built with either
CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=yorCONFIG_NO_HZ_FULL=y, additional CPUs must be added torcu_nocb_mask. Except that kernels booted without the rcu_nocb_mask= will not havercu_nocb_mask= ----> rcu_nocbs=
Quoted 73 lines
allocated
rcu_nocb_mask. And the currentrcu_init_nohz()function uses itsneed_rcu_nocb_maskandoffload_alllocal variables to track thercu_nocbandnohz_fullstate.But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using
cpumask_available()to check thercu_nocb_maskstate. This commit takes this approach, thereby simplifying and shortening thercu_init_nohz()function.Signed-off-by Zhen Lei <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>kernel/rcu/tree_nocb.h +9
-23@@ -1210,45 +1210,31 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);void __init rcu_init_nohz (void ) {int cpu; -bool need_rcu_nocb_mask = false; -bool offload_all = false;struct rcu_data *rdp; +const struct cpumask *cpumask =NULL ;#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL ) -if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ - -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false;/* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + cpumask = cpu_possible_mask; +#elif defined(CONFIG_NO_HZ_FULL ) +if (tick_nohz_full_running && !cpumask_empty (tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif -if (need_rcu_nocb_mask) { +if (cpumask) {if (!cpumask_available (rcu_nocb_mask)) {if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) {pr_info ("rcu_nocb_mask allocation failed, callback offloading disabled.\n" );return ; } } + +cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)return ; -#if defined(CONFIG_NO_HZ_FULL ) -if (tick_nohz_full_running) -cpumask_or (rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - -if (offload_all) -cpumask_setall (rcu_nocb_mask); -if (!cpumask_subset (rcu_nocb_mask, cpu_possible_mask)) {pr_info ("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n" ); cpumask_and(rcu_nocb_mask, cpu_possible_mask,.
Signature · 2 lines
Regards, Zhen Lei