Re: [PATCH v6 12/23] virt: Introduce steal monitor driver
From: Yury Norov
Date: Fri Jul 03 2026 - 14:28:31 EST
On Fri, Jul 03, 2026 at 02:20:32PM -0400, Yury Norov wrote:
> On Wed, Jul 01, 2026 at 07:46:43PM +0530, Shrikanth Hegde wrote:
> > Introduce a new driver in virt named steal_monitor. This driver
> > will compute the steal time and drive the policy decisions of preferred
> > CPU state.
> >
> > More on it can be found in the Documentation/driver-api/steal-monitor.rst
> > Introduce the skeleton code first.
> >
> > There is no new kconfig. It depends on CONFIG_PREFERRED_CPU.
> > - If CONFIG_PREFERRED_CPU=y, it gets compiled as a module. It is not
> > loaded by default.
What if I've got my own monitor, and don't need this one? Please add a
way to not compile it, even if CONFIG_PREFERRED_CPU is enabled.
> > - If CONFIG_PREFERRED_CPU=n, module isn't compiled.
> >
> > File layout of the driver is designed with having arch specific
> > files in the future.
> >
> > - sm_core.c - contains main driver code. This includes the periodic
> > work function and take action on steal time.
> > - defaults.c - contains the default implementation defined with __weak
> > symbols.
> > - sm_core.h - header file which includes data structure.
> >
> > Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
>
> You've split the driver code into 12 patches. It makes it impossible
> to review the driver as a whole. Please make it less granular. 2 or 3
> patches for the new driver is more than enough, I think.
>
> > ---
> > drivers/virt/Makefile | 1 +
> > drivers/virt/steal_monitor/Makefile | 14 ++++++++++++
> > drivers/virt/steal_monitor/sm_core.c | 33 ++++++++++++++++++++++++++++
> > drivers/virt/steal_monitor/sm_core.h | 11 ++++++++++
> > 4 files changed, 59 insertions(+)
> > create mode 100644 drivers/virt/steal_monitor/Makefile
> > create mode 100644 drivers/virt/steal_monitor/sm_core.c
> > create mode 100644 drivers/virt/steal_monitor/sm_core.h
> >
> > diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile
> > index f29901bd7820..aff715cea42d 100644
> > --- a/drivers/virt/Makefile
> > +++ b/drivers/virt/Makefile
> > @@ -9,4 +9,5 @@ obj-y += vboxguest/
> >
> > obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/
> > obj-$(CONFIG_ACRN_HSM) += acrn/
> > +obj-$(CONFIG_PREFERRED_CPU) += steal_monitor/
> > obj-y += coco/
> > diff --git a/drivers/virt/steal_monitor/Makefile b/drivers/virt/steal_monitor/Makefile
> > new file mode 100644
> > index 000000000000..24cee55342ce
> > --- /dev/null
> > +++ b/drivers/virt/steal_monitor/Makefile
> > @@ -0,0 +1,14 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +#
> > +# Steal time monitor to alter preferred CPU state.
> > +#
> > +# Arch can implement strong function definitions and override the
> > +# default by adding them in arch specific file. It must ensure
> > +# that preferred is always subset of active.
> > +#
> > +# It is always compiled as module if CONFIG_PREFERRED_CPU=y
> > +# One has to enable the module.
>
> Why?
>
> > +#
> > +obj-$(subst y,m,$(CONFIG_PREFERRED_CPU)) += steal_monitor.o
> > +
> > +steal_monitor-y := sm_core.o
> > diff --git a/drivers/virt/steal_monitor/sm_core.c b/drivers/virt/steal_monitor/sm_core.c
> > new file mode 100644
> > index 000000000000..e320559c6576
> > --- /dev/null
> > +++ b/drivers/virt/steal_monitor/sm_core.c
> > @@ -0,0 +1,33 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Steal time Monitor.
> > + *
> > + * Periodically compute steal time. Based on the thresholds either
> > + * reduce/increase the preferred CPUs which can be made use
> > + * by the workload to avoid vCPU preemption to an extent possible.
> > + *
> > + * Available as module with CONFIG_PREFERRED_CPU=y
> > + *
> > + * Copyright (C) 2026 IBM
> > + * Author: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> > + */
> > +
> > +#include "sm_core.h"
> > +
> > +static int __init steal_monitor_init(void)
> > +{
> > + pr_info("steal_monitor is enabled\n");
> > + return 0;
> > +}
> > +
> > +static void __exit steal_monitor_exit(void)
> > +{
> > + pr_info("steal_monitor is disabled\n");
> > +}
> > +
> > +module_init(steal_monitor_init);
> > +module_exit(steal_monitor_exit);
> > +
> > +MODULE_LICENSE("GPL");
> > +MODULE_AUTHOR("IBM Corporation");
> > +MODULE_DESCRIPTION("Virtualization Steal Time Monitor");
> > diff --git a/drivers/virt/steal_monitor/sm_core.h b/drivers/virt/steal_monitor/sm_core.h
> > new file mode 100644
> > index 000000000000..684a258526e1
> > --- /dev/null
> > +++ b/drivers/virt/steal_monitor/sm_core.h
> > @@ -0,0 +1,11 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +#ifndef __VIRT_STEAL_CORE_H
> > +#define __VIRT_STEAL_CORE_H
> > +
> > +#include <linux/types.h>
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/init.h>
> > +
> > +#endif /* __VIRT_STEAL_CORE_H */
> > --
> > 2.47.3