• Lukasz Luba's avatar
    cpufreq, sched/util: Optimize operations with single CPU capacity lookup · 948fb4c4
    Lukasz Luba authored
    The max CPU capacity is the same for all CPUs sharing frequency domain.
    There is a way to avoid heavy operations in a loop for each CPU by
    leveraging this knowledge. Thus, simplify the looping code in the
    sugov_next_freq_shared() and drop heavy multiplications. Instead, use
    simple max() to get the highest utilization from these CPUs.
    
    This is useful for platforms with many (4 or 6) little CPUs. We avoid
    heavy 2*PD_CPU_NUM multiplications in that loop, which is called billions
    of times, since it's not limited by the schedutil time delta filter in
    sugov_should_update_freq(). When there was no need to change frequency
    the code bailed out, not updating the sg_policy::last_freq_update_time.
    Then every visit after delta_ns time longer than the
    sg_policy::freq_update_delay_ns goes through and triggers the next
    frequency calculation code. Although, if the next frequency, as outcome
    of that, would be the same as current frequency, we won't update the
    sg_policy::last_freq_update_time and the story will be repeated (in
    a very short period, sometimes a few microseconds).
    
    The max CPU capacity must be fetched every time we are called, due to
    difficulties during the policy setup, where we are not able to get the
    normalized CPU capacity at the right time.
    
    The fetched CPU capacity value is than used in sugov_iowait_apply() to
    calculate the right boost. This required a few changes in the local
    functions and arguments. The capacity value should hopefully be fetched
    once when needed and then passed over CPU registers to those functions.
    Signed-off-by: default avatarLukasz Luba <lukasz.luba@arm.com>
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20221208160256.859-2-lukasz.luba@arm.com
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Patrick Bellasi <patrick.bellasi@arm.com>
    Cc: Vincent Guittot <vincent.guittot@linaro.org>
    Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Cc: Viresh Kumar <viresh.kumar@linaro.org>
    948fb4c4
cpufreq_schedutil.c 23.5 KB