From patchwork Wed Jul 31 02:58:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 170120 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp3391953ile; Tue, 30 Jul 2019 19:59:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGJBq3socnemWV+ZmW5KEmj0KEwhfhOiyjkGgYbI8WB1+3OpRVNi9S8BWBfy3EadhR96Hq X-Received: by 2002:a17:902:9041:: with SMTP id w1mr4472872plz.132.1564541950523; Tue, 30 Jul 2019 19:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564541950; cv=none; d=google.com; s=arc-20160816; b=hA94Wq/IqQpYhMMzZF5IO2IlYGQtGbzJzSb7Q96MCEXV46vu0DTmi1pTksgDJybYI9 0+Fa7XVnSd65DttpFHTLlQG4SXv5ODkAMvUVpiAYI8oHjRpGvEybGwN5xaoy1wKSHYt3 uDn7fEQixXxdKpJU0XE+TSkOE7pqjcUCSZh7xbk7LmoPpbISF2l4Xq7JWAvrSyLq8rv/ VBY/irIuceO0DC2akREWurji+bFAeE3RS7+mMKpC3W4JV84fgjgqPeBmqT55AdO9A2Ws HrWk6zrHvsq1NV/lVDPu+t3GfWRAq0jRsDA1oIMZw1RTQIq3iadczSCQ3X/wT/lS/vSF 3hzg== 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=B7l52D/cRUQyEKtM6D9Z02BVoe/7k/AeNEzc9yQ+CeI=; b=OMyK6lmlrF7iyxIHfNt87i3/5IDdgQ7LWTWmfr3MvKHYhuy+Lu3VfQHEbojzn0IW5L OCjoQfz630W97ZtECqCV0J+u/jnVsNmc5bI1C77dSw13W+Xw1Rg6SGRap3n/A4OyGlnc WPyS3Gxup9Mn7BES1w2y8WN70do3br0lwgfHsS7hC7WH+OM8Y+Fr3aa4MVJ7AXvMU1Au bi3pgLWYVKTIdgGnytDQw71ajYtPuCQe+OWpKwmCSHlb+q57pYhoPqX6ALsDW6AsCr0O jRn4gRK0p3ufuSoBFKsx+99Yqbfd+Le2WWV/JdorxUAw8kB3Ff5Na05BG7Oq6wJG5JNZ utcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bkoXiW2Z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 bf7si28563033plb.216.2019.07.30.19.59.09; Tue, 30 Jul 2019 19:59:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=bkoXiW2Z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726522AbfGaC7J (ORCPT + 11 others); Tue, 30 Jul 2019 22:59:09 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39855 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbfGaC7J (ORCPT ); Tue, 30 Jul 2019 22:59:09 -0400 Received: by mail-pg1-f196.google.com with SMTP id u17so31129224pgi.6 for ; Tue, 30 Jul 2019 19:59:08 -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=B7l52D/cRUQyEKtM6D9Z02BVoe/7k/AeNEzc9yQ+CeI=; b=bkoXiW2ZCG3VyC8G6LPZgBZuI3y0v2RUc/ccSE0ChSGLNoZT6BX5NE8m9Z8F/1Y46T OlrlmQZ/RU9gu6V2zSy+QA4wqnBGe23ABaN6+GETOMjbLTwv1v0b6ssiRxV1BOsJR6OV Uq1l0VsAIibFVMIuqQKhdKY/kCgPlFwMeCZh5+PL7h55QoJDscTpXhbqdZiuWmNXmreq YpyyRZaweDEJoQ+Rsj6RPXrtLPb3B5O3q6827dDVLuy49O+OVtJuCmfTYghgQ0IhHMIu ZAZGttFO4gUbQBSHY8UfufkMuYWTuIvjBg4AE05QyoJdH+v2asCd9GLKgyhlytygWTJa xG3w== 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=B7l52D/cRUQyEKtM6D9Z02BVoe/7k/AeNEzc9yQ+CeI=; b=Oj6GJMVD4SAYxOXatCf8/pCokAUfmuznfQpC2HPElkxGjey5XWNjqgLe3dabsy2CFn CFW2A6kcrgCJ8bwHz/Sj5XACM/nr6oynT5rFWHMUhuPKXLZlKfTe0RA41qP/NQUr64f6 ZEOfbxNRNeyzGst1Nnp6iOskL1b3arFDbB81sN9f5u8sX0h/Uy8BZsZjzXa1merrcKGg 2v7nhzZAHLGjY+Fnzz2XvzvD4/QVwK4RXKsnda4Z63knDPr+5Tyf6n8qR3TcYPj0cYng PwQIQsfJ+jUpJRJoSDTei+egXpNinegdSY4K8sDCpZPazWu1vxh1bwgmtIDXrK1+bEWs JkOA== X-Gm-Message-State: APjAAAWQpWQlQLYCGIeGNPz2fheZkY3tUZZYC1tlNA1fw/l/kpCWU1Nm 0A8Xu9nln2j71IvI2dbR5X5Upg== X-Received: by 2002:a17:90a:1b48:: with SMTP id q66mr502148pjq.83.1564541948328; Tue, 30 Jul 2019 19:59:08 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id v18sm63769086pgl.87.2019.07.30.19.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 19:59:07 -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] cpufreq: schedutil: Don't skip freq update when limits change Date: Wed, 31 Jul 2019 08:28:57 +0530 Message-Id: <04ff2be6ef108585d57aa2462aa7a4c676b6d1cd.1564541875.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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. 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 --- @Doug: Can you please provide your Tested-by for this commit, as it already fixed the issue around acpi-cpufreq driver. We will continue to see what's wrong with intel-pstate though. 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 = {