From f85a7fc271b95e35a81a8e6c69d49445b9fd54a1 Mon Sep 17 00:00:00 2001 From: Jim Somerville Date: Fri, 7 Oct 2022 16:30:40 -0400 Subject: [PATCH] rcu: Avoid running boost kthreads on isolated CPUs Problem: The rcub tasks are allowed to run on isolated CPUs. This is a two-fold problem. The first is that these rcub tasks steal precious yielded CPU time away from kworker tasks that need to run on the isolated cpu. The second is that they interfere with nohz_full behavior. Solution: This is already solved for us upstream, so we simply backport the patch here. It affines the rcub tasks away from any nohz_full cpus. Note that even though this issue only pertains to our rt kernel, we also apply the patch to the std kernel for completeness. Verification: - Boot rt kernel without this patch applied, and check the affinity of the rcub tasks. They are set to run on any cpu, even the nohz_full ones. - Boot rt kernel with this patch included, and now see that the nohz_full cpus are excluded from rcub affinity. Closes-Bug: 1992201 Signed-off-by: Jim Somerville Change-Id: I53cbfeddcd7c89b17bd7465134c02311caa7914f --- kernel-rt/centos/kernel-rt.spec | 1 + ...ning-boost-kthreads-on-isolated-CPUs.patch | 39 +++++++++++++++++++ ...ning-boost-kthreads-on-isolated-CPUs.patch | 39 +++++++++++++++++++ kernel-rt/debian/patches/series | 1 + kernel-std/centos/kernel.spec | 1 + ...ning-boost-kthreads-on-isolated-CPUs.patch | 39 +++++++++++++++++++ ...ning-boost-kthreads-on-isolated-CPUs.patch | 39 +++++++++++++++++++ kernel-std/debian/patches/series | 1 + 8 files changed, 160 insertions(+) create mode 100644 kernel-rt/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch create mode 100644 kernel-rt/debian/patches/0034-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch create mode 100644 kernel-std/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch create mode 100644 kernel-std/debian/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch diff --git a/kernel-rt/centos/kernel-rt.spec b/kernel-rt/centos/kernel-rt.spec index 93ffbda5..760ea8e3 100644 --- a/kernel-rt/centos/kernel-rt.spec +++ b/kernel-rt/centos/kernel-rt.spec @@ -808,6 +808,7 @@ Patch28: 0029-Enable-CONFIG_PAGE_POOL-by-default.patch Patch29: 0030-x86-Enumerate-AVX512-FP16-CPUID-feature-flag.patch Patch30: 0031-KVM-x86-Expose-AVX512_FP16-for-supported-CPUID.patch Patch31: 0032-tools-headers-cpufeatures-Sync-with-the-kernel-sourc.patch +Patch32: 0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch # END OF PATCH DEFINITIONS %endif diff --git a/kernel-rt/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch b/kernel-rt/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch new file mode 100644 index 00000000..973f8c16 --- /dev/null +++ b/kernel-rt/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch @@ -0,0 +1,39 @@ +From 547921028c785f90e52adb7f54cc2f13103934de Mon Sep 17 00:00:00 2001 +Message-Id: <547921028c785f90e52adb7f54cc2f13103934de.1665174246.git.jim.somerville@windriver.com> +From: Zqiang +Date: Mon, 15 Nov 2021 13:15:46 +0800 +Subject: [PATCH] rcu: Avoid running boost kthreads on isolated CPUs + +When the boost kthreads are created on systems with nohz_full CPUs, +the cpus_allowed_ptr is set to housekeeping_cpumask(HK_FLAG_KTHREAD). +However, when the rcu_boost_kthread_setaffinity() is called, the original +affinity will be changed and these kthreads can subsequently run on +nohz_full CPUs. This commit makes rcu_boost_kthread_setaffinity() +restrict these boost kthreads to housekeeping CPUs. + +Signed-off-by: Zqiang +Signed-off-by: Paul E. McKenney +[ commit c2cf0767e98eb4487444e5c7ebba491a866811ce upstream ] +Signed-off-by: Jim Somerville +--- + kernel/rcu/tree_plugin.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h +index 9db906dcbdac..0a18fa5d27b3 100644 +--- a/kernel/rcu/tree_plugin.h ++++ b/kernel/rcu/tree_plugin.h +@@ -1185,8 +1185,9 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) + if ((mask & leaf_node_cpu_bit(rnp, cpu)) && + cpu != outgoingcpu) + cpumask_set_cpu(cpu, cm); ++ cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU)); + if (cpumask_weight(cm) == 0) +- cpumask_setall(cm); ++ cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU)); + set_cpus_allowed_ptr(t, cm); + free_cpumask_var(cm); + } +-- +2.25.1 + diff --git a/kernel-rt/debian/patches/0034-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch b/kernel-rt/debian/patches/0034-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch new file mode 100644 index 00000000..973f8c16 --- /dev/null +++ b/kernel-rt/debian/patches/0034-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch @@ -0,0 +1,39 @@ +From 547921028c785f90e52adb7f54cc2f13103934de Mon Sep 17 00:00:00 2001 +Message-Id: <547921028c785f90e52adb7f54cc2f13103934de.1665174246.git.jim.somerville@windriver.com> +From: Zqiang +Date: Mon, 15 Nov 2021 13:15:46 +0800 +Subject: [PATCH] rcu: Avoid running boost kthreads on isolated CPUs + +When the boost kthreads are created on systems with nohz_full CPUs, +the cpus_allowed_ptr is set to housekeeping_cpumask(HK_FLAG_KTHREAD). +However, when the rcu_boost_kthread_setaffinity() is called, the original +affinity will be changed and these kthreads can subsequently run on +nohz_full CPUs. This commit makes rcu_boost_kthread_setaffinity() +restrict these boost kthreads to housekeeping CPUs. + +Signed-off-by: Zqiang +Signed-off-by: Paul E. McKenney +[ commit c2cf0767e98eb4487444e5c7ebba491a866811ce upstream ] +Signed-off-by: Jim Somerville +--- + kernel/rcu/tree_plugin.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h +index 9db906dcbdac..0a18fa5d27b3 100644 +--- a/kernel/rcu/tree_plugin.h ++++ b/kernel/rcu/tree_plugin.h +@@ -1185,8 +1185,9 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) + if ((mask & leaf_node_cpu_bit(rnp, cpu)) && + cpu != outgoingcpu) + cpumask_set_cpu(cpu, cm); ++ cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU)); + if (cpumask_weight(cm) == 0) +- cpumask_setall(cm); ++ cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU)); + set_cpus_allowed_ptr(t, cm); + free_cpumask_var(cm); + } +-- +2.25.1 + diff --git a/kernel-rt/debian/patches/series b/kernel-rt/debian/patches/series index 17ea94e8..4bfa88c8 100644 --- a/kernel-rt/debian/patches/series +++ b/kernel-rt/debian/patches/series @@ -29,3 +29,4 @@ 0031-x86-Enumerate-AVX512-FP16-CPUID-feature-flag.patch 0032-KVM-x86-Expose-AVX512_FP16-for-supported-CPUID.patch 0033-tools-headers-cpufeatures-Sync-with-the-kernel-sourc.patch +0034-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch diff --git a/kernel-std/centos/kernel.spec b/kernel-std/centos/kernel.spec index b2ae98da..0888e4ae 100644 --- a/kernel-std/centos/kernel.spec +++ b/kernel-std/centos/kernel.spec @@ -839,6 +839,7 @@ Patch28: 0029-Enable-CONFIG_PAGE_POOL-by-default.patch Patch29: 0030-x86-Enumerate-AVX512-FP16-CPUID-feature-flag.patch Patch30: 0031-KVM-x86-Expose-AVX512_FP16-for-supported-CPUID.patch Patch31: 0032-tools-headers-cpufeatures-Sync-with-the-kernel-sourc.patch +Patch32: 0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch # END OF PATCH DEFINITIONS %endif diff --git a/kernel-std/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch b/kernel-std/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch new file mode 100644 index 00000000..973f8c16 --- /dev/null +++ b/kernel-std/centos/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch @@ -0,0 +1,39 @@ +From 547921028c785f90e52adb7f54cc2f13103934de Mon Sep 17 00:00:00 2001 +Message-Id: <547921028c785f90e52adb7f54cc2f13103934de.1665174246.git.jim.somerville@windriver.com> +From: Zqiang +Date: Mon, 15 Nov 2021 13:15:46 +0800 +Subject: [PATCH] rcu: Avoid running boost kthreads on isolated CPUs + +When the boost kthreads are created on systems with nohz_full CPUs, +the cpus_allowed_ptr is set to housekeeping_cpumask(HK_FLAG_KTHREAD). +However, when the rcu_boost_kthread_setaffinity() is called, the original +affinity will be changed and these kthreads can subsequently run on +nohz_full CPUs. This commit makes rcu_boost_kthread_setaffinity() +restrict these boost kthreads to housekeeping CPUs. + +Signed-off-by: Zqiang +Signed-off-by: Paul E. McKenney +[ commit c2cf0767e98eb4487444e5c7ebba491a866811ce upstream ] +Signed-off-by: Jim Somerville +--- + kernel/rcu/tree_plugin.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h +index 9db906dcbdac..0a18fa5d27b3 100644 +--- a/kernel/rcu/tree_plugin.h ++++ b/kernel/rcu/tree_plugin.h +@@ -1185,8 +1185,9 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) + if ((mask & leaf_node_cpu_bit(rnp, cpu)) && + cpu != outgoingcpu) + cpumask_set_cpu(cpu, cm); ++ cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU)); + if (cpumask_weight(cm) == 0) +- cpumask_setall(cm); ++ cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU)); + set_cpus_allowed_ptr(t, cm); + free_cpumask_var(cm); + } +-- +2.25.1 + diff --git a/kernel-std/debian/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch b/kernel-std/debian/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch new file mode 100644 index 00000000..973f8c16 --- /dev/null +++ b/kernel-std/debian/patches/0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch @@ -0,0 +1,39 @@ +From 547921028c785f90e52adb7f54cc2f13103934de Mon Sep 17 00:00:00 2001 +Message-Id: <547921028c785f90e52adb7f54cc2f13103934de.1665174246.git.jim.somerville@windriver.com> +From: Zqiang +Date: Mon, 15 Nov 2021 13:15:46 +0800 +Subject: [PATCH] rcu: Avoid running boost kthreads on isolated CPUs + +When the boost kthreads are created on systems with nohz_full CPUs, +the cpus_allowed_ptr is set to housekeeping_cpumask(HK_FLAG_KTHREAD). +However, when the rcu_boost_kthread_setaffinity() is called, the original +affinity will be changed and these kthreads can subsequently run on +nohz_full CPUs. This commit makes rcu_boost_kthread_setaffinity() +restrict these boost kthreads to housekeeping CPUs. + +Signed-off-by: Zqiang +Signed-off-by: Paul E. McKenney +[ commit c2cf0767e98eb4487444e5c7ebba491a866811ce upstream ] +Signed-off-by: Jim Somerville +--- + kernel/rcu/tree_plugin.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h +index 9db906dcbdac..0a18fa5d27b3 100644 +--- a/kernel/rcu/tree_plugin.h ++++ b/kernel/rcu/tree_plugin.h +@@ -1185,8 +1185,9 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) + if ((mask & leaf_node_cpu_bit(rnp, cpu)) && + cpu != outgoingcpu) + cpumask_set_cpu(cpu, cm); ++ cpumask_and(cm, cm, housekeeping_cpumask(HK_FLAG_RCU)); + if (cpumask_weight(cm) == 0) +- cpumask_setall(cm); ++ cpumask_copy(cm, housekeeping_cpumask(HK_FLAG_RCU)); + set_cpus_allowed_ptr(t, cm); + free_cpumask_var(cm); + } +-- +2.25.1 + diff --git a/kernel-std/debian/patches/series b/kernel-std/debian/patches/series index 2b9bd5bf..ad8420dd 100644 --- a/kernel-std/debian/patches/series +++ b/kernel-std/debian/patches/series @@ -28,3 +28,4 @@ 0030-x86-Enumerate-AVX512-FP16-CPUID-feature-flag.patch 0031-KVM-x86-Expose-AVX512_FP16-for-supported-CPUID.patch 0032-tools-headers-cpufeatures-Sync-with-the-kernel-sourc.patch +0033-rcu-Avoid-running-boost-kthreads-on-isolated-CPUs.patch