Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp350430pxx; Wed, 28 Oct 2020 06:29:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxN9JDYOJLGoBg8ByaHEMB92oEwk1HRgxQU2snTSzwSiqDquqrDacz2ww8WOyjLQKMtQuo X-Received: by 2002:a17:906:141b:: with SMTP id p27mr7837200ejc.205.1603891767179; Wed, 28 Oct 2020 06:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603891767; cv=none; d=google.com; s=arc-20160816; b=fbi6uGwEExGh08E6RjxpidkYKceR8IEtw0O8t3nFwzKwpAhf/d67hy1Fri1kVK+5e1 eNeYsFkQ3GIriJd/pMUKHIFZ6ncLslzkAt30HUXfdOONbi+6CT4AmdeJioDWOJcxzOBs XLNb0T6tOvBEx4XUPF7Z6sT8C9LufuH12vxExhEp0OjEbgy2BX0pX4Q7ml29z8mHOIbh FW/8UzcRz8rMpcJ7fWKLGc9LwqCsv3xhDvNAdqQVuZOLKI0KPO+YZ+XVP4dKsv2jj2Wo ZGaOJ3fDkF4TZAupVwkQFzjg8RLPDTT11zXQUHbDZAiI7bqZgZOHSZaxGAZODiu0TRNJ 7hZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5UfMeK/4QOpfKdioCwuDY6GsJstO/WN75gDFAYwoNo0=; b=EbZ/uKS74WOGNx4bCQ/hhLlFsVQi4WIxAuBg0DkuPCgHw6BG7opXXVUqfdsTMM5vjO oCxOnX38CULiFnOkz9e0BM99sRgl5+OfOIk7CoJgKwtoWTshEhWAVs+RoR48hhOFgBt6 mMdGXctKsB/RCxukuknr0VXfrppjOcOPgU5Axl2DWPdwMlrRkyMJ+B6yb3+HYKYaNClg Ixtr5GBeUaxoL9S5YJih5l8MqLBB7ElJvMCGLxj9Lb9Z5TGGsZoGhNTG4KhiVPxx/T7X zF2aXRjyPdLWDfi2/HvqX6R33eyG0u8gMkqhEUeSjdOKt0pZBPgW6hqJvuj//c6EQkCo +Wkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si2524555edb.466.2020.10.28.06.29.04; Wed, 28 Oct 2020 06:29:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1802047AbgJ0Pp2 (ORCPT + 99 others); Tue, 27 Oct 2020 11:45:28 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:44138 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800447AbgJ0Pfy (ORCPT ); Tue, 27 Oct 2020 11:35:54 -0400 Received: from 89-64-86-244.dynamic.chello.pl (89.64.86.244) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.491) id 9e1452c9f4f6bfa2; Tue, 27 Oct 2020 16:35:51 +0100 From: "Rafael J. Wysocki" To: Linux PM , Viresh Kumar Cc: LKML , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v2.1 4/4] cpufreq: schedutil: Always call driver if need_freq_update is set Date: Tue, 27 Oct 2020 16:35:51 +0100 Message-ID: <12275472.W5IoEtXICo@kreacher> In-Reply-To: <1905098.zDJocX6404@kreacher> References: <2183878.gTFULuzKx9@kreacher> <1905098.zDJocX6404@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Because sugov_update_next_freq() may skip a frequency update even if the need_freq_update flag has been set for the policy at hand, policy limits updates may not take effect as expected. For example, if the intel_pstate driver operates in the passive mode with HWP enabled, it needs to update the HWP min and max limits when the policy min and max limits change, respectively, but that may not happen if the target frequency does not change along with the limit at hand. In particular, if the policy min is changed first, causing the target frequency to be adjusted to it, and the policy max limit is changed later to the same value, the HWP max limit will not be updated to follow it as expected, because the target frequency is still equal to the policy min limit and it will not change until that limit is updated. To address this issue, modify get_next_freq() to let the driver callback run if the CPUFREQ_NEED_UPDATE_LIMITS cpufreq driver flag is set regardless of whether or not the new frequency to set is equal to the previous one. Fixes: f6ebbcf08f37 ("cpufreq: intel_pstate: Implement passive mode with HWP enabled") Reported-by: Zhang Rui Tested-by: Zhang Rui Cc: 5.9+ # 5.9+ Signed-off-by: Rafael J. Wysocki --- v2 -> v2.1 * Fix typo in the subject. * Make get_next_freq() and sugov_update_next_freq() ignore the sg_policy->next_freq == next_freq case when CPUFREQ_NEED_UPDATE_LIMITS is set for the driver. * Add Tested-by from Rui (this version lets the driver callback run more often than the v2, so the behavior in the Rui's case doesn't change). --- kernel/sched/cpufreq_schedutil.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) Index: linux-pm/kernel/sched/cpufreq_schedutil.c =================================================================== --- linux-pm.orig/kernel/sched/cpufreq_schedutil.c +++ linux-pm/kernel/sched/cpufreq_schedutil.c @@ -102,11 +102,12 @@ static bool sugov_should_update_freq(str static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time, unsigned int next_freq) { - if (sg_policy->next_freq == next_freq) + if (sg_policy->next_freq == next_freq && !sg_policy->need_freq_update) return false; sg_policy->next_freq = next_freq; sg_policy->last_freq_update_time = time; + sg_policy->need_freq_update = false; return true; } @@ -161,10 +162,12 @@ static unsigned int get_next_freq(struct freq = map_util_freq(util, freq, max); - if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) + if (cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS)) + sg_policy->need_freq_update = true; + else if (freq == sg_policy->cached_raw_freq && + !sg_policy->need_freq_update) return sg_policy->next_freq; - sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = freq; return cpufreq_driver_resolve_freq(policy, freq); }