Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1406359ybl; Thu, 22 Aug 2019 14:06:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFvBgO111SlaDTIO/XGSuxvB5bKW3xMpFvD7TCeGOyPMoOJwV1fPdNEOAHaUNXuK+1GVli X-Received: by 2002:a63:e14d:: with SMTP id h13mr971168pgk.431.1566507994962; Thu, 22 Aug 2019 14:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566507994; cv=none; d=google.com; s=arc-20160816; b=tOAaF7PREwKdnvaH/DOOi6f6DjUfCGMC531Ewpr5b6ceyMEAmJvuiQeXuc7Q5977qL CZO5j+TWw/OJxjPsugLarJznjKtA3SR8Anzff5JMYuRurFUqgrTwwMSW0asG2kBYLiGI ai3Tdf7MCj4J2HPpQxSfMtHz2SlMN4C8CTe4G3v8qUP348r/RzwybLOfvnNGaJnje4ZF ajy1k9D/k1sizYh5cDafu8oQsHBmgnkCsI0PyfuRvxjM/ycfqsSV97BhqB29aIX8A4kK vyD7lkdGw/PUgpu93meMMkq1SwW2z8pinqUtUcdA0V0tLrFqK86S7IFHVCgwgZV1yye/ hCpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uZXe0LU6Q9Afw1M+6MAkug6vpZLnqFc1yqzaq3hqoKc=; b=mah7YReaAFLvXT5LKn/Usp762LqNPVAynQVQzdKSbQkIl/7+go1wpIkZLnrA0pyadK RoIRqSD2DN23k4GaIPiDCLEB/SrUrHgoQnEljiPXx0RhIAimNPZ+H1Np8Uh5FX4Mw1SZ B/li/c+RVJM8fPHy3/QJMU/iPa0RKpdv3HvyBTN+FfiWGXWhvcbKrUifnDyUTsp5+3ZU gx1x/GBrK6gChaUo2IDK6vq4KLRuiaqnGZnrfQcujD0W05o1e2Y1ZyjQksCVKubcu1tK 3/7cR1iKISsnaX5BILO1DMm6DZIB6cbmy3o17LePb/VkR731xT2hDFyNrSmARG8moEpN OQog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KwjzNmWp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 98si544962ple.6.2019.08.22.14.06.20; Thu, 22 Aug 2019 14:06:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KwjzNmWp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390327AbfHVRI0 (ORCPT + 99 others); Thu, 22 Aug 2019 13:08:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:57798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390278AbfHVRIW (ORCPT ); Thu, 22 Aug 2019 13:08:22 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E5B923406; Thu, 22 Aug 2019 17:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493701; bh=P70geCj8NkRYahbgDe4eJ2CV5IMgGeWdoyYlOA1e7jA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwjzNmWphoEDdk9k+DfOaYD0zPdDDmX5N9vbdXpt+E6vDv9eUgON+b/fk7tUJkG19 JIPCzCqUPD9Ihrzinxg/CkaFBTocyuX5q1+VYXZtEZE38uBry7s60Yb261hv4p6Fe0 fOEcRRpaPRYLbjGVonrrmNCvypMevURLbtP5bUG0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Viresh Kumar , Doug Smythies , "Rafael J . Wysocki" , Greg Kroah-Hartman Subject: [PATCH 5.2 012/135] cpufreq: schedutil: Don't skip freq update when limits change Date: Thu, 22 Aug 2019 13:06:08 -0400 Message-Id: <20190822170811.13303-13-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viresh Kumar commit 600f5badb78c316146d062cfd7af4a2cfb655baa upstream. To avoid reducing the frequency of a CPU prematurely, we skip reducing the frequency if the CPU had been busy recently. This should not be done when the limits of the policy are changed, for example due to thermal throttling. We should always get the frequency within the new limits as soon as possible. Trying to fix this by using only one flag, i.e. need_freq_update, can lead to a race condition where the flag gets cleared without forcing us to change the frequency at least once. And so this patch introduces another flag to avoid that race condition. Fixes: ecd288429126 ("cpufreq: schedutil: Don't set next_freq to UINT_MAX") Cc: v4.18+ # v4.18+ Reported-by: Doug Smythies Tested-by: Doug Smythies Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- kernel/sched/cpufreq_schedutil.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 962cf343f798f..ae3ec77bb92f6 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -40,6 +40,7 @@ struct sugov_policy { struct task_struct *thread; bool work_in_progress; + bool limits_changed; bool need_freq_update; }; @@ -89,8 +90,11 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) !cpufreq_this_cpu_can_update(sg_policy->policy)) return false; - if (unlikely(sg_policy->need_freq_update)) + if (unlikely(sg_policy->limits_changed)) { + sg_policy->limits_changed = false; + sg_policy->need_freq_update = true; return true; + } delta_ns = time - sg_policy->last_freq_update_time; @@ -427,7 +431,7 @@ static inline bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) { return false; } static inline void ignore_dl_rate_limit(struct sugov_cpu *sg_cpu, struct sugov_policy *sg_policy) { if (cpu_bw_dl(cpu_rq(sg_cpu->cpu)) > sg_cpu->bw_dl) - sg_policy->need_freq_update = true; + sg_policy->limits_changed = true; } static void sugov_update_single(struct update_util_data *hook, u64 time, @@ -447,7 +451,8 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (!sugov_should_update_freq(sg_policy, time)) return; - busy = sugov_cpu_is_busy(sg_cpu); + /* Limits may have changed, don't skip frequency update */ + busy = !sg_policy->need_freq_update && sugov_cpu_is_busy(sg_cpu); util = sugov_get_util(sg_cpu); max = sg_cpu->max; @@ -821,6 +826,7 @@ static int sugov_start(struct cpufreq_policy *policy) sg_policy->last_freq_update_time = 0; sg_policy->next_freq = 0; sg_policy->work_in_progress = false; + sg_policy->limits_changed = false; sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = 0; @@ -869,7 +875,7 @@ static void sugov_limits(struct cpufreq_policy *policy) mutex_unlock(&sg_policy->work_lock); } - sg_policy->need_freq_update = true; + sg_policy->limits_changed = true; } struct cpufreq_governor schedutil_gov = { -- 2.20.1