mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
cpufreq: schedutil: Serialize sugov_start() against rate limit updates
The current value of sg_policy->tunables->rate_limit_us is used in
sugov_start() without locking to update sg_policy->freq_update_delay_ns,
so if rate_limit_us_store() runs in parallel with it, the rate limit
update may go unnoticed and the new freq_update_delay_ns value may be
stale until the rate limit is updated again.
To avoid that, acquire the update_lock mutex of the rate limit sysfs
attribute, that is held by rate_limit_us_store() during rate limit
updates, around the freq_update_delay_ns in sugov_start().
Fixes: 9bdcb44e39 ("cpufreq: schedutil: New governor based on scheduler utilization data")
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Signed-off-by: Hui Su <sh_def@163.com>
Cc: All applicable <stable@vger.kernel.org>
[ rjw: Subject adjustment, new changelog, edits of the new comment ]
[ rjw: Add empty code line after guard()() ]
Link: https://patch.msgid.link/20261013034235.2678177-1-sh_def@163.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
b85cc49bc2
commit
ce390caf55
|
|
@ -73,6 +73,18 @@ static void sugov_update_rate_limit_us(struct sugov_policy *sg_policy)
|
|||
(s64)sg_policy->tunables->rate_limit_us * NSEC_PER_USEC;
|
||||
}
|
||||
|
||||
static void sugov_update_rate_limit_us_sync(struct sugov_policy *sg_policy)
|
||||
{
|
||||
/*
|
||||
* Serialize with rate_limit_us_store() to prevent this path from using
|
||||
* a stale rate limit tunable value to set the limit for the given
|
||||
* policy.
|
||||
*/
|
||||
guard(mutex)(&sg_policy->tunables->attr_set.update_lock);
|
||||
|
||||
sugov_update_rate_limit_us(sg_policy);
|
||||
}
|
||||
|
||||
static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
|
||||
{
|
||||
s64 delta_ns;
|
||||
|
|
@ -861,7 +873,7 @@ static int sugov_start(struct cpufreq_policy *policy)
|
|||
void (*uu)(struct update_util_data *data, u64 time, unsigned int flags);
|
||||
unsigned int cpu;
|
||||
|
||||
sugov_update_rate_limit_us(sg_policy);
|
||||
sugov_update_rate_limit_us_sync(sg_policy);
|
||||
sg_policy->last_freq_update_time = 0;
|
||||
sg_policy->next_freq = 0;
|
||||
sg_policy->work_in_progress = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user