Re: [PATCH v7 03/12] sysfs: Add preferred CPU file

From: Yury Norov

Date: Fri Jul 10 2026 - 11:42:14 EST


On Fri, Jul 10, 2026 at 03:26:39AM +0530, Shrikanth Hegde wrote:
> Add "preferred" file in /sys/devices/system/cpu
>
> This offers
> - User can quickly check which CPUs are marked as preferred at this
> moment.
> - Userspace algorithms irqbalance could use this mask to send irq into
> preferred CPUs.
>
> For example:
> cat /sys/devices/system/cpu/online
> 0-719
> cat /sys/devices/system/cpu/preferred
> 0-599 <<< Implies 0-599 are preferred for workloads and 600-719
> should be avoided at this moment.
>
> cat /sys/devices/system/cpu/preferred
> 0-719 <<< All CPUs are usable. There is no preference.
>
> Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> ---
> Documentation/ABI/testing/sysfs-devices-system-cpu | 11 +++++++++++
> drivers/base/cpu.c | 8 ++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
> index 82d10d556cc8..ac1dbb209cc7 100644
> --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> @@ -806,3 +806,14 @@ Date: Nov 2022
> Contact: Linux kernel mailing list <linux-kernel@xxxxxxxxxxxxxxx>
> Description:
> (RO) the list of CPUs that can be brought online.
> +
> +What: /sys/devices/system/cpu/preferred
> +Date: July 2026
> +Contact: Linux kernel mailing list <linux-kernel@xxxxxxxxxxxxxxx>
> +Description:
> + (RO) the list of preferred CPUs at this moment.
> + These are the only CPUs meant to be used at the moment.
> + Using CPU outside of the list could lead to more
> + contention of underlying physical CPU resource. Dynamically
> + changes based on steal time. With CONFIG_PREFERRED_CPU=n it
> + is same as active CPUs. See sched-arch.rst for more details.

This should mention that it's about paravirtualization.

> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> index 19d288a3c80c..4ac990efee7c 100644
> --- a/drivers/base/cpu.c
> +++ b/drivers/base/cpu.c
> @@ -391,6 +391,13 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
> }
> #endif
>
> +static ssize_t preferred_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_preferred_mask));
> +}
> +static DEVICE_ATTR_RO(preferred);
> +
> const struct bus_type cpu_subsys = {
> .name = "cpu",
> .dev_name = "cpu",
> @@ -532,6 +539,7 @@ static struct attribute *cpu_root_attrs[] = {
> #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
> &dev_attr_modalias.attr,
> #endif
> + &dev_attr_preferred.attr,

#ifdef CONFIG_PREFERRED_CPUS ?

> NULL
> };
>
> --
> 2.47.3