Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1667788ybe; Tue, 3 Sep 2019 01:33:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGC6S/subFiAFZlj3/UQazJ3QaUOu1GgeS8XbcLAWO1N8SHQHJv6/X7vL1UIbl+otr7Xzd X-Received: by 2002:aa7:9309:: with SMTP id 9mr11727353pfj.37.1567499595327; Tue, 03 Sep 2019 01:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567499595; cv=none; d=google.com; s=arc-20160816; b=XGC4kb1lQX88mxGz+cG3pbuo0tTrskBR08M1880SgagYrnHguA2F9hkK2U4KoI7uRA rLNi1Dx3UQ4Q9vo91+FHQxppfb973+I7mRIiOGBn73prZ8oGRH2yNvc98Bq0rOtAfbfS ZeDOxLUGqKDJmDKjLHuI8KxCL4Glz/CCuoVMjqeQgffdZ+XLc8b5Mzvc1bvQOLjjiedQ SalqjICEmv+rVMnGegUK/lszube323a34Eis3ZfQeyjfRVRi7HhbViHZB/Vwd+Br9khJ LpLy7fc8khCQ/iNch4hd16/UG43nptZI47GdTf1E+pQOTSBczePRuOjSfd9q/bwTTLXK DgCw== 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=4bplXwc7DPt+xSk/7YZpvQJqA1nBnVNF3YzsbuFo734=; b=Eygdfhj0bT9hOvaAsnqtCVeAuKYrhAsmkAIE+pMfo68e60wsy6NCwmszNKMWrkAuW7 +hQcGr94SS2/3e1k+joFUqOgSgVb//m1yylB3InyZLh5rzR+Qy58yifaVi/kQcgKKTHg qQANieRJ67WKX7CnE1kcKO0dM9gd9ESbplqV5jAJ2yw/U3tQP0f4VfPTJH2wOgyUfzeh otLUgLzZe6jyIvN0ywkW1jTGATuvSBl5/TUpOFoqko8DNC5BlP2LX9vgWamIpxyYoIuQ 8rkBrDaVGJi7GjSi8Ehk4nf/a2C1mpBqOdhRi7rNZwyo3SKD2tpE8eNJP+LWn5CT+A32 lqNg== 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 c10si6512097pjn.38.2019.09.03.01.32.59; Tue, 03 Sep 2019 01:33:15 -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 S1728346AbfICIby (ORCPT + 99 others); Tue, 3 Sep 2019 04:31:54 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:59207 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728285AbfICIbt (ORCPT ); Tue, 3 Sep 2019 04:31:49 -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 1i54Do-0002iq-At; Tue, 03 Sep 2019 10:31:28 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id D04A91C0DDE; 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: Update CPU's refcount on TG's clamp changes 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-6-patrick.bellasi@arm.com> References: <20190822132811.31294-6-patrick.bellasi@arm.com> MIME-Version: 1.0 Message-ID: <156749948767.12894.5150732137197774157.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: babbe170e053c6ec2343751749995b7b9fd5fd2c Gitweb: https://git.kernel.org/tip/babbe170e053c6ec2343751749995b7b9fd5fd2c Author: Patrick Bellasi AuthorDate: Thu, 22 Aug 2019 14:28:10 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Sep 2019 09:17:40 +02:00 sched/uclamp: Update CPU's refcount on TG's clamp changes On updates of task group (TG) clamp values, ensure that these new values are enforced on all RUNNABLE tasks of the task group, i.e. all RUNNABLE tasks are immediately boosted and/or capped as requested. Do that each time we update effective clamps from cpu_util_update_eff(). Use the *cgroup_subsys_state (css) to walk the list of tasks in each affected TG and update their RUNNABLE tasks. Update each task by using the same mechanism used for cpu affinity masks updates, i.e. by taking the rq lock. 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-6-patrick.bellasi@arm.com Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c32ac07..55a1c07 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1043,6 +1043,54 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) uclamp_rq_dec_id(rq, p, clamp_id); } +static inline void +uclamp_update_active(struct task_struct *p, unsigned int clamp_id) +{ + struct rq_flags rf; + struct rq *rq; + + /* + * Lock the task and the rq where the task is (or was) queued. + * + * We might lock the (previous) rq of a !RUNNABLE task, but that's the + * price to pay to safely serialize util_{min,max} updates with + * enqueues, dequeues and migration operations. + * This is the same locking schema used by __set_cpus_allowed_ptr(). + */ + rq = task_rq_lock(p, &rf); + + /* + * Setting the clamp bucket is serialized by task_rq_lock(). + * If the task is not yet RUNNABLE and its task_struct is not + * affecting a valid clamp bucket, the next time it's enqueued, + * it will already see the updated clamp bucket value. + */ + if (!p->uclamp[clamp_id].active) { + uclamp_rq_dec_id(rq, p, clamp_id); + uclamp_rq_inc_id(rq, p, clamp_id); + } + + task_rq_unlock(rq, p, &rf); +} + +static inline void +uclamp_update_active_tasks(struct cgroup_subsys_state *css, + unsigned int clamps) +{ + struct css_task_iter it; + struct task_struct *p; + unsigned int clamp_id; + + css_task_iter_start(css, 0, &it); + while ((p = css_task_iter_next(&it))) { + for_each_clamp_id(clamp_id) { + if ((0x1 << clamp_id) & clamps) + uclamp_update_active(p, clamp_id); + } + } + css_task_iter_end(&it); +} + #ifdef CONFIG_UCLAMP_TASK_GROUP static void cpu_util_update_eff(struct cgroup_subsys_state *css); static void uclamp_update_root_tg(void) @@ -7160,8 +7208,13 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css) uc_se[clamp_id].bucket_id = uclamp_bucket_id(eff[clamp_id]); clamps |= (0x1 << clamp_id); } - if (!clamps) + if (!clamps) { css = css_rightmost_descendant(css); + continue; + } + + /* Immediately update descendants RUNNABLE tasks */ + uclamp_update_active_tasks(css, clamps); } }