Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3046532pxx; Sun, 1 Nov 2020 20:46:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlYcT8ml/JB/sPNaWG12mm3lakwyMc/cx/plDHkiNBsotF3tsbYOFZV+2Iv4+FSMksQQ2b X-Received: by 2002:a17:906:a149:: with SMTP id bu9mr13367051ejb.115.1604292412934; Sun, 01 Nov 2020 20:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604292412; cv=none; d=google.com; s=arc-20160816; b=b3YsK6Y8ccXz1L6EA8KCuTIcJuHGLG2b+uZZKen7eFMlteQoNfhvjet2GirI3fo1fR IbKqRZK42NrV4tnivmHwMtRAuyYhj83a/sdsaQu7qXATnqPFr0sBTgm5CeCH6JOO1Hds onDCOhDh43orMv+PxNDJpVRJx04D9Qm3dhI+KVraN29FlIbD8bFBg3Oa+EfrJ1N4fHY7 0wy12c1ao4zJ+dhMjNVOgifT3lKbiOs8ntDjPX4hkanZG1nPDimcOh79eyqsTD2JyjoJ zBVUYynuc1F0ynJCPUotV6QudM9tUzBzkaZFYf6Er4aJRfJAubDByiOyp+APhfTJeGYn mYvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=srks28iO1gRpgZNbb5QK/SCn40SAhZrPX4c/7fjgLFw=; b=wHj3p641rpTDlD7avdF2Lf68ZnN8tU+ce4kYh0dPaL5VtLz0t5rScyJNntwHmPUSfF AB1UkAOPtKFAHZJwRr10yBjTnWl+NQXWqU7M12mjxRsKETa+szfVrflX7ZYAzB7bQ43p qMwIeD/BecBQDt1w/OaZ+53fw9F3tZ/3MB1Nt5Z+mG2kIt4q+CshTt3c7gY6Xv22Z5Qv 18prJFCqAVhpJu48Ka7fTEGlR1H1aTuBS8DfW5Bs2uHbizQe7qceyriUl24oaRXnVvy4 L1OWJ8q2Ba78oSqiYhYI7MFAsPGm6BfdYJBAUVkQd1CQaiAnHF3cmJaknot2fKWcsyS3 3e4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ub+qiSgS; 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 r12si6246765edb.155.2020.11.01.20.46.14; Sun, 01 Nov 2020 20:46:52 -0800 (PST) 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=ub+qiSgS; 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 S1727727AbgKBEnQ (ORCPT + 99 others); Sun, 1 Nov 2020 23:43:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727726AbgKBEnQ (ORCPT ); Sun, 1 Nov 2020 23:43:16 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC49C0617A6 for ; Sun, 1 Nov 2020 20:43:16 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id x13so9705446pgp.7 for ; Sun, 01 Nov 2020 20:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=srks28iO1gRpgZNbb5QK/SCn40SAhZrPX4c/7fjgLFw=; b=ub+qiSgSbfLn/SnED3PuPrLhmyL3iqBvzfQlSF6LEuubARqPGjU1EmwDT+CDViGRn3 vYweN7kq/UsFjLrUSYgoylXCBBbmu3Dsq1+JRYCYuvclcvBjaoWto+WJmOoyCotvGsGD Nua1Jbwl2lg4SycCfIUVR81iMH27j2fz6AINkdxhrZOUJpGyWnbSl2Q4sM2LPFeTeVqa opZzMqO6BHppw16XNgtJ6fOOBCb0Cj4hUU94aWB/IvLoXRdpgwe6Xk2lsYTODdeCpWbp tq8jblB9dPPcKkE8k4x85piEWR3z7+uJMueoYzFqSj6JyOjiSXMdtLIQSyHRv5OXJvSZ t0Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=srks28iO1gRpgZNbb5QK/SCn40SAhZrPX4c/7fjgLFw=; b=ek70teyERBf3CZd4TC5RPWkzXFR9PNUrCTAJ67GBUJ3Y/MmtLTyYaEG1RAApr9E+2a uK5b+mPrSHyFcH+cwCgqjZOx/2p/UxCL9VDCzqPgKUbo2tYoMUxviaKaDwd1aTqvUopi L31E9gJWZ9LeUFkP2TFtMunP8D1yoITMx2oQtp90DWOliLC38EjTU9uv8EESooRza7BV 5xt3vrqDgximlmV+RVF3LVfM+O/EBg2h92Sm//6YSBEaV+6F4rq5+4plsEwxG9SsAIWa r6hWfHl1J+JTk+ziPvDT09ZltJ16Bc9jt1obqHZ/ZE35TkdtOyCyeMxVUcR03DWS53UF oAeQ== X-Gm-Message-State: AOAM531BLMzrh8xWe/Pg17ZHAi8X4YYSVL2L//7SZzp42hYmciRxkwN4 xzPR40C9CFKdbWCUz4c0sDsQ1A== X-Received: by 2002:a62:55c6:0:b029:160:1c33:a0f7 with SMTP id j189-20020a6255c60000b02901601c33a0f7mr20050354pfb.35.1604292195495; Sun, 01 Nov 2020 20:43:15 -0800 (PST) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id r19sm10162020pjo.23.2020.11.01.20.43.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Nov 2020 20:43:14 -0800 (PST) Date: Mon, 2 Nov 2020 10:13:12 +0530 From: Viresh Kumar To: "Rafael J. Wysocki" Cc: Rafael Wysocki , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Linux PM , zhuguangqing , "Rafael J . Wysocki" , Linux Kernel Mailing List Subject: Re: [PATCH] cpufreq: schedutil: Don't skip freq update if need_freq_update is set Message-ID: <20201102044312.4oxgfsmx3v5raq6d@vireshk-i7> References: <2954009.kBar6x9KXa@kreacher> <207ae817a778d79a99c30cb48f2ea1f527416519.1604042421.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30-10-20, 16:23, Rafael J. Wysocki wrote: > On Fri, Oct 30, 2020 at 4:07 PM Rafael J. Wysocki wrote: > > > > On Fri, Oct 30, 2020 at 8:31 AM Viresh Kumar wrote: > > > > > > 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 > > > > Thanks for following my suggestion! > > > > > 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; > > One nit, though. > > This can be changed into > > } else { > sg_policy->need_freq_update = > cpufreq_driver_test_flags(CPUFREQ_NEED_UPDATE_LIMITS); > } > > to save a branch and because need_freq_update is there in the cache > already, this should be a fast update. Nice. -- viresh