Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1064543pxx; Fri, 30 Oct 2020 00:33:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn6OkrTLP3Ocp4OVouC/i/9AuQbpnFWxyBdlO5w4QPQdzWqe8ioiKiXyC7s8E55Gr/GUCm X-Received: by 2002:a17:906:7c9:: with SMTP id m9mr221238ejc.178.1604043182968; Fri, 30 Oct 2020 00:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604043182; cv=none; d=google.com; s=arc-20160816; b=M2/EY8abS4HZKwFi1nMzrAt+MmoUzZC4YaCYZDSJlm3uvzCDQU0aywiGaTh5oAAFiU IwjyJGYk0miGj5+BbqeSaX6mr32jVVvZARcIebUnIa8SZJOm+DSZ2cTpqNyjtB2+rI3g AaZDLs6Bnom4gFaf/1URIP1BC4QzKBVB3Rr9uAjZfrjNtxTh04lgn8YaaYrg4+Q4jEt2 vXETm47xgpqfqvam++7rO0m8xLYFDyh4yrgkAiIB71N5htRaZ/vOFFmJNkpUSK01nD7y tCcUlJUfkhArc16qh44onOggSuJlapmqrfvTgjg9L+Q31fObtActCODbLZujFJkvKYD6 jGUQ== 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 :dkim-signature; bh=FKffrVOQX7anjwx1MfdXS1XL/Tw95pOKF2Q6qrmVHDE=; b=sSDwPdpRXwZ+KJPEiAX8utunC5zFrriOt6/wWs/iU8jwvwHAmxkGRAhyib/lA4nPPY gjx52wBJOU/xf3TCMTdr4h8460E0QZJNwKA4a0oHDzb399AP54NjG78LqBu3sQKj9nIj W6K3sIq/x6pGiZ+GayvLlM+2GYMZgnNoEG0vl2Olc68IUmInawHS/igzgB4M2z+N5lJE arJcO7VV3X6pYMRAt5abiY8e6uP43magHXcU+sq24xNZ9CeR5si6zQ1CJ0zxyx/Fcbfy QadT2xjgc1GVBY88JZS755zS9C1lTLDdcS/n3rq/o1QwoA116gv7m9NLqIae9PaTkJaE Zyzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hBoHo5nv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si3573626ejq.401.2020.10.30.00.32.40; Fri, 30 Oct 2020 00:33:02 -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; dkim=pass header.i=@linaro.org header.s=google header.b=hBoHo5nv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbgJ3HbF (ORCPT + 99 others); Fri, 30 Oct 2020 03:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgJ3HbE (ORCPT ); Fri, 30 Oct 2020 03:31:04 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2B0C0613CF for ; Fri, 30 Oct 2020 00:21:15 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o3so4437638pgr.11 for ; Fri, 30 Oct 2020 00:21:15 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=FKffrVOQX7anjwx1MfdXS1XL/Tw95pOKF2Q6qrmVHDE=; b=hBoHo5nv0l5AXDe0dorVGfDWr4y1RVEy4vrUnJXlMep3X8WWcdiu2KQ24MeBpkT5E6 Yn7Gc5Nd839ZswOuefX+h6OgXwVL6AgJ/DewfHXqrRhXuoJxwKEu9IAH/vJfC6SlxU11 lDtnkGl5EjjFkXyIouXEyyNEBfcU0eFx0mQBO4fqD79yEnd2kT8umR8lV14TOzILs3NN uv2gRxmgv5p0m6oQMKgU2eSerYdv32qi5UzHRNf9nMp1dj8PWcKnfR21OENDaxMEYQwu wKByzuPCi9GKwDznCzl9KTABGmL+d3aTwfvBe8R0adaVlDiODhFL3/gD6Q1tZGxp5NHU sDMA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=FKffrVOQX7anjwx1MfdXS1XL/Tw95pOKF2Q6qrmVHDE=; b=aCDKNEXa+CM+lRSR5LnCtMH4AgBQlT3Jh/MTCDdGKPBZ7dPQ88E2QonBEbXxGc4gIK KKFDVp9LiXCLnH7DBGgc2SoMfqoMGt/CeEyxRvvxpkF1NY0xIQsSOcm62OHWpAgwN7Ca ikHLOhUwP22F/KSLiRnZ2gaJoYXVgrbodXyi5OUkSPTYzn12RhfU/FfPV3QluSv8PyQx bc84DQGiHrEPB2yXFgaa7eDmTqnEl3zSpu8KgSVFDdqAKNooVrGUA8iud8jG9M6oiavt T5rQhY+t7hN4Itk9csazdY8hZY0x3UYIrO2ndcCBmzGVxJdbA9mwIN73hNOySEXEM2iv bYGg== X-Gm-Message-State: AOAM530qY8xdmtkrXRQVVq6FFs2LHQ4E+vtT2nv4Nh/sO+veJs+LaMHc y1piWNCeWMWw8anHskIpcoyazw== X-Received: by 2002:a62:216:0:b029:164:bdf3:2cbf with SMTP id 22-20020a6202160000b0290164bdf32cbfmr5943609pfc.33.1604042474765; Fri, 30 Oct 2020 00:21:14 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id kk14sm2004031pjb.47.2020.10.30.00.21.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Oct 2020 00:21:13 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: linux-pm@vger.kernel.org, zhuguangqing , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: schedutil: Don't skip freq update if need_freq_update is set Date: Fri, 30 Oct 2020 12:51:08 +0530 Message-Id: <207ae817a778d79a99c30cb48f2ea1f527416519.1604042421.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <2954009.kBar6x9KXa@kreacher> References: <2954009.kBar6x9KXa@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq policy's frequency limits (min/max) can get changed at any point of time, while schedutil is trying to update the next frequency. Though the schedutil governor has necessary locking and support in place to make sure we don't miss any of those updates, there is a corner case where the governor will find that the CPU is already running at the desired frequency and so may skip an update. For example, consider that the CPU can run at 1 GHz, 1.2 GHz and 1.4 GHz and is running at 1 GHz currently. Schedutil tries to update the frequency to 1.2 GHz, during this time the policy limits get changed as policy->min = 1.4 GHz. As schedutil (and cpufreq core) does clamp the frequency at various instances, we will eventually set the frequency to 1.4 GHz, while we will save 1.2 GHz in sg_policy->next_freq. Now lets say the policy limits get changed back at this time with policy->min as 1 GHz. The next time schedutil is invoked by the scheduler, we will reevaluate the next frequency (because need_freq_update will get set due to limits change event) and lets say we want to set the frequency to 1.2 GHz again. At this point sugov_update_next_freq() will find the next_freq == current_freq and will abort the update, while the CPU actually runs at 1.4 GHz. Until now need_freq_update was used as a flag to indicate that the policy's frequency limits have changed, and that we should consider the new limits while reevaluating the next frequency. This patch fixes the above mentioned issue by extending the purpose of the need_freq_update flag. If this flag is set now, the schedutil governor will not try to abort a frequency change even if next_freq == current_freq. As similar behavior is required in the case of CPUFREQ_NEED_UPDATE_LIMITS flag as well, need_freq_update will never be set to false if that flag is set for the driver. We also don't need to consider the need_freq_update flag in sugov_update_single() anymore to handle the special case of busy CPU, as we won't abort a frequency update anymore. Reported-by: zhuguangqing Suggested-by: Rafael J. Wysocki Signed-off-by: Viresh Kumar --- kernel/sched/cpufreq_schedutil.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index c03a5775d019..c6861be02c86 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -102,9 +102,12 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time, unsigned int next_freq) { - if (sg_policy->next_freq == next_freq && - !cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS)) - return false; + if (!sg_policy->need_freq_update) { + if (sg_policy->next_freq == next_freq) + return false; + } else if (!cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS)) { + sg_policy->need_freq_update = false; + } sg_policy->next_freq = next_freq; sg_policy->last_freq_update_time = time; @@ -162,11 +165,9 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, freq = map_util_freq(util, freq, max); - if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update && - !cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS)) + 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); } @@ -442,7 +443,6 @@ 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; unsigned int cached_freq = sg_policy->cached_raw_freq; sugov_iowait_boost(sg_cpu, time, flags); @@ -453,9 +453,6 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (!sugov_should_update_freq(sg_policy, time)) return; - /* 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; util = sugov_iowait_apply(sg_cpu, time, util, max); @@ -464,7 +461,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, * Do not reduce the frequency if the CPU has not been idle * recently, as the reduction is likely to be premature then. */ - if (busy && next_f < sg_policy->next_freq) { + if (sugov_cpu_is_busy(sg_cpu) && next_f < sg_policy->next_freq) { next_f = sg_policy->next_freq; /* Restore cached freq as next_freq has changed */ @@ -829,9 +826,10 @@ static int sugov_start(struct cpufreq_policy *policy) 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; + sg_policy->need_freq_update = cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS); + for_each_cpu(cpu, policy->cpus) { struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu); -- 2.25.0.rc1.19.g042ed3e048af