genirq/cpuhotplug: Adjust managed interrupts according to change of housekeeping cpumask
Subsystems (3)
v4 cover genirq/cpuhotplug: Adjust managed interrupts according to change of housekeeping cpumask
This series of patches is based on series
isolation: Exclude dynamically isolated CPUs from housekeeping masks:
https://lore.kernel.org/lkml/[email protected]/
Its purpose is to exclude dynamically isolated CPUs from some housekeeping masks so that subsystems that check the housekeeping masks at run time will not use those isolated CPUs.
However, some of subsystems can use obsolete housekeeping CPU masks. Therefore, to prevent the use of these isolated CPUs, it is necessary to explicitly propagate changes of the housekeeping masks to all subsystems depending on the mask.
---
v4:
- Use CPU hotplug as recommended by Thomas Gleixner.
v3:
- Address the comments by Thomas Gleixner.
v2:
- Focus in this patch series on managed interrupts only.
Costa Shulyupin (4):
cgroup/cpuset: Add HK_TYPE_MANAGED_IRQ to HOUSEKEEPING_FLAGS genirq/cpuhotplug: Dynamically isolate CPUs from managed interrupts cgroup/cpuset: Restart CPUs whose isolated_cpus bits have changed DO NOT MERGE: Test CPU isolation from managed interrupts
MAINTAINERS | 2 + kernel/cgroup/cpuset.c | 36 +++++++++++ kernel/irq/cpuhotplug.c | 3 + tests/managed_irq.sh | 135 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100755 tests/managed_irq.sh
Signature · 1 line
2.47.0
RFC PATCH v4 1/4 cgroup/cpuset: Add HK_TYPE_MANAGED_IRQ to HOUSEKEEPING_FLAGS
update_isolation_cpumasks() should also update
housekeeping.cpumasks[HK_TYPE_MANAGED_IRQ]
The patch amends
https://lore.kernel.org/lkml/[email protected]/
--- kernel/cgroup/cpuset.c | 1 + 1 file changed, 1 insertion(+)
kernel/cgroup/cpuset.c +1 -0
@@ -90,6 +90,7 @@ static struct list_head remote_children;#define HOUSEKEEPING_FLAGS (BIT(HK_TYPE_TIMER) | BIT(HK_TYPE_RCU) |\ BIT(HK_TYPE_SCHED) | BIT(HK_TYPE_MISC) |\ BIT(HK_TYPE_DOMAIN) | BIT(HK_TYPE_WQ) |\ + BIT(HK_TYPE_MANAGED_IRQ) |\ BIT(HK_TYPE_KTHREAD))/*
Signature · 1 line
2.47.0
RFC PATCH v4 2/4 genirq/cpuhotplug: Dynamically isolate CPUs from managed interrupts
In reply to Costa ShulyupinAfter change of housekeeping_cpumask(HK_TYPE_MANAGED_IRQ) during runtime managed interrupts continue to run on isolated CPUs.
Dynamic CPUs isolation is complex task. One of approaches is:
1. Set affected CPUs offline and disable relevant interrupts
2. Change housekeeping_cpumask
3. Set affected CPUs online and enable relevant interrupts
irq_restore_affinity_of_irq() restores managed interrupts during complex CPU hotplug process of bringing back a CPU online.
Leave the interrupts disabled those affinity doesn't intersect with new housekeeping_cpumask thereby ensuring isolation of the CPU from managed intrrupts.
--- kernel/irq/cpuhotplug.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/irq/cpuhotplug.c +3 -0
@@ -218,6 +218,9 @@ static void irq_restore_affinity_of_irq(struct irq_desc *desc, unsigned int cpu)if (desc->istate &IRQS_SUSPENDED )return ; +if (!cpumask_intersects (affinity,housekeeping_cpumask (HK_TYPE_MANAGED_IRQ ))) +return ; +if (irqd_is_managed_and_shutdown (data))irq_startup (desc,IRQ_RESEND ,IRQ_START_COND );
Signature · 1 line
2.47.0
Re: [RFC PATCH v4 2/4] genirq/cpuhotplug: Dynamically isolate CPUs from managed interrupts
Quoted 8 lines · Costa Shulyupin
After change of
housekeeping_cpumask(HK_TYPE_MANAGED_IRQ)during runtime managed interrupts continue to run on isolated CPUs.Dynamic CPUs isolation is complex task. One of approaches is:
1. Set affected CPUs offline and disable relevant interrupts
2. Changehousekeeping_cpumask
3. Set affected CPUs online and enable relevant interrupts
Quoted 6 lines
irq_restore_affinity_of_irq()restores managed interrupts during complex CPU hotplug process of bringing back a CPU online.Leave the interrupts disabled those affinity doesn't intersect with new
housekeeping_cpumaskthereby ensuring isolation of the CPU from managed intrrupts.
And thereby breaking drivers, which will restore the per cpu queue and expect interrupts to work.
The semantics of HK_TYPE_MANAGED_IRQ are clearly not what you try to make them. See the description of the "managed_irq" command line parameter:
Isolate from being targeted by managed interrupts which have an interrupt mask containing isolated CPUs. The affinity of managed interrupts is handled by the kernel and cannot be changed via the /proc/irq/* interfaces.
This isolation is best effort and only effective if the automatically assigned interrupt mask of a device queue contains isolated and housekeeping CPUs. If housekeeping CPUs are online then such interrupts are directed to the housekeeping CPU so that IO submitted on the housekeeping CPU cannot disturb the isolated CPU.
If a queue's affinity mask contains only isolated CPUs then this parameter has no effect on the interrupt routing decision, though interrupts are only delivered when tasks running on those isolated CPUs submit IO. IO submitted on housekeeping CPUs has no influence on those queues.
It's pretty clear, no?
Thanks,
tglx
A message that is not in the archive (sent off-list or not yet received): CADDUTFx3bS4bQ+6s2MSpAL=aN+5CP7V9i5vu-EnrfLrSYbQ_vg@mail.gmail.com
Re: [RFC PATCH v4 2/4] genirq/cpuhotplug: Dynamically isolate CPUs from managed interrupts
Quoted 5 lines · Costa Shulyupin
On Sun, 1 Dec 2024 at 15:43, Thomas Gleixner <[email protected]> wrote:
It is introduced by commita46c27026da1(blk-mq: don't schedule block kworker on isolated CPUs)I don't know what to do with the remaining drivers.
As long as that is not fixed, you obviously cannot change the semantics.
Quoted 2 lines
I am exploring the possibility of improving CPU isolation from best-effort to guaranteed.
If all drivers are fixed then the interrupt enabled state itself becomes irrelevant. If there is nothing which tickles them then they won't be raised, no?
Thanks,
tglx
RFC PATCH v4 3/4 cgroup/cpuset: Restart CPUs whose isolated_cpus bits have changed
In reply to Costa ShulyupinThe goal is to dynamically isolate CPUs to prevent interference from housekeeping subsystems.
The housekeeping CPU masks, set up by the "isolcpus" and "nohz_full" boot command line options, are used at boot time to exclude selected CPUs from running some kernel housekeeping subsystems to minimize interference with latency sensitive userspace applications such as DPDK. This options can only be changed with a reboot. This is a problem for containerized workloads running on OpenShift/Kubernetes where a mix of low latency and "normal" workloads can be created/destroyed dynamically and the number of CPUs allocated to each workload is often not known at boot time.
CPU hotplug can be used to isolate CPUs by restarting related CPUs only, without complete reboot.
Experimental solution.
Automatically restart changed CPUs when the isolated_cpus is modified through the cgroup/cpuset interface.
No additional manipulation of the CPU online status from userspace is required, and it remains compatible with existing software.
cpu_device_down()/cpu_device_up() can't be called within subroutines of cpuset_write_resmask() because it locks cpu_hotplug_lock with cpus_read_lock() but _cpu_down()/_cpu_up() lock cpu_hotplug_lock with cpus_write_lock().
Intuitively the change of isolated_cpus should be performed between cpu_device_down() and cpu_device_up(). Since cpu_device_down(), at least for managed interrupts, doesn't depends on isolated_cpus and housekeeping it is more simple to call cpu_device_down() after change of isolated_cpus and housekeeping and cpus_read_unlock().
--- kernel/cgroup/cpuset.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
kernel/cgroup/cpuset.c +35 -0
@@ -3131,6 +3131,27 @@ static void cpuset_attach(struct cgroup_taskset *tset)mutex_unlock (&cpuset_mutex); } +/* +* Restart CPUs whose isolated_cpus bits have changed. +* Enforce subsystems to adopt the new isolated_cpus and housekeeping masks +* using CPU hotplug. +*/ +static void propogate_isolated_cpus_change (struct cpumask *isolated_cpus_prev) +{ +unsigned int cpu; + +if (!isolated_cpus_prev) +return ; + +for_each_online_cpu (cpu) { +if (cpumask_test_cpu (cpu, isolated_cpus_prev) != +cpumask_test_cpu (cpu, isolated_cpus)) { +remove_cpu (cpu); +add_cpu (cpu); + } + } +} +/* * Common handling for a write to a "cpus" or "mems" file. */
@@ -3138,6 +3159,7 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct cpuset *cs = css_cs(of_css(of)); +cpumask_var_t isolated_cpus_prev;struct cpuset *trialcs;int retval = -ENODEV ;
@@ -3167,6 +3189,12 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file *of,cpus_read_lock ();mutex_lock (&cpuset_mutex); +if (!alloc_cpumask_var (&isolated_cpus_prev,GFP_KERNEL )) { + retval = -ENOMEM ; + goto out_unlock; + } + +cpumask_copy (isolated_cpus_prev, isolated_cpus);if (!is_cpuset_online (cs)) goto out_unlock;
@@ -3200,6 +3228,13 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file *of,kernfs_unbreak_active_protection (of->kn);css_put (&cs->css);flush_workqueue (cpuset_migrate_mm_wq); + +/* If isolated_cpus modified, the change must be propagated +* to all subsystems. +*/ +propogate_isolated_cpus_change (isolated_cpus_prev); +free_cpumask_var (isolated_cpus_prev); +return retval ?: nbytes; }
Signature · 1 line
2.47.0
RFC PATCH v4 4/4 DO NOT MERGE: Test CPU isolation from managed interrupts
In reply to Costa ShulyupinTest CPU isolation to ensure it is unaffected by managed interrupts.
Target: irq_restore_affinity_of_irq()
Managed interrupts can be created in various ways. One of them:
qemu-img create -f qcow2 test.qcow2 100M
virtme-ng -v --cpus 4 --rw --user root \ --qemu-opts '\-drive id=d1,if=none,file=test.qcow2 \ \-device nvme,id=i1,drive=d1,serial=1,bootindex=2'
---
v4:
- Remove /sys/devices/system/cpu/cpu$isolate/online
v3:
- No changes
v2:
- use shell script only
--- MAINTAINERS | 2 + tests/managed_irq.sh | 135 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100755 tests/managed_irq.sh
MAINTAINERS +2 -0
@@ -26046,3 +26046,5 @@ S: Buried alive in reporters T: git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git F: * F: */ + +# disable warning
tests/managed_irq.sh new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.47.0