Re: [PATCH v2 2/3] x86/sched: Add basic support for CPU capacity scaling

From: Rafael J. Wysocki
Date: Tue Aug 13 2024 - 07:08:09 EST


Hi,

On Tue, Aug 13, 2024 at 3:27 AM Chen Yu <yu.c.chen@xxxxxxxxx> wrote:
>
> Hi Rafael,
>
> On 2024-08-12 at 14:42:26 +0200, Rafael J. Wysocki wrote:
> > +void arch_set_cpu_capacity(int cpu, unsigned long cap, unsigned long base_cap,
> > + unsigned long max_freq, unsigned long base_freq)
> > +{
> > + if (static_branch_likely(&arch_hybrid_cap_scale_key)) {
> > + WRITE_ONCE(per_cpu_ptr(arch_cpu_scale, cpu)->capacity,
> > + div_u64(cap << SCHED_CAPACITY_SHIFT, base_cap));
> > + WRITE_ONCE(per_cpu_ptr(arch_cpu_scale, cpu)->freq_ratio,
> > + div_u64(max_freq << SCHED_CAPACITY_SHIFT, base_freq));
> >
>
> Would the capacity update be frequently invoked?

I hope not.

> Just wonder if we could
> first READ_ONCE() to check if the value is already the value we want to
> change to, to avoid one write and less cache snoop overhead (in case other
> CPU reads this CPU's capacity)

Well, I'd rather not complicate the code beyond what is necessary
unless this is demonstrated to make a measurable difference.

Besides, AFAICS the only case in the caller in which the same values
can be passed to arch_set_cpu_capacity() is the CPU offline one and
that should not happen too often.