Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp393429pxv; Wed, 30 Jun 2021 08:00:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiHA5P/6XSYk6GcnKaoLTu95yFKRU8q1pBAj3LYFnYqM+pa0G0wrQcXniMrez0TYKxai/U X-Received: by 2002:a17:907:9d1:: with SMTP id bx17mr35748355ejc.322.1625065219906; Wed, 30 Jun 2021 08:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625065219; cv=none; d=google.com; s=arc-20160816; b=uCBN1L5kJkDpxK5cuWMe7W5GKicECjCzgZdbtGcrINlWxSFiD6AEcj5FppyfE/fAfI u4HCU0lFC7dLG4MbtTGvyHdzCF52gUv5A35BJlllqsHPC7xcrUrWChiV6kkynxFLRZIc eIgzsLvumUt8u3uU2EjHmlW6Y/rwS9s3g8gBayUa0a85ZDtpabRhLlswVqTw88dihahv dFHvoIqFgricSH7e4pGluUeVuGIOxT1B8B8S0ggTapoFY3a3xhxFgbzsI3QYi6DJWjgW XWQ6f8ZXyHlB4zDlci21jChTsGfZhgANR8O78yk3jeomPkjri2FJtqA4gZr2oGd9EYTQ 69Ng== 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; bh=XpwfGy9yJuFN7cWt0ppfNwYml9MNAvp5slG3B6fsThQ=; b=0jTlcEo+OwYp013Azu4D2tYzX/aiG77EVFFV9bp83aRZscft/Hi7sIKAh3LE7TSWCE 6VNR/ZhJzhfQYSHXgkRBrPjP+6pOyistVkM4BvDQO0IpzXZWA15y4ahQj05gnmoOlAXl bQhiM29HCUPz+xZbrfxlCj8Kdxj2y3CgO1zPuJz4KLGLfGNbGPxATWh+uXKC121i6AGX JKvSVbYJ9PuhaqZqz4xrZznfIE5mi9eYuX+0mXIZeU+dzBELoFF5jpWJ9c7kEfI3JNYV T/S/EaZ5y+1kzYEeKh0YbbNUsFebIA7WnOx8Trl0jQYafH6tyWCaOYjpHNsfty9ZOewH 9GrQ== 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 zp26si12010368ejb.452.2021.06.30.07.59.53; Wed, 30 Jun 2021 08:00:19 -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 S235428AbhF3PBV (ORCPT + 99 others); Wed, 30 Jun 2021 11:01:21 -0400 Received: from foss.arm.com ([217.140.110.172]:40286 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235177AbhF3PBV (ORCPT ); Wed, 30 Jun 2021 11:01:21 -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 480FB1FB; Wed, 30 Jun 2021 07:58:52 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (unknown [10.1.195.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B37F73F718; Wed, 30 Jun 2021 07:58:50 -0700 (PDT) Date: Wed, 30 Jun 2021 15:58:48 +0100 From: Qais Yousef To: Quentin Perret Cc: mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rickyiu@google.com, wvw@google.com, patrick.bellasi@matbug.net, xuewen.yan94@gmail.com, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 1/3] sched: Fix UCLAMP_FLAG_IDLE setting Message-ID: <20210630145848.htb7pnwsl2gao77x@e107158-lin.cambridge.arm.com> References: <20210623123441.592348-1-qperret@google.com> <20210623123441.592348-2-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210623123441.592348-2-qperret@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Quentin On 06/23/21 12:34, Quentin Perret wrote: > The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last > active task to maintain the last uclamp.max and prevent blocked util > from suddenly becoming visible. > > However, there is an asymmetry in how the flag is set and cleared which > can lead to having the flag set whilst there are active tasks on the rq. > Specifically, the flag is cleared in the uclamp_rq_inc() path, which is > called at enqueue time, but set in uclamp_rq_dec_id() which is called > both when dequeueing a task _and_ in the update_uclamp_active() path. As > a result, when both uclamp_rq_{dec,ind}_id() are called from > update_uclamp_active(), the flag ends up being set but not cleared, > hence leaving the runqueue in a broken state. > > Fix this by clearing the flag in uclamp_idle_reset() which is also > called in both paths to ensure things remain symmetrical. > > Fixes: e496187da710 ("sched/uclamp: Enforce last task's UCLAMP_MAX") > Reported-by: Rick Yiu > Reviewed-by: Qais Yousef > Signed-off-by: Quentin Perret > --- > kernel/sched/core.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 4ca80df205ce..e514a093a0ba 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -980,6 +980,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id, > if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE)) > return; > > + rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; I just realized this needs if (clamp_id == UCLAMP_MAX) rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; The code is only set for UCLAMP_MAX, so should be cleared for UCLAMP_MAX too. Though there's ugly overload here: if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE)) return; This check would fail prematurely if UCLAMP_MAX was reset before UCLAMP_MIN. The code before your change would reset both then do the clear. But now when we do it from here, we need to be more careful about that. Not sure what we can do beside adding a comment. The options I'm thinking about are too intrusive FWIW. Cheers -- Qais Yousef > WRITE_ONCE(rq->uclamp[clamp_id].value, clamp_value); > } > > @@ -1252,10 +1253,6 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p) > > for_each_clamp_id(clamp_id) > uclamp_rq_inc_id(rq, p, clamp_id); > - > - /* Reset clamp idle holding when there is one RUNNABLE task */ > - if (rq->uclamp_flags & UCLAMP_FLAG_IDLE) > - rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; > } > > static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) > -- > 2.32.0.288.g62a8d224e6-goog >