Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4511220pxv; Tue, 29 Jun 2021 08:40:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxktB8A13Lfy5K5zCcIrLG66g01zKJIKwTyG9Ef7TGNmLwsFk6Lx+0Xcn3dQh2+nIMwSsK3 X-Received: by 2002:a17:906:52d5:: with SMTP id w21mr31320650ejn.490.1624981207943; Tue, 29 Jun 2021 08:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624981207; cv=none; d=google.com; s=arc-20160816; b=rLCD5AxyTAQIVN/J//l/jT5jwx4I7N8/n/NYZwRUBjSLs7SAEMXH4QOyh4Uo3vSoh/ 07fDAbtxsNogk0JaqKs8+z9pe9FFLVkSZV/7MqpikEbK9+43AnTu4PmhXYfC+BcubzdJ lAuE3kAJYOiaR2dulxAzViVqeosZHR/mdnefgM753nNyl48iaWVLZmAPBpBaN7+hR3Wb qQHcmfFAPf3eioGEDxYHHoY2WJ+J1aZhD/TZwYxw13WcBkwg1nZQAJ2MdZS1k972v11e jkOfk7DwXdNdShi13aLmXThLmQa3PkG256IoItuPdBzi6/suq+fnqnjlAc/ued7qH0CF 8qZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=aOC/axVt8d2egKJDIN3HVqvxiqgsF/7lV3Gr2t969PM=; b=pWDc+EXk8MsjIsvjL1ZkOSwJTHZUjjny86Xo1iRfGzmseDNhha1ddwN8IbhGhYLF8M MO9NrprQR6PyUahcinG3GfirHEJIxahNhiyL5hq9v5kab77ucAyM7K8tzYV8A13Uhqw6 A3KFu6IFIAHXhNqwa9JbJGdmJF1lWtW9KRHCyJpTHXqqe0jixzdjsSre0bGGTcHGLM8o CqNVTyPKziHQC7PyIc6aM4E2gbD0Tc8bA8Lt4wwGktJr2mYLHK6fNroGgVRl3/Jfi3DD XsKHrfiLXucX5gGP2uxPP/OugpbZL+zWULPdpuMNNw93IPt2sO1FEfKLDakFStg84kRS Mr4Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si18000546eds.64.2021.06.29.08.39.38; Tue, 29 Jun 2021 08:40:07 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233729AbhF2Nw5 (ORCPT + 99 others); Tue, 29 Jun 2021 09:52:57 -0400 Received: from foss.arm.com ([217.140.110.172]:51666 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbhF2Nwz (ORCPT ); Tue, 29 Jun 2021 09:52:55 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 435CF106F; Tue, 29 Jun 2021 06:50:28 -0700 (PDT) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9432C3F718; Tue, 29 Jun 2021 06:50:26 -0700 (PDT) From: Valentin Schneider To: Xuewen Yan , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com Cc: rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, Patrick Bellasi , zhang.lyra@gmail.com Subject: Re: [PATCH] sched/uclamp: Fix getting unreasonable ucalmp_max when rq is idle In-Reply-To: <20210618072349.503-1-xuewen.yan94@gmail.com> References: <20210618072349.503-1-xuewen.yan94@gmail.com> Date: Tue, 29 Jun 2021 14:50:21 +0100 Message-ID: <87fsx093vm.mognet@arm.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Cc Patrick's current address On 18/06/21 15:23, 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 task's UCLAMP_MAX; > (2)the p's uc_eff_max < uc_rq_max. > > The result is 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. > > Inserts whether the rq is idle in the uclamp_rq_util_with(). > > Signed-off-by: Xuewen Yan > --- > kernel/sched/sched.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index a189bec13729..0feef6af89f2 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -2550,7 +2550,10 @@ unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util, > > if (p) { > min_util = max(min_util, uclamp_eff_value(p, UCLAMP_MIN)); > - max_util = max(max_util, uclamp_eff_value(p, UCLAMP_MAX)); > + if (rq->uclamp_flags & UCLAMP_FLAG_IDLE) > + max_util = uclamp_eff_value(p, UCLAMP_MAX); > + else > + max_util = max(max_util, uclamp_eff_value(p, UCLAMP_MAX)); That makes sense to me - enqueuing the task will lift UCLAMP_FLAG_IDLE and set the rq clamp as the task's via uclamp_idle_reset(). Does this want a Fixes: 9d20ad7dfc9a ("sched/uclamp: Add uclamp_util_with()") ? Also, when we have UCLAMP_FLAG_IDLE, we don't even need to read the rq max - and I'm pretty sure the same applies to the rq min. What about something like: --- diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 6510f0a46789..a2c6f6ae6392 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2833,23 +2833,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)); + 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) - max_util = uclamp_eff_value(p, UCLAMP_MAX); - else - max_util = max(max_util, uclamp_eff_value(p, UCLAMP_MAX)); + 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