Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1668570ybe; Tue, 3 Sep 2019 01:33:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrgBuetMYyOBdL/DXGEgzVhbC+43uN/cQYXgIDlmtrX8SDIQuRmlDmwm/2ymyOnTDo603U X-Received: by 2002:a63:e62:: with SMTP id 34mr28616821pgo.331.1567499636728; Tue, 03 Sep 2019 01:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567499636; cv=none; d=google.com; s=arc-20160816; b=UClwOkV77a+dV1tZR6eWbDRKGVIhr/EfRdegUylQfTNrIoPCIbfhcwgmx3ujmjQl2J LXDMWUfZbvz9dKbQ7vQsbtRwI8ezgiI7dtzmhX0e7WZbhnp4mwTAASvzpxSWfGiQtQmV +hy47fOjaj7Sp197hi1HddyGEXE7Az65P6Tlfl5Ul0afNeebi8QgSzsZWgPzzGqUcUwB VDDHALsEHHxc6/wq3c+dqx1rPg2Rg7ksg8MFoms316MeqaQD1gWwFgI4BlaD9q+ODuX4 RPJOYwyQCk1IsRXset/KT3neMZtT3EXYJwWyQBQQdKzaeACPJlOIhf8u/DzmBgVivMXO z4Hg== 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=uufdukyJzLYo/0Y0gOkkjdTgVfnkqVOfDukXL0L5IbA=; b=NP+xg+V6uyKiIqIAetWglniuB9mg6Vomvi1dbxhQKDsPOYM06bJGQGhQcmhx8TsvTg kmZkaq5V/2IU71KygWfeLwfDaW3xV8yH3Zqdl1DURI0smD1FzSeoKWtZj+jnV+4R6mkJ EuhXyIExOuWWrIU7rTv0qBWwGzg/CuBkGK2aKSjeHhBL8wolkuOxZpprXMj3usONCst4 Yixd+AQIbO8pQkckeCA4dsAgZyz5/OCSIUEtTE0Jru6E4JW0YX5f3rUHkUFy2v9zMIwu ue7Oeg4LbwjkZbcg+wQC73qCEUqY3TpU4XagMc8+g+awA5x3Ifj/MtJJYqtFVMoi9qrB I9gQ== 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 b6si14206989pge.44.2019.09.03.01.33.41; Tue, 03 Sep 2019 01:33:56 -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 S1728575AbfICIcZ (ORCPT + 99 others); Tue, 3 Sep 2019 04:32:25 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59211 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728320AbfICIbx (ORCPT ); Tue, 3 Sep 2019 04:31:53 -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 1i54Dn-0002gL-Kl; Tue, 03 Sep 2019 10:31:27 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 370651C0772; Tue, 3 Sep 2019 10:31:27 +0200 (CEST) Date: Tue, 03 Sep 2019 08:31:27 -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: Use TG's clamps to restrict TASK's 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-5-patrick.bellasi@arm.com> References: <20190822132811.31294-5-patrick.bellasi@arm.com> MIME-Version: 1.0 Message-ID: <156749948707.12887.5752456843363605543.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: 3eac870a324728e5d17118888840dad70bcd37f3 Gitweb: https://git.kernel.org/tip/3eac870a324728e5d17118888840dad70bcd37f3 Author: Patrick Bellasi AuthorDate: Thu, 22 Aug 2019 14:28:09 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Sep 2019 09:17:39 +02:00 sched/uclamp: Use TG's clamps to restrict TASK's clamps When a task specific clamp value is configured via sched_setattr(2), this value is accounted in the corresponding clamp bucket every time the task is {en,de}qeued. However, when cgroups are also in use, the task specific clamp values could be restricted by the task_group (TG) clamp values. Update uclamp_cpu_inc() to aggregate task and TG clamp values. Every time a task is enqueued, it's accounted in the clamp bucket tracking the smaller clamp between the task specific value and its TG effective value. This allows to: 1. ensure cgroup clamps are always used to restrict task specific requests, i.e. boosted not more than its TG effective protection and capped at least as its TG effective limit. 2. implement a "nice-like" policy, where tasks are still allowed to request less than what enforced by their TG effective limits and protections Do this by exploiting the concept of "effective" clamp, which is already used by a TG to track parent enforced restrictions. Apply task group clamp restrictions only to tasks belonging to a child group. While, for tasks in the root group or in an autogroup, system defaults are still enforced. 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-5-patrick.bellasi@arm.com Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e6800fe..c32ac07 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -873,16 +873,42 @@ unsigned int uclamp_rq_max_value(struct rq *rq, unsigned int clamp_id, return uclamp_idle_value(rq, clamp_id, clamp_value); } +static inline struct uclamp_se +uclamp_tg_restrict(struct task_struct *p, unsigned int 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 + * restricted by system defaults. + */ + if (task_group_is_autogroup(task_group(p))) + return uc_req; + 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; +#endif + + return uc_req; +} + /* * The effective clamp bucket index of a task depends on, by increasing * priority: * - the task specific clamp value, when explicitly requested from userspace + * - the task group effective clamp value, for tasks not either in the root + * group or in an autogroup * - the system default clamp value, defined by the sysadmin */ static inline struct uclamp_se uclamp_eff_get(struct task_struct *p, unsigned int clamp_id) { - struct uclamp_se uc_req = p->uclamp_req[clamp_id]; + struct uclamp_se uc_req = uclamp_tg_restrict(p, clamp_id); struct uclamp_se uc_max = uclamp_default[clamp_id]; /* System default restrictions always apply */