Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1669978ybe; Tue, 3 Sep 2019 01:35:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsTzXgm11qLC/5mhUS3Gi4hQMaiblbvbxfjk+8z8Iv1/sPJMDxR3u3Vdnifa6hfcfC2a+T X-Received: by 2002:a17:902:b18f:: with SMTP id s15mr808230plr.181.1567499717904; Tue, 03 Sep 2019 01:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567499717; cv=none; d=google.com; s=arc-20160816; b=VGyAiojBTOZjgIXEJ8nzniKgAXsNmRpBWnK/llY+f3//O3Ma+hNuhhRW2Wj6T4Lt7R Y375tzxGNmN5Izj1PrK2buWfMgyKFgoMbTKVGFggFEDz+rTHoxrcAwOmB6pOWGMU0NQs 3K++IrUnbQTW9Pt+4HCK68zCQU98y0k8fhufc49i1LldAl0e142pDfj9x7Yc0ISjIcUB kYif9MMUF0rfNqWi+qgnzgFqjxXpyVOpbOMdMVq7AYg0oIrvsQ7G5u0zBiDXw1JespT3 1QIgqxKlQaYXN3TKWsCRSD6P71OLeUgMy1EK8q/WPu7PIzc51HAz4yeP1cBJ5j30TLr6 6d9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=F8i7jqcdFtfZQ6KF6IFuLa/p4SHs6A1iLk2KPNb2ScU=; b=PL01Gr1Ep4CxmTbzLFw5q5i853u9XyI2qzdepOHgmBPb5dKdsP/qdO/KB33sWkzYu9 wn3FDVUyhyeUMJL4469mZz15WQ3YkCofxQGUaRwSjDKumkmQ/7k1VmR0TgF1YWiaqhNm e81fjLLRrdic7Z0aHpRXinQmfNELjcipfmf0FXAAbK7p8xV7i7VsB8vUjR3B0F0FFJtB hmO3BhmRMvNF3fAoyTTgIcRR/V90vMFyoiWx0Bt2JElGw8KzFNCGV06q6VAYJf65r8J4 asMR3LjmFePhJVN4SGk4h6bxCWSz7PsUp0rzoI7P7AXZz9uipVW/vqtZouudULPXrWPu Fvww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c75si3587318pfc.180.2019.09.03.01.35.02; Tue, 03 Sep 2019 01:35:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbfICIbw (ORCPT + 99 others); Tue, 3 Sep 2019 04:31:52 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59206 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728263AbfICIbu (ORCPT ); Tue, 3 Sep 2019 04:31:50 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1i54Dm-0002fV-KI; Tue, 03 Sep 2019 10:31:26 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 196221C0772; Tue, 3 Sep 2019 10:31:26 +0200 (CEST) Date: Tue, 03 Sep 2019 08:31:25 -0000 From: "tip-bot2 for Patrick Bellasi" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/uclamp: Propagate parent clamps Cc: Patrick Bellasi , "Peter Zijlstra (Intel)" , Michal Koutny , Tejun Heo , Alessio Balsini , Dietmar Eggemann , Joel Fernandes , Juri Lelli , Linus Torvalds , Morten Rasmussen , Paul Turner , Quentin Perret , "Rafael J . Wysocki" , Steve Muckle , Suren Baghdasaryan , Thomas Gleixner , Todd Kjos , Vincent Guittot , Viresh Kumar , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20190822132811.31294-3-patrick.bellasi@arm.com> References: <20190822132811.31294-3-patrick.bellasi@arm.com> MIME-Version: 1.0 Message-ID: <156749948592.12881.9832071454008370865.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org 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: 0b60ba2dd342016e4e717dbaa4ca9af3a43f4434 Gitweb: https://git.kernel.org/tip/0b60ba2dd342016e4e717dbaa4ca9af3a43f4434 Author: Patrick Bellasi AuthorDate: Thu, 22 Aug 2019 14:28:07 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Sep 2019 09:17:38 +02:00 sched/uclamp: Propagate parent clamps In order to properly support hierarchical resources control, the cgroup delegation model requires that attribute writes from a child group never fail but still are locally consistent and constrained based on parent's assigned resources. This requires to properly propagate and aggregate parent attributes down to its descendants. Implement this mechanism by adding a new "effective" clamp value for each task group. The effective clamp value is defined as the smaller value between the clamp value of a group and the effective clamp value of its parent. This is the actual clamp value enforced on tasks in a task group. Since it's possible for a cpu.uclamp.min value to be bigger than the cpu.uclamp.max value, ensure local consistency by restricting each "protection" (i.e. min utilization) with the corresponding "limit" (i.e. max utilization). Do that at effective clamps propagation to ensure all user-space write never fails while still always tracking the most restrictive values. Signed-off-by: Patrick Bellasi Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Michal Koutny Acked-by: Tejun Heo Cc: Alessio Balsini Cc: Dietmar Eggemann Cc: Joel Fernandes Cc: Juri Lelli Cc: Linus Torvalds Cc: Morten Rasmussen Cc: Paul Turner Cc: Peter Zijlstra Cc: Quentin Perret Cc: Rafael J . Wysocki Cc: Steve Muckle Cc: Suren Baghdasaryan Cc: Thomas Gleixner Cc: Todd Kjos Cc: Vincent Guittot Cc: Viresh Kumar Link: https://lkml.kernel.org/r/20190822132811.31294-3-patrick.bellasi@arm.com Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 44 +++++++++++++++++++++++++++++++++++++++++++- kernel/sched/sched.h | 2 ++- 2 files changed, 46 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c186abe..8855481 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1166,6 +1166,7 @@ static void __init init_uclamp(void) uclamp_default[clamp_id] = uc_max; #ifdef CONFIG_UCLAMP_TASK_GROUP root_task_group.uclamp_req[clamp_id] = uc_max; + root_task_group.uclamp[clamp_id] = uc_max; #endif } } @@ -6824,6 +6825,7 @@ static inline void alloc_uclamp_sched_group(struct task_group *tg, for_each_clamp_id(clamp_id) { uclamp_se_set(&tg->uclamp_req[clamp_id], uclamp_none(clamp_id), false); + tg->uclamp[clamp_id] = parent->uclamp[clamp_id]; } #endif } @@ -7070,6 +7072,45 @@ static void cpu_cgroup_attach(struct cgroup_taskset *tset) } #ifdef CONFIG_UCLAMP_TASK_GROUP +static void cpu_util_update_eff(struct cgroup_subsys_state *css) +{ + struct cgroup_subsys_state *top_css = css; + struct uclamp_se *uc_parent = NULL; + struct uclamp_se *uc_se = NULL; + unsigned int eff[UCLAMP_CNT]; + unsigned int clamp_id; + unsigned int clamps; + + css_for_each_descendant_pre(css, top_css) { + uc_parent = css_tg(css)->parent + ? css_tg(css)->parent->uclamp : NULL; + + for_each_clamp_id(clamp_id) { + /* Assume effective clamps matches requested clamps */ + eff[clamp_id] = css_tg(css)->uclamp_req[clamp_id].value; + /* Cap effective clamps with parent's effective clamps */ + if (uc_parent && + eff[clamp_id] > uc_parent[clamp_id].value) { + eff[clamp_id] = uc_parent[clamp_id].value; + } + } + /* Ensure protection is always capped by limit */ + eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX]); + + /* Propagate most restrictive effective clamps */ + clamps = 0x0; + uc_se = css_tg(css)->uclamp; + for_each_clamp_id(clamp_id) { + if (eff[clamp_id] == uc_se[clamp_id].value) + continue; + uc_se[clamp_id].value = eff[clamp_id]; + uc_se[clamp_id].bucket_id = uclamp_bucket_id(eff[clamp_id]); + clamps |= (0x1 << clamp_id); + } + if (!clamps) + css = css_rightmost_descendant(css); + } +} /* * Integer 10^N with a given N exponent by casting to integer the literal "1eN" @@ -7138,6 +7179,9 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf, */ tg->uclamp_pct[clamp_id] = req.percent; + /* Update effective clamps to track the most restrictive value */ + cpu_util_update_eff(of_css(of)); + rcu_read_unlock(); mutex_unlock(&uclamp_mutex); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index ae1be61..5b34311 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -397,6 +397,8 @@ struct task_group { unsigned int uclamp_pct[UCLAMP_CNT]; /* Clamp values requested for a task group */ struct uclamp_se uclamp_req[UCLAMP_CNT]; + /* Effective clamp values used for a task group */ + struct uclamp_se uclamp[UCLAMP_CNT]; #endif };