• Rafael J. Wysocki's avatar
    intel_pstate: Fix intel_pstate_get() · 6d45b719
    Rafael J. Wysocki authored
    After commit 8fa520af "intel_pstate: Remove freq calculation from
    intel_pstate_calc_busy()" intel_pstate_get() calls get_avg_frequency()
    to compute the average frequency, which is problematic for two reasons.
    
    First, intel_pstate_get() may be invoked before the driver reads the
    CPU feedback registers for the first time and if that happens,
    get_avg_frequency() will attempt to divide by zero.
    
    Second, the get_avg_frequency() call in intel_pstate_get() is racy
    with respect to intel_pstate_sample() and it may end up returning
    completely meaningless values for this reason.
    
    Moreover, after commit 7349ec04 "intel_pstate: Move
    intel_pstate_calc_busy() into get_target_pstate_use_performance()"
    sample.core_pct_busy is never computed on Atom, but it is used in
    intel_pstate_adjust_busy_pstate() in that case too.
    
    To address those problems notice that if sample.core_pct_busy
    was used in the average frequency computation carried out by
    get_avg_frequency(), both the divide by zero problem and the
    race with respect to intel_pstate_sample() would be avoided.
    
    Accordingly, move the invocation of intel_pstate_calc_busy() from
    get_target_pstate_use_performance() to intel_pstate_update_util(),
    which also will take care of the uninitialized sample.core_pct_busy
    on Atom, and modify get_avg_frequency() to use sample.core_pct_busy
    as per the above.
    Reported-by: default avatarkernel test robot <ying.huang@linux.intel.com>
    Link: http://marc.info/?l=linux-kernel&m=146226437623173&w=4
    Fixes: 8fa520af "intel_pstate: Remove freq calculation from intel_pstate_calc_busy()"
    Fixes: 7349ec04 "intel_pstate: Move intel_pstate_calc_busy() into get_target_pstate_use_performance()"
    Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    6d45b719
intel_pstate.c 42.3 KB