From patchwork Fri Aug 2 05:44:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 170403 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp341827ile; Thu, 1 Aug 2019 22:44:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZGOqWbaekIGq2e2QxIFw6eQ/dqPSVIicc2c+TezwZVPYp4uw8B4hCMX2FxmndiEHII8tL X-Received: by 2002:a17:902:8207:: with SMTP id x7mr129940975pln.63.1564724685956; Thu, 01 Aug 2019 22:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564724685; cv=none; d=google.com; s=arc-20160816; b=qKrU8/XCPeawaM3GnYgqo/v84PFkeTNZcLtpPm401s7T5QBEgnriw113Hn3GsZpRJc YVNAhaxfO4AYz6JyFpbUUuXUeedQZeTm0frcD3D753CDQZwpE4RRAGV5CS8RxMHeEue4 skcGR4osoEgXgtdaldX+vCAu4l8tAaHjd+UePZ952tXVwX2KEbQ9+EvSz+0wh/4XlvmI N/UaewuStkurbSagS++5QHhYSCa04YDmHQ57nMOBS/styIpWapVDC2JDmrn3vbWLCpMC 9AYnQVdJilzeAUYAz/HknXxJSKWqRpNn1I6rB2QamkF3oUr46OyAiZ0x0CHc9PYzeUXF BNsQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=IQiEltWXcaJ4ww5AxptfVEQnJ5UMr5Pimco/lTpuDRE=; b=T4ncRYRnNK0wh+aj6ikGm+zbDs2D6ORNk2F2uhmPjmWHZHwXvmTKpNdhrPdUFSFyQt Mtj0hNuQoOBigu103YIBVxooVtb9FdUQ9c52RbLfpEELkDscAb87GYhFNa07wHCxZ7sZ KVjXo6faJKRZdPP3wpDJGMX2UNTx9Qb1Y/tUA5yUB3qhRPPwfbl/lkThOKieRoyZPQaq fov/4cxN+5tsK75+XHbTXVPEJzGb0/JCxHcz6GSLNjOGcOSwsb/etVk/9hO5NymG8bwp 3r9ROo2zll6OzptBEVsvuximLKrOlqXRQZN8lozxYvNiNBxuEvChbxzdCjxmAKDPjWk3 kgJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AWtoJNTQ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si33257988pll.324.2019.08.01.22.44.45; Thu, 01 Aug 2019 22:44:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=AWtoJNTQ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387939AbfHBFoo (ORCPT + 14 others); Fri, 2 Aug 2019 01:44:44 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42394 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732723AbfHBFoo (ORCPT ); Fri, 2 Aug 2019 01:44:44 -0400 Received: by mail-pl1-f196.google.com with SMTP id ay6so33244503plb.9 for ; Thu, 01 Aug 2019 22:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IQiEltWXcaJ4ww5AxptfVEQnJ5UMr5Pimco/lTpuDRE=; b=AWtoJNTQKLi0c8mDS75fkbk24KpEbX7Z3HpsQ5ZCk7Iowak2phz7Hma5th9nwG6rt4 5vhCMeeUidwGlPHoROnI+CbVRiNBRdz+8UgqyhDqZC6VSUhnylilIe2CkRhX4fpAj1pS YYPuA6mZEmrhWfPpMVINnKvYF9s+RCU4crV9T0rHo88AMcxll6r6Zn8KdOUobLf3jAgq d7WMo+P9jfqtF5hC4Nf3mzQYLI/P6SrxmrUuPRCy5rlBU9s0Ie9QLJkO72+XYz53sEKC vFRlMGxwV5khY/ApjPR/A4aOn48+zhq7/bINnhSPZSuHjBPdivQtfcCKwLNAFAIyEaH1 JNLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IQiEltWXcaJ4ww5AxptfVEQnJ5UMr5Pimco/lTpuDRE=; b=n4T3UWBaBPfnu3UB0i0UwCo6g3g6/rPb6gNEQX8cqoNBw2Wh71Bwzar5y5pMAK0olw u2mFLuFYMdJCGGIfTljYM2xOKuY6fQlwOzyKiCroOGONyEA29cHlAGCPnBQoa5JsvaDx GQr7QbdmZxJMQ6vSkizTQIjJ6VoKJV8kvmDID2WGu89wOFdAGVS1r9Rk2GRx9ffFErv1 9KQ98Z5sOq3k7VCv5+QEavc6KB1OFO3V9MHYdj6JTDzQpXbfE8lHWSzobCPh3O35pZSb zvrG+jqVcjBt4GbRmmqsr0n4avBRq7SwH1EQZB/1pCe9cmhW3DMVZXbKMjfNKQOi5Hhl AcaA== X-Gm-Message-State: APjAAAWB2Qt8LNRo1DRtQxZ6MrYdNNkNE52RdOSMcSx6nRjFet/GkA9q rrZvr32dFjZJ8qEKyf6u6IzF4g== X-Received: by 2002:a17:902:bd06:: with SMTP id p6mr132909092pls.189.1564724683238; Thu, 01 Aug 2019 22:44:43 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id g8sm83671355pgk.1.2019.08.01.22.44.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 22:44:41 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Ingo Molnar , Peter Zijlstra Cc: linux-pm@vger.kernel.org, Vincent Guittot , "v4 . 18+" , Doug Smythies , linux-kernel@vger.kernel.org Subject: [PATCH V3 1/2] cpufreq: schedutil: Don't skip freq update when limits change Date: Fri, 2 Aug 2019 11:14:29 +0530 Message-Id: <7dedb6bd157b8183c693bb578e25e313cf4f451d.1564724511.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 Signed-off-by: Viresh Kumar --- V2->V3: - Updated commit log. V1->V2: - Fixed the race condition using a different flag. @Doug: I haven't changed the code since you last tested these. Your Tested-by tag can be useful while applying the patches. Thanks. kernel/sched/cpufreq_schedutil.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 636ca6f88c8e..2f382b0959e5 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; @@ -437,7 +441,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,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, struct sugov_policy *sg_policy = sg_cpu->sg_policy; unsigned long util, max; unsigned int next_f; - bool busy; + bool busy = false; sugov_iowait_boost(sg_cpu, time, flags); sg_cpu->last_update = time; @@ -457,7 +461,9 @@ 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 */ + if (!sg_policy->need_freq_update) + busy = sugov_cpu_is_busy(sg_cpu); util = sugov_get_util(sg_cpu); max = sg_cpu->max; @@ -831,6 +837,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; @@ -879,7 +886,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 = {