Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp698878pxt; Fri, 6 Aug 2021 11:28:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4CkPoIDuddleNwR+ct8Oipxgf3Gs7gQoof9gfNsLeIutsVNtThxFL3/S4DcEix/We9t6i X-Received: by 2002:a05:6e02:1d95:: with SMTP id h21mr557977ila.23.1628274510311; Fri, 06 Aug 2021 11:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628274510; cv=none; d=google.com; s=arc-20160816; b=ZCBcoHwqZv726+V26EoY2QvYcLnu5K59ltC/SA2cu4h3+bm2dwBThI/9SWzl4CKY7S UT1xMnIkSQkh69OVxTAw9qgZMSyvvueBWyeUlrja/2wwQwuhWPrXxbw+ZUe8wsjxgme1 61lLHFWZQ8NqwbxEnzDggYvFKvQw/BRd+3TBALoe49pPetBVdM5QwrMznuw6wZrc/ciB V1sOTIxb9LobAQ1/nWTSathsHD1rs7aK0grlF3+96iEQR4QyoKq8obbgIsFunTiocQhT OSLDP7SduY9hfYsIosV7c9rh3xP2PLJ3RLqLvwzLLz7HvoI2Hxd6laTUd9OjxhRYpQju /whQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=2idvsD2lqlCRupIROj9rsnljoApBJGnd/H3NSPAFnyY=; b=XYvt83avKPuSJtfcMeC/1yM1YgHtKntePKCamWM06RgDe63n8q8UP06imteYfoLKJE QxHfHArdqa0I37YGzTsXZha/bRfgN3DboAskc7HviHxONCIE3dgTjTWAc4+tLHHFqQFB aEwi5CEwZVqQZeh9h7CmYKqK3OvKOoebwiM3rxcOPn+27mjI1ippBTnX+HiKGVnHb8Gw myQF84pM62+8klp/7oJbco7j3XysjCcoeM+rrwesWM9H8Iq9H0FZ9kg1mKsZZur21knj 3Cnv/lJ7t3qh/lIkPknAC6rKbhPfb5U9r8CPE9RJA6Ch41lN/bNS5BmAbnqd9gQKMJPZ Zn4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1YHshLTX; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si9885104jap.117.2021.08.06.11.28.19; Fri, 06 Aug 2021 11:28:30 -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=@linutronix.de header.s=2020 header.b=1YHshLTX; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343804AbhHFM6J (ORCPT + 99 others); Fri, 6 Aug 2021 08:58:09 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50350 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244018AbhHFM6I (ORCPT ); Fri, 6 Aug 2021 08:58:08 -0400 Date: Fri, 06 Aug 2021 12:57:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628254671; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2idvsD2lqlCRupIROj9rsnljoApBJGnd/H3NSPAFnyY=; b=1YHshLTX4J51sxEN2rNj9pu22nUt4onxVbkRgC0XM3TdzWxY/oTmN23tjvLR+TBu9HKydt Smh7lOXE0LmlPx+lGFPHD+h3sn3Foa+ZndE6SU0lZycJDygDzA1Ds5Q3oeAByekY28Mr8G hHq3codqXySYuAw0HLo/o3KbJROWBYAp17ewDbgvuEfBkZV4akpGK0ujUIkdE9Fj4/t8bX GRQ0/0Ot3RMDtJZ6DZDMCgbx2WGAU8JxtYej+qjrMhCWUhoqM/gUgJ/UXyBXo+sxl8Xh0I URzVzMYVaKnR0kUcXuybbYkiywO1hjqR1k2g+bqk0PYhOy3jjsgZz4R4X7jBvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628254671; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2idvsD2lqlCRupIROj9rsnljoApBJGnd/H3NSPAFnyY=; b=pxCyk1xvh2K9uO5Sr24QY134hqBCmsT+U8iwncGXXD8uTJAerqWESQBGXxEoIIjv/vhIFl TXh/TydOno+fbbBQ== From: "tip-bot2 for Quentin Perret" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: Fix UCLAMP_FLAG_IDLE setting Cc: Rick Yiu , Quentin Perret , "Peter Zijlstra (Intel)" , Qais Yousef , Dietmar Eggemann , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210805102154.590709-2-qperret@google.com> References: <20210805102154.590709-2-qperret@google.com> MIME-Version: 1.0 Message-ID: <162825467066.395.3955621672709689514.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: ca4984a7dd863f3e1c0df775ae3e744bff24c303 Gitweb: https://git.kernel.org/tip/ca4984a7dd863f3e1c0df775ae3e744bff24c303 Author: Quentin Perret AuthorDate: Thu, 05 Aug 2021 11:21:53 +01:00 Committer: Peter Zijlstra CommitterDate: Fri, 06 Aug 2021 14:25:25 +02:00 sched: Fix UCLAMP_FLAG_IDLE setting The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last uclamp active task (that is, when buckets.tasks reaches 0 for all buckets) 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 update_uclamp_active() as well. Fixes: e496187da710 ("sched/uclamp: Enforce last task's UCLAMP_MAX") Reported-by: Rick Yiu Signed-off-by: Quentin Perret Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Qais Yousef Tested-by: Dietmar Eggemann Link: https://lore.kernel.org/r/20210805102154.590709-2-qperret@google.com --- kernel/sched/core.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 314f70d..df0480a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1621,6 +1621,23 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) uclamp_rq_dec_id(rq, p, clamp_id); } +static inline void uclamp_rq_reinc_id(struct rq *rq, struct task_struct *p, + enum uclamp_id clamp_id) +{ + if (!p->uclamp[clamp_id].active) + return; + + uclamp_rq_dec_id(rq, p, clamp_id); + uclamp_rq_inc_id(rq, p, clamp_id); + + /* + * Make sure to clear the idle flag if we've transiently reached 0 + * active tasks on rq. + */ + if (clamp_id == UCLAMP_MAX && (rq->uclamp_flags & UCLAMP_FLAG_IDLE)) + rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; +} + static inline void uclamp_update_active(struct task_struct *p) { @@ -1644,12 +1661,8 @@ uclamp_update_active(struct task_struct *p) * affecting a valid clamp bucket, the next time it's enqueued, * it will already see the updated clamp bucket value. */ - for_each_clamp_id(clamp_id) { - if (p->uclamp[clamp_id].active) { - uclamp_rq_dec_id(rq, p, clamp_id); - uclamp_rq_inc_id(rq, p, clamp_id); - } - } + for_each_clamp_id(clamp_id) + uclamp_rq_reinc_id(rq, p, clamp_id); task_rq_unlock(rq, p, &rf); }