[PATCH v5 19/24] virt/steal_monitor: Provide default method to get systemwide steal time

From: Shrikanth Hegde

Date: Thu Jun 25 2026 - 08:51:08 EST


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>
---
v4->v5:
- new patch

drivers/virt/steal_monitor/Makefile | 2 +-
drivers/virt/steal_monitor/defaults.c | 27 +++++++++++++++++++++++++++
drivers/virt/steal_monitor/sm_core.h | 2 ++
3 files changed, 30 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..17f57afacbe6
--- /dev/null
+++ b/drivers/virt/steal_monitor/defaults.c
@@ -0,0 +1,27 @@
+// 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.
+ *
+ * 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;
+
+ 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 d50138ad8c42..e09745a2b813 100644
--- a/drivers/virt/steal_monitor/sm_core.h
+++ b/drivers/virt/steal_monitor/sm_core.h
@@ -9,6 +9,7 @@
#include <linux/init.h>
#include <linux/cpumask.h>
#include <linux/workqueue.h>
+#include <linux/kernel_stat.h>

struct steal_monitor {
struct delayed_work work;
@@ -22,4 +23,5 @@ struct steal_monitor {

extern struct steal_monitor sm_core_ctx;

+u64 get_system_steal_time(void);
#endif /* __VIRT_STEAL_CORE_H */
--
2.47.3