Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2621010ybi; Thu, 18 Jul 2019 11:19:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxmpYu96JAaE8cg1sennWugYAV1EOwG1TxCSZV17ott86ebo8yC5cBNTrKQWMVMndu+oBg X-Received: by 2002:a17:902:2f:: with SMTP id 44mr52451057pla.5.1563473982754; Thu, 18 Jul 2019 11:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563473982; cv=none; d=google.com; s=arc-20160816; b=OG1P0ODS/2xneVfJPvUiQhizby20uRXALMVc8VNm8wKINf2jOpX7UhYdUjouZRUe/Y MwnoLvaPs9poLPdpvBa3eBS2gfc1n4xDGPaTsINGxJ0HfvyPiQfeQ/+bCgWMUPhcaPcS MzDu8yJ49KAnqxUd/8R3l0Lrle/KVxUhyyqWpp1nbLl3Y8BR5H2MB4GdsJuiAmbuF84r wAeYDAEgGye5bLP59MdEJ+Pv2/WYA5LKEVryJs6zFQPFFRTVkv8rDQYRSJ+rB7m96mSu 7zZJq9pw3l6mWChgY1ttrc9OjwmaxJtBzGrGXh1tbQmEAvOTLSjCgmpQajL09yzLZu1U nZgw== 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=UtJOR7sI4AUUmROZNBaiyDEN5ihajUMLIWs9uI3oXwU=; b=H6f1iZC42K0qmL5UMdVZ445xB76asJaAYHhV+y+tvhD8w3rIhrSuqFuZ1C6nrrQBj2 eNAtrzPdTytFrrZXnLLP1SAIoykEQKDD9tihUaG4IdV4w3rmm26aspCs1qm2N/SljZHa 9oeVpAD4UkVKS9EDns2JMd+5PN8CGEUVF1oW4FjxYm9eBMKwGq4yV1PxYxLHGbM32677 Y/AeWdTvLi3LhhnVpHlsnVXvxD5eB5AoxAWc5Im8LIE9FdYRzVPtXMbidFnmEwLkTI2s DatDPonpvbCxF8GGAZ/Tlu5C1EJLd5tniTK7E0L8SwEjFNjDcliVdyAXUGThQciDTeZU FLSw== 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 z191si28032716pgd.572.2019.07.18.11.19.27; Thu, 18 Jul 2019 11:19:42 -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 S2391206AbfGRSSb (ORCPT + 99 others); Thu, 18 Jul 2019 14:18:31 -0400 Received: from foss.arm.com ([217.140.110.172]:33476 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391161AbfGRSS2 (ORCPT ); Thu, 18 Jul 2019 14:18:28 -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 77D4A1516; Thu, 18 Jul 2019 11:18:27 -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 C73103F71A; Thu, 18 Jul 2019 11:18:24 -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 v12 5/6] sched/core: uclamp: Update CPU's refcount on TG's clamp changes Date: Thu, 18 Jul 2019 19:17:47 +0100 Message-Id: <20190718181748.28446-6-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718181748.28446-1-patrick.bellasi@arm.com> References: <20190718181748.28446-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 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 Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Tejun Heo --- kernel/sched/core.c | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 426736b2c4d7..26ac1cbec0be 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1043,6 +1043,57 @@ 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) + goto done; + + uclamp_rq_dec_id(rq, p, clamp_id); + uclamp_rq_inc_id(rq, p, clamp_id); + +done: + + 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) @@ -7091,8 +7142,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); } } -- 2.22.0