Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3901474pxv; Mon, 19 Jul 2021 11:31:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5l2FlaRAPY4juPX0r98DcemSZwpyr2Hvc77X9IgLhrlrY/O856r/tenYbkaksbMksADrb X-Received: by 2002:a17:907:986e:: with SMTP id ko14mr28562401ejc.219.1626719371796; Mon, 19 Jul 2021 11:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626719371; cv=none; d=google.com; s=arc-20160816; b=c+gQttMBQIO0R0no1LaZE/2hc8efi/BGQn7rxJmnbMsl6B1NW3+nkMUZvqwRvLBk/X n1rCjWFqvpjjI/yMzKPjpuddGC24iiqSqHHSfc3Bfux+y5Az/nP8ESV1GnvnjRXeybxv TbtmsEtt+/3Z7a804/qtS1ILRYrZuf8glDQFELFiQBhZk50BcMWBinmwg7RIUCMmnbqE 40vCHGb+vYMJVE2C1SBBuuFQgzlAWSPI4BXwGcxJH3ItYW5wwxW6kLSwkXktWcGQeoJF OlcSkCIm9O+DrL7jL5Yw3AARgiMwogMHDuy0TnE1vnzrD8ck4tYE+l29RNcFYdjdb9IX t67g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=955jy5r50NSymyY9CjIOhHjhQv83gd51kW+YMawez+s=; b=FLTliJOkihnvh4wrsKNosyJljRtjWDdS7C80PI1Qggbthmpt7DW3bxr0fPGXsblQEY G9k+IDqAhS77FyE5OAdGJYQjttRqbRe+ovTNJAjT0czh7gEOZhLYF8xTs6H4gJculy9r KTgBuF5EhaNAVS3fs3jCollOIfVFoBjHTaX+YCJ3fmkBcKWxuW7lSF/w1weGdzAtr7Hg yOAp268UGwe4nrzyATaBBvSk6T9i610CSvr0cFGViRgYK8B36PT5NaXUaDUqPl5Qf4Hl +1Aik5D627YJFdfipuA4hBbD05LwHeR2Eow2zK6qZRlQ8WnsEg2QQb/OBfCJyc11hpFS LJhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w1P+Fu1E; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si20824355edu.543.2021.07.19.11.29.07; Mon, 19 Jul 2021 11:29:31 -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=@linuxfoundation.org header.s=korg header.b=w1P+Fu1E; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380749AbhGSRgs (ORCPT + 99 others); Mon, 19 Jul 2021 13:36:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350452AbhGSPvE (ORCPT ); Mon, 19 Jul 2021 11:51:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 22D6C6112D; Mon, 19 Jul 2021 16:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626712176; bh=vHpaj8DjY9ZSf0mKh7DBDsXIZprWGE6ESd2A+llvKI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w1P+Fu1Elrk35X1rcHP7a5gk1KVK/3K1vorBh8t4KTHV+D7lXZ7vdBeSyPBrgN9LK qkJVBl1jlUEwG4Czw0eIS2UgNnlqIchwogvApcScrR/Kk0GuV69u7rmUGZuZm5G1Rs 7suCgzEGdwS0rhSFw2REkaaUPc1MA7u7P7ykHjlY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xuewen Yan , "Peter Zijlstra (Intel)" , Valentin Schneider , Qais Yousef , Sasha Levin Subject: [PATCH 5.12 279/292] sched/uclamp: Ignore max aggregation if rq is idle Date: Mon, 19 Jul 2021 16:55:41 +0200 Message-Id: <20210719144952.092878540@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.514164272@linuxfoundation.org> References: <20210719144942.514164272@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xuewen Yan [ Upstream commit 3e1493f46390618ea78607cb30c58fc19e2a5035 ] When a task wakes up on an idle rq, uclamp_rq_util_with() would max aggregate with rq value. But since there is no task enqueued yet, the values are stale based on the last task that was running. When the new task actually wakes up and enqueued, then the rq uclamp values should reflect that of the newly woken up task effective uclamp values. This is a problem particularly for uclamp_max because it default to 1024. If a task p with uclamp_max = 512 wakes up, then max aggregation would ignore the capping that should apply when this task is enqueued, which is wrong. Fix that by ignoring max aggregation if the rq is idle since in that case the effective uclamp value of the rq will be the ones of the task that will wake up. Fixes: 9d20ad7dfc9a ("sched/uclamp: Add uclamp_util_with()") Signed-off-by: Xuewen Yan Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider [qias: Changelog] Reviewed-by: Qais Yousef Link: https://lore.kernel.org/r/20210630141204.8197-1-xuewen.yan94@gmail.com Signed-off-by: Sasha Levin --- 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 e4e4f47cee6a..eee49ce2d596 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2524,20 +2524,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.30.2