Dynamic Housekeeping Management (DHM) via CPUSets
Subsystems (11)
v2 cover Dynamic Housekeeping Management (DHM) via CPUSets
This series introduces Dynamic Housekeeping Management (DHM) to the Linux kernel.
Previously known as the DHEI (Dynamic Housekeeping Environment Interface) patchset (RFC and v1), this series has been fundamentally refactored in response to upstream feedback. The custom sysfs interface has been entirely dropped. Instead, DHM is now natively integrated into the cgroup v2 cpuset controller.
By exposing cpuset.housekeeping.cpus on the root cgroup, system administrators and workload orchestrators (like Kubernetes) can dynamically update the kernel's global housekeeping masks at runtime, without requiring a node reboot.
This version provides dynamic reconfiguration support for the following subsystems:
- RCU (NOCB offloading)
- Tick/NOHZ (Full dynticks)
- Global Workqueues and Timers
- Managed Interrupts (genirq)
- Hardlockup Detectors (Watchdog)
- Scheduler Domains (Isolation)
- Memory Management (vmstat/lru_add_drain)
- Kthreads and Softirqs (Affinity)
Many thanks to the maintainers for the valuable guidance that led to this significantly improved and upstream-aligned architecture.
To: Ingo Molnar <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Juri Lelli <[email protected]>
To: Vincent Guittot <[email protected]>
To: Dietmar Eggemann <[email protected]>
To: Steven Rostedt <[email protected]>
To: Ben Segall <[email protected]>
To: Mel Gorman <[email protected]>
To: Valentin Schneider <[email protected]>
To: Paul E. McKenney <[email protected]>
To: Frederic Weisbecker <[email protected]>
To: Neeraj Upadhyay <[email protected]>
To: Joel Fernandes <[email protected]>
To: Josh Triplett <[email protected]>
To: Boqun Feng <[email protected]>
To: Uladzislau Rezki <[email protected]>
To: Mathieu Desnoyers <[email protected]>
To: Lai Jiangshan <[email protected]>
To: Zqiang <[email protected]>
To: Anna-Maria Behnsen <[email protected]>
To: Ingo Molnar <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Tejun Heo <[email protected]>
To: Andrew Morton <[email protected]>
To: Vlastimil Babka <[email protected]>
To: Suren Baghdasaryan <[email protected]>
To: Michal Hocko <[email protected]>
To: Brendan Jackman <[email protected]>
To: Johannes Weiner <[email protected]>
To: Zi Yan <[email protected]>
To: Waiman Long <[email protected]>
To: Chen Ridong <[email protected]>
To: Michal Koutný <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Changes in v2:
- Rebranded series from DHEI to DHM (Dynamic Housekeeping Management).
- Entirely dropped custom sysfs interface.
- Integrated housekeeping control into cgroup v2 cpuset controller at the root level.
- Added SMT-aware pipeline logic (cpuset.housekeeping.smt_aware) to prevent splitting SMT siblings.
- Added comprehensive documentation and cgroup functional selftests for the DHM APIs.
- Refactored the internal mask transition logic to use RCU-safe handover.
- Separated patch series into 4 logical phases for review.
v1 Link: https://lore.kernel.org/all/[email protected]
---
Qiliang Yuan (12):
sched/isolation: Separate housekeeping types in enum hk_type sched/isolation: Introduce housekeeping notifier infrastructure
rcu: Support runtime NOCB initialization and dynamic offloading tick/nohz: Transition to dynamic full dynticks state management
genirq: Support dynamic migration for managed interrupts
watchdog: Allow runtime toggle of lockup detector affinity sched/core: Dynamically update scheduler domain housekeeping mask workqueue, mm: Support dynamic housekeeping mask updates cgroup/cpuset: Introduce CPUSet-driven dynamic housekeeping (DHM) cgroup/cpuset: Implement SMT-aware grouping and safety guards
Documentation: cgroup-v2: Document dynamic housekeeping (DHM)
selftests: cgroup: Add functional tests for dynamic housekeeping
Documentation/admin-guide/cgroup-v2.rst | 24 +++++ include/linux/sched/isolation.h | 51 ++++++++--- kernel/cgroup/cpuset-internal.h | 2 + kernel/cgroup/cpuset.c | 73 +++++++++++++++ kernel/irq/manage.c | 49 ++++++++++ kernel/rcu/rcu.h | 4 + kernel/rcu/tree.c | 75 ++++++++++++++++ kernel/rcu/tree.h | 2 +- kernel/rcu/tree_nocb.h | 31 ++++--- kernel/sched/core.c | 23 +++++ kernel/sched/isolation.c | 74 ++++++++++++++- kernel/time/tick-sched.c | 130 +++++++++++++++++++++------ kernel/watchdog.c | 26 ++++++ kernel/workqueue.c | 42 +++++++++ mm/compaction.c | 27 ++++++ tools/testing/selftests/cgroup/test_cpuset.c | 36 ++++++++ 16 files changed, 620 insertions(+), 49 deletions(-)
---
base-commit: bfe62a454542cfad3379f6ef5680b125f41e20f4
change-id: 20260408-wujing-dhm-8f43e2d49cd8
Best regards,
Signature · 1 line
Qiliang Yuan <[email protected]>
PATCH v2 1/12 sched/isolation: Separate housekeeping types in enum hk_type
Most kernel noise types (TICK, TIMER, RCU, etc.) are currently aliased to a single HK_TYPE_KERNEL_NOISE enum value. This prevents fine-grained runtime isolation control as all masks are forced to be identical.
Un-alias service-specific housekeeping types in enum hk_type. This separation provides the necessary granularity for DHM subsystems to subscribe to and maintain independent affinity masks.
--- include/linux/sched/isolation.h | 20 ++++++++------------ kernel/sched/isolation.c | 10 +++++++++- 2 files changed, 17 insertions(+), 13 deletions(-)
include/linux/sched/isolation.h +8 -12
@@ -17,21 +17,17 @@ enum hk_type {/* Inverse of boot-time isolcpus=managed_irq argument */ HK_TYPE_MANAGED_IRQ ,/* Inverse of boot-time nohz_full= or isolcpus=nohz arguments */ -HK_TYPE_KERNEL_NOISE , +HK_TYPE_TICK , +HK_TYPE_TIMER , +HK_TYPE_RCU , +HK_TYPE_MISC , +HK_TYPE_WQ , +HK_TYPE_KTHREAD , HK_TYPE_MAX, - -/* -* The following housekeeping types are only set by the nohz_full -* boot commandline option. So they can share the same value. -*/ -HK_TYPE_TICK =HK_TYPE_KERNEL_NOISE , -HK_TYPE_TIMER =HK_TYPE_KERNEL_NOISE , -HK_TYPE_RCU =HK_TYPE_KERNEL_NOISE , -HK_TYPE_MISC =HK_TYPE_KERNEL_NOISE , -HK_TYPE_WQ =HK_TYPE_KERNEL_NOISE , -HK_TYPE_KTHREAD =HK_TYPE_KERNEL_NOISE }; +#define HK_TYPE_KERNEL_NOISE HK_TYPE_TICK +#ifdef CONFIG_CPU_ISOLATION DECLARE_STATIC_KEY_FALSE (housekeeping_overridden);extern int housekeeping_any_cpu (enum hk_type type);
kernel/sched/isolation.c +9 -1
@@ -15,9 +15,17 @@ enum hk_flags {HK_FLAG_DOMAIN_BOOT =BIT (HK_TYPE_DOMAIN_BOOT ),HK_FLAG_DOMAIN =BIT (HK_TYPE_DOMAIN ),HK_FLAG_MANAGED_IRQ =BIT (HK_TYPE_MANAGED_IRQ ), -HK_FLAG_KERNEL_NOISE =BIT (HK_TYPE_KERNEL_NOISE ), +HK_FLAG_TICK =BIT (HK_TYPE_TICK ), +HK_FLAG_TIMER =BIT (HK_TYPE_TIMER ), +HK_FLAG_RCU =BIT (HK_TYPE_RCU ), +HK_FLAG_MISC =BIT (HK_TYPE_MISC ), +HK_FLAG_WQ =BIT (HK_TYPE_WQ ), + HK_FLAG_KTHREAD = BIT(HK_TYPE_KTHREAD), }; +#define HK_FLAG_KERNEL_NOISE (HK_FLAG_TICK | HK_FLAG_TIMER | HK_FLAG_RCU | \ + HK_FLAG_MISC | HK_FLAG_WQ | HK_FLAG_KTHREAD) +DEFINE_STATIC_KEY_FALSE (housekeeping_overridden);EXPORT_SYMBOL_GPL (housekeeping_overridden);
Signature · 1 line
2.43.0
Waiman Long
maintainerRe: [PATCH v2 01/12] sched/isolation: Separate housekeeping types in enum hk_type
Quoted 7 lines · Qiliang Yuan
Most kernel noise types (TICK, TIMER, RCU, etc.) are currently aliased to a single
HK_TYPE_KERNEL_NOISEenum value. This prevents fine-grained runtime isolation control as all masks are forced to be identical.Un-alias service-specific housekeeping types in enum
hk_type. This separation provides the necessary granularity for DHM subsystems to subscribe to and maintain independent affinity masks.
Usually, if we want to run a latency sensitive workload like DPDK, we try to minimize all sorts of kernel noises or interference as much as possible. Do you have a good use case where it is advantageous to remove some types of kernel noises from a given set of CPUs but not the others?
Cheers,
Longman
Quoted 64 lines
Signed-off-by Qiliang Yuan <[email protected]>--- include/linux/sched/isolation.h | 20 ++++++++------------ kernel/sched/isolation.c | 10 +++++++++- 2 files changed, 17 insertions(+), 13 deletions(-)include/linux/sched/isolation.h +8
-12@@ -17,21 +17,17 @@ enum hk_type {/* Inverse of boot-time isolcpus=managed_irq argument */ HK_TYPE_MANAGED_IRQ ,/* Inverse of boot-time nohz_full= or isolcpus=nohz arguments */ -HK_TYPE_KERNEL_NOISE , +HK_TYPE_TICK , +HK_TYPE_TIMER , +HK_TYPE_RCU , +HK_TYPE_MISC , +HK_TYPE_WQ , +HK_TYPE_KTHREAD , HK_TYPE_MAX, - -/* -* The following housekeeping types are only set by the nohz_full -* boot commandline option. So they can share the same value. -*/ -HK_TYPE_TICK =HK_TYPE_KERNEL_NOISE , -HK_TYPE_TIMER =HK_TYPE_KERNEL_NOISE , -HK_TYPE_RCU =HK_TYPE_KERNEL_NOISE , -HK_TYPE_MISC =HK_TYPE_KERNEL_NOISE , -HK_TYPE_WQ =HK_TYPE_KERNEL_NOISE , -HK_TYPE_KTHREAD =HK_TYPE_KERNEL_NOISE }; +#define HK_TYPE_KERNEL_NOISE HK_TYPE_TICK +#ifdef CONFIG_CPU_ISOLATION DECLARE_STATIC_KEY_FALSE (housekeeping_overridden);extern int housekeeping_any_cpu (enum hk_type type);kernel/sched/isolation.c +9
-1@@ -15,9 +15,17 @@ enum hk_flags {HK_FLAG_DOMAIN_BOOT =BIT (HK_TYPE_DOMAIN_BOOT ),HK_FLAG_DOMAIN =BIT (HK_TYPE_DOMAIN ),HK_FLAG_MANAGED_IRQ =BIT (HK_TYPE_MANAGED_IRQ ), -HK_FLAG_KERNEL_NOISE =BIT (HK_TYPE_KERNEL_NOISE ), +HK_FLAG_TICK =BIT (HK_TYPE_TICK ), +HK_FLAG_TIMER =BIT (HK_TYPE_TIMER ), +HK_FLAG_RCU =BIT (HK_TYPE_RCU ), +HK_FLAG_MISC =BIT (HK_TYPE_MISC ), +HK_FLAG_WQ =BIT (HK_TYPE_WQ ), + HK_FLAG_KTHREAD = BIT(HK_TYPE_KTHREAD), }; +#define HK_FLAG_KERNEL_NOISE (HK_FLAG_TICK | HK_FLAG_TIMER | HK_FLAG_RCU | \ + HK_FLAG_MISC | HK_FLAG_WQ | HK_FLAG_KTHREAD) +DEFINE_STATIC_KEY_FALSE (housekeeping_overridden);EXPORT_SYMBOL_GPL (housekeeping_overridden);
Frederic Weisbecker
maintainerRe: [PATCH v2 01/12] sched/isolation: Separate housekeeping types in enum hk_type
Quoted 5 lines · Waiman Long
Quoted 4 lines · Qiliang Yuan
Most kernel noise types (TICK, TIMER, RCU, etc.) are currently aliased to a single
HK_TYPE_KERNEL_NOISEenum value. This prevents fine-grained runtime isolation control as all masks are forced to be identical.
Quoted 8 lines
Quoted 3 lines
Un-alias service-specific housekeeping types in enum
hk_type. This separation provides the necessary granularity for DHM subsystems to subscribe to and maintain independent affinity masks.Usually, if we want to run a latency sensitive workload like DPDK, we try to minimize all sorts of kernel noises or interference as much as possible. Do you have a good use case where it is advantageous to remove some types of kernel noises from a given set of CPUs but not the others?
Right what we want to do here is to remove the aliases (HK_TYPE_TIMER, HK_TYPE_WQ, ...) and rename them to HK_TYPE_KERNEL_NOISE.
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH v2 2/12 sched/isolation: Introduce housekeeping notifier infrastructure
In reply to Qiliang YuanSubsystems currently rely on static housekeeping masks determined at boot. Supporting runtime reconfiguration (DHM v2) requires a mechanism to broadcast mask changes to affected kernel components.
Implement a blocking notifier chain for housekeeping mask updates. This infrastructure enables subsystems like genirq, workqueues, and RCU to react dynamically to isolation changes triggered by cpusets.
--- include/linux/sched/isolation.h | 21 +++++++++++++++++++++ kernel/sched/isolation.c | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
include/linux/sched/isolation.h +21 -0
@@ -4,6 +4,7 @@#include <linux/cpumask.h> #include <linux/init.h> #include <linux/tick.h> +#include <linux/notifier.h> enum hk_type {/* Inverse of boot-time isolcpus= argument */
@@ -28,6 +29,13 @@ enum hk_type {#define HK_TYPE_KERNEL_NOISE HK_TYPE_TICK +struct housekeeping_update { +enum hk_type type; +const struct cpumask *new_mask; +}; + +#define HK_UPDATE_MASK 0x01 +#ifdef CONFIG_CPU_ISOLATION DECLARE_STATIC_KEY_FALSE (housekeeping_overridden);extern int housekeeping_any_cpu (enum hk_type type);
@@ -38,6 +46,9 @@ extern bool housekeeping_test_cpu(int cpu, enum hk_type type);extern int housekeeping_update (struct cpumask *isol_mask);extern void __init housekeeping_init (void ); +extern int housekeeping_register_notifier (struct notifier_block *nb); +extern int housekeeping_unregister_notifier (struct notifier_block *nb); +#else static inline int housekeeping_any_cpu (enum hk_type type)
@@ -65,6 +76,16 @@ static inline bool housekeeping_test_cpu(int cpu, enum hk_type type)static inline int housekeeping_update (struct cpumask *isol_mask) {return 0 ; }static inline void housekeeping_init (void ) { } + +static inline int housekeeping_register_notifier (struct notifier_block *nb) +{ +return 0 ; +} + +static inline int housekeeping_unregister_notifier (struct notifier_block *nb) +{ +return 0 ; +}#endif /* CONFIG_CPU_ISOLATION */ static inline bool housekeeping_cpu (int cpu,enum hk_type type)
kernel/sched/isolation.c +26 -0
@@ -10,6 +10,7 @@#include <linux/sched/isolation.h> #include <linux/pci.h> #include "sched.h" +#include <linux/notifier.h> enum hk_flags {HK_FLAG_DOMAIN_BOOT =BIT (HK_TYPE_DOMAIN_BOOT ),
@@ -26,6 +27,8 @@ enum hk_flags {#define HK_FLAG_KERNEL_NOISE (HK_FLAG_TICK | HK_FLAG_TIMER | HK_FLAG_RCU | \ HK_FLAG_MISC | HK_FLAG_WQ | HK_FLAG_KTHREAD) +static BLOCKING_NOTIFIER_HEAD (housekeeping_notifier_list); +DEFINE_STATIC_KEY_FALSE (housekeeping_overridden);EXPORT_SYMBOL_GPL (housekeeping_overridden);
@@ -170,6 +173,29 @@ int housekeeping_update(struct cpumask *isol_mask)return 0 ; } +int housekeeping_register_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_register (&housekeeping_notifier_list, nb); +} +EXPORT_SYMBOL_GPL (housekeeping_register_notifier); + +int housekeeping_unregister_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_unregister (&housekeeping_notifier_list, nb); +} +EXPORT_SYMBOL_GPL (housekeeping_unregister_notifier); + +int housekeeping_update_notify (enum hk_type type,const struct cpumask *new_mask) +{ +struct housekeeping_update update = { + .type = type, + .new_mask = new_mask, + }; + +return blocking_notifier_call_chain (&housekeeping_notifier_list,HK_UPDATE_MASK , &update); +} +EXPORT_SYMBOL_GPL (housekeeping_update_notify); +void __init housekeeping_init (void ) {enum hk_type type;
Signature · 1 line
2.43.0
Thomas Gleixner
maintainerRe: [PATCH v2 02/12] sched/isolation: Introduce housekeeping notifier infrastructure
kernel/sched/isolation.c int housekeeping_update(struct cpumask *isol_mask) · line 186
Quoted 12 lines · Qiliang Yuan
kernel/sched/isolation.c +11
-0+int housekeeping_register_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_register (&housekeeping_notifier_list, nb); +} +EXPORT_SYMBOL_GPL (housekeeping_register_notifier); + +int housekeeping_unregister_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_unregister (&housekeeping_notifier_list, nb); +} +EXPORT_SYMBOL_GPL (housekeeping_unregister_notifier);
As I said before, notifiers are a horrible interface especially for things where most callers are built-in. Especially providing proper ordering of the callbacks is a badly defined mechanism as demonstrated by the now eliminated CPU hotplug notifiers.
kernel/sched/isolation.c int housekeeping_update(struct cpumask *isol_mask) · line 197
Quoted 10 lines
kernel/sched/isolation.c +10
-0+int housekeeping_update_notify (enum hk_type type,const struct cpumask *new_mask) +{ +struct housekeeping_update update = { + .type = type, + .new_mask = new_mask, + }; + +return blocking_notifier_call_chain (&housekeeping_notifier_list,HK_UPDATE_MASK , &update); +} +EXPORT_SYMBOL_GPL (housekeeping_update_notify);
Why is this exported? Are random modules allowed to invoke this?
PATCH v2 3/12 rcu: Support runtime NOCB initialization and dynamic offloading
In reply to Qiliang YuanContext:
The RCU Non-Callback (NOCB) infrastructure traditionally requires boot-time parameters (e.g., rcu_nocbs) to allocate masks and spawn management kthreads (rcuog/rcuo). This prevents systems from activating offloading on-demand without a reboot.
Problem:
Dynamic Housekeeping Management requires CPUs to transition to NOCB mode at runtime when they are newly isolated. Without boot-time setup, the NOCB masks are unallocated, and critical kthreads are missing, preventing effective tick suppression and isolation.
Solution:
Refactor RCU initialization to support dynamic on-demand setup.
- Introduce rcu_init_nocb_dynamic() to allocate masks and organize kthreads if the system wasn't initially configured for NOCB.
- Introduce rcu_housekeeping_reconfigure() to iterate over CPUs and perform safe offload/deoffload transitions via hotplug sequences (cpu_down -> offload -> cpu_up) when a housekeeping cpuset triggers a notifier event.
- Remove __init from rcu_organize_nocb_kthreads to allow runtime reconfiguration of the callback management hierarchy.
This enables a true "Zero-Conf" isolation experience where any CPU can be fully isolated at runtime regardless of boot parameters.
--- kernel/rcu/rcu.h | 4 +++ kernel/rcu/tree.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/tree.h | 2 +- kernel/rcu/tree_nocb.h | 31 +++++++++++++-------- 4 files changed, 100 insertions(+), 12 deletions(-)
kernel/rcu/rcu.h +4 -0
@@ -663,8 +663,12 @@ unsigned long srcu_batches_completed(struct srcu_struct *sp);#endif // #else // #ifdef CONFIG_TINY_SRCU #ifdef CONFIG_RCU_NOCB_CPU +void rcu_init_nocb_dynamic (void ); +void rcu_spawn_cpu_nocb_kthread (int cpu);void rcu_bind_current_to_nocb (void );#else +static inline void rcu_init_nocb_dynamic (void ) { } +static inline void rcu_spawn_cpu_nocb_kthread (int cpu) { }static inline void rcu_bind_current_to_nocb (void ) { }#endif
kernel/rcu/tree.c +75 -0
79 lines not on this page · raw message
kernel/rcu/tree.h +1 -1
@@ -517,7 +517,7 @@ static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp, unsigned long flags);static void rcu_lockdep_assert_cblist_protected (struct rcu_data *rdp);#ifdef CONFIG_RCU_NOCB_CPU -static void __init rcu_organize_nocb_kthreads (void ); +static void rcu_organize_nocb_kthreads (void );/* * Disable IRQs before checking offloaded state so that local
kernel/rcu/tree_nocb.h +20 -11
@@ -1259,6 +1259,22 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) }#endif // #ifdef CONFIG_RCU_LAZY +void rcu_init_nocb_dynamic (void ) +{ +if (rcu_state.nocb_is_setup) +return ; + +if (!cpumask_available (rcu_nocb_mask)) { +if (!zalloc_cpumask_var (&rcu_nocb_mask,GFP_KERNEL )) { +pr_info ("rcu_nocb_mask allocation failed, dynamic offloading disabled.\n" ); +return ; + } + } + + rcu_state.nocb_is_setup = true; +rcu_organize_nocb_kthreads (); +} +void __init rcu_init_nohz (void ) {int cpu;
@@ -1276,15 +1292,8 @@ void __init rcu_init_nohz(void) cpumask = cpu_possible_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 ; - } - } - +rcu_init_nocb_dynamic ();cpumask_or (rcu_nocb_mask, rcu_nocb_mask, cpumask); - rcu_state.nocb_is_setup = true; }if (!rcu_state.nocb_is_setup)
@@ -1344,7 +1353,7 @@ static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)* rcuo CB kthread, spawn it. Additionally, if the rcuo GP kthread * for this CPU's group has not yet been created, spawn it as well. */ -static void rcu_spawn_cpu_nocb_kthread (int cpu) +void rcu_spawn_cpu_nocb_kthread (int cpu) {struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_data *rdp_gp;
@@ -1416,7 +1425,7 @@ module_param(rcu_nocb_gp_stride, int, 0444);/* * Initialize GP-CB relationships for all no-CBs CPU. */ -static void __init rcu_organize_nocb_kthreads (void ) +static void rcu_organize_nocb_kthreads (void ) {int cpu;bool firsttime = true;
@@ -1668,7 +1677,7 @@ static bool do_nocb_deferred_wakeup(struct rcu_data *rdp)return false; } -static void rcu_spawn_cpu_nocb_kthread (int cpu) +void rcu_spawn_cpu_nocb_kthread (int cpu) { }
Signature · 1 line
2.43.0
Frederic Weisbecker
maintainerRe: [PATCH v2 03/12] rcu: Support runtime NOCB initialization and dynamic offloading
Quoted 73 lines · Qiliang Yuan
Context:
The RCU Non-Callback (NOCB) infrastructure traditionally requires boot-time parameters (e.g.,rcu_nocbs) to allocate masks and spawn management kthreads (rcuog/rcuo). This prevents systems from activating offloading on-demand without a reboot.Problem:
Dynamic Housekeeping Management requires CPUs to transition to NOCB mode at runtime when they are newly isolated. Without boot-time setup, the NOCB masks are unallocated, and critical kthreads are missing, preventing effective tick suppression and isolation.Solution:
Refactor RCU initialization to support dynamic on-demand setup.
- Introducercu_init_nocb_dynamic()to allocate masks and organize kthreads if the system wasn't initially configured for NOCB.
- Introducercu_housekeeping_reconfigure()to iterate over CPUs and perform safe offload/deoffload transitions via hotplug sequences (cpu_down-> offload ->cpu_up) when a housekeeping cpuset triggers a notifier event.
- Remove__initfromrcu_organize_nocb_kthreadsto allow runtime reconfiguration of the callback management hierarchy.This enables a true "Zero-Conf" isolation experience where any CPU can be fully isolated at runtime regardless of boot parameters.
Signed-off-by Qiliang Yuan <[email protected]>--- kernel/rcu/rcu.h | 4 +++ kernel/rcu/tree.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/tree.h | 2 +- kernel/rcu/tree_nocb.h | 31 +++++++++++++-------- 4 files changed, 100 insertions(+), 12 deletions(-)kernel/rcu/rcu.h +4
-0@@ -663,8 +663,12 @@ unsigned long srcu_batches_completed(struct srcu_struct *sp);#endif // #else // #ifdef CONFIG_TINY_SRCU #ifdef CONFIG_RCU_NOCB_CPU +void rcu_init_nocb_dynamic (void ); +void rcu_spawn_cpu_nocb_kthread (int cpu);void rcu_bind_current_to_nocb (void );#else +static inline void rcu_init_nocb_dynamic (void ) { } +static inline void rcu_spawn_cpu_nocb_kthread (int cpu) { }static inline void rcu_bind_current_to_nocb (void ) { }#endif kernel/rcu/tree.c +14
-0@@ -4928,4 +4928,79 @@ void __init rcu_init(void)#include "tree_stall.h" #include "tree_exp.h" #include "tree_nocb.h" + +#ifdef CONFIG_SMP +static int rcu_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *upd = data; +struct task_struct *t; +int cpu; + +if (action !=HK_UPDATE_MASK || upd->type !=HK_TYPE_RCU ) +return NOTIFY_OK ; + +rcu_init_nocb_dynamic (); +
kernel/rcu/tree.c void __init rcu_init(void) · line 4954
Quoted 10 lines
kernel/rcu/tree.c +10
-0+for_each_possible_cpu (cpu) { +struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu); +bool isolated = !cpumask_test_cpu (cpu, upd->new_mask); +bool offloaded =rcu_rdp_is_offloaded (rdp); + +if (isolated && !offloaded) { +/* Transition to NOCB */ +pr_info ("rcu: CPU %d transitioning to NOCB mode\n" , cpu); +if (cpu_online (cpu)) { +remove_cpu (cpu);
We plan to assume that the CPU is offline while updating HK_TYPE_KERNEL_NOISE through cpusets. So you shouldn't need to care about offlining here.
Quoted 25 lines
kernel/rcu/tree.c +25
-0+rcu_spawn_cpu_nocb_kthread (cpu); +rcu_nocb_cpu_offload (cpu); +add_cpu (cpu); + }else { +rcu_spawn_cpu_nocb_kthread (cpu); +rcu_nocb_cpu_offload (cpu); + } + }else if (!isolated && offloaded) { +/* Transition to CB */ +pr_info ("rcu: CPU %d transitioning to CB mode\n" , cpu); +if (cpu_online (cpu)) { +remove_cpu (cpu); +rcu_nocb_cpu_deoffload (cpu); +add_cpu (cpu); + }else { +rcu_nocb_cpu_deoffload (cpu); + } + } + } + + t =READ_ONCE (rcu_state.gp_kthread); +if (t) +housekeeping_affine (t,HK_TYPE_RCU ); + +#ifdef CONFIG_TASKS_RCU
kernel/rcu/tree.c void __init rcu_init(void) · line 4989
Quoted 10 lines
kernel/rcu/tree.c +10
-0+ t =get_rcu_tasks_gp_kthread (); +if (t) +housekeeping_affine (t,HK_TYPE_RCU ); +#endif + +#ifdef CONFIG_TASKS_RUDE_RCU + t =get_rcu_tasks_rude_gp_kthread (); +if (t) +housekeeping_affine (t,HK_TYPE_RCU ); +#endif
No need to handle kthreads affinities. This is already taken care of by isolated cpuset partitions.
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH v2 4/12 tick/nohz: Transition to dynamic full dynticks state management
In reply to Qiliang YuanContext:
Full dynticks (NOHZ_FULL) is typically a static configuration determined at boot time. DHEI extends this to support runtime activation.
Problem:
Switching to NOHZ_FULL at runtime requires careful synchronization of context tracking and housekeeping states. Re-invoking setup logic multiple times could lead to inconsistencies or warnings, and RCU dependency checks often prevented tick suppression in Zero-Conf setups.
Solution:
- Replace the static tick_nohz_full_enabled() checks with a dynamic tick_nohz_full_running state variable.
- Refactor tick_nohz_full_setup to be safe for runtime invocation, adding guards against re-initialization and ensuring IRQ work interrupt support.
- Implement boot-time pre-activation of context tracking (shadow init) for all possible CPUs to avoid instruction flow issues during dynamic transitions.
- Hook into housekeeping_notifier_list to update NO_HZ states dynamically.
This provides the core state machine for reliable, on-demand tick suppression and high-performance isolation.
--- kernel/time/tick-sched.c | 130 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 25 deletions(-)
kernel/time/tick-sched.c +105 -25
@@ -27,6 +27,7 @@#include <linux/posix-timers.h> #include <linux/context_tracking.h> #include <linux/mm.h> +#include <linux/sched/isolation.h> #include <asm/irq_regs.h>
@@ -624,13 +625,25 @@ void __tick_nohz_task_switch(void)/* Get the boot-time nohz CPU list from the kernel parameters. */ void __init tick_nohz_full_setup (cpumask_var_t cpumask) { -alloc_bootmem_cpumask_var (&tick_nohz_full_mask); +if (!tick_nohz_full_mask) { +if (!slab_is_available ()) +alloc_bootmem_cpumask_var (&tick_nohz_full_mask); +else +zalloc_cpumask_var (&tick_nohz_full_mask,GFP_KERNEL ); + }cpumask_copy (tick_nohz_full_mask, cpumask); tick_nohz_full_running = true; }bool tick_nohz_cpu_hotpluggable (unsigned int cpu) { +/* +* Allow all CPUs to go down during shutdown/reboot to avoid +* interfering with the final power-off sequence. +*/ +if (system_state >SYSTEM_RUNNING ) +return true; +/* * The 'tick_do_timer_cpu' CPU handles housekeeping duty (unbound * timers, workqueues, timekeeping, ...) on behalf of full dynticks
@@ -646,45 +659,112 @@ static int tick_nohz_cpu_down(unsigned int cpu)return tick_nohz_cpu_hotpluggable (cpu) ?0 : -EBUSY ; } +static int tick_nohz_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *upd = data; +int cpu; + +if (action ==HK_UPDATE_MASK && upd->type ==HK_TYPE_TICK ) { +cpumask_var_t non_housekeeping_mask; + +if (!alloc_cpumask_var (&non_housekeeping_mask,GFP_KERNEL )) +return NOTIFY_BAD ; + +cpumask_andnot (non_housekeeping_mask, cpu_possible_mask, upd->new_mask); + +if (!tick_nohz_full_mask) { +if (!zalloc_cpumask_var (&tick_nohz_full_mask,GFP_KERNEL )) { +free_cpumask_var (non_housekeeping_mask); +return NOTIFY_BAD ; + } + } + +/* Kick all CPUs to re-evaluate tick dependency before change */ +for_each_online_cpu (cpu) +tick_nohz_full_kick_cpu (cpu); + +cpumask_copy (tick_nohz_full_mask, non_housekeeping_mask); + tick_nohz_full_running = !cpumask_empty (tick_nohz_full_mask); + +/* +* If nohz_full is running, the timer duty must be on a housekeeper. +* If the current timer CPU is not a housekeeper, or no duty is assigned, +* pick the first housekeeper and assign it. +*/ +if (tick_nohz_full_running) { +int timer_cpu =READ_ONCE (tick_do_timer_cpu); +if (timer_cpu ==TICK_DO_TIMER_NONE || + !cpumask_test_cpu (timer_cpu, upd->new_mask)) { +int next_timer =cpumask_first (upd->new_mask); +if (next_timer < nr_cpu_ids) +WRITE_ONCE (tick_do_timer_cpu, next_timer); + } + } + +/* Kick all CPUs again to apply new nohz full state */ +for_each_online_cpu (cpu) +tick_nohz_full_kick_cpu (cpu); + +free_cpumask_var (non_housekeeping_mask); + } + +return NOTIFY_OK ; +} + +static struct notifier_block tick_nohz_housekeeping_nb = { + .notifier_call = tick_nohz_housekeeping_reconfigure, +}; +void __init tick_nohz_init (void ) {int cpu, ret; -if (!tick_nohz_full_running) -return ; - -/* -* Full dynticks uses IRQ work to drive the tick rescheduling on safe -* locking contexts. But then we need IRQ work to raise its own -* interrupts to avoid circular dependency on the tick. -*/ -if (!arch_irq_work_has_interrupt ()) { -pr_warn ("NO_HZ: Can't run full dynticks because arch doesn't support IRQ work self-IPIs\n" ); -cpumask_clear (tick_nohz_full_mask); - tick_nohz_full_running = false; -return ; +if (!tick_nohz_full_mask) { +if (!slab_is_available ()) +alloc_bootmem_cpumask_var (&tick_nohz_full_mask); +else +zalloc_cpumask_var (&tick_nohz_full_mask,GFP_KERNEL ); } -if (IS_ENABLED (CONFIG_PM_SLEEP_SMP ) && - !IS_ENABLED (CONFIG_PM_SLEEP_SMP_NONZERO_CPU )) { - cpu =smp_processor_id (); +housekeeping_register_notifier (&tick_nohz_housekeeping_nb); -if (cpumask_test_cpu (cpu, tick_nohz_full_mask)) { -pr_warn ("NO_HZ: Clearing %d from nohz_full range " -"for timekeeping\n" , cpu); -cpumask_clear_cpu (cpu, tick_nohz_full_mask); +if (tick_nohz_full_running) { +/* +* Full dynticks uses IRQ work to drive the tick rescheduling on safe +* locking contexts. But then we need IRQ work to raise its own +* interrupts to avoid circular dependency on the tick. +*/ +if (!arch_irq_work_has_interrupt ()) { +pr_warn ("NO_HZ: Can't run full dynticks because arch doesn't support IRQ work self-IPIs\n" ); +cpumask_clear (tick_nohz_full_mask); + tick_nohz_full_running = false; + goto out; } + +if (IS_ENABLED (CONFIG_PM_SLEEP_SMP ) && + !IS_ENABLED (CONFIG_PM_SLEEP_SMP_NONZERO_CPU )) { + cpu =smp_processor_id (); + +if (cpumask_test_cpu (cpu, tick_nohz_full_mask)) { +pr_warn ("NO_HZ: Clearing %d from nohz_full range " +"for timekeeping\n" , cpu); +cpumask_clear_cpu (cpu, tick_nohz_full_mask); + } + } + +pr_info ("NO_HZ: Full dynticks CPUs: %*pbl.\n" , +cpumask_pr_args (tick_nohz_full_mask)); } -for_each_cpu (cpu, tick_nohz_full_mask) +out: +for_each_possible_cpu (cpu)ct_cpu_track_user (cpu); ret =cpuhp_setup_state_nocalls (CPUHP_AP_ONLINE_DYN ,"kernel/nohz:predown" ,NULL , tick_nohz_cpu_down);WARN_ON (ret <0 ); -pr_info ("NO_HZ: Full dynticks CPUs: %*pbl.\n" , -cpumask_pr_args (tick_nohz_full_mask)); }#endif /* #ifdef CONFIG_NO_HZ_FULL */
@@ -1209,7 +1289,7 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)if (unlikely (report_idle_softirq ()))return false; -if (tick_nohz_full_enabled ()) { +if (tick_nohz_full_running) {int tick_cpu =READ_ONCE (tick_do_timer_cpu);/*
Signature · 1 line
2.43.0
Thomas Gleixner
maintainerRe: [PATCH v2 04/12] tick/nohz: Transition to dynamic full dynticks state management
Quoted 3 lines · Qiliang Yuan
Context:
Full dynticks (NOHZ_FULL) is typically a static configuration determined at boot time. DHEI extends this to support runtime activation.
I have no idea what DHEI is. Provide proper information and not magic acronyms.
Quoted 5 lines
Problem:
Switching toNOHZ_FULLat runtime requires careful synchronization of context tracking and housekeeping states. Re-invoking setup logic multiple times could lead to inconsistencies or warnings, and RCU dependency checks often prevented tick suppression in Zero-Conf setups.
And that careful synchronization is best achieved with an opaque notifier callchain which relies on build time ordering. Impressive.
Quoted 3 lines
Solution:
- Replace the statictick_nohz_full_enabled()checks with a dynamictick_nohz_full_runningstate variable.
That variable existed before and you are telling the what and not why this is required and how that is correct vs. the other checks in tick_nohz_full_enabled(). Also what's static about that function aside of being marked static inline?
Quoted 3 lines
- Refactor
tick_nohz_full_setupto be safe for runtime invocation, adding guards against re-initialization and ensuring IRQ work interrupt support.
Refactoring has to be done in a preparatory patch and not
Quoted 3 lines
- Implement boot-time pre-activation of context tracking (shadow init) for all possible CPUs to avoid instruction flow issues during dynamic transitions.
Again lot's of hand waving without a proper explanation.
Quoted 1 line
- Hook into
housekeeping_notifier_listto updateNO_HZstates dynamically.
See above.
Quoted 2 lines
This provides the core state machine for reliable, on-demand tick suppression and high-performance isolation.
I can find a lot of hacks, but definitely not the slightest notion of a state machine. Don't throw random buzzwords into a changelog if there is no evidence for their existance.
Quoted 14 lines
kernel/time/tick-sched.c +14
-0+static int tick_nohz_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *upd = data; +int cpu; + +if (action ==HK_UPDATE_MASK && upd->type ==HK_TYPE_TICK ) { +cpumask_var_t non_housekeeping_mask; + +if (!alloc_cpumask_var (&non_housekeeping_mask,GFP_KERNEL )) +return NOTIFY_BAD ; + +cpumask_andnot (non_housekeeping_mask, cpu_possible_mask, upd->new_mask); +
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 685
Quoted 10 lines
kernel/time/tick-sched.c +10
-0+if (!tick_nohz_full_mask) { +if (!zalloc_cpumask_var (&tick_nohz_full_mask,GFP_KERNEL )) { +free_cpumask_var (non_housekeeping_mask); +return NOTIFY_BAD ; + } + } + +/* Kick all CPUs to re-evaluate tick dependency before change */ +for_each_online_cpu (cpu) +tick_nohz_full_kick_cpu (cpu);
That solves what?
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 687
Quoted 1 line
kernel/time/tick-sched.c +1
-0+cpumask_copy (tick_nohz_full_mask, non_housekeeping_mask);
What's the exact point of this non_housekeeping_mask?
Why can't you simply do:
cpumask_andnot(tick_nohz_full_mask, cpu_possible_mask, upd->new_mask);
That'd be too simple and comprehensible, right?
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 696
Quoted 9 lines
kernel/time/tick-sched.c +9
-0+ tick_nohz_full_running = !cpumask_empty (tick_nohz_full_mask); + +/* +* If nohz_full is running, the timer duty must be on a housekeeper. +* If the current timer CPU is not a housekeeper, or no duty is assigned, +* pick the first housekeeper and assign it. +*/ +if (tick_nohz_full_running) { +int timer_cpu =READ_ONCE (tick_do_timer_cpu);
New line between declaration and code.
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 698
Quoted 2 lines
kernel/time/tick-sched.c +2
-0+if (timer_cpu ==TICK_DO_TIMER_NONE || + !cpumask_test_cpu (timer_cpu, upd->new_mask)) {
No line break required. You have 100 characters
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 699
Quoted 1 line
kernel/time/tick-sched.c +1
-0+int next_timer =cpumask_first (upd->new_mask);
next_timer? Please pick variable names which are comprehensible and self explaining. Also why can't you re-use timer_cpu, which would be actually useful?
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 700
Quoted 1 line
kernel/time/tick-sched.c +1
-0+if (next_timer < nr_cpu_ids)
How can upd->new_mask be empty? That'd be a bug, no?
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 707
Quoted 7 lines
kernel/time/tick-sched.c +7
-0+WRITE_ONCE (tick_do_timer_cpu, next_timer); + } + } + +/* Kick all CPUs again to apply new nohz full state */ +for_each_online_cpu (cpu) +tick_nohz_full_kick_cpu (cpu);
This whole thing lacks an explanation why it is even remotely correct.
Quoted 1 line
void
__inittick_nohz_init(void)
...
kernel/time/tick-sched.c void __tick_nohz_task_switch(void) · line 636
Quoted 6 lines
kernel/time/tick-sched.c +5
-0+if (!tick_nohz_full_mask) { +if (!slab_is_available ()) +alloc_bootmem_cpumask_var (&tick_nohz_full_mask); +else +zalloc_cpumask_var (&tick_nohz_full_mask,GFP_KERNEL ); }
I've seen the same code sequence before. Copy & paste is simpler than providing helper functions.....
kernel/time/tick-sched.c static int tick_nohz_cpu_down(unsigned int cpu) · line 732
Quoted 10 lines
kernel/time/tick-sched.c +2
-7-if (IS_ENABLED (CONFIG_PM_SLEEP_SMP ) && - !IS_ENABLED (CONFIG_PM_SLEEP_SMP_NONZERO_CPU )) { - cpu =smp_processor_id (); +housekeeping_register_notifier (&tick_nohz_housekeeping_nb); -if (cpumask_test_cpu (cpu, tick_nohz_full_mask)) { -pr_warn ("NO_HZ: Clearing %d from nohz_full range " -"for timekeeping\n" , cpu); -cpumask_clear_cpu (cpu, tick_nohz_full_mask); +if (tick_nohz_full_running) {
This indentation and the resulting goto mess can be completely avoided if you actually refactor the code and not just claim to do so.
Again, this does too many things at once and then explains them badly, which makes it unreviewable.
Thanks,
tglx
PATCH v2 5/12 genirq: Support dynamic migration for managed interrupts
In reply to Qiliang YuanManaged interrupts currently have their affinity determined once, honoring boot-time isolation settings. There is no mechanism to migrate them when housekeeping boundaries change at runtime.
Enable managed interrupts to respond dynamically to housekeeping updates.
This ensures that managed interrupts are migrated away from newly isolated CPUs or redistributed when housekeeping CPUs are added.
--- kernel/irq/manage.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
kernel/irq/manage.c +49 -0
@@ -2801,3 +2801,52 @@ bool irq_check_status_bit(unsigned int irq, unsigned int bitmask)return res; }EXPORT_SYMBOL_GPL (irq_check_status_bit); + +#ifdef CONFIG_SMP +static int irq_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *upd = data; +unsigned int irq; + +if (action !=HK_UPDATE_MASK || upd->type !=HK_TYPE_MANAGED_IRQ ) +return NOTIFY_OK ; + +irq_lock_sparse (); +for_each_active_irq (irq) { +struct irq_data *irqd; +struct irq_desc *desc; + + desc =irq_to_desc (irq); +if (!desc) +continue ; + + scoped_guard(raw_spinlock_irqsave, &desc->lock) { + irqd =irq_desc_get_irq_data (desc); +if (!irqd_affinity_is_managed (irqd) || !desc->action || + !irq_data_get_irq_chip (irqd)) +continue ; + +/* +* Re-apply existing affinity to honor the new +* housekeeping mask via __irq_set_affinity() logic. +*/ +irq_set_affinity_locked (irqd,irq_data_get_affinity_mask (irqd), false); + } + } +irq_unlock_sparse (); + +return NOTIFY_OK ; +} + +static struct notifier_block irq_housekeeping_nb = { + .notifier_call = irq_housekeeping_reconfigure, +}; + +static int __init irq_init_housekeeping_notifier (void ) +{ +housekeeping_register_notifier (&irq_housekeeping_nb); +return 0 ; +} +core_initcall (irq_init_housekeeping_notifier); +#endif
Signature · 1 line
2.43.0
Thomas Gleixner
maintainerRe: [PATCH v2 05/12] genirq: Support dynamic migration for managed interrupts
kernel/irq/manage.c bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) · line 2817
Quoted 3 lines · Qiliang Yuan
kernel/irq/manage.c +3
-0+irq_lock_sparse (); +for_each_active_irq (irq) { +struct irq_data *irqd;
Please move the declaration into the scope where it is used.
kernel/irq/manage.c bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) · line 2828
Quoted 11 lines
kernel/irq/manage.c +11
-0+struct irq_desc *desc; + + desc =irq_to_desc (irq); +if (!desc) +continue ; + + scoped_guard(raw_spinlock_irqsave, &desc->lock) { + irqd =irq_desc_get_irq_data (desc); +if (!irqd_affinity_is_managed (irqd) || !desc->action || + !irq_data_get_irq_chip (irqd)) +continue ;
That's a pretty random choice of conditions.
kernel/irq/manage.c bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) · line 2834
Quoted 5 lines
kernel/irq/manage.c +5
-0+/* +* Re-apply existing affinity to honor the new +* housekeeping mask via __irq_set_affinity() logic. +*/ +irq_set_affinity_locked (irqd,irq_data_get_affinity_mask (irqd), false);
That's not sufficient. Assume an interrupt was shut down before the change because there was no online CPU in the affinity mask, but now the affinity mask changes so there is an online CPU. What starts it up? Same the other way around.
kernel/irq/manage.c bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) · line 2851
Quoted 10 lines
kernel/irq/manage.c +10
-0+static struct notifier_block irq_housekeeping_nb = { + .notifier_call = irq_housekeeping_reconfigure, +}; + +static int __init irq_init_housekeeping_notifier (void ) +{ +housekeeping_register_notifier (&irq_housekeeping_nb); +return 0 ; +} +core_initcall (irq_init_housekeeping_notifier);
I fundamentaly despise notifiers especially when they are just invoking something which is built in.
PATCH v2 6/12 watchdog: Allow runtime toggle of lockup detector affinity
In reply to Qiliang YuanThe hardlockup detector threads are affined to CPUs based on the HK_TYPE_TIMER housekeeping mask at boot. If this mask is updated at runtime, these threads remain on their original CPUs, potentially running on isolated cores.
Synchronize watchdog thread affinity with HK_TYPE_TIMER updates.
This ensures that hardlockup detector threads correctly follow the dynamic housekeeping boundaries for timers.
--- kernel/watchdog.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
kernel/watchdog.c +26 -0
@@ -26,6 +26,7 @@#include <linux/sysctl.h> #include <linux/tick.h> #include <linux/sys_info.h> +#include <linux/sched/isolation.h> #include <linux/sched/clock.h> #include <linux/sched/debug.h>
@@ -1361,6 +1362,30 @@ static int __init lockup_detector_check(void) }late_initcall_sync (lockup_detector_check); +static int watchdog_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +if (action ==HK_UPDATE_MASK ) { +struct housekeeping_update *upd = data; +unsigned int type = upd->type; + +if (type ==HK_TYPE_TIMER ) { +mutex_lock (&watchdog_mutex); +cpumask_copy (&watchdog_cpumask, +housekeeping_cpumask (HK_TYPE_TIMER )); +cpumask_and (&watchdog_cpumask, &watchdog_cpumask, cpu_possible_mask); +__lockup_detector_reconfigure (false); +mutex_unlock (&watchdog_mutex); + } + } + +return NOTIFY_OK ; +} + +static struct notifier_block watchdog_housekeeping_nb = { + .notifier_call = watchdog_housekeeping_reconfigure, +}; +void __init lockup_detector_init (void ) {if (tick_nohz_full_enabled ())
@@ -1375,4 +1400,5 @@ void __init lockup_detector_init(void) allow_lockup_detector_init_retry = true;lockup_detector_setup (); +housekeeping_register_notifier (&watchdog_housekeeping_nb); }
Signature · 1 line
2.43.0
PATCH v2 7/12 sched/core: Dynamically update scheduler domain housekeeping mask
In reply to Qiliang YuanScheduler domains rely on HK_TYPE_DOMAIN to identify which CPUs are isolated from general load balancing. Currently, these boundaries are static and determined only during boot-time domain initialization.
Trigger a scheduler domain rebuild when the HK_TYPE_DOMAIN mask changes.
This ensures that scheduler isolation boundaries can be reconfigured at runtime via the DHEI sysfs or cpuset interface.
--- kernel/sched/core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
kernel/sched/core.c +23 -0
@@ -39,6 +39,7 @@#include <linux/sched/nohz.h> #include <linux/sched/rseq_api.h> #include <linux/sched/rt.h> +#include <linux/sched/topology.h> #include <linux/blkdev.h> #include <linux/context_tracking.h>
@@ -10959,3 +10960,25 @@ void sched_change_end(struct sched_change_ctx *ctx) p->sched_class->prio_changed (rq, p, ctx->prio); } } + +static int sched_housekeeping_update (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *update = data; + +if (action ==HK_UPDATE_MASK && update->type ==HK_TYPE_DOMAIN ) +rebuild_sched_domains (); + +return NOTIFY_OK ; +} + +static struct notifier_block sched_housekeeping_nb = { + .notifier_call = sched_housekeeping_update, +}; + +static int __init sched_housekeeping_init (void ) +{ +housekeeping_register_notifier (&sched_housekeeping_nb); +return 0 ; +} +late_initcall (sched_housekeeping_init);
Signature · 1 line
2.43.0
Frederic Weisbecker
maintainerRe: [PATCH v2 07/12] sched/core: Dynamically update scheduler domain housekeeping mask
Quoted 31 lines · Qiliang Yuan
Scheduler domains rely on
HK_TYPE_DOMAINto identify which CPUs are isolated from general load balancing. Currently, these boundaries are static and determined only during boot-time domain initialization.Trigger a scheduler domain rebuild when the
HK_TYPE_DOMAINmask changes.This ensures that scheduler isolation boundaries can be reconfigured at runtime via the DHEI sysfs or cpuset interface.
Signed-off-by Qiliang Yuan <[email protected]>--- kernel/sched/core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)kernel/sched/core.c +2
-0@@ -39,6 +39,7 @@#include <linux/sched/nohz.h> #include <linux/sched/rseq_api.h> #include <linux/sched/rt.h> +#include <linux/sched/topology.h> #include <linux/blkdev.h> #include <linux/context_tracking.h> @@ -10959,3 +10960,25 @@ void sched_change_end(struct sched_change_ctx *ctx) p->sched_class->prio_changed (rq, p, ctx->prio); } } +
kernel/sched/core.c void sched_change_end(struct sched_change_ctx *ctx) · line 10973
Quoted 10 lines
kernel/sched/core.c +10
-0+static int sched_housekeeping_update (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *update = data; + +if (action ==HK_UPDATE_MASK && update->type ==HK_TYPE_DOMAIN ) +rebuild_sched_domains (); + +return NOTIFY_OK ; +}
This is already handled by cpuset isolated partitions.
Thanks.
Quoted 15 lines
kernel/sched/core.c +11
-0+ +static struct notifier_block sched_housekeeping_nb = { + .notifier_call = sched_housekeeping_update, +}; + +static int __init sched_housekeeping_init (void ) +{ +housekeeping_register_notifier (&sched_housekeeping_nb); +return 0 ; +} +late_initcall (sched_housekeeping_init);Signature · 2 lines
-- 2.43.0
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH v2 8/12 workqueue, mm: Support dynamic housekeeping mask updates
In reply to Qiliang YuanUnbound workqueues and kcompactd threads determine their default CPU affinity from housekeeping masks (HK_TYPE_WQ, HK_TYPE_DOMAIN, and HK_TYPE_KTHREAD) at boot. Currently, these boundaries are static and are not updated if housekeeping is reconfigured at runtime.
Implement housekeeping notifiers for both workqueue and mm compaction.
This ensures that unbound workqueue tasks and background compaction threads honor dynamic isolation boundaries configured via sysfs or cpuset at runtime.
--- kernel/workqueue.c | 42 ++++++++++++++++++++++++++++++++++++++++++ mm/compaction.c | 27 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
kernel/workqueue.c +42 -0
@@ -8008,6 +8008,47 @@ static void __init wq_cpu_intensive_thresh_init(void) wq_cpu_intensive_thresh_us = thresh; } +static int wq_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +if (action ==HK_UPDATE_MASK ) { +struct housekeeping_update *upd = data; +unsigned int type = upd->type; + +if (type ==HK_TYPE_WQ || type ==HK_TYPE_DOMAIN ) { +cpumask_var_t cpumask; + +if (!alloc_cpumask_var (&cpumask,GFP_KERNEL )) { +pr_warn ("workqueue: failed to allocate cpumask for housekeeping update\n" ); +return NOTIFY_BAD ; + } + +cpumask_copy (cpumask, cpu_possible_mask); +if (!cpumask_empty (housekeeping_cpumask (HK_TYPE_WQ ))) +cpumask_and (cpumask, cpumask,housekeeping_cpumask (HK_TYPE_WQ )); +if (!cpumask_empty (housekeeping_cpumask (HK_TYPE_DOMAIN ))) +cpumask_and (cpumask, cpumask,housekeeping_cpumask (HK_TYPE_DOMAIN )); + +workqueue_set_unbound_cpumask (cpumask); + +if (type ==HK_TYPE_DOMAIN ) { +apply_wqattrs_lock (); +cpumask_andnot (wq_isolated_cpumask, cpu_possible_mask, +housekeeping_cpumask (HK_TYPE_DOMAIN )); +apply_wqattrs_unlock (); + } + +free_cpumask_var (cpumask); + } + } + +return NOTIFY_OK ; +} + +static struct notifier_block wq_housekeeping_nb = { + .notifier_call = wq_housekeeping_reconfigure, +}; +/** * workqueue_init - bring workqueue subsystem fully online *
@@ -8068,6 +8109,7 @@ void __init workqueue_init(void) wq_online = true;wq_watchdog_init (); +housekeeping_register_notifier (&wq_housekeeping_nb); }/*
mm/compaction.c +27 -0
@@ -24,6 +24,7 @@#include <linux/page_owner.h> #include <linux/psi.h> #include <linux/cpuset.h> +#include <linux/sched/isolation.h> #include "internal.h" #ifdef CONFIG_COMPACTION
@@ -3246,6 +3247,7 @@ void __meminit kcompactd_run(int nid)pr_err ("Failed to start kcompactd on node %d\n" , nid); pgdat->kcompactd =NULL ; }else { +housekeeping_affine (pgdat->kcompactd,HK_TYPE_KTHREAD );wake_up_process (pgdat->kcompactd); } }
@@ -3320,6 +3322,30 @@ static const struct ctl_table vm_compaction[] = { }, }; +static int kcompactd_housekeeping_reconfigure (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct housekeeping_update *upd = data; +unsigned int type = upd->type; + +if (action ==HK_UPDATE_MASK && type ==HK_TYPE_KTHREAD ) { +int nid; + +for_each_node_state (nid,N_MEMORY ) { +pg_data_t *pgdat =NODE_DATA (nid); + +if (pgdat->kcompactd) +housekeeping_affine (pgdat->kcompactd,HK_TYPE_KTHREAD ); + } + } + +return NOTIFY_OK ; +} + +static struct notifier_block kcompactd_housekeeping_nb = { + .notifier_call = kcompactd_housekeeping_reconfigure, +}; +static int __init kcompactd_init (void ) {int nid;
@@ -3327,6 +3353,7 @@ static int __init kcompactd_init(void)for_each_node_state (nid,N_MEMORY )kcompactd_run (nid);register_sysctl_init ("vm" , vm_compaction); +housekeeping_register_notifier (&kcompactd_housekeeping_nb);return 0 ; }subsys_initcall (kcompactd_init)
Signature · 1 line
2.43.0
Frederic Weisbecker
maintainerRe: [PATCH v2 08/12] workqueue, mm: Support dynamic housekeeping mask updates
Quoted 5 lines · Qiliang Yuan
Unbound workqueues and kcompactd threads determine their default CPU affinity from housekeeping masks (
HK_TYPE_WQ,HK_TYPE_DOMAIN, andHK_TYPE_KTHREAD) at boot. Currently, these boundaries are static and are not updated if housekeeping is reconfigured at runtime.
Quoted 7 lines
Implement housekeeping notifiers for both workqueue and mm compaction.
This ensures that unbound workqueue tasks and background compaction threads honor dynamic isolation boundaries configured via sysfs or cpuset at runtime.
Signed-off-by Qiliang Yuan <[email protected]>
Unbound workqueues and kthreads are already handled by cpuset isolated partitions.
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH v2 9/12 cgroup/cpuset: Introduce CPUSet-driven dynamic housekeeping (DHM)
In reply to Qiliang YuanCurrently, subsystem housekeeping masks are generally static and can only be configured via boot-time parameters (e.g., isolcpus, nohz_full). This inflexible approach forces a system reboot whenever an orchestrator needs to change workload isolation boundaries.
This patch introduces CPUSet-driven Dynamic Housekeeping Management (DHM) by exposing the cpuset.housekeeping.cpus control file on the root cgroup. Writing a new cpumask to this file dynamically updates the housekeeping masks of all registered subsystems (scheduler, RCU, timers, tick, workqueues, and managed IRQs) simultaneously, without restarting the node.
At the cpuset and isolation core level, this change implements:
1. housekeeping_update_all_types(const struct cpumask *new_mask) API inside isolation.c to safely allocate, update, and replace all enabled hk_type masks.
2. The cpuset.housekeeping.cpus attribute in dfl_files for the root cpuset.
3. Hooking the write operation to iterate over enabled housekeeping types and invoke housekeeping_update_notify() (the DHM notifier chain) to push these configuration changes live into individual kernel subsystems.
--- include/linux/sched/isolation.h | 12 ++++++++++++ kernel/cgroup/cpuset-internal.h | 1 + kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++++++++++++++++++ kernel/sched/isolation.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+)
include/linux/sched/isolation.h +12 -0
@@ -48,6 +48,8 @@ extern void __init housekeeping_init(void);extern int housekeeping_register_notifier (struct notifier_block *nb);extern int housekeeping_unregister_notifier (struct notifier_block *nb); +extern int housekeeping_update_notify (enum hk_type type,const struct cpumask *new_mask); +extern int housekeeping_update_all_types (const struct cpumask *new_mask);#else
@@ -86,6 +88,16 @@ static inline int housekeeping_unregister_notifier(struct notifier_block *nb) {return 0 ; } + +static inline int housekeeping_update_notify (enum hk_type type,const struct cpumask *new_mask) +{ +return 0 ; +} + +static inline int housekeeping_update_all_types (const struct cpumask *new_mask) +{ +return 0 ; +}#endif /* CONFIG_CPU_ISOLATION */ static inline bool housekeeping_cpu (int cpu,enum hk_type type)
kernel/cgroup/cpuset-internal.h +1 -0
@@ -60,6 +60,7 @@ typedef enum {FILE_EXCLUSIVE_CPULIST ,FILE_EFFECTIVE_XCPULIST ,FILE_ISOLATED_CPULIST , +FILE_HOUSEKEEPING_CPULIST ,FILE_CPU_EXCLUSIVE ,FILE_MEM_EXCLUSIVE , FILE_MEM_HARDWALL,
kernel/cgroup/cpuset.c +36 -0
@@ -3201,6 +3201,30 @@ static void cpuset_attach(struct cgroup_taskset *tset)mutex_unlock (&cpuset_mutex); } +/* +* DHM interface: root cpuset allows updating global housekeeping cpumask. +*/ +static ssize_t cpuset_write_housekeeping_cpus (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +cpumask_var_t new_mask; +int retval; + +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ; + + buf =strstrip (buf); + retval =cpulist_parse (buf, new_mask); +if (retval) + goto out_free; + + retval =housekeeping_update_all_types (new_mask); + +out_free: +free_cpumask_var (new_mask); +return retval ?: nbytes; +} +/* * Common handling for a write to a "cpus" or "mems" file. */
@@ -3290,6 +3314,9 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v)case FILE_ISOLATED_CPULIST :seq_printf (sf,"%*pbl\n" ,cpumask_pr_args (isolated_cpus));break ; +case FILE_HOUSEKEEPING_CPULIST : +seq_printf (sf,"%*pbl\n" ,cpumask_pr_args (housekeeping_cpumask (HK_TYPE_DOMAIN ))); +break ;default : ret = -EINVAL ; }
@@ -3428,6 +3455,15 @@ static struct cftype dfl_files[] = { .flags = CFTYPE_ONLY_ON_ROOT, }, + { + .name = "housekeeping.cpus", + .seq_show = cpuset_common_seq_show, + .write = cpuset_write_housekeeping_cpus, + .max_write_len = (100U + 6 * NR_CPUS), + .private = FILE_HOUSEKEEPING_CPULIST, + .flags = CFTYPE_ONLY_ON_ROOT, + }, + { }/* terminate */ };
kernel/sched/isolation.c +38 -0
@@ -27,6 +27,7 @@ enum hk_flags {#define HK_FLAG_KERNEL_NOISE (HK_FLAG_TICK | HK_FLAG_TIMER | HK_FLAG_RCU | \ HK_FLAG_MISC | HK_FLAG_WQ | HK_FLAG_KTHREAD) +static DEFINE_MUTEX (housekeeping_mutex);static BLOCKING_NOTIFIER_HEAD (housekeeping_notifier_list);DEFINE_STATIC_KEY_FALSE (housekeeping_overridden);
@@ -196,6 +197,43 @@ int housekeeping_update_notify(enum hk_type type, const struct cpumask *new_mask }EXPORT_SYMBOL_GPL (housekeeping_update_notify); +int housekeeping_update_all_types (const struct cpumask *new_mask) +{ +enum hk_type type; +struct cpumask *old_masks[HK_TYPE_MAX ] = {NULL }; + +if (cpumask_empty (new_mask) || !cpumask_intersects (new_mask, cpu_online_mask)) +return -EINVAL ; + +if (!housekeeping.flags) +static_branch_enable (&housekeeping_overridden); + +mutex_lock (&housekeeping_mutex); +for_each_set_bit (type, &housekeeping.flags,HK_TYPE_MAX ) { +struct cpumask *nmask =kmalloc (cpumask_size (),GFP_KERNEL ); + +if (!nmask) { +mutex_unlock (&housekeeping_mutex); +return -ENOMEM ; + } + +cpumask_copy (nmask, new_mask); + old_masks[type] =housekeeping_cpumask_dereference (type); +rcu_assign_pointer (housekeeping.cpumasks[type], nmask); + } +mutex_unlock (&housekeeping_mutex); + +synchronize_rcu (); + +for_each_set_bit (type, &housekeeping.flags,HK_TYPE_MAX ) { +housekeeping_update_notify (type, new_mask); +kfree (old_masks[type]); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (housekeeping_update_all_types); +void __init housekeeping_init (void ) {enum hk_type type;
Signature · 1 line
2.43.0
Frederic Weisbecker
maintainerRe: [PATCH v2 09/12] cgroup/cpuset: Introduce CPUSet-driven dynamic housekeeping (DHM)
Quoted 10 lines · Qiliang Yuan
Currently, subsystem housekeeping masks are generally static and can only be configured via boot-time parameters (e.g., isolcpus,
nohz_full). This inflexible approach forces a system reboot whenever an orchestrator needs to change workload isolation boundaries.This patch introduces CPUSet-driven Dynamic Housekeeping Management (DHM) by exposing the
cpuset.housekeeping.cpuscontrol file on the root cgroup. Writing a new cpumask to this file dynamically updates the housekeeping masks of all registered subsystems (scheduler, RCU, timers, tick, workqueues, and managed IRQs) simultaneously, without restarting the node.
There is already the "isolated" partition type which does scheduler, timers and workqueues isolation. Shouldn't we extend that to dynamically apply nohz_full instead of adding a new unrelated file?
I don't know which form that should take. Perhaps reuse the "isolated" partition but add some sort of parameter to define if we want only domain isolation or also full isolation (that is nohz_full). Waiman should have a better idea for an interface here.
Quoted 5 lines
At the cpuset and isolation core level, this change implements:
1.housekeeping_update_all_types(const struct cpumask *new_mask)API insideisolation.cto safely allocate, update, and replace all enabledhk_type
masks.
HK_TYPE_DOMAIN is handled by "isolated" partitions. What remains to handle is HK_TYPE_KERNEL_NOISE.
As for managed IRQs this will require more thinking but we should include that into "full isolation" in the future.
Quoted 1 line
+int
housekeeping_update_all_types(const struct cpumask *new_mask)
Please reuse housekeeping_update().
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH v2 10/12 cgroup/cpuset: Implement SMT-aware grouping and safety guards
In reply to Qiliang YuanDynamic Housekeeping Management allows runtime configuration of kernel overhead isolation boundaries. However, configuring CPUMASKs that separate SMT siblings (e.g., placing one hardware thread in the housekeeping mask and leaving the other isolated) can lead to severe performance degradation due to shared L1 caches and pipeline resources.
This patch introduces cpuset.housekeeping.smt_aware, a robust safety guard to prevent user-space from splitting SMT sibling pairs across isolation boundaries.
When cpuset.housekeeping.smt_aware is enabled (1):
- Any write to cpuset.housekeeping.cpus must include all SMT siblings for each CPU presented in the new mask (verified via topology_sibling_cpumask).
- If an invalid mask is supplied, the write operation is aborted with -EINVAL.
This ensures the kernel's housekeeping constraints are met while maintaining maximum hardware thread efficiency.
--- kernel/cgroup/cpuset-internal.h | 1 + kernel/cgroup/cpuset.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
kernel/cgroup/cpuset-internal.h +1 -0
@@ -61,6 +61,7 @@ typedef enum {FILE_EFFECTIVE_XCPULIST ,FILE_ISOLATED_CPULIST ,FILE_HOUSEKEEPING_CPULIST , +FILE_HOUSEKEEPING_SMT_AWARE ,FILE_CPU_EXCLUSIVE ,FILE_MEM_EXCLUSIVE , FILE_MEM_HARDWALL,
kernel/cgroup/cpuset.c +37 -0
@@ -37,6 +37,7 @@#include <linux/wait.h> #include <linux/workqueue.h> #include <linux/task_work.h> +#include <linux/topology.h> DEFINE_STATIC_KEY_FALSE (cpusets_pre_enable_key);DEFINE_STATIC_KEY_FALSE (cpusets_enabled_key);
@@ -156,6 +157,9 @@ static bool update_housekeeping; /* RWCS */*/ static cpumask_var_t isolated_hk_cpus;/* T */ +/* DHM: Enable SMT-aware boundary checks */ +static bool cpuset_housekeeping_smt_aware = false; +/* * A flag to force sched domain rebuild at the end of an operation. * It can be set in
@@ -3218,6 +3222,16 @@ static ssize_t cpuset_write_housekeeping_cpus(struct kernfs_open_file *of,if (retval) goto out_free; +if (cpuset_housekeeping_smt_aware) { +int cpu; +for_each_cpu (cpu, new_mask) { +if (!cpumask_subset (topology_sibling_cpumask (cpu), new_mask)) { + retval = -EINVAL ; + goto out_free; + } + } + } + retval =housekeeping_update_all_types (new_mask); out_free:
@@ -3225,6 +3239,18 @@ static ssize_t cpuset_write_housekeeping_cpus(struct kernfs_open_file *of,return retval ?: nbytes; } +static ssize_t cpuset_write_housekeeping_smt_aware (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +bool val; + +if (kstrtobool (buf, &val)) +return -EINVAL ; + + cpuset_housekeeping_smt_aware = val; +return nbytes; +} +/* * Common handling for a write to a "cpus" or "mems" file. */
@@ -3317,6 +3343,9 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v)case FILE_HOUSEKEEPING_CPULIST :seq_printf (sf,"%*pbl\n" ,cpumask_pr_args (housekeeping_cpumask (HK_TYPE_DOMAIN )));break ; +case FILE_HOUSEKEEPING_SMT_AWARE : +seq_printf (sf,"%d\n" , cpuset_housekeeping_smt_aware); +break ;default : ret = -EINVAL ; }
@@ -3464,6 +3493,14 @@ static struct cftype dfl_files[] = { .flags = CFTYPE_ONLY_ON_ROOT, }, + { + .name = "housekeeping.smt_aware", + .seq_show = cpuset_common_seq_show, + .write = cpuset_write_housekeeping_smt_aware, + .private = FILE_HOUSEKEEPING_SMT_AWARE, + .flags = CFTYPE_ONLY_ON_ROOT, + }, + { }/* terminate */ };
Signature · 1 line
2.43.0
PATCH v2 11/12 Documentation: cgroup-v2: Document dynamic housekeeping (DHM)
In reply to Qiliang YuanUpdate the admin-guide for cgroup-v2 to explicitly document the newly introduced cpuset.housekeeping.cpus and cpuset.housekeeping.smt_aware files.
The documentation explains the use of the DHM framework for reconfiguring kernel subsystem isolation masks natively through the root cpuset without incurring system reboots, and describes the functional restrictions of SMT grouping safety constraints.
--- Documentation/admin-guide/cgroup-v2.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Documentation/admin-guide/cgroup-v2.rst +24 -0
@@ -2592,6 +2592,30 @@ Cpuset Interface Files isolated partitions. It will be empty if no isolated partition is created. + cpuset.housekeeping.cpus + A read-write multiple values file that exists only on the root cgroup. + + This file is part of the Dynamic Housekeeping Management (DHM) + framework. It allows dynamic reconfiguration of the global + kernel housekeeping CPU mask without a system reboot. + + By writing a mask of CPUs (e.g. "0-3,8"), DHM will update all internal + housekeeping subsystem masks (scheduler domains, RCU NOCB, tick offload, + timers, unbound workqueues, and managed IRQs) in real time. + + The new mask must have at least one online CPU. The value stays constant + until changed or affected by CPU hot-unplug. + + cpuset.housekeeping.smt_aware + A read-write single value file that exists only on the root cgroup. + It accepts "0" or "1". The default value is "0" (false). + + This file enables the SMT-aware pipeline logic for DHM. When enabled (1), + any update to "cpuset.housekeeping.cpus" is strictly validated to ensure + Hardware Threads (SMT siblings) are kept together. If an SMT sibling pair + is split across the housekeeping boundary, the mask update is rejected + with an error to avoid severe cache and pipeline contention penalties. + cpuset.cpus.partition A read-write single value file which exists on non-root cpuset-enabled cgroups. This flag is owned by the parent cgroup
Signature · 1 line
2.43.0
PATCH v2 12/12 selftests: cgroup: Add functional tests for dynamic housekeeping
In reply to Qiliang YuanThis extends the cgroup v2 testing framework in selftests to validate the newly added Dynamic Housekeeping Management (DHM) cpuset interface:cpuset.housekeeping.cpus and cpuset.housekeeping.smt_aware.
The test_cpuset_housekeeping functional test verifies:
- Validation of DHM's SMT safety guard (cpuset.housekeeping.smt_aware) by ensuring writing to it behaves as expected.
- Basic read and write capabilities of cpuset.housekeeping.cpus using the base CPU mask.
If the DHM functionality is not present in the kernel, the selftest skips gracefully.
--- tools/testing/selftests/cgroup/test_cpuset.c | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/testing/selftests/cgroup/test_cpuset.c +36 -0
@@ -232,6 +232,41 @@ static int test_cpuset_perms_subtree(const char *root)return ret; } +static int test_cpuset_housekeeping (const char *root) +{ +char buf[PAGE_SIZE ]; +int ret =KSFT_FAIL ; + +/* If the kernel doesn't have DHM patch, skip */ +if (cg_read (root,"cpuset.housekeeping.cpus" , buf,sizeof (buf))) +return KSFT_SKIP ; + +/* Test writing 1 and 0 to smt_aware */ +if (cg_write (root,"cpuset.housekeeping.smt_aware" ,"1" )) + goto cleanup; + +if (cg_read_strstr (root,"cpuset.housekeeping.smt_aware" ,"1" )) + goto cleanup; + +if (cg_write (root,"cpuset.housekeeping.smt_aware" ,"0" )) + goto cleanup; + +if (cg_read_strstr (root,"cpuset.housekeeping.smt_aware" ,"0" )) + goto cleanup; + +/* Read root cpuset.cpus.effective */ +if (cg_read (root,"cpuset.cpus.effective" , buf,sizeof (buf))) + goto cleanup; + +/* Write it back to housekeeping.cpus */ +if (cg_write (root,"cpuset.housekeeping.cpus" , buf)) + goto cleanup; + + ret =KSFT_PASS ; + +cleanup: +return ret; +}#define T (x) { x, #x }struct cpuset_test {
@@ -241,6 +276,7 @@ struct cpuset_test {T (test_cpuset_perms_object_allow),T (test_cpuset_perms_object_deny),T (test_cpuset_perms_subtree), + T(test_cpuset_housekeeping), };#undef T
Signature · 1 line
2.43.0