Re: [PATCH v4 1/2] arm64: topology: fix arch_freq_get_on_cpu() overflow above 4.19 GHz

From: Dietmar Eggemann

Date: Thu Sep 17 2026 - 13:01:39 EST


On 17.09.26 17:32, Peter Zijlstra wrote:
> On Thu, Sep 17, 2026 at 02:51:11PM +0200, Oleg Keri wrote:

[...]
>> diff --git a/include/linux/topology.h b/include/linux/topology.h
>> index 709a2dcf4c73..0a4ee12a98d5 100644
>> --- a/include/linux/topology.h
>> +++ b/include/linux/topology.h
>> @@ -351,4 +351,6 @@ static inline unsigned long topology_get_cpu_scale(int cpu)
>>
>> void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
>>
>> +#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
>
> This might not be a very good generic helper, since it relies on either
> of the variables to be u64 for correctness.

So moving it to a static inline function instead?

static inline u64 cap_scale(u64 value, u64 scale)
{
return value * scale >> SCHED_CAPACITY_SHIFT;
}