Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3898229rwo; Mon, 24 Jul 2023 19:36:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQT3YmMMg78tdFYcqibYN+RaoXp4P6B3BScvLGxsEzMKCT25wzAPviM5i3kC51Gktnp/fW X-Received: by 2002:a17:907:8a1f:b0:99b:9374:c230 with SMTP id sc31-20020a1709078a1f00b0099b9374c230mr1100719ejc.34.1690252590706; Mon, 24 Jul 2023 19:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690252590; cv=none; d=google.com; s=arc-20160816; b=rdejZBXXv0HNnZhr+gIraop5+7PaKDTZA6FUx65Vlojr+vFSgnTD/Kqn1/3OPX9mqZ tID/pwZRuWtp6ygmLk3NqSyydxKESSare2BmkNcvSLL2hGtTWbl0ozQK1nDtYsewUyEh oaaVptQl9pr/pcXdQORYAvViWYHFMNWk1DC52x5ynOfg2/Sad80VJauH9t4PWmkoWzDc mPLnPqhtrUjXzi6dpgq5rXxRi8vY4t/LeaAK9nOqhrzFFUlcfy+zpsX+YR09Q7CFgHzK SzrAa5I0EAFdGWRa53uUFIbMA8GqM/f7HL40ghQi2CQUwpdWqTZQRb0m1+/fckWdFTrV 3V5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pTHbFq1+FFxNZgfCTCOGl7TBf00vI13bg8s8rIJm8N0=; fh=fxKM6qaZpX3Nz6lOjIdqh4dh88MDIwRluqnXzAroQxc=; b=xuWsz/U8+OwZZ2VVzsuGk6T798LWzUU3CJ4lTfk7WfUPLGVVSNBbwshKIpiQ+QS6Bd 0kst0jeSz1gVoJruZg7Rch/Yh5FQgiVDYPsFOdAw/gIFOOedqd9yZRiFKkqcdtKnem5v lA9lfQwJmri1GqmCIWQ6HkFNWQrY5wlKNLjCqs1h/cn/eKjnCq12nqtLR+B7Flq8KxYv qaOJIE+jAdiSACxhmtqwFNvQWLgHRA1DU7fhFHf2WmifVmDZJSRMl8smzc78EFvVxPW7 CEtsi4HhOi+UWpl0kYVjk8VU46myJiZD6BuSxiBhrZkmfEH4V6AGy6FZWdb/+lbx3LzK ZR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=FmR4eal4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170906d10a00b00992765dcbd1si7254508ejz.866.2023.07.24.19.36.06; Mon, 24 Jul 2023 19:36:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=FmR4eal4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbjGYCVl (ORCPT + 99 others); Mon, 24 Jul 2023 22:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjGYCVj (ORCPT ); Mon, 24 Jul 2023 22:21:39 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B232CD; Mon, 24 Jul 2023 19:21:38 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6b9ede6195cso4302367a34.3; Mon, 24 Jul 2023 19:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690251697; x=1690856497; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pTHbFq1+FFxNZgfCTCOGl7TBf00vI13bg8s8rIJm8N0=; b=FmR4eal4jbWnp3sxXDLx0IEXrT1EWCeJT1ock7PDfFHYcXbzYCMktgiTISmcJzueif M+rycqWDLNlqAq3vhMffM+CvOyuLkPVsQlmKQOABxjgIl55WFLH1eHVEw0CTmwePZJ6o 8AFhDURbWIcNTojA9UDL17kqV69Eh01wo41WoEScGUeE9ozuEm4OwbBWgQWMxpbExpdF je74sXvA2dMcIjBuZZzFfRB6fKJ6wVbvpCNIwmtBPT/d9uqBguQTDGcvUt5qWA/4LcuD u+5kOUN+F4xZDWZOdoOHp4XYAAS08otxN9ziCDuxSK6dmsf6sXfEXNzP3Ea2hVZQ4VKI m/jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690251697; x=1690856497; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pTHbFq1+FFxNZgfCTCOGl7TBf00vI13bg8s8rIJm8N0=; b=L/qmHCBiocegx98e1ZIvH2yrrwKt58bVKrWwICNZZifQKrivXRR1BEmlgGVhxNdaCR VxOoIiYG97V3rH2FZ81k52PosUUt1gA05SMtmGdwgwupjeHRQMAC2589m11IZTzhTbTL cADPS93tDw9loLZSyg1/OPNv2Kv11FBkO5EFhP485/1rVGM+0w9kTW88jV1Z8Iu2vXLA j6U6hazaEY3LjdDIeELpNNspRrhgyNXzrc1wwjEmW3UtAHMG51dkBbMg2TMZabdyqhj7 fInyJzx4I/4B5IsW4RI2BYWAo+5yMPYjS9e2U2jgkLhwL7baa7wM7tX8kDxyFeJFUj1e ZzfQ== X-Gm-Message-State: ABy/qLYUASRLCZbsmaw3PKI3oYdEDvvqN6vH8MpHuI0L6TqfALZ7BWep neY/VkYKdhKKSe4xAE4hqRNGlpdx8wxIoBgc4PM= X-Received: by 2002:a05:6870:2192:b0:1ba:617f:5f26 with SMTP id l18-20020a056870219200b001ba617f5f26mr13202632oae.51.1690251697445; Mon, 24 Jul 2023 19:21:37 -0700 (PDT) MIME-Version: 1.0 References: <20230719130527.8074-1-xuewen.yan@unisoc.com> <20230721221944.dthg3tf25j4qgc2z@airbuntu> <20230724155328.7odez6dcoafksr3i@airbuntu> In-Reply-To: <20230724155328.7odez6dcoafksr3i@airbuntu> From: Xuewen Yan Date: Tue, 25 Jul 2023 10:21:26 +0800 Message-ID: Subject: Re: [PATCH] cpufreq: schedutil: next_freq need update when cpufreq_limits changed To: Qais Yousef Cc: Xuewen Yan , rafael@kernel.org, viresh.kumar@linaro.org, mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, guohua.yan@unisoc.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 24, 2023 at 11:53=E2=80=AFPM Qais Yousef = wrote: > > On 07/24/23 11:36, Xuewen Yan wrote: > > On Sat, Jul 22, 2023 at 7:02=E2=80=AFAM Qais Yousef wrote: > > > > > > On 07/19/23 21:05, Xuewen Yan wrote: > > > > When cpufreq's policy is single, there is a scenario that will > > > > cause sg_policy's next_freq to be unable to update. > > > > > > > > When the cpu's util is always max, the cpufreq will be max, > > > > and then if we change the policy's scaling_max_freq to be a > > > > lower freq, indeed, the sg_policy's next_freq need change to > > > > be the lower freq, however, because the cpu_is_busy, the next_freq > > > > would keep the max_freq. > > > > > > > > For example: > > > > The cpu7 is single cpu: > > > > > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # while true;do done= & > > > > [1] 4737 > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # taskset -p 80 4737 > > > > pid 4737's current affinity mask: ff > > > > pid 4737's new affinity mask: 80 > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # cat scaling_max_fr= eq > > > > 2301000 > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # cat scaling_cur_fr= eq > > > > 2301000 > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # echo 2171000 > sca= ling_max_freq > > > > unisoc:/sys/devices/system/cpu/cpufreq/policy7 # cat scaling_max_fr= eq > > > > 2171000 > > > > > > > > At this time, the sg_policy's next_freq would keep 2301000. > > > > > > > > To prevent the case happen, add the judgment of the need_freq_updat= e flag. > > > > > > > > Signed-off-by: Xuewen Yan > > > > Co-developed-by: Guohua Yan > > > > Signed-off-by: Guohua Yan > > > > --- > > > > kernel/sched/cpufreq_schedutil.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufre= q_schedutil.c > > > > index 4492608b7d7f..458d359f5991 100644 > > > > --- a/kernel/sched/cpufreq_schedutil.c > > > > +++ b/kernel/sched/cpufreq_schedutil.c > > > > @@ -350,7 +350,8 @@ static void sugov_update_single_freq(struct upd= ate_util_data *hook, u64 time, > > > > * Except when the rq is capped by uclamp_max. > > > > */ > > > > if (!uclamp_rq_is_capped(cpu_rq(sg_cpu->cpu)) && > > > > - sugov_cpu_is_busy(sg_cpu) && next_f < sg_policy->next_fre= q) { > > > > + sugov_cpu_is_busy(sg_cpu) && next_f < sg_policy->next_fre= q && > > > > + !sg_policy->need_freq_update) { > > > > > > What about sugov_update_single_perf()? It seems to have the same prob= lem, no? > > > > There is no problem in sugov_update_single_perf, because the next_freq > > is updated by drivers, maybe the next_freq is not used when using > > sugov_update_single_perf.. > > Ah I see; we just use prev_util but the request will go through and the d= river > should observe the new limit regardless of what util value we pass to it.= Got > ya. > > > > > But for the last_freq_update_time, I think there are some problems > > when using sugov_update_single_perf: > > Now, there is no judgment condition for the update of the > > last_freq_update_time. That means the last_freq_update_time is always > > updated in sugov_update_single_perf. > > And in sugov_should_update_freq: it would judge the > > freq_update_delay_ns. As a result, If we use the > > sugov_update_single_perf, the cpu frequency would only be periodically > > updated according to freq_update_delay_ns. > > Maybe we should judge the cpufreq_driver_adjust_perf's return value, > > if the freq is not updated, the last_freq_update_time also does not > > have to update. > > > > Just like: > > --- > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_sc= hedutil.c > > index 458d359f5991..10f18b054f01 100644 > > --- a/kernel/sched/cpufreq_schedutil.c > > +++ b/kernel/sched/cpufreq_schedutil.c > > @@ -381,6 +381,7 @@ static void sugov_update_single_perf(struct > > update_util_data *hook, u64 time, > > struct sugov_cpu *sg_cpu =3D container_of(hook, struct > > sugov_cpu, update_util); > > unsigned long prev_util =3D sg_cpu->util; > > unsigned long max_cap; > > + bool freq_updated; > > > > /* > > * Fall back to the "frequency" path if frequency invariance is= not > > @@ -407,10 +408,11 @@ static void sugov_update_single_perf(struct > > update_util_data *hook, u64 time, > > sugov_cpu_is_busy(sg_cpu) && sg_cpu->util < prev_util) > > sg_cpu->util =3D prev_util; > > > > - cpufreq_driver_adjust_perf(sg_cpu->cpu, map_util_perf(sg_cpu->b= w_dl), > > + freq_updated =3D cpufreq_driver_adjust_perf(sg_cpu->cpu, > > map_util_perf(sg_cpu->bw_dl), > > map_util_perf(sg_cpu->util), max_cap= ); > > > > - sg_cpu->sg_policy->last_freq_update_time =3D time; > > + if (freq_updated) > > + sg_cpu->sg_policy->last_freq_update_time =3D time; > > } > > Sound reasonable in principle, but it could lead to overhead; for example= when > the system is busy and maxed out, the last_freq_update_time will never be > updated and will end up continuously calling to the driver to change freq= uency > without any rate limit AFAICS. Which might not be an acceptable overhead, > I don't know. Logically this is wasted cycles preventing the tasks from d= oing > useful work. I think we need to look at such corner cases and treat them > appropriately to not call the driver if we go with this approach. Hi Qais, I can understand what you mean, but I don't think this is a problem. For the driver, the calculation of whether to update the frequency may not be the main time-consuming, but the main time-consuming may be the frequency conversion time of the hardware. If the hardware does not need frequency conversion, the operation of calculating the frequency takes a very short time. If the operation of calling the driver frequently is unacceptable, can prev_util be used? --- diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedu= til.c index 4492608b7d7f..3febfd032eee 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -379,7 +379,9 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time, { struct sugov_cpu *sg_cpu =3D container_of(hook, struct sugov_cpu, update_util); unsigned long prev_util =3D sg_cpu->util; + unsigned long prev_bw_dl =3D sg_cpu->bw_dl; unsigned long max_cap; + bool freq_updated; /* * Fall back to the "frequency" path if frequency invariance is not @@ -406,10 +408,14 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time, sugov_cpu_is_busy(sg_cpu) && sg_cpu->util < prev_util) sg_cpu->util =3D prev_util; - cpufreq_driver_adjust_perf(sg_cpu->cpu, map_util_perf(sg_cpu->bw_dl= ), + if (prev_util =3D=3D sg_cpu->util && prev_bw_dl =3D=3D sg_cpu->bw_d= l) + return; + + freq_updated =3D cpufreq_driver_adjust_perf(sg_cpu->cpu, map_util_perf(sg_cpu->bw_dl), map_util_perf(sg_cpu->util), max_cap); - sg_cpu->sg_policy->last_freq_update_time =3D time; + if (freq_updated) + sg_cpu->sg_policy->last_freq_update_time =3D time; } static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 t= ime) BR --- xuewen > > > Cheers > > -- > Qais Yousef > > > > > > > BR > > Thanks! > > > > --- > > xuewen > > > > > > LGTM otherwise. > > > > > > > > > Cheers > > > > > > -- > > > Qais Yousef > > > > > > > next_f =3D sg_policy->next_freq; > > > > > > > > /* Restore cached freq as next_freq has changed */ > > > > -- > > > > 2.25.1 > > > >