Re: [PATCH v6 21/23] virt/steal_monitor: Add direction control
From: Yury Norov
Date: Mon Jul 06 2026 - 16:37:04 EST
On Wed, Jul 01, 2026 at 07:46:52PM +0530, Shrikanth Hegde wrote:
> Cache the previous direction on steal time. So two consecutive values of
> high values or low values are taken for decrease/increase of preferred
> CPUs. This helps to avoid oscillations.
>
> Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
> ---
> drivers/virt/steal_monitor/sm_core.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virt/steal_monitor/sm_core.c b/drivers/virt/steal_monitor/sm_core.c
> index 7b7435f79b85..4810bad96818 100644
> --- a/drivers/virt/steal_monitor/sm_core.c
> +++ b/drivers/virt/steal_monitor/sm_core.c
> @@ -20,6 +20,12 @@ struct steal_monitor sm_core_ctx = {
> .low_threshold = 200, /* 2% */
> };
>
> +enum sm_direction {
> + SM_DIR_INCREASE = -1,
> + SM_DIR_NONE = 0,
> + SM_DIR_DECREASE = 1,
> +};
> +
> module_param_named(interval_ms, sm_core_ctx.interval_ms, uint, 0644);
> MODULE_PARM_DESC(interval_ms,
> "Sampling frequency for steal values in milliseconds (default: 1000)");
> @@ -59,12 +65,22 @@ static void compute_preferred_cpus_work(struct work_struct *work)
>
> steal_ratio = div64_u64(delta_steal, delta_ns);
> /* If the steal time values are high, reduce preferred CPUs */
> - if (steal_ratio > sm_core_ctx.high_threshold)
> + if (sm_core_ctx.prev_direction == SM_DIR_DECREASE &&
> + steal_ratio > sm_core_ctx.high_threshold)
> decrease_preferred_cpus(&sm_core_ctx);
> /* If the steal time values are low, increase preferred CPUs */
> - if (steal_ratio <= sm_core_ctx.low_threshold)
> + if (sm_core_ctx.prev_direction == SM_DIR_INCREASE &&
> + steal_ratio <= sm_core_ctx.low_threshold)
> increase_preferred_cpus(&sm_core_ctx);
>
> + /* mark the direction. This helps to avoid ping-pongs */
Increasing the gap between hi and lo_threshold helps to avoid
ping-pongs.
> + if (steal_ratio > sm_core_ctx.high_threshold)
> + sm_core_ctx.prev_direction = SM_DIR_DECREASE;
> + else if (steal_ratio <= sm_core_ctx.low_threshold)
> + sm_core_ctx.prev_direction = SM_DIR_INCREASE;
> + else
> + sm_core_ctx.prev_direction = SM_DIR_NONE;
> +
> /* At least one core is kept as preferred */
> WARN_ON(cpumask_empty(cpu_preferred_mask));
>
> --
> 2.47.3