Re: [PATCH v6 17/23] virt/steal_monitor: Provide default method to get systemwide steal time
From: Yury Norov
Date: Fri Jul 03 2026 - 15:16:26 EST
On Wed, Jul 01, 2026 at 07:46:48PM +0530, Shrikanth Hegde wrote:
> steal monitor takes global view of steal time instead of individual
> vCPU. For this collect overall steal values across all the vCPUs or
> vCPUs of interest.
>
> Default implementation chooses steal time across all active CPUs.
>
> Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> ---
> v5->v6:
> - Add cpus_read_lock() for hotplug safety
>
> drivers/virt/steal_monitor/Makefile | 2 +-
> drivers/virt/steal_monitor/defaults.c | 28 +++++++++++++++++++++++++++
> drivers/virt/steal_monitor/sm_core.h | 3 +++
> 3 files changed, 32 insertions(+), 1 deletion(-)
> create mode 100644 drivers/virt/steal_monitor/defaults.c
>
> diff --git a/drivers/virt/steal_monitor/Makefile b/drivers/virt/steal_monitor/Makefile
> index 24cee55342ce..7c16f8cf9583 100644
> --- a/drivers/virt/steal_monitor/Makefile
> +++ b/drivers/virt/steal_monitor/Makefile
> @@ -11,4 +11,4 @@
> #
> obj-$(subst y,m,$(CONFIG_PREFERRED_CPU)) += steal_monitor.o
>
> -steal_monitor-y := sm_core.o
> +steal_monitor-y := sm_core.o defaults.o
> diff --git a/drivers/virt/steal_monitor/defaults.c b/drivers/virt/steal_monitor/defaults.c
> new file mode 100644
> index 000000000000..6681f9938f6a
> --- /dev/null
> +++ b/drivers/virt/steal_monitor/defaults.c
> @@ -0,0 +1,28 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Base file contains the default implementations.
> + * These are defined as __weak so that arch may define
> + * strong symbols to override.
But there's no arch doing that, right? It looks like overcomplication
with no benefit.
There's just ~50 drivers defining weak symbols, so this is not a
common practice. I think it would be much simpler for the arch people
to simply write their own driver controlling cpu_preferred_mask,
rather than tweaking your code.
> + * Copyright (C) 2026 IBM
> + * Author: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> + */
> +#include "sm_core.h"
> +
> +/*
> + * Compute steal time of the full system.
> + *
> + * Default implementation returns steal time across all active CPUs
> + */
> +
> +u64 __weak get_system_steal_time(void)
> +{
> + int tmp_cpu;
> + u64 total_steal = 0;
> +
> + guard(cpus_read_lock)();
> + for_each_cpu(tmp_cpu, cpu_active_mask)
> + total_steal += kcpustat_cpu(tmp_cpu).cpustat[CPUTIME_STEAL];
> +
> + return total_steal;
> +}
> diff --git a/drivers/virt/steal_monitor/sm_core.h b/drivers/virt/steal_monitor/sm_core.h
> index ea06e83c228c..634c9f5a2610 100644
> --- a/drivers/virt/steal_monitor/sm_core.h
> +++ b/drivers/virt/steal_monitor/sm_core.h
> @@ -11,6 +11,7 @@
> #include <linux/cpumask.h>
> #include <linux/workqueue.h>
> #include <linux/sched/isolation.h>
> +#include <linux/kernel_stat.h>
>
> struct steal_monitor {
> struct delayed_work work;
> @@ -24,4 +25,6 @@ struct steal_monitor {
>
> extern struct steal_monitor sm_core_ctx;
>
> +u64 get_system_steal_time(void);
> +
> #endif /* __VIRT_STEAL_CORE_H */
> --
> 2.47.3