Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4025286pxj; Tue, 8 Jun 2021 04:50:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoFn7ni+xkPUYcjSt+QyE2B6Apt51sAuZwoRlkuyedSxOaJpqpNGP3YWCKbElKZ85NWFKu X-Received: by 2002:a17:906:ca4c:: with SMTP id jx12mr23166684ejb.155.1623153035988; Tue, 08 Jun 2021 04:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623153035; cv=none; d=google.com; s=arc-20160816; b=If+XXvRocCLPOBTL44KjzBeDnDqz6hvR/t1OrztfbbcknLCZtduerw5TFq6KVVYkbR DtxFINy2U3RBJfiLSMEvDpjWnzluc7ubHJAQsNzCQqQmkVmYrDqhwqukGQifYZnbBjrU fqGfmOgzysWC6FWzasdqLuuBwvpWhBqUVbqtJHBtYXwgsggVZ2CBXOSq4tX+PL5oemTx VEa6Cc9HploOhmQ4ZZ4yaSll/ialxNBO4GGHiKpi9IuOPjC37NquJylLebYeCIy9qIui 6XkePiuaitNTuhU/QOo7YPmwM3DxiPnhLjUgkEpaZn12JphF5wt+ShA8e6tSe/haoMlH e/xw== 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=lSpJR4JGaHgDiWzGIah7bTjYhAXYw8Q1sE4YSNVI0i4=; b=QQOioMDNzKjHz/ESJ8IjiRb4YRTqjbHFwq9P5+PfL3GJttYiz32NM5T2v3HfWDILSa MqfZp7wkIGQZGp8JWkxeuxUKGXjEGeuWVV3kQNEuFjXdJ1SdyYoPP0lb3bToGUtYvsTl NqY6YWBsnfvwEHlbcHlG6D4O7Ly+i4OARmJgW6lyKbygIIWgjDVFg2Rf6BJB4ikLKaq+ C8tN5D7Z820pLh6QjdLbv+k9M3aD/jh1B3uxkW5NSyHENQF44BfZXwgeR/6fHxX/MhWt oZy8tWFTnSBJhsqqFmbiV8UebtUv8J1SVnb4eBfMuNUwz73aOPK6/3TfJOwS1Y/QhgEK w4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=COvYHpq+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j20si10823972edp.274.2021.06.08.04.50.12; Tue, 08 Jun 2021 04:50:35 -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=@gmail.com header.s=20161025 header.b=COvYHpq+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232059AbhFHLti (ORCPT + 99 others); Tue, 8 Jun 2021 07:49:38 -0400 Received: from mail-lj1-f179.google.com ([209.85.208.179]:37751 "EHLO mail-lj1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbhFHLti (ORCPT ); Tue, 8 Jun 2021 07:49:38 -0400 Received: by mail-lj1-f179.google.com with SMTP id e2so26610508ljk.4 for ; Tue, 08 Jun 2021 04:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lSpJR4JGaHgDiWzGIah7bTjYhAXYw8Q1sE4YSNVI0i4=; b=COvYHpq+JVYGRzoy39ufIMUDfL75CBgXUZYk8XAKcGrpy16GXOlcUhTqkN2HT+oUSH ZFAaKfhcpyU3fgow/qYTC/O6oGaVjsQ9zfpUhSO0yv0hc9RTOJyPZ3YBTj0QL5JKdEQn iOCdwJ61YmmjKfMdiQBgvycVPZhgpY2d4oERw0CbgYnmNtWHKti7v9+yWs9v0cUEEmDI WD45PoL4d80hJWTcebGcKRFVX7wxkEt6nlmAwoPAlTB312F2FUOvMINrQdyfe8vmKKdj tKssusa6KbMH6Jv73zBZ3nETh06Z3EtjheJ9aO9MW6O7uABEIyEV3sTGPuTzTgO7S57I ez9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=lSpJR4JGaHgDiWzGIah7bTjYhAXYw8Q1sE4YSNVI0i4=; b=eO1/EpwlLmGZC+flwkKPmzdY5+ZzYRC4URLTGZQOtxsdVGKRAXbTYhGpzSoUafZOAi mrQ74KPGhlTF7Lt+kKeWVO6xaWORJQU/iRc1HxrPB6TmjGZfYctlWEg+EpmJllLotkHW cUP4BTlIEsBQLDuneMN9Ob/yi8TXN7WriIzr6rOHckoRXWKlc+Z2Jf6d6XhSxwW+pf5b q13s1RrjD5fg3AhZqfxwLfkspa9ec+eypxcSEi9TjHMjXZ+uYaecyS+TVXvSK5U6FZGs fWOugpRtKTGA3Lxm/Vp2xXbqDCbf7EupEfKmY8JBUYd7f18MgYAvCDWcFrJPUFTJa4XJ xOBQ== X-Gm-Message-State: AOAM531K9Dx9DvyiwvwLtmi3soSzeTjj4+xCd5V9g+umazRbDOSAusPy swWJM6KlsIZBbhxH37KCbEs5gMG/zjc/mglfbSg= X-Received: by 2002:a2e:700f:: with SMTP id l15mr18148985ljc.52.1623152796007; Tue, 08 Jun 2021 04:46:36 -0700 (PDT) MIME-Version: 1.0 References: <20210602123803.15738-1-xuewen.yan94@gmail.com> <20210604160839.2op4ak75vle3gmt3@e107158-lin.cambridge.arm.com> <20210605114908.mqfsip5pskamls6k@e107158-lin.cambridge.arm.com> <20210607134902.nlgvqtzj35rhjg7x@e107158-lin.cambridge.arm.com> In-Reply-To: <20210607134902.nlgvqtzj35rhjg7x@e107158-lin.cambridge.arm.com> From: Xuewen Yan Date: Tue, 8 Jun 2021 19:45:32 +0800 Message-ID: Subject: Re: [PATCH] sched/uclamp: Avoid setting cpu.uclamp.min bigger than cpu.uclamp.max To: Qais Yousef Cc: Quentin Perret , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , linux-kernel , Chunyan Zhang , Ryan Y , Patrick Bellasi , tj@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org First of all, sorry for the late reply.. On Mon, Jun 7, 2021 at 9:49 PM Qais Yousef wrote: > > On 06/05/21 21:24, Xuewen Yan wrote: > > Hi Qais > > > > On Sat, Jun 5, 2021 at 7:49 PM Qais Yousef wrote: > > > > > > > > > In addition=EF=BC=8CIn your patch: > > > > 6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclam= p.min") > > > > https://lkml.kernel.org/r/20210510145032.1934078-2-qais.yousef@arm.= com > > > > > > > > + switch (clamp_id) { > > > > + case UCLAMP_MIN: { > > > > + struct uclamp_se uc_min =3D task_group(p)->uclamp[clamp_id]; > > > > + if (uc_req.value < uc_min.value) > > > > + return uc_min; > > > > + break; > > > > > > > > When the clamp_id =3D UCLAMP_MIN, why not judge the uc_req.value is > > > > bigger than task_group(p)->uclamp[UCLAMP_MAX] ? > > > > > > Because of the requirement I pointed you to in cgroup-v2.rst. We must= allow any > > > value to be requested. > > > > > > Ultimately if we had > > > > > > cpu.uclamp.min =3D 80 > > > cpu.uclamp.max =3D 50 > > > > > > then we want to remember the original request but make sure the effec= tive value > > > is capped. > > > > > > For the user in the future modifies the values such that > > > > > > cpu.uclamp.max =3D max > > > > > > Then we want to remember cpu.uclamp.min =3D 80 and apply it since now= the > > > cpu.uclamp.max was relaxed to allow the boost value. > > > > > > > Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp= [UCLAMP_MAX], > > > > the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into > > > > [ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_= MAX] ]. > > > > > > > > Is it necessary to fix it here=EF=BC=9F > > > > > > Nope. We must allow any combination values to be accepted and remembe= r them so > > > if one changes we ensure the new effective value is updated according= ly. > > > This is how cgroups API works. > > > > Sorry. I may not have expressed it clearly. In your patch (which has > > not yet merged into the mainline): > > > > 6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.mi= n") > > https://lkml.kernel.org/r/20210510145032.1934078-2-qais.yousef@arm.com > > > > This patch will not affect p->uclamp_req, but consider the following si= tuation: > > > > tg->cpu.uclamp.min =3D 0 > > tg->cpu.uclamp.max =3D 50% > > > > p->uclamp_req[UCLAMP_MIN] =3D 60% > > p->uclamp_req[UCLAMP_MIN] =3D 80% sorry, here should be p->uclamp_req[UCLAMP_MIN] =3D 60% p->uclamp_req[UCLAMP_MAX] =3D 80% > > > > The function call process is as follows=EF=BC=9A > > uclamp_eff_value() -> uclamp_eff_get() ->uclamp_tg_restrict() > > > > with your patch, the result is: > > > > p->effective_uclamp_min =3D 60% > > p->effective_uclamp_max =3D 50% > > > > It would not affect the uclamp_task_util(p), but affect the rq: > > when p enqueued: > > rq->uclamp[UCLAMP_MIN] =3D 60% > > rq->uclamp[UCLAMP_MIN] =3D 50% sorry, here should be rq->uclamp[UCLAMP_MIN] =3D 60% rq->uclamp[UCLAMP_MAX] =3D 50% > > > > futher more, in uclamp_rq_util_with() { > > ... > > > > min_util =3D READ_ONCE(rq->uclamp[UCLAMP_MIN].value); //60% > > max_util =3D READ_ONCE(rq->uclamp[UCLAMP_MAX].value);//50% > > ... > > if (unlikely(min_util >=3D max_util)) > > return min_util; > > > > return clamp(util, min_util, max_util); > > ... > > } > > as a result, it would return 60%. > > Looking at this again now, I better understand what you were trying to sa= y. > I got confused that you were still arguing about cgroup inverted > cpu.uclamp.min/max, but you're actually talking about something else. Generally speaking, this kind of situation does not basically exist, but I just consider all the situations that can occur when users use it. > > It would be a lot easier to not cross talk threads and reply to my patch > directly with this remark. Sorry for the trouble because of my unfamiliar with the maillist, I will pay attention next time :=EF=BC=89 > > Anyways, still well spotted! > > What you're saying is we need something like the patch below to ensure th= at the > *task request* is within tg uclamp range, right? The worry is that the ta= sk's > uclamp_min is higher than the tg's uclamp_min, so we end up with the inve= rsion > because of that which will not be corrected later. Yeah, the task's uclamp_min is higher than the tg's uclamp_max. > > Hmm I need to think a bit more about this.. > > Cheers > > -- > Qais Yousef > > --->8--- > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 9e9a5be35cde..e867813b9d5e 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1405,6 +1405,7 @@ uclamp_tg_restrict(struct task_struct *p, enum ucla= mp_id clamp_id) > { > struct uclamp_se uc_req =3D p->uclamp_req[clamp_id]; > #ifdef CONFIG_UCLAMP_TASK_GROUP > + unsigned long uc_min, uc_max, val; > > /* > * Tasks in autogroups or root task group will be > @@ -1415,23 +1416,10 @@ uclamp_tg_restrict(struct task_struct *p, enum uc= lamp_id clamp_id) > if (task_group(p) =3D=3D &root_task_group) > return uc_req; > > - switch (clamp_id) { > - case UCLAMP_MIN: { > - struct uclamp_se uc_min =3D task_group(p)->uclamp[clamp_i= d]; > - if (uc_req.value < uc_min.value) > - return uc_min; > - break; > - } > - case UCLAMP_MAX: { > - struct uclamp_se uc_max =3D task_group(p)->uclamp[clamp_i= d]; > - if (uc_req.value > uc_max.value) > - return uc_max; > - break; > - } > - default: > - WARN_ON_ONCE(1); > - break; > - } > + uc_min =3D task_group(p)->uclamp[UCLAMP_MIN].value; > + uc_max =3D task_group(p)->uclamp[UCLAMP_MAX].value; > + val =3D uc_req.value; > + uc_req.value =3D clamp(val, uc_min, uc_max); This is not a good solution, because it just clamp the uc_req.value, but the uc_req.bucket_id is not changed. > #endif > > return uc_req; > Thanks! xuewen