Re: [PATCH 6/7] virt: steal_governor: restart sampling immediately after CPU hotplug

From: Yury Norov

Date: Thu Nov 19 2026 - 12:39:34 EST


On Thu, Nov 19, 2026 at 11:36:46AM +0530, Shrikanth Hegde wrote:
> Hi Yury.
>
> On 11/14/26 12:12 AM, Yury Norov wrote:
> > CPU hotplug between samples can distort the calculated steal ratio because
> > the governor divides accumulated steal time by the current active CPU
> > count, even when that count changed during the sampling interval.
> >
> > For example, assume a constant 3% steal rate on each CPU, with four active
> > CPUs for 900ms followed by two active CPUs for 100ms. The accumulated
> > steal time is:
> >
> > 4 * 900ms * 3% + 2 * 100ms * 3% = 108ms + 6ms = 114ms
>
>
> This example is not realistic. If you had 3% steal with 4 CPUs, and if they become 2,
> your steal time will definitely increase. It will likely double. So
> governor likely calculates 6%.

You say it's not realistic, and then you confirm the math. So
realistic or not?

On my VM, there are 4 or 8 vCPUs, and the steal time hovers around 3%
normally. Offlining half of them triggers steal governor pretty
consistently.

> But yes, you can have realistic examples, where governor may calculate
> the values which goes slightly above or below. But IMHO those examples are very
> limited. Even in the above examples, the steal governor was supposed to trigger
> high threshold since the steal time with 2 CPUs is 6%. So if not now, in the next
> delta it would have triggered it anyways.

Sorry, I don't understand this. The governor is not supposed to
trigger decrease_preferred_cpus() on offline event. If some system
event skews steal ratio, the governor must adjust to that, or simply
skip the iteration. This patch implements the 2nd approach, which is
simpler IMO.

> Some examples are really corner cases. Maybe like
>
> 60 CPUs 3% steal, and then 40 CPUs 5.1% steal = 4.55%
> (Below threshold, but should have been high). One interval missed. But if you see
> large duration was in low threshold, so it is agreeable to miss it.

Don't understand this either. Can you elaborate on your case and math
please?

> > The elapsed time is 1000ms. Using the final count of two active CPUs, the
> > governor calculates:
> >
> > 114ms / (2 * 1000ms) = 5.7%
> >
> > This exceeds the default 5% high threshold, even though the actual steal
> > rate stayed at 3%. Using the CPU counts over the whole interval gives:
> >
> > 114ms / (4 * 900ms + 2 * 100ms) = 3%
> >
> > Checking num_online_cpus() doesn't account for cases where CPUs go online
> > and offline such that the total number of online CPUs doesn't change. So,
> > implement the sampling restart on hotplug event.
> >
>
> I am not sure if we really need to stress about hotplug cases. IIUC, when a user
> does hotplug, systems are usually idle. (Atleast that is what we have observed in
> real life use cases). And hotplug is really user driven, so user knows system is going
> through some transitions and will be stable soon.

The follow-up series brings a real counter example: Android daemon
running on Qualcomm SoC offlines CPUs on thermal event. So, it's
automatic and the offlined CPU is likely not idling.

Thanks,
Yury