Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2707921pxv; Sun, 11 Jul 2021 23:22:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFlEhu9wRxC45STekmdsYmSjJSzIGS0QJu6on+pXlgZqX0CBZ9jsKm1um5WcRmjg3nfsru X-Received: by 2002:a92:c504:: with SMTP id r4mr11180566ilg.131.1626070973834; Sun, 11 Jul 2021 23:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070973; cv=none; d=google.com; s=arc-20160816; b=ZRMzySW8KzpEABECA2QaJnuVwchp0UM0irO219B9l6k+61+Qt7v/INm3QNI744jLn3 Uo0FFF6GSbnCTYFSPgGy9JuHrEqaFbELfAaYNfENDsWA2OZDkKX1XAoHH5BzeIjPmqXa BsK3G2u8RAQJqJhWzW33eJV2iFA+cuclDJA0KYjQSllQC/d8Wxhv+fZfGEq9QRZVi6pu Rwd80mALzZwf1PRajAeQHZ9cZSltMcQV62gsI8cPVMw8UkkOg9cXDBqBftmalYW5tN5B UxdMAI1r8gN10J4B36aDV7PpVOWOI0DXgGlotPqo0iaW7rahGiQICF/p8C8dKlg6o7V8 eR3Q== 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=jgEB8LyPPzTNl28hngmLeG0dyk/WCxH/9nFWbCPur1k=; b=iExZNT+pbM5anueNNPAhitVJjqGAK2ihzH3i1Zn3mHUiQwLgSBQJwhaYP9Ecemaa+R 8RAUy8tpBrzbWpqJG9LCNIb75M16C74p24B0EHl/UjkwVZiNZVKeuIY5R0vd+LbrD9Ml JZXHcSOuCp2k7aumbtD6xzk+7wynPR2Uq1mMesBv6ZsixfYF8Heu3Yvde9Vv9+0bORN4 5FdHdOG0JfKKgnk40dmpb0l8LMsS05WLObzr2P4/ya/sCQeYAkndY4uS1lZoMC2Ai86t P0a1IK6eg7ZOxrD7F2juFkraWAeJxk/yepj9N0OmdKF42k6ELLQr0wnvZw/xhq5TD9Tq Kwhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ioblv9G7; 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 y4si15526424iln.36.2021.07.11.23.22.41; Sun, 11 Jul 2021 23:22:53 -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=Ioblv9G7; 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 S235295AbhGLGYo (ORCPT + 99 others); Mon, 12 Jul 2021 02:24:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:39694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234537AbhGLGXY (ORCPT ); Mon, 12 Jul 2021 02:23:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 21CDD6112D; Mon, 12 Jul 2021 06:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070796; bh=j/7tVsymMq9QVi58iXBZ24Din+me3PdZx8eKDcEVJXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ioblv9G7oOvL+RCjaCG3Pnny0qX4qtgc/yFuIOLmib0VyCqXJEXNCZkgRPRdWssp/ Mol2Lp7rnbTp8e0oE82Zn0e2hHWi9j4NQKAqNIqyO2uHnA4wpHYlXMYBk4WDyBeLZA q0XCqGKTsd8cChlmg7hYCsfPK3FP0ZKm65Z1tPb0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qais Yousef , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 144/348] sched/uclamp: Fix wrong implementation of cpu.uclamp.min Date: Mon, 12 Jul 2021 08:08:48 +0200 Message-Id: <20210712060720.215542426@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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: Qais Yousef [ Upstream commit 0c18f2ecfcc274a4bcc1d122f79ebd4001c3b445 ] cpu.uclamp.min is a protection as described in cgroup-v2 Resource Distribution Model Documentation/admin-guide/cgroup-v2.rst which means we try our best to preserve the minimum performance point of tasks in this group. See full description of cpu.uclamp.min in the cgroup-v2.rst. But the current implementation makes it a limit, which is not what was intended. For example: tg->cpu.uclamp.min = 20% p0->uclamp[UCLAMP_MIN] = 0 p1->uclamp[UCLAMP_MIN] = 50% Previous Behavior (limit): p0->effective_uclamp = 0 p1->effective_uclamp = 20% New Behavior (Protection): p0->effective_uclamp = 20% p1->effective_uclamp = 50% Which is inline with how protections should work. With this change the cgroup and per-task behaviors are the same, as expected. Additionally, we remove the confusing relationship between cgroup and !user_defined flag. We don't want for example RT tasks that are boosted by default to max to change their boost value when they attach to a cgroup. If a cgroup wants to limit the max performance point of tasks attached to it, then cpu.uclamp.max must be set accordingly. Or if they want to set different boost value based on cgroup, then sysctl_sched_util_clamp_min_rt_default must be used to NOT boost to max and set the right cpu.uclamp.min for each group to let the RT tasks obtain the desired boost value when attached to that group. As it stands the dependency on !user_defined flag adds an extra layer of complexity that is not required now cpu.uclamp.min behaves properly as a protection. The propagation model of effective cpu.uclamp.min in child cgroups as implemented by cpu_util_update_eff() is still correct. The parent protection sets an upper limit of what the child cgroups will effectively get. Fixes: 3eac870a3247 (sched/uclamp: Use TG's clamps to restrict TASK's clamps) Signed-off-by: Qais Yousef Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210510145032.1934078-2-qais.yousef@arm.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a3e95d7779e1..9a01e51b25f4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -896,7 +896,6 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id) { struct uclamp_se uc_req = p->uclamp_req[clamp_id]; #ifdef CONFIG_UCLAMP_TASK_GROUP - struct uclamp_se uc_max; /* * Tasks in autogroups or root task group will be @@ -907,9 +906,23 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id) if (task_group(p) == &root_task_group) return uc_req; - uc_max = task_group(p)->uclamp[clamp_id]; - if (uc_req.value > uc_max.value || !uc_req.user_defined) - return uc_max; + switch (clamp_id) { + case UCLAMP_MIN: { + struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id]; + if (uc_req.value < uc_min.value) + return uc_min; + break; + } + case UCLAMP_MAX: { + struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id]; + if (uc_req.value > uc_max.value) + return uc_max; + break; + } + default: + WARN_ON_ONCE(1); + break; + } #endif return uc_req; -- 2.30.2