Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1262352ybl; Thu, 22 Aug 2019 11:46:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1WrKqVMKVFe/k6J5yfCh+mivU1TFhduALDxg+Yb6DhSdXWFgK+cy/hBzEYLdolFPpDEr6 X-Received: by 2002:a17:902:a70c:: with SMTP id w12mr276127plq.288.1566499619881; Thu, 22 Aug 2019 11:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566499619; cv=none; d=google.com; s=arc-20160816; b=QEaSeRFTQz8bf8CUgqoIKJb0UzEmonIUWck9saUavlKDcflne1kxfbdzWST77BXSNb BQtsOc85XI2kXqfPtuXo/jysSywNm+L7fZC/TiAp2foeJMDwdSq+YdCixqkRm2SrWcVI kqFp8GCzo7dwB2uEgwYjycOciNyGyJskqlAp2EP8wxjQBHOfTVZ8XZD/RNtGT7/GjuVf 9vxJRgUq7o0+v1KdMKZQalPxmfLNcFoJy+I4ros5AW36SNljcn6e88fcvU+YHLQ9XJL4 G3c/Qvp+i0Dxcu8eDzD/4vfbU6SAqpdcVCgzlDRH41yRsBKvcapLqYjR/dmBgufh7mNV UL1Q== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=d5ogHXvlCZD3fInVJdIZFYeE2wieVfBCfsyzr+xtkns=; b=wyUQ5Q6D7Sa33DcPJR3LdWNIL8WpKw0DPw6HLLqYa5RBvLDjOMWltIFXllIdgxaizM FOTujTEqluoBY4tzR9/EFys05TU+PNV6cOKtPkos0HPJBgstXc3d2gFCBvuLdqhTbDtP r7bOduGvr5m+FQlEN77VKdthtfhu5+1GZrbprv3Jm0FNDlEtmvyAZFY8mZ1DGREC4SSa jpk0Jc77uLvHDk+yMNHh2zU1Tu/R4X70KKxO/O5+Z9kpeHdtRS6r1/Zz8yvMMgaAPHiS M0YC3LQg9i/4fBbX169TZ9Oi4kllYWTWb5n/O+8k3qKkTSzdAIBnTPs2+7jcmfuOOwfH tQkw== 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 t189si84665pgt.428.2019.08.22.11.46.44; Thu, 22 Aug 2019 11:46:59 -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 S2389080AbfHVN2i (ORCPT + 99 others); Thu, 22 Aug 2019 09:28:38 -0400 Received: from foss.arm.com ([217.140.110.172]:45820 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730723AbfHVN2a (ORCPT ); Thu, 22 Aug 2019 09:28:30 -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 BE87715A2; Thu, 22 Aug 2019 06:28:29 -0700 (PDT) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0FF973F706; Thu, 22 Aug 2019 06:28:26 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, cgroups@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Michal Koutny , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan , Alessio Balsini Subject: [PATCH v14 2/6] sched/core: uclamp: Propagate parent clamps Date: Thu, 22 Aug 2019 14:28:07 +0100 Message-Id: <20190822132811.31294-3-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190822132811.31294-1-patrick.bellasi@arm.com> References: <20190822132811.31294-1-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Michal Koutny Acked-by: Tejun Heo Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Tejun Heo --- 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 7b610e1a4cda..8dab64247597 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); + } +} #define _POW10(exp) ((unsigned int)1e##exp) #define POW10(exp) _POW10(exp) @@ -7133,6 +7174,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 ae1be61fb279..5b343112a47b 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 }; -- 2.22.0