Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1525596pxv; Fri, 2 Jul 2021 06:03:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqxLe8Ia9aVco+H15LSzLjOr2WCCf/2Unsq7E2pw4vqYabVyPkq6RZjZ8Cn/5Svay2yrt4 X-Received: by 2002:a92:a005:: with SMTP id e5mr583799ili.22.1625231033795; Fri, 02 Jul 2021 06:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625231033; cv=none; d=google.com; s=arc-20160816; b=yrxmc2jsGBQjuknjSiPPVqx8+qAXs75Br3SEyrSNzZovq1QF/i8UAAmxL2qgyFZD1P i+vg70KcDpGeVjZP/cclvkZ2mRHK9BlIN1yYhx+B6HChZQ+U0OUekN1XtfuUmYDNiQLu 5xedRtHuGUDPI6rpHeq06mEsJA2hgnp9I/nj++9KY2syCkRcOeV37zWIgfeT/IfmNePQ MB+jJDjmO6EYE+fwyPIBURpLjhb/GoERMdSbNIVoQUnvNFKxw7kemFrZeKOwiv8Edb7W /hi1N2an4De0V8ZZr0o9I0q3OsgKcYVySMgE5q/dUtsKJN0BAwqwj+NnwfIrbf0WFaBb AGbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=n3ZL5mkrhEYr2VcrInZbn1X+Tb8h0bzNV1DESPBO+fc=; b=xmqyaohkEGBQZxOzG4W+lsRmgOa1vI7LrrVc7ksNy3G4fggaU3T5sUd1OEd0cD02lz tV/CnXmicFaOzxvF9lzikm+CEiSuOBUX5QLLoasTvbWUwk1+656bQdYq4j8HtR3eygCh IShWk2Gfn4Mt/6He48UZ6tUEl/legM7yiftQLCSrpnmCHcLBoH2tQJLRw/z7sZXPF2jB DBbpxEXbz+QdHZnZBfZpCw6kg8t2bC42Yc6KnWVyWW2v6MMB5/nX/cavPqVuLVyvMXYK T6LGo8OhJWnf9IbB9dvoOuc6YwQdw/h/+PoKK1QPTZRZ7v2FXdu44NasVQFzyFmwNzVN fLmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=WBW0uF5B; 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 t15si2968849jai.117.2021.07.02.06.03.14; Fri, 02 Jul 2021 06:03:53 -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=@infradead.org header.s=desiato.20200630 header.b=WBW0uF5B; 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 S231803AbhGBLPi (ORCPT + 99 others); Fri, 2 Jul 2021 07:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbhGBLPh (ORCPT ); Fri, 2 Jul 2021 07:15:37 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA68DC061762 for ; Fri, 2 Jul 2021 04:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=n3ZL5mkrhEYr2VcrInZbn1X+Tb8h0bzNV1DESPBO+fc=; b=WBW0uF5BM+0qp8Znl7C1Wo9Fpl BERgSS7E1WNTyeeAvjFVMBkgJVoiyDZpufRVlBS89q7mQGzwHvUmSknN8RZpYBHridZBDoOP6rqyD WtT16R4K6TY5ahPazEpqwhBLcz7bnxcIVVXHpUevvpuiegENchvg1UYodS+MhoXmY5gmUkeeFfP2X G2NhoF7+RdbqUS184XdRu+WPi5Uri2XoNvEWQrqwiaNFQe8gBVIWNXDQVYvLsVzKc7t33NGvAHlP2 gIVcT+R+u384gXs3dZL8zxx8PZ8a3fJU+0NiixSh1W5QKMZdTUzoYVCeCiZHjJXRsKXBZeVkXF+Di o6jHApDQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzH6I-00DqH9-A0; Fri, 02 Jul 2021 11:12:51 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 83485300091; Fri, 2 Jul 2021 13:12:49 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4CC4620195214; Fri, 2 Jul 2021 13:12:49 +0200 (CEST) Date: Fri, 2 Jul 2021 13:12:49 +0200 From: Peter Zijlstra To: Xuewen Yan Cc: valentin.schneider@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, patrick.bellasi@matbug.net, qais.yousef@arm.com, qperret@google.com Subject: Re: [PATCH v2] sched/uclamp: Avoid getting unreasonable ucalmp value when rq is idle Message-ID: References: <20210630141204.8197-1-xuewen.yan94@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210630141204.8197-1-xuewen.yan94@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 30, 2021 at 10:12:04PM +0800, Xuewen Yan wrote: > From: Xuewen Yan > > Now in uclamp_rq_util_with(), when the task != NULL, the uclamp_max as following: > uc_rq_max = rq->uclamp[UCLAMP_MAX].value; > uc_eff_max = uclamp_eff_value(p, UCLAMP_MAX); > uclamp_max = max{uc_rq_max, uc_eff_max}; > > Consider the following scenario: > (1)the rq is idle, the uc_rq_max is last runnable task's UCLAMP_MAX; > (2)the p's uc_eff_max < uc_rq_max. > > As a result, the uclamp_max = uc_rq_max instead of uc_eff_max, it is unreasonable. > > The scenario often happens in find_energy_efficient_cpu(), when the task has smaller UCLAMP_MAX. > > When rq has UCLAMP_FLAG_IDLE flag, enqueuing the task will lift UCLAMP_FLAG_IDLE > and set the rq clamp as the task's via uclamp_idle_reset(). It doesn't need > to read the rq clamp. And it can also avoid the problems described above. > > Fixes: 9d20ad7dfc9a ("sched/uclamp: Add uclamp_util_with()") > > Signed-off-by: Xuewen Yan Valentin, Qais, can either of you write a Changelog/comment for this, I can't seem to make any sense of it. Is this about wake-from-idle, where the first task's uclamp goes amis because the rq->uclamp values haven't been updated yet? > --- > kernel/sched/sched.h | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index c80d42e9589b..14a41a243f7b 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -2818,20 +2818,27 @@ static __always_inline > unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util, > struct task_struct *p) > { > - unsigned long min_util; > - unsigned long max_util; > + unsigned long min_util = 0; > + unsigned long max_util = 0; > > if (!static_branch_likely(&sched_uclamp_used)) > return util; > > - min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value); > - max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value); > - > if (p) { > - min_util = max(min_util, uclamp_eff_value(p, UCLAMP_MIN)); > - max_util = max(max_util, uclamp_eff_value(p, UCLAMP_MAX)); > + min_util = uclamp_eff_value(p, UCLAMP_MIN); > + max_util = uclamp_eff_value(p, UCLAMP_MAX); > + > + /* > + * Ignore last runnable task's max clamp, as this task will > + * reset it. Similarly, no need to read the rq's min clamp. > + */ > + if (rq->uclamp_flags & UCLAMP_FLAG_IDLE) > + goto out; > } > > + min_util = max_t(unsigned long, min_util, READ_ONCE(rq->uclamp[UCLAMP_MIN].value)); > + max_util = max_t(unsigned long, max_util, READ_ONCE(rq->uclamp[UCLAMP_MAX].value)); > +out: > /* > * Since CPU's {min,max}_util clamps are MAX aggregated considering > * RUNNABLE tasks with _different_ clamps, we can end up with an > -- > 2.25.1 >