sched: Expose writable interface for preferred CPUs mask
Subsystems (8)
cover sched: Expose writable interface for preferred CPUs mask
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor
# echo 0 > /sys/devices/system/cpu/cpu3/preferred
# taskset -c 3 ./my_workload
# echo 1 > /sys/devices/system/cpu/cpu3/preferredThe current preferred list is still readable from:
/sys/devices/system/cpu/preferred
This provides task-placement isolation similar to a use of isolcpus=domain, with a runtime interface. Scheduling domains remain intact, tick suppression, RCU offloading, and managed-IRQ avoidance can be configured separately when needed.
Different preferred cpumask governors may coexist; all update the same mask under common locking. Manual settings are not privileged, and later governor updates may override them.
The first patch relaxes preferred cpumask dependency on config PARAVIRT, because the manual control has a broader use. Even if preferred cpumask is intended to be used by steal governor, it doesn't require config PARAVIRT because s390/LPAR doesn't enable the config for their hardware assisted virtualization. Thus, patch #1 may be applied separately from the rest of the series.
Yury Norov (6):
sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
cpumask: Add reset_preferred_cpumask() helper
sched: Restore preferred CPUs when hotplug removes the last one
sched: serialize preferred cpumask update better
virt: steal_governor: Warn on unexpected preferred mask states
cpu: Add per-CPU preferred sysfs control
.../ABI/testing/sysfs-devices-system-cpu | 14 ++--- .../sysfs-devices-system-cpu-preferred | 37 +++++++++++++ Documentation/scheduler/sched-paravirt.rst | 26 +++++++-- drivers/base/cpu.c | 55 +++++++++++++++++++ drivers/virt/Kconfig | 8 ++- drivers/virt/steal_governor.c | 36 +++++++----- include/linux/cpumask.h | 20 +++++++ kernel/Kconfig.preempt | 19 ++++++- kernel/cpu.c | 4 ++ kernel/sched/core.c | 8 +++ 10 files changed, 196 insertions(+), 31 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-cpu-preferred
Signature · 1 line
2.53.0
PATCH 1/6 sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config VIRT_CPU_ACCOUNTING_NATIVE is enabled.
Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make PREFERRED_CPU a user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.
Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
---
Can be applied independently from the rest of the series.
drivers/virt/Kconfig | 8 ++++++-- kernel/Kconfig.preempt | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
drivers/virt/Kconfig +6 -2
@@ -43,9 +43,9 @@ config FSL_HV_MANAGER config STEAL_GOVERNOR tristate "Dynamic vCPU management based on steal time" - depends on PARAVIRT && SMP + depends on SMP select PREFERRED_CPU - default m + default m if PARAVIRT help This driver helps to reduce the steal time in paravirtualized environments, thereby reducing vCPU preemption costs.
@@ -55,6 +55,10 @@ config STEAL_GOVERNOR preferred CPUs could become subset of active CPUs. More details are at: Documentation/driver-api/steal-governor.rst + It doesn't depend on config PARAVIRT because certain architectures + like LPAR on s390 don't enable PARAVIRT for their hardware assisted + virtualization, while providing steal time accounting. + It is recommended to build it as module and load the module to enable it.
kernel/Kconfig.preempt +10 -2
@@ -196,5 +196,13 @@ config SCHED_CLASS_EXT https://github.com/sched-ext/scx config PREFERRED_CPU - bool - depends on SMP && PARAVIRT + bool "Preferred CPU scheduling" + depends on SMP + help + Allow the fair scheduler to favor a subset of active CPUs while + respecting task CPU affinity. Non-preferred CPUs remain online + and can still run tasks whose affinity requires it. + + See Documentation/scheduler/sched-paravirt.rst for details. + + If unsure, say N.
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.
Quoted 6 lines
Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
In reply to Yury NorovQuoted 19 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>
Quoted 6 lines
---
Can be applied independently from the rest of the series.drivers/virt/Kconfig | 8 ++++++-- kernel/Kconfig.preempt | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining CONFIG_PARAVIRT. Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Thanks!
[...]
Peter Zijlstra
maintainerRe: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.
Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++-- kernel/Kconfig.preempt | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.
And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
--- arch/Kconfig | 9 +++++++++ arch/powerpc/platforms/pseries/Kconfig | 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-)
arch/Kconfig +9 -0
@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTING config HAVE_PV_STEAL_CLOCK_GEN bool +# +# Archs that can account CPUTIME_STEAL; normal route is through PARAVIRT which +# selects HAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 and PPC-LPAR +# which have their own thing and don't go through generic cputime accounting. +# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN + config HAVE_MOVE_PUD bool help
arch/powerpc/platforms/pseries/Kconfig +1 -0
@@ -41,6 +41,7 @@ config PPC_SPLPAR depends on PPC_PSERIES select PARAVIRT_SPINLOCKS if PPC_QUEUED_SPINLOCKS select PARAVIRT_TIME_ACCOUNTING if VIRT_CPU_ACCOUNTING_GEN + select HAVE_CPUTIME_STEAL default y help Enabling this option will make the kernel run more efficiently
arch/s390/Kconfig +1 -0
@@ -291,6 +291,7 @@ config S390 select USER_STACKTRACE_SUPPORT select VDSO_GETRANDOM select VIRT_CPU_ACCOUNTING + select HAVE_CPUTIME_STEAL select VMAP_STACK select ZONE_DMA # Note: keep the above list sorted alphabetically
drivers/virt/Kconfig +1 -1
@@ -43,7 +43,7 @@ config FSL_HV_MANAGER config STEAL_GOVERNOR tristate "Dynamic vCPU management based on steal time" - depends on PARAVIRT && SMP + depends on SMP && HAVE_CPUTIME_STEAL select PREFERRED_CPU default m help
Re: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 100 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++-- kernel/Kconfig.preempt | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
--- arch/Kconfig | 9 +++++++++ arch/powerpc/platforms/pseries/Kconfig | 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-)arch/Kconfig +9
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTING config HAVE_PV_STEAL_CLOCK_GEN bool +# +# Archs that can account CPUTIME_STEAL; normal route is through PARAVIRT which +# selects HAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 and PPC-LPAR +# which have their own thing and don't go through generic cputime accounting. +# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN + config HAVE_MOVE_PUD bool helparch/powerpc/platforms/pseries/Kconfig +1
-0@@ -41,6 +41,7 @@ config PPC_SPLPAR depends on PPC_PSERIES select PARAVIRT_SPINLOCKS if PPC_QUEUED_SPINLOCKS select PARAVIRT_TIME_ACCOUNTING if VIRT_CPU_ACCOUNTING_GEN + select HAVE_CPUTIME_STEAL default y help Enabling this option will make the kernel run more efficientlyarch/s390/Kconfig +1
-0@@ -291,6 +291,7 @@ config S390 select USER_STACKTRACE_SUPPORT select VDSO_GETRANDOM select VIRT_CPU_ACCOUNTING + select HAVE_CPUTIME_STEAL select VMAP_STACK select ZONE_DMA # Note: keep the above list sorted alphabeticallydrivers/virt/Kconfig +0
-0
drivers/virt/Kconfig config FSL_HV_MANAGER · line 49
Quoted 8 lines
drivers/virt/Kconfig +1
-1@@ -43,7 +43,7 @@ config FSL_HV_MANAGER config STEAL_GOVERNOR tristate "Dynamic vCPU management based on steal time" - depends on PARAVIRT && SMP + depends on SMP && HAVE_CPUTIME_STEAL select PREFERRED_CPU default m help
I can't comment on the PPC part, but for s390 this works fine with the following addition:
kernel/Kconfig.preempt +1 -1
@@ -197,4 +197,4 @@ config SCHED_CLASS_EXT config PREFERRED_CPU bool - depends on SMP && PARAVIRT + depends on SMP && HAVE_CPUTIME_STEAL
Shrikanth Hegde
maintainerRe: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Hi.
Quoted 54 lines · Ilya Leoshkevich
Quoted 51 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 7 lines
arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig
Quoted 9 lines
arch/Kconfig +9
-0+# +# Archs that can account CPUTIME_STEAL; normal route is through PARAVIRT which +# selects HAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 and PPC-LPAR +# which have their own thing and don't go through generic cputime accounting. +# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +
Can't PARAVIRT_TIME_ACCOUNTING be the kconfig we can rely upon. s390 can add it to the config (similar to HAVE_CPUTIME_STEAL)?
I guess it is selected currently where the steal time reporting happens.
Quoted 46 lines
Quoted 32 lines
config
HAVE_MOVE_PUD
bool
helparch/powerpc/platforms/pseries/Kconfig +0
-0@@ -41,6 +41,7 @@ config PPC_SPLPARdepends on
PPC_PSERIES
selectPARAVIRT_SPINLOCKSifPPC_QUEUED_SPINLOCKSselectPARAVIRT_TIME_ACCOUNTINGifVIRT_CPU_ACCOUNTING_GEN+ selectHAVE_CPUTIME_STEAL
default y
help
Enabling this option will make the kernel run more efficientlyarch/s390/Kconfig +0
-0@@ -291,6 +291,7 @@ config S390select
USER_STACKTRACE_SUPPORT
selectVDSO_GETRANDOM
selectVIRT_CPU_ACCOUNTING
+ selectHAVE_CPUTIME_STEAL
selectVMAP_STACK
selectZONE_DMA
# Note: keep the above list sorted alphabeticallydrivers/virt/Kconfig +0
-0@@ -43,7 +43,7 @@ config FSL_HV_MANAGERQuoted 7 lines
config
STEAL_GOVERNOR
tristate "Dynamic vCPU management based on steal time" - depends on PARAVIRT && SMP
+ depends on SMP &&HAVE_CPUTIME_STEAL
selectPREFERRED_CPU
default m
helpI can't comment on the PPC part, but for s390 this works fine with the following addition:
kernel/Kconfig.preempt config SCHED_CLASS_EXT · line 200
Quoted 5 lines
kernel/Kconfig.preempt +1
-1@@ -197,4 +197,4 @@ config SCHED_CLASS_EXT config PREFERRED_CPU bool - depends on SMP && PARAVIRT + depends on SMP && HAVE_CPUTIME_STEAL
PS: I haven't read the series yet.
Will try to do so when it get little bit of time.
Re: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 81 lines · Shrikanth Hegde
Hi.
Quoted 65 lines · Ilya Leoshkevich
Quoted 62 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig +2
-0+# +# Archs that can account CPUTIME_STEAL; normal route is throughPARAVIRT which
+# selectsHAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 andQuoted 8 lines
arch/Kconfig
Quoted 8 lines
PPC-LPAR
+# which have their own thing and don't go through generic cputime accounting.arch/Kconfig +5
-0+# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +Can't
PARAVIRT_TIME_ACCOUNTINGbe the kconfig we can rely upon. s390 can add it to the config (similar toHAVE_CPUTIME_STEAL)?
Quoted 1 line
I guess it is selected currently where the steal time reporting happens.
Looking at update_rq_clock_task(), s390 would still need to provide a pointless dummy paravirt_steal_clock() implementation in this case.
[...]
Shrikanth Hegde
maintainerRe: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 81 lines · Ilya Leoshkevich
Quoted 78 lines · Shrikanth Hegde
Hi.
Quoted 54 lines · Ilya Leoshkevich
Quoted 51 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)Quoted 16 lines
Quoted 7 lines
arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig
Quoted 9 lines
arch/Kconfig +9
-0+# +# Archs that can account CPUTIME_STEAL; normal route is through PARAVIRT which +# selects HAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 and PPC-LPAR +# which have their own thing and don't go through generic cputime accounting. +# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +Can't
PARAVIRT_TIME_ACCOUNTINGbe the kconfig we can rely upon. s390 can add it to the config (similar toHAVE_CPUTIME_STEAL)?
Quoted 6 lines
Quoted 1 line
I guess it is selected currently where the steal time reporting happens.
Looking at
update_rq_clock_task(), s390 would still need to provide a pointless dummyparavirt_steal_clock()implementation in this case.[...]
Ah. Peter's change seems fine to me.
Shrikanth Hegde
maintainerRe: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
In reply to Ilya LeoshkevichHi Ilya,
Quoted 81 lines · Ilya Leoshkevich
Quoted 78 lines · Shrikanth Hegde
Hi.
Quoted 54 lines · Ilya Leoshkevich
Quoted 51 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)Quoted 16 lines
Quoted 7 lines
arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig
Quoted 9 lines
arch/Kconfig +9
-0+# +# Archs that can account CPUTIME_STEAL; normal route is through PARAVIRT which +# selects HAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 and PPC-LPAR +# which have their own thing and don't go through generic cputime accounting. +# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +Can't
PARAVIRT_TIME_ACCOUNTINGbe the kconfig we can rely upon. s390 can add it to the config (similar toHAVE_CPUTIME_STEAL)?
Quoted 6 lines
Quoted 1 line
I guess it is selected currently where the steal time reporting happens.
Looking at
update_rq_clock_task(), s390 would still need to provide a pointless dummyparavirt_steal_clock()implementation in this case.[...]
Other possible option is, you could use CONFIG_HAVE_PV_STEAL_CLOCK_GEN which defines the dummy implementation and you don't update that method. That way you may implement PARAVIRT_TIME_ACCOUNTING mostly with kconfig changes.
But it needs the arch to implement static calls. I am not sure if s390 has it.
Re: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 92 lines · Shrikanth Hegde
Hi Ilya,
Quoted 89 lines · Ilya Leoshkevich
Quoted 81 lines · Shrikanth Hegde
Hi.
Quoted 65 lines · Ilya Leoshkevich
Quoted 62 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig +2
-0+# +# Archs that can account CPUTIME_STEAL; normal route is throughPARAVIRT which
+# selectsHAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 andQuoted 8 lines
arch/Kconfig
Quoted 8 lines
PPC-LPAR
+# which have their own thing and don't go through generic cputime accounting.arch/Kconfig +5
-0+# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +Can't
PARAVIRT_TIME_ACCOUNTINGbe the kconfig we can rely upon. s390 can add it to the config (similar toHAVE_CPUTIME_STEAL)?Quoted 1 line
I guess it is selected currently where the steal time reporting happens.
Looking at
update_rq_clock_task(), s390 would still need to provide a pointless dummyparavirt_steal_clock()implementation in this case.
Quoted 7 lines
Quoted 1 line
[...]
Other possible option is, you could use
CONFIG_HAVE_PV_STEAL_CLOCK_GENwhich defines the dummy implementation and you don't update that method. That way you may implementPARAVIRT_TIME_ACCOUNTINGmostly with kconfig changes.But it needs the arch to implement static calls. I am not sure if s390 has it.
We will get non-optimized static calls soon [1], so this would be not so great from performance PoV.
I think HAVE_CPUTIME_STEAL is a good solution. It allows to disable PREFERRED_CPU and STEAL_GOVERNOR on systems which do not do steal time accounting, while, unlike PARAVIRT, PARAVIRT_TIME_ACCOUNTING, and HAVE_PV_STEAL_CLOCK_GEN, not prescribing how the other architectures should implement steal time accounting.
Re: [PATCH 1/6] sched: decouple PREFERRED_CPU from PARAVIRT in Kconfig.preempt
Quoted 97 lines · Ilya Leoshkevich
Quoted 94 lines · Shrikanth Hegde
Hi Ilya,
Quoted 90 lines · Ilya Leoshkevich
Quoted 81 lines · Shrikanth Hegde
Hi.
Quoted 65 lines · Ilya Leoshkevich
Quoted 62 lines · Peter Zijlstra
Quoted 25 lines · Ilya Leoshkevich
Quoted 22 lines · Yury Norov
The IBM s390 doesn't enable PARAVIRT config for their hardware virtualized Logical Partitions (LPAR). However, the steal time is accounted for the LPARs, once the config
VIRT_CPU_ACCOUNTING_NATIVEis enabled.Preferred cpumask doesn't rely on any feature gated by PARAVIRT config, and requires it to minimize the configuration space and runtime overhead, with the lack of non-paravirt user. Now that s390 wants to adopt preferred cpumask, there's no reason to keep it coupled to paravirt.
Make
PREFERRED_CPUa user-configurable option, even if paravirtualization is not enabled, and drop PARAVIRT dependency on the steal governor.Keep the default module selection conditional on PARAVIRT so other SMP configurations can opt in without enabling the governor by default.
CC Mete Durlu <[email protected]>Signed-off-by Yury Norov <[email protected]>---
Can be applied independently from the rest of the series.Quoted 7 lines
Quoted 3 lines
drivers/virt/Kconfig | 8 ++++++--
kernel/Kconfig.preempt| 12 ++++++++++--2 files changed, 16 insertions(+), 4 deletions(-)This is really useful to us, since even though s390 is nominally paravirtualized, it does not technically benefit from defining
CONFIG_PARAVIRT.And therefore removing PARAVIRT is the only possible solution?
Quoted 3 lines
Specifically, steal time accounting happens by computing a difference between wall time and CPU time, and not by explicitly querying the hypervisor.
Nobody explicitly asks the hypervisor, that would be horrendously slow.
Something trivial like this should do.
---
arch/Kconfig | 9 +++++++++arch/powerpc/platforms/pseries/Kconfig| 1 + arch/s390/Kconfig | 1 + drivers/virt/Kconfig | 2 +-4 files changed, 12 insertions(+), 1 deletion(-)arch/Kconfig +0
-0@@ -1080,6 +1080,15 @@ config HAVE_IRQ_TIME_ACCOUNTINGconfig
HAVE_PV_STEAL_CLOCK_GEN
boolarch/Kconfig +2
-0+# +# Archs that can account CPUTIME_STEAL; normal route is throughPARAVIRT which
+# selectsHAVE_PV_STEAL_CLOCK_GEN. Directly selected by s390 andQuoted 8 lines
arch/Kconfig
Quoted 8 lines
PPC-LPAR
+# which have their own thing and don't go through generic cputime accounting.arch/Kconfig +5
-0+# +config HAVE_CPUTIME_STEAL + bool + default y if HAVE_PV_STEAL_CLOCK_GEN +Can't
PARAVIRT_TIME_ACCOUNTINGbe the kconfig we can rely upon. s390 can add it to the config (similar toHAVE_CPUTIME_STEAL)?Quoted 1 line
I guess it is selected currently where the steal time reporting happens.
Looking at
update_rq_clock_task(), s390 would still need to provide a pointless dummyparavirt_steal_clock()implementation in this case.[...]
Quoted 8 lines
Quoted 5 lines
Other possible option is, you could use
CONFIG_HAVE_PV_STEAL_CLOCK_GENwhich defines the dummy implementation and you don't update that method. That way you may implementPARAVIRT_TIME_ACCOUNTINGmostly with kconfig changes.But it needs the arch to implement static calls. I am not sure if s390 has it.
We will get non-optimized static calls soon [1], so this would be not so great from performance PoV.
I just realized it's enabled only when CFI is enabled, so it's not an option anyway.
[...]
PATCH 2/6 cpumask: Add reset_preferred_cpumask() helper
In reply to Yury NorovThis series adds more flexibility to control the 'preferred' status of CPUs. As a preparation, move the steal governor's preferred-mask reset into cpumask.h to make it globally available.
While there, rename it to shorter "reset_preferred_cpumask()".
--- drivers/virt/steal_governor.c | 15 ++++----------- include/linux/cpumask.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-)
drivers/virt/steal_governor.c +4 -11
@@ -51,15 +51,6 @@ static struct steal_governor sg_ctx = { .low_threshold = 200, /* 2% */ }; -static void restore_preferred_to_active (void ) -{ -int cpu; - -guard (cpus_read_lock)(); -for_each_cpu (cpu, cpu_active_mask) -set_cpu_preferred (cpu, true); -} -static int param_set_interval_ms (const char *val,const struct kernel_param *kp) {unsigned int interval;
@@ -247,7 +238,8 @@ static void steal_governor_loop(struct work_struct *work)* module restores to active if CPU hotplug breaks those assumptions. */ if (!preferred_cpus_valid ()) { -restore_preferred_to_active (); +scoped_guard (cpus_read_lock) +reset_preferred_cpumask ();return ; }
@@ -284,7 +276,8 @@ static int __init steal_governor_init(void) static void __exit steal_governor_exit(void) {disable_delayed_work_sync (&sg_ctx.work); -restore_preferred_to_active (); +scoped_guard (cpus_read_lock) +reset_preferred_cpumask ();pr_info ("disabled\n" ); }
include/linux/cpumask.h +12 -0
@@ -1195,6 +1195,18 @@ void init_cpu_possible(const struct cpumask *src);#define set_cpu_preferred (cpu, preferred) do { } while (0)#endif +/** +* reset_preferred_cpumask - reset preferred CPUs to the active mask. +* +* Callers must serialize against CPU hotplug and other preferred cpumask +* writers. +*/ +static inline void reset_preferred_cpumask (void ) +{ +if (IS_ENABLED (CONFIG_PREFERRED_CPU )) +cpumask_copy (&__cpu_preferred_mask, cpu_active_mask); +} +void set_cpu_online (unsigned int cpu,bool online);void set_cpu_possible (unsigned int cpu,bool possible);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/6] cpumask: Add reset_preferred_cpumask() helper
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
This series adds more flexibility to control the 'preferred' status of CPUs. As a preparation, move the steal governor's preferred-mask reset into
cpumask.hto make it globally available.While there, rename it to shorter "
reset_preferred_cpumask()".Signed-off-by Yury Norov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/6 sched: Restore preferred CPUs when hotplug removes the last one
In reply to Yury NorovOfflining the last preferred CPU leaves cpu_preferred_mask empty. Normal fair load balancing stops, potentially leaving CPUs idle while tasks remain queued.
Currently, the steal governor is the only module that may modify the mask, so it takes care of this by resetting the mask to mirror the active cpumask, but stops sampling after that.
This series adds more ways to control the preferred cpumask, so steal governor may not be active.
Restore all remaining active CPUs as preferred in sched_cpu_deactivate() path, without relying on the steal governor to recover.
--- kernel/sched/core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/sched/core.c +8 -0
@@ -8712,6 +8712,14 @@ int sched_cpu_deactivate(unsigned int cpu)set_cpu_active (cpu, false); +#ifdef CONFIG_PREFERRED_CPU +if (cpumask_empty (cpu_preferred_mask)) { +pr_notice ("sched: last preferred CPU%u offlined; make all active CPUs preferred\n" , + cpu); +reset_preferred_cpumask (); + } +#endif +/* * From this point forward, this CPU will refuse to run any task that * is not: migrate_disable() or KTHREAD_IS_PER_CPU, and will actively
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 3/6] sched: Restore preferred CPUs when hotplug removes the last one
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Offlining the last preferred CPU leaves
cpu_preferred_maskempty. Normal fair load balancing stops, potentially leaving CPUs idle while tasks remain queued.Currently, the steal governor is the only module that may modify the mask, so it takes care of this by resetting the mask to mirror the active cpumask, but stops sampling after that.
Quoted 7 lines
This series adds more ways to control the preferred cpumask, so steal governor may not be active.
Restore all remaining active CPUs as preferred in
sched_cpu_deactivate()path, without relying on the steal governor to recover.Signed-off-by Yury Norov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/6] sched: Restore preferred CPUs when hotplug removes the last one
In reply to Yury Norovkernel/sched/core.c int sched_cpu_deactivate(unsigned int cpu) · line 8719
Quoted 13 lines
kernel/sched/core.c +5
-0@@ -8712,6 +8712,14 @@ int sched_cpu_deactivate(unsigned int cpu)set_cpu_active (cpu, false); +#ifdef CONFIG_PREFERRED_CPU +if (cpumask_empty (cpu_preferred_mask)) { +pr_notice ("sched: last preferred CPU%u offlined; make all active CPUs preferred\n" , + cpu); +reset_preferred_cpumask ();
Hi, Yury
If the CPU being offlined is the only preferred CPU, after reset_preferred_cpumask(), the steal governor may still need some time to tighten the mask again, and eventually only one preferred CPU may remain. Would this introduce additional task migration overhead?
Regards,
Fushuai.
Quoted 6 lines
kernel/sched/core.c +3
-0+ } +#endif +/* * From this point forward, this CPU will refuse to run any task that * is not: migrate_disable() or KTHREAD_IS_PER_CPU, and will actively
Re: [PATCH 3/6] sched: Restore preferred CPUs when hotplug removes the last one
Quoted 16 lines · Fushuai Wang
kernel/sched/core.c int sched_cpu_deactivate(unsigned int cpu) · line 8719
Quoted 13 lines
kernel/sched/core.c +5
-0@@ -8712,6 +8712,14 @@ int sched_cpu_deactivate(unsigned int cpu)set_cpu_active (cpu, false); +#ifdef CONFIG_PREFERRED_CPU +if (cpumask_empty (cpu_preferred_mask)) { +pr_notice ("sched: last preferred CPU%u offlined; make all active CPUs preferred\n" , + cpu); +reset_preferred_cpumask ();Hi, Yury
Quoted 5 lines
If the CPU being offlined is the only preferred CPU, after
reset_preferred_cpumask(), the steal governor may still need some time to tighten the mask again, and eventually only one preferred CPU may remain. Would this introduce additional task migration overhead?
This is the safest fallback from the scheduler POV. Current steal governor implementation would require multiple iterations to get back to the old equilibrium. If it will show up as a real problem, we can teach steal governor to converge faster, and/or detect the preferred mask reset.
Thanks,
Yury
PATCH 4/6 sched: serialize preferred cpumask update better
In reply to Yury NorovThis series adds more flexibility to control the 'preferred' status of CPUs, so that multiple modules may access the mask concurrently. Thus, add the cpu_preferred_mutex.
With that, the scheme would look like this:
- if your code takes cpus_write_lock(), it's enough to write-access the preferred cpumask;
- if your code takes cpus_read_lock(), you'd also take cpu_preferred_mutex in order to modify the preferred mask.
This approach also fixes the existing race between steal governor sampling and hotplug/unplug.
--- drivers/virt/steal_governor.c | 21 ++++++++++++++++----- include/linux/cpumask.h | 15 ++++++++++++--- kernel/cpu.c | 4 ++++ 3 files changed, 32 insertions(+), 8 deletions(-)
drivers/virt/steal_governor.c +16 -5
@@ -23,6 +23,7 @@#include <linux/ktime.h> #include <linux/math64.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/sched/isolation.h> #include <linux/topology.h> #include <linux/types.h>
@@ -134,7 +135,8 @@ static void decrease_preferred_cpus(void)int target_cpu = nr_cpu_ids;int cpu; -guard (cpus_read_lock)(); +lockdep_assert_cpus_held (); +lockdep_assert_held (&cpu_preferred_mutex); cpu =cpumask_first_and (housekeeping_cpumask (HK_TYPE_KERNEL_NOISE ), cpu_preferred_mask);if (cpu >= nr_cpu_ids)
@@ -174,7 +176,8 @@ static void increase_preferred_cpus(void) {int first_cpu, cpu; -guard (cpus_read_lock)(); +lockdep_assert_cpus_held (); +lockdep_assert_held (&cpu_preferred_mutex); first_cpu =cpumask_first_andnot (cpu_active_mask, cpu_preferred_mask);/* All CPUs are preferred. Nothing to increase further */
@@ -188,6 +191,9 @@ static void increase_preferred_cpus(void)static bool preferred_cpus_valid (void ) { +lockdep_assert_cpus_held (); +lockdep_assert_held (&cpu_preferred_mutex); +if (cpumask_empty (cpu_preferred_mask)) {pr_err ("empty preferred mask. stopping\n" );return false;
@@ -208,6 +214,9 @@ static void steal_governor_loop(struct work_struct *work)u64 curr_steal, delta_steal, delta_ns, steal_ratio;ktime_t now; +guard (cpus_read_lock)(); +guard (mutex)(&cpu_preferred_mutex); + now =ktime_get (); delta_ns =ktime_to_ns (ktime_sub (now, sg_ctx.time));
@@ -238,8 +247,7 @@ static void steal_governor_loop(struct work_struct *work)* module restores to active if CPU hotplug breaks those assumptions. */ if (!preferred_cpus_valid ()) { -scoped_guard (cpus_read_lock) -reset_preferred_cpumask (); +reset_preferred_cpumask ();return ; }
@@ -276,8 +284,11 @@ static int __init steal_governor_init(void) static void __exit steal_governor_exit(void) {disable_delayed_work_sync (&sg_ctx.work); -scoped_guard (cpus_read_lock) +scoped_guard (cpus_read_lock) { +guard (mutex)(&cpu_preferred_mutex); +reset_preferred_cpumask (); + }pr_info ("disabled\n" ); }
include/linux/cpumask.h +12 -3
@@ -123,7 +123,14 @@ extern struct cpumask __cpu_active_mask;extern struct cpumask __cpu_dying_mask;#ifdef CONFIG_PREFERRED_CPU +/* +* Drivers must take cpus_read_lock() before cpu_preferred_mutex and +* hold both across mask validation and updates. If cpus_write_lock() +* is held, it guarantees the exclusive access to the mask, thus +* holding cpu_preferred_mutex isn't necessary. +*/ extern struct cpumask __cpu_preferred_mask; +extern struct mutex cpu_preferred_mutex;#else #define __cpu_preferred_mask __cpu_active_mask#endif
@@ -1199,12 +1206,14 @@ void init_cpu_possible(const struct cpumask *src);* reset_preferred_cpumask - reset preferred CPUs to the active mask. * * Callers must serialize against CPU hotplug and other preferred cpumask -* writers. +* writers. Requires cpus_read_lock() and cpu_preferred_mutex; or +* cpus_write_lock(). */ static inline void reset_preferred_cpumask (void ) { -if (IS_ENABLED (CONFIG_PREFERRED_CPU )) -cpumask_copy (&__cpu_preferred_mask, cpu_active_mask); +#ifdef CONFIG_PREFERRED_CPU +cpumask_copy (&__cpu_preferred_mask, cpu_active_mask); +#endif }void set_cpu_online (unsigned int cpu,bool online);
kernel/cpu.c +4 -0
@@ -3106,6 +3106,10 @@ EXPORT_SYMBOL(__num_online_cpus);#ifdef CONFIG_PREFERRED_CPU struct cpumask __cpu_preferred_mask__read_mostly ;EXPORT_SYMBOL_GPL (__cpu_preferred_mask); + +/* Serialize policy drivers; acquire inside cpus_read_lock(). */ +DEFINE_MUTEX (cpu_preferred_mutex); +EXPORT_SYMBOL_GPL (cpu_preferred_mutex);#endif void init_cpu_present (const struct cpumask *src)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 4/6] sched: serialize preferred cpumask update better
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
This series adds more flexibility to control the 'preferred' status of CPUs, so that multiple modules may access the mask concurrently. Thus, add the
cpu_preferred_mutex.With that, the scheme would look like this:
- if your code takes
cpus_write_lock(), it's enough to write-access the preferred cpumask;
- if your code takescpus_read_lock(), you'd also takecpu_preferred_mutexin order to modify the preferred mask.
Quoted 5 lines
This approach also fixes the existing race between steal governor sampling and hotplug/unplug.
Fixes 27d47ebce4d6 ("virt/steal_governor: Implement steal_governor policy loop")Signed-off-by Yury Norov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH 5/6 virt: steal_governor: Warn on unexpected preferred mask states
In reply to Yury NorovNow that preferred cpumask access is properly serialized, and CPU hotplug restores all remaining active CPUs as preferred when the last preferred CPU gets offlined, the corresponding logic in the driver is redundant.
Instead of removing it completely, add WARN_ON()s in the corresponding conditionals to harden the preferred CPUs mask management and highlight that this condition is not expected during normal operation.
--- drivers/virt/steal_governor.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/virt/steal_governor.c +4 -2
@@ -145,7 +145,9 @@ static void decrease_preferred_cpus(void)/* Always leave first housekeeping core as preferred. */ first_hk_core =topology_sibling_cpumask (cpu); cpu =cpumask_last (cpu_preferred_mask); -if (cpu >= nr_cpu_ids) + +/* We can't end up with no preferred CPUs under normal conditions. */ +if (WARN_ON (cpu >= nr_cpu_ids))return ;/* Find the last CPU which doesn't belong to that first hk_core. */
@@ -246,7 +248,7 @@ static void steal_governor_loop(struct work_struct *work)* else: steal ratio is within bounds. Still do design checks so that * module restores to active if CPU hotplug breaks those assumptions. */ -if (!preferred_cpus_valid ()) { +if (WARN_ON (!preferred_cpus_valid ())) {reset_preferred_cpumask ();return ; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 5/6] virt: steal_governor: Warn on unexpected preferred mask states
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] virt: steal_governor: unreachable WARN_ON() in decrease_preferred_cpus() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] virt: steal_governor: unreachable WARN_ON() in decrease_preferred_cpus() --
commit 735c9f0cd33ee22cf920d749e3d1bde33a6cf851
Author: Yury Norov <[email protected]>
virt: steal_governor: Warn on unexpected preferred mask states
This commit adds WARN_ON() checks in decrease_preferred_cpus() and steal_governor_loop() to warn if cpu_preferred_mask enters an unexpected state.
drivers/virt/steal_governor.c static void decrease_preferred_cpus(void) · line 151
Quoted 13 lines
drivers/virt/steal_governor.c +3
-1@@ -145,7 +145,9 @@ static void decrease_preferred_cpus(void)/* Always leave first housekeeping core as preferred. */ first_hk_core =topology_sibling_cpumask (cpu); cpu =cpumask_last (cpu_preferred_mask); -if (cpu >= nr_cpu_ids) + +/* We can't end up with no preferred CPUs under normal conditions. */ +if (WARN_ON (cpu >= nr_cpu_ids))return ;
[Severity: Low]
Can this WARN_ON() in decrease_preferred_cpus() ever be reached?
Just above this check in drivers/virt/steal_governor.c, decrease_preferred_cpus() already checks whether the intersection of the housekeeping cpumask and cpu_preferred_mask is empty while holding cpus_read_lock() and cpu_preferred_mutex:
cpu = cpumask_first_and(housekeeping_cpumask(HK_TYPE_KERNEL_NOISE), cpu_preferred_mask); if (cpu >= nr_cpu_ids) return;
If cpu_preferred_mask is empty on entry, cpumask_first_and() returns nr_cpu_ids and decrease_preferred_cpus() returns early before reaching cpumask_last(cpu_preferred_mask). Otherwise, at least one bit in cpu_preferred_mask is set, so cpumask_last(cpu_preferred_mask) is guaranteed to be less than nr_cpu_ids.
Should this check be removed, or should the warning be placed on the earlier check if an empty preferred mask is what this is meant to catch?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH 6/6 cpu: Add per-CPU preferred sysfs control
In reply to Yury NorovExpose a writable preferred attribute for each CPU so users can manually select CPUs for scheduler placement. This allows users to select any desired combination of preferred CPUs, except for selecting inactive CPUs and deselecting the last preferred CPU.
The manual method doesn't imply any preference over automated governors. If an automated module is loaded, it may override user preferences, and vice versa.
Fair tasks whose allowed CPUs contain no preferred CPU can still run on active non-preferred CPUs. Other scheduling classes are unaffected. This creates an environment similar to isolcpus, except that the list of isolated CPUs can't be changed at runtime. Tick suppression, RCU offloading, and managed-IRQ avoidance are compatible with preferred CPUs, but may require separate configuration.
--- .../ABI/testing/sysfs-devices-system-cpu | 14 ++--- .../sysfs-devices-system-cpu-preferred | 37 +++++++++++++ Documentation/scheduler/sched-paravirt.rst | 26 +++++++-- drivers/base/cpu.c | 55 +++++++++++++++++++ kernel/Kconfig.preempt | 9 ++- 5 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-system-cpu-preferred
Documentation/ABI/testing/sysfs-devices-system-cpu +6 -8
@@ -821,12 +821,10 @@ What: /sys/devices/system/cpu/preferred Date: Sep 2026 Contact: Linux kernel mailing list <[email protected]> Description: - (RO) the list of preferred CPUs applicable in - paravirtualized environments. + (RO) the list of CPUs preferred for fair-task placement. + Fair tasks whose allowed CPUs contain no preferred CPU can + still run on active non-preferred CPUs. Other scheduling + classes are unaffected. - The steal governor driver dynamically adjusts this mask - based on observed steal time. Scheduling tasks on - CPUs outside of this list may lead to performance - degradations due to underlying physical CPU contention. - - See Documentation/scheduler/sched-paravirt.rst for more details. + See: Documentation/ABI/testing/sysfs-devices-system-cpu-preferred; + Documentation/scheduler/sched-paravirt.rst for more details.
Documentation/ABI/testing/sysfs-devices-system-cpu-preferred new file +37 -0
@@ -0,0 +1,37 @@ +What: /sys/devices/system/cpu/cpu[0-9]*/preferred +Date: October 2026 +Contact: Yury Norov <[email protected]> +Description: + Control the availability of a given CPU for fair scheduler to + place tasks. Reads 1 if this CPU is preferred, 0 otherwise. + Fair tasks whose allowed CPUs contain no preferred CPU can + still run on active non-preferred CPUs. Other scheduling + classes are unaffected. + + As for the online attribute, boolean spellings such as 1/0, y/n + or on/off are accepted to set the preferred status of the CPU. + + Removing a CPU from the preferred list and pinning a certain + task(s) on it provides a runtime environment similar to + isolcpus. Tick suppression, RCU offloading, and managed-IRQ + avoidance are compatible with preferred CPUs as well. + + Selecting an inactive CPU, deselecting the last preferred CPU, + or writing an invalid boolean fails with EINVAL without changing + the mask. Writing the current value is a no-op. Writes across + all CPUs are serialized. To replace a selection, select new CPUs + before deselecting the old ones. + + The list of preferred CPUs can be found in: + + /sys/devices/system/cpu/preferred. + + CPU hotplug sets the status of new active CPU as preferred, and + deactivated CPUs become non-preferred. Offlining the last + preferred CPU resets the status such that all remaining active + CPUs become preferred; and emits a notice in the kernel log. + + This interface can be used together with automated interfaces, + like steal governor. All interfaces have the same priority: if + running in parallel, they may override each other's policy in + any order.
Documentation/scheduler/sched-paravirt.rst +22 -4
@@ -42,13 +42,31 @@ This is achieved by: ``/sys/devices/system/cpu/preferred`` prints the current ``cpu_preferred_mask`` in cpulist format. +Manual selection is available with ``CONFIG_PREFERRED_CPU`` (which can coexist +with ``CONFIG_STEAL_GOVERNOR``). Write ``1`` or ``0`` to a CPU's ``preferred`` +attribute as root, for example:: + + echo 1 > /sys/devices/system/cpu/cpu1/preferred + echo 0 > /sys/devices/system/cpu/cpu0/preferred + +Only active CPUs can be selected, and the last preferred CPU cannot be +deselected. The attribute is available even for CPUs without an ``online`` +attribute. The aggregate ``/sys/devices/system/cpu/preferred`` remains +read-only. + +Manual writes and steal governor updates are serialized. Manual selections +are not persistent constraints: subsequent governor samples may change them. + +See ``Documentation/ABI/testing/sysfs-devices-system-cpu-preferred`` for the +interface and CPU hotplug semantics. + Notes: 1. This feature is available under ``CONFIG_PREFERRED_CPU``. Driver which makes decisions should enable it. For example, steal_governor driver (``CONFIG_STEAL_GOVERNOR``). On enabling the driver, CPU preferred state - can change based on steal time. Without the driver, preferred CPUs is - same as active CPUs. + can change based on steal time. Initially, all active CPUs are preferred. + Manual sysfs writes can change the mask without a policy driver. 2. This feature works for the FAIR class only.
@@ -56,8 +74,8 @@ Notes: to run based on its affinity. But no load balancing happens if it is affined only on non-preferred CPUs. -4. Decision to change the preferred CPU state is driven by the kernel. - Hence it shouldn't break user affinities. One of the main reasons why +4. Preferred CPU state can be changed by a kernel policy driver or through + sysfs, while preserving task affinity. One of the main reasons why CPU hotplug or Isolated cpuset partitions was not a solution. 5. This feature works best only when all the Guest VMs enable the feature as
drivers/base/cpu.c +55 -0
79 lines not on this page · raw message
kernel/Kconfig.preempt +8 -1
@@ -203,6 +203,13 @@ config PREFERRED_CPU respecting task CPU affinity. Non-preferred CPUs remain online and can still run tasks whose affinity requires it. - See Documentation/scheduler/sched-paravirt.rst for details. + Preferred CPUs can be selected manually through the per-CPU + preferred sysfs attribute or managed automatically, e.g. by the + steal governor to reduce CPU contention in virtual machines. All + active CPUs are preferred initially. + + See Documentation/scheduler/sched-paravirt.rst and + Documentation/ABI/testing/sysfs-devices-system-cpu-preferred + for details. If unsure, say N.
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 6/6] cpu: Add per-CPU preferred sysfs control
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Expose a writable preferred attribute for each CPU so users can manually select CPUs for scheduler placement. This allows users to select any desired combination of preferred CPUs, except for selecting inactive CPUs and deselecting the last preferred CPU.
The manual method doesn't imply any preference over automated governors. If an automated module is loaded, it may override user preferences, and vice versa.
Quoted 8 lines
Fair tasks whose allowed CPUs contain no preferred CPU can still run on active non-preferred CPUs. Other scheduling classes are unaffected. This creates an environment similar to isolcpus, except that the list of isolated CPUs can't be changed at runtime. Tick suppression, RCU offloading, and managed-IRQ avoidance are compatible with preferred CPUs, but may require separate configuration.
Signed-off-by Yury Norov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Peter Zijlstra
maintainerQuoted 3 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
Sceptical, I am.
Quoted 2 lines
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
That's exactly the kind of nonsense we don't need and makes me want to stop reading right here.
We already have cpusets that is more than capable of doing this.
Quoted 15 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredThe current preferred list is still readable from:
/sys/devices/system/cpu/preferred
Quoted 8 lines
This provides task-placement isolation similar to a use of isolcpus=domain, with a runtime interface. Scheduling domains remain intact, tick suppression, RCU offloading, and managed-IRQ avoidance can be configured separately when needed.
Different preferred cpumask governors may coexist; all update the same mask under common locking. Manual settings are not privileged, and later governor updates may override them.
That is a recipe for disaster.
Don't bother trying again, this isn't happening.
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
Quoted 7 lines
Sceptical, I am.
Quoted 2 lines
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
That's exactly the kind of nonsense we don't need and makes me want to stop reading right here.
OK, I started with the wrong argument. Please consider this as the argument #3.
#1 is: conceptually, preferred cpumask improves performance because it moves the scheduling decision from host to the guest level. The guest can do it better because it knows more about the workload. But then we'd consider moving steal governor logic to the guest userspace, because it knows the nature of user workload even more.
#2: convenience and scope. Some systems don't allow loading modules - either on config level, through selinux, or somehow else. They don't even have compiler installed sometimes. The sysfs, on the other hand, is typically available.
I want to be able to write a simple userspace daemon that implements steal governing without loading any modules; and i want to be able to tailor my daemon to my specific workload. That all requires write interface.
Quoted 1 line
we already have cpusets that is more than capable of doing this.
Then why do we need the steal governor at all? We can steer all processes away from a given vCPU without any driver, only by playing with each individual process' affinity. For vCPU throttling, task isolation, or whatever purpose.
Because of the overhead and convenience to use. Setting an explicit affinity for each task would require preserving the original cpumask, not mentioning that it's much more invasive.
The overhead grows linearly with the number of threads. On my working station right now the number of processes is over 500, and number of threads is over 1500, and it runs pretty much idle.
This is so impractical that people would rather use boot-time isolcpus, not to mess with thousands of individual affinities on runtime.
Quoted 20 lines
Quoted 20 lines
a user can mark a cpu non-preferred and pin a workload to it. fair tasks whose affinity includes preferred cpus are steered away, while tasks whose allowed cpus contain no preferred cpu can still run there. the cpu stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredthe current preferred list is still readable from:
/sys/devices/system/cpu/preferredThis provides task-placement isolation similar to a use of isolcpus=domain, with a runtime interface. Scheduling domains remain intact, tick suppression, RCU offloading, and managed-IRQ avoidance can be configured separately when needed.
Quoted 5 lines
Quoted 3 lines
Different preferred cpumask governors may coexist; all update the same mask under common locking. Manual settings are not privileged, and later governor updates may override them.
That is a recipe for disaster.
OK, that's fair. I can make it mutually exclusive.
Thanks,
Yury
Peter Zijlstra
maintainerQuoted 14 lines · Yury Norov
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
Quoted 7 lines
Sceptical, I am.
Quoted 2 lines
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
That's exactly the kind of nonsense we don't need and makes me want to stop reading right here.
Quoted 8 lines
OK, I started with the wrong argument. Please consider this as the argument #3.
#1 is: conceptually, preferred cpumask improves performance because it moves the scheduling decision from host to the guest level. The guest can do it better because it knows more about the workload. But then we'd consider moving steal governor logic to the guest userspace, because it knows the nature of user workload even more.
I am confused; it is a simple control loop and has nothing to do with guest workload.
The host is over-committed, this results in vcpu steal time. The guests observe steal time and reduce vcpu utilization.
It is a co-operative scheme; a bad actor can game the system. It is imperative all guests behave the same or do not play at all.
If there is no level of trust (our coconut friends) do not use this.
Quoted 3 lines
#2: convenience and scope. Some systems don't allow loading modules - either on config level, through selinux, or somehow else. They don't even have compiler installed sometimes.
You hurt if you shoot your foot off; not my problem. If you run guests like that you don't use this.
Quoted 6 lines
Quoted 1 line
we already have cpusets that is more than capable of doing this.
Then why do we need the steal governor at all? We can steer all processes away from a given vCPU without any driver, only by playing with each individual process' affinity. For vCPU throttling, task isolation, or whatever purpose.
Different level of operation; different semantics. Cpusets is for strong bounds on your own workloads, this preferred mask is weak bounds on the system due to outside pressure.
In a way it isn't much different from ACPI idle injection.
Quoted 27 lines · Peter Zijlstra
Quoted 14 lines · Yury Norov
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
Quoted 7 lines
Sceptical, I am.
Quoted 2 lines
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
That's exactly the kind of nonsense we don't need and makes me want to stop reading right here.
Quoted 8 lines
OK, I started with the wrong argument. Please consider this as the argument #3.
#1 is: conceptually, preferred cpumask improves performance because it moves the scheduling decision from host to the guest level. The guest can do it better because it knows more about the workload. But then we'd consider moving steal governor logic to the guest userspace, because it knows the nature of user workload even more.
I am confused; it is a simple control loop and has nothing to do with guest workload.
Quoted 7 lines
The host is over-committed, this results in vcpu steal time. The guests observe steal time and reduce vcpu utilization.
It is a co-operative scheme; a bad actor can game the system. It is imperative all guests behave the same or do not play at all.
If there is no level of trust (our coconut friends) do not use this.
That is correct. I'm just trying to let trusted userspace to be able to make a final decision, not to cheat the policy.
I believe that the preferred cpumask approach may find more use cases than just a blind vCPU throttling.
Even in case of throttling, the userspace might know more about the nature of external pressure, workload and VM priorities, etc., so be able to make a better decision on the preferred vCPU candidates, beyond the steal time accounting.
I can imagine a host running two VMs - one for performance critical workload like AI training, and another for latency critical inference. In case of vCPU overcommitment, symmetrical throttling of both VMs may substantially affect user experience. The better solution would be allowing both VMs to communicate to each other and decide how many vCPUs should become non-preferred on each side.
Steal governor is a reasonable default approach to the vCPU overcommit problem. But I also want to be able to adjust it to my local needs, if I have to.
Quoted 6 lines
Quoted 3 lines
#2: convenience and scope. Some systems don't allow loading modules - either on config level, through selinux, or somehow else. They don't even have compiler installed sometimes.
You hurt if you shoot your foot off; not my problem. If you run guests like that you don't use this.
I don't configure systems that way - I only request shared access to the particular hardware, i.e. to run some tests, often for just a few hours. Sometimes those machines don't allow loading modules, sometimes it takes few iterations to reach to admins and ask them to update drivers...
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
we already have cpusets that is more than capable of doing this.
Then why do we need the steal governor at all? We can steer all processes away from a given vCPU without any driver, only by playing with each individual process' affinity. For vCPU throttling, task isolation, or whatever purpose.
Quoted 5 lines
Different level of operation; different semantics. Cpusets is for strong bounds on your own workloads, this preferred mask is weak bounds on the system due to outside pressure.
In a way it isn't much different from ACPI idle injection.
The idle-injection indeed has userspace interface. Powerclamp exposes its actuator through /sys/class/thermal/cooling_deviceXX, and documents userspace control loop.
By the way, preferred CPUs approach may prepend hotplug in the overheat defense chain, as a cheap but weaker alternative.
Thanks,
Yury
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 11 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferred
My use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Thanks!
--
Maxim Kuvyrkov
Garden City Compilers
Shrikanth Hegde
maintainerHi,
Quoted 20 lines · Maxim Kuvyrkov
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 7 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
Quoted 7 lines
Quoted 4 lines
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredMy use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Do you change it when running workload based on any signal/event? or you set it before starting it?
If it is set before starting, you might as well offline the CPUs to achieve the same. I assume you are managing the preferred CPUs manually with write interface. You can do the same for online state. (Though it takes a longer)
Quoted 6 lines
Thanks!
--
Maxim Kuvyrkov
Garden City Compilers
Quoted 28 lines · Shrikanth Hegde
Hi,
Quoted 25 lines · Maxim Kuvyrkov
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 11 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferred
Quoted 8 lines
Quoted 2 lines
My use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Do you change it when running workload based on any signal/event? or you set it before starting it?
If it is set before starting, you might as well offline the CPUs to achieve the same. I assume you are managing the preferred CPUs manually with write interface. You can do the same for online state. (Though it takes a longer)
How that? I tried, and offlining destroys the affinity, as it should:
# taskset -c 3 sh -c 'while :; do :; done' & [1] 380 # taskset -pc "$pid" pid 380's current affinity list: 3 # echo 0 >/sys/devices/system/cpu/cpu3/online [ 115.767634] process 380 (sh) no longer affine to cpu3 [ 115.772881] smpboot: CPU 3 is now offline taskset -pc 380 pid 380's current affinity list: 0-2,4-7
Did you mean something else, maybe?
Shrikanth Hegde
maintainerQuoted 32 lines · Yury Norov
Quoted 31 lines · Shrikanth Hegde
Hi,
Quoted 27 lines · Maxim Kuvyrkov
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 11 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredMy use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Quoted 8 lines
Quoted 5 lines
Do you change it when running workload based on any signal/event? or you set it before starting it?
If it is set before starting, you might as well offline the CPUs to achieve the same. I assume you are managing the preferred CPUs manually with write interface. You can do the same for online state. (Though it takes a longer)
How that? I tried, and offlining destroys the affinity, as it should:
You are doing "hotplug when workload is running".
Quoted 11 lines
# taskset -c 3 sh -c 'while :; do :; done' & [1] 380 # taskset -pc "$pid" pid 380's current affinity list: 3 # echo 0 >/sys/devices/system/cpu/cpu3/online [ 115.767634] process 380 (sh) no longer affine to cpu3 [ 115.772881] smpboot: CPU 3 is now offline taskset -pc 380 pid 380's current affinity list: 0-2,4-7Did you mean something else, maybe?
What matters is how/when you start the workload.
From the use case, I see it is about using only specific set of CPUs and there is no explicit affinity assigned.
Sequence1:
1. You are setting preferred CPUs.
2. You start the workload. Workload finishes using preferred CPUs.
3. You set the preferred same as active.
In that sequence, offlining the CPUs is going to be similar. You are managing preferred CPUs, you can as well manage offline CPUs. Most of the workload check the CPU state before assigning any explicit affinity or spawning threads etc.
Sequence 2:
1. workload is long running job. Lets say comprising of warmup/steady/closure phases.
2. You only to run on specific CPUs during steady phase.
3. You fallback to active during closure phase again.
In that sequence what you said about offline breaking affinities is very much possibility. It is good to set preferred CPUs in this sequence.
but reading maxim's description it fitted Sequence1.
Quoted 20 lines · Maxim Kuvyrkov
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 7 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
Quoted 6 lines
Quoted 4 lines
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredMy use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Hi Maxim,
Thank you for the feedback.
I agree, this trick with pinning a workload to an non-preferred CPU looks promising for benchmarking purposes, and probably for more.
I'm going to split this series to the cleanup and follow-up parts. In the follow-up, I'll focus on this writable interface. I'll keep you in CC there.
Thanks,
Yury
Shrikanth Hegde
maintainerHi Yury,
Quoted 26 lines · Yury Norov
Quoted 25 lines · Maxim Kuvyrkov
Quoted 8 lines · Yury Norov
The preferred CPU mask currently lets the steal governor reduce vCPU demand when physical CPUs are contended. This series adds manual control, opening more use cases.
For example, setting CPUs aside for selected fair tasks at runtime while steering other fair tasks toward the remaining CPUs.
Hi Yury,
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 11 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferred
Quoted 9 lines
Quoted 1 line
My use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Hi Maxim,
Thank you for the feedback.
I agree, this trick with pinning a workload to an non-preferred CPU looks promising for benchmarking purposes, and probably for more.
Sorry, i don't follow.
Did you mean pin to preferred CPUs? Why would anyone want to run their workload only on non-preferred CPUs? By definition, they are not meant to be used as much as possible. and It is benchmarking.
Quoted 6 lines
I'm going to split this series to the cleanup and follow-up parts. In the follow-up, I'll focus on this writable interface. I'll keep you in CC there.
Thanks,
Yury
Hi Shrikanth,
Quoted 24 lines
Quoted 14 lines
Quoted 14 lines
I've been trying to do this with crutches in user-space for a long time. Thanks for implementing this in the kernel, and with a convenient user interface.
Quoted 10 lines
A user can mark a CPU non-preferred and pin a workload to it. Fair tasks whose affinity includes preferred CPUs are steered away, while tasks whose allowed CPUs contain no preferred CPU can still run there. The CPU stays online, task affinity is preserved, and the selection can be reversed without rebooting:
# rmmod steal_governor # echo 0 > /sys/devices/system/cpu/cpu3/preferred # taskset -c 3 ./my_workload # echo 1 > /sys/devices/system/cpu/cpu3/preferredQuoted 9 lines
Quoted 1 line
My use-case (being a compiler optimization engineer) is to pin benchmarks to specific cores, and stop the system from using those cores even when the cores are idle. This prevents L1/L2 cache pollution and makes performance numbers more stable.
Hi Maxim,
Thank you for the feedback.
I agree, this trick with pinning a workload to an non-preferred CPU looks promising for benchmarking purposes, and probably for more.
Quoted 5 lines
Sorry, i don't follow.
Did you mean pin to preferred CPUs? Why would anyone want to run their workload only on non-preferred CPUs? By definition, they are not meant to be used as much as possible. and It is benchmarking.
I think they want to prevent anything else *besides* their workload from running on these CPUs by marking them non-preferred and then pinning their workload there.
Sort of like like dynamically configurable isolated CPUs.
IMO this fits 1-1 with what Yury is describing with this patchset.
Thanks,
-Mete
Peter Zijlstra
maintainerQuoted 10 lines · Mete Durlu
Quoted 3 lines
Did you mean pin to preferred CPUs? Why would anyone want to run their workload only on non-preferred CPUs? By definition, they are not meant to be used as much as possible. and It is benchmarking.
I think they want to prevent anything else *besides* their workload from running on these CPUs by marking them non-preferred and then pinning their workload there.
Sort of like like dynamically configurable isolated CPUs.IMO this fits 1-1 with what Yury is describing with this patchset.
That's what we have cpusets for. It can do configurable isolated CPUs just fine, in fact, it was made for that.