Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp366673yba; Wed, 15 May 2019 02:49:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOYvsQTi45XbW84Rr6WbrF+xZ5FqYRvXN1Pz+CxOxZ+FZLlPcxKyqJe+mLUkHPiisUTCcA X-Received: by 2002:a17:902:7783:: with SMTP id o3mr6247442pll.21.1557913758259; Wed, 15 May 2019 02:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557913758; cv=none; d=google.com; s=arc-20160816; b=0YRMviEH4Ua+EyyehWBwFDkHkfADaZDU7JiUnLwbmZg0PpZi5ho0uNXgoehP67xmME bGeA0iYMDjVVy90qHSBm4+48/5uoxVZZkG8wG5HYSJS8Ok155w/DUdk9WSwZzq0zNITa VH3mK5wHyjUgBYvaQ2EJ/l18r2pW45+gK6wNGoCiolm/kqXVeF2CVnxhe5nsp80TtwyD KSCycQgqZYo8FFKY1f0RXBv0u0giXgNyVTIeBkSH9HerW7kbPKemaF/Ap/YLn8JsH+zs ROjENhXbCtpTOCPkolGoKXTzUQBQAI5p7r6BF3WgaWjjvE3gFUsR41CrMsAM3mW13qLu zUxA== 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=ZIM11AdbDx2suAetS0+DTYrXzF+1jYWyStgVz3IdKYM=; b=RZmeJrsTUpGBiQb5gzIdLGIhfRw4kJnkA7gr5ySgV36iJHQZZT+/K4qDk95a8oqLpq r4Y5YA7x9BEsHDDeK3+7EE3IEz16A3bVW85SGuObtSbETBoxz2HSZDts+ntTkS4OUS95 Zo1hFcMXwsIvM0TfIYpXzGfOHjpRbG9QnpME3UtzdJvBrIPTH1/IeSI4tvt+RvA0ufMd cCANjmAn9Jwlf1kylq29kpiFLDRiT1+oBYMDMOBjUriO9tG6FJoehmrnF/Tpo87TsK8/ JgKJwGgiZ1n79f6Gsw9mi6Ar2tEZ2KKcc8+T/JW6C7TOfXOJhLnu7rFeYhZLp9/2ey/2 MLdg== 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 u5si1349944plr.312.2019.05.15.02.49.03; Wed, 15 May 2019 02:49:18 -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 S1726281AbfEOJq1 (ORCPT + 99 others); Wed, 15 May 2019 05:46:27 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39496 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726856AbfEOJqZ (ORCPT ); Wed, 15 May 2019 05:46:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A67580D; Wed, 15 May 2019 02:46:25 -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 629CA3F703; Wed, 15 May 2019 02:46:22 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: [PATCH v9 16/16] sched/core: uclamp: Update CPU's refcount on TG's clamp changes Date: Wed, 15 May 2019 10:44:59 +0100 Message-Id: <20190515094459.10317-17-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515094459.10317-1-patrick.bellasi@arm.com> References: <20190515094459.10317-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 clamped as requested. Do that by slightly refactoring uclamp_bucket_inc(). An additional parameter *cgroup_subsys_state (css) is used to walk the list of tasks in the TGs and update the RUNNABLE ones. Do that by taking the rq lock for each task, the same mechanism used for cpu affinity masks updates. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Tejun Heo --- kernel/sched/core.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 354d925a6ba8..0c078d586f36 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1031,6 +1031,51 @@ 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, int clamp_id) +{ + struct css_task_iter it; + struct task_struct *p; + + css_task_iter_start(css, 0, &it); + while ((p = css_task_iter_next(&it))) + 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, unsigned int clamp_id); @@ -7044,6 +7089,9 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css, uc_se->value = value; uc_se->bucket_id = uclamp_bucket_id(value); + + /* Immediately update descendants RUNNABLE tasks */ + uclamp_update_active_tasks(css, clamp_id); } } -- 2.21.0