From patchwork Thu Feb 1 16:51:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126555 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1877994ljc; Thu, 1 Feb 2018 08:51:22 -0800 (PST) X-Google-Smtp-Source: AH8x227R9Y+u+3VdE0mM5LHU8pQS9mCizz7Z1LIIjjaRWUvYuULaEwSUXE/Z7Ai4GVgs20fjBlLJ X-Received: by 2002:a17:902:69c5:: with SMTP id m5-v6mr31814060pln.347.1517503881981; Thu, 01 Feb 2018 08:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503881; cv=none; d=google.com; s=arc-20160816; b=zzDCH/Q8P8zrlxp2G86b/ULHqzyoOJICgp9iDckRP/i69fOIBfKlOEZH/JOhEwqQxg asWC74Ufhzq9JdXizgqNxtlDkqCdmKFs4m/ftdudJ8q9UcNHatODHkUXUJJgeOQITH96 u9pVdNGI/d1vJLl/XuVv6hASU7NenGP9IztNM2XaaflGlPFtlVWt0SkW3UeDZj/nButh O51VvjPm63aJstpHaym5jySrsdTijrR9uOlsUAWtzPQyPm6qe4amBARNVsAj83SIiLqr mrhNboJdIqcSdl6jjKF9WkkFeADE7eniljKiWwdVT2yf9xoWSfeQSRRGQNzJcMWD6ilc BusQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=mYYC+yffuETXI7b8rW2UZcOnw5oDCib6paviSuYzsC4=; b=ZiupwrSzacQtJCaVFK5eUd/9yXxh+FwfPWg880KtSvTcG07oYm95+czQ6RNaX04Nzz zLlzCnxdkzGZLj+WGwJT+vz3s79pvQdAmGlHNwS/Val9GMUIfl8FVjejbV2WRUpL5QnY Hc1aVNg3Cml1+WzKzhVNnhrRUnuevLrD6DZArA1p6uz8Pbtt3ktaQd38zRk4MZ/1chaP OzcAE0l/nKHi7IzWAS7oz3raGAWN7fS8rFOXF+eG3JAREnUFY6fGkDoO5G5kP2Nm3irE EhmT931zrozimCMs+hyR+3tur4OSuk2qfc6vespKZcmGsPU/JD78/bf5aSJXt4Hfz72J ylwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gfP6dVVn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 95-v6si4565934ple.831.2018.02.01.08.51.21; Thu, 01 Feb 2018 08:51:21 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=gfP6dVVn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752788AbeBAQvU (ORCPT + 28 others); Thu, 1 Feb 2018 11:51:20 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:44191 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752696AbeBAQvO (ORCPT ); Thu, 1 Feb 2018 11:51:14 -0500 Received: by mail-io0-f194.google.com with SMTP id z6so19872731iob.11 for ; Thu, 01 Feb 2018 08:51:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mYYC+yffuETXI7b8rW2UZcOnw5oDCib6paviSuYzsC4=; b=gfP6dVVnmRrzPl50T/G+U9WxBE7nd7NAzH6GLsBhjPvfcFTBFgszkviYBNUknk/cml 2nanXHEs+Hcak1hThzs/uRcCqljQi1SnukNMrrmi39ScVqsBDpNyT2TdqfnpCmRa8N1A hGpD6hvwMPdvqxQUZuIpAZduS7OQHb+NcRs68= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mYYC+yffuETXI7b8rW2UZcOnw5oDCib6paviSuYzsC4=; b=WTZN05WpF0LpbS46a1e6X25pZ+sjpSU4xgCk6rhQ5I317lgahJIb2JyZhR1y3Gki8m XP3mZuJxMm2XHbCklcJjwfwzl2Gdp3vGrAlmqmuA5glGS58kN4nXoFI4IElZDpU0M/iP YCRnp1xDLKRj9ybK+l0XK6N0529dUKm1DscCeKE9cWVeleNiNCNp63kPOzBZarGaEFT7 4jbrsUewr6wQTdzPethiGJg+Cy/P3+7YuWOq7ap/ig2qFnJ+W+verBkuY8ELxN0D0YQj pgozaLVhjKMpoQvofb/qWUXjsC3WutfjZ80NCwGvK/k7QrKHorrflXQOo5NzuJGyB/kc WnZg== X-Gm-Message-State: AKwxytdRTXz5YiCgb2OT2adYSNtvS/CtoAUuwW/n1rxvAP3x3t5xIMEA jFxbtwUyxopJw1wUIpsfRyENOQ== X-Received: by 10.107.168.25 with SMTP id r25mr38123189ioe.16.1517503873918; Thu, 01 Feb 2018 08:51:13 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:13 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/7] sched/topology: Adding function partition_sched_domains_locked() Date: Thu, 1 Feb 2018 09:51:03 -0700 Message-Id: <1517503869-3179-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introducing function partition_sched_domains_locked() by taking the mutex locking code out of the original function. That way the work done by partition_sched_domains_locked() can be reused without dropping the mutex lock. This patch doesn't change the functionality provided by the original code. Signed-off-by: Mathieu Poirier --- include/linux/sched/topology.h | 9 +++++++++ kernel/sched/topology.c | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index cf257c2e728d..118141c3216a 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -162,6 +162,9 @@ static inline struct cpumask *sched_domain_span(struct sched_domain *sd) return to_cpumask(sd->span); } +extern void partition_sched_domains_locked(int ndoms_new, + cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new); extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], struct sched_domain_attr *dattr_new); @@ -207,6 +210,12 @@ extern void set_sched_topology(struct sched_domain_topology_level *tl); struct sched_domain_attr; static inline void +partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) +{ +} + +static inline void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], struct sched_domain_attr *dattr_new) { diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 41bf2a531ee5..892e1f9c78f0 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1842,15 +1842,15 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, * ndoms_new == 0 is a special case for destroying existing domains, * and it will not create the default domain. * - * Call with hotplug lock held + * Call with hotplug lock and sched_domains_mutex held */ -void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], - struct sched_domain_attr *dattr_new) +void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) { int i, j, n; int new_topology; - mutex_lock(&sched_domains_mutex); + lockdep_assert_held(&sched_domains_mutex); /* Always unregister in case we don't destroy any domains: */ unregister_sched_domain_sysctl(); @@ -1915,7 +1915,16 @@ void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], ndoms_cur = ndoms_new; register_sched_domain_sysctl(); +} +/* + * Call with hotplug lock held + */ +void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) +{ + mutex_lock(&sched_domains_mutex); + partition_sched_domains_locked(ndoms_new, doms_new, dattr_new); mutex_unlock(&sched_domains_mutex); } From patchwork Thu Feb 1 16:51:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126556 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1878077ljc; Thu, 1 Feb 2018 08:51:27 -0800 (PST) X-Google-Smtp-Source: AH8x225nalVTmWKkVLUTqWe/AtT4r+7cL4GixjfqGqLvOznHxtwU2D4GbTHr4Lawny5GSY+Fjdty X-Received: by 10.98.61.208 with SMTP id x77mr38271154pfj.2.1517503887646; Thu, 01 Feb 2018 08:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503887; cv=none; d=google.com; s=arc-20160816; b=fR5kfk6y2gnIICs2ZlthAyD7Htbdbu/kRi7Ytc98hqpDleIVev102yY2oZWiy8I04y /KRw2nFb/0OcQ026LVs+gvHBD6qSmKG2J6HTa814z56ah/39e1DD8nhDOF3pvKcuj5xW +Iuw3zohWxlg1iwsQd7T9Sy54XYxQEtrEQeAHU0CHEY8fl6wS4GdAy2nU5ZqrfnQRfpN V3dTtafR26FOZ0nZ+h5AWkcZdUsUjdWzFtilzvgYmcgWfn3SxDCPw46ae1nQSmPGOA+e l/Ft9Esj9O/edfrqiezK7hmGc2gQcVNMwva+wjt9oCcRq7b2EdGd45gmQIPuMMBlhdQW BuJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xmYP/tp+X0rbv3201hQOHCnuavjxyqXudrz6xOx+u2A=; b=ctB8GxGg/z5/wUzLIt/ZP0fRGpMTRFBUUC3VWm4hIRtCuWfeS6ifzH6BVJuC1fBiE4 xiP8eV4G1tZn0NAIp+4DxFsARWV5z8tSD2ohdX9FUzLdPkzcwBCZFUZRoJALXfdkBMZk d5mIGhc929XPzcbYe9zJWF5cNThAPARr+5YutPRLTyQHbwrQN/K6LUzLsUz9LG2vkaB4 2GHkp1XvrvwnS8dL/XJmQIkQhyur1E2FhcbeDgBo7FwUTt6MGVEy7Q3Q78S0n0u5k/ti BTghlBeQwJlgrRdx9eKuo1nmxrppeC+IioajsNE1QNkcbrTkHCTc2L8T6hjHOP0PCD9/ qSlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wr6eV8hL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a129si3548829pgc.515.2018.02.01.08.51.27; Thu, 01 Feb 2018 08:51:27 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=Wr6eV8hL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752810AbeBAQvZ (ORCPT + 28 others); Thu, 1 Feb 2018 11:51:25 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:54984 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752765AbeBAQvQ (ORCPT ); Thu, 1 Feb 2018 11:51:16 -0500 Received: by mail-it0-f68.google.com with SMTP id k131so4989652ith.4 for ; Thu, 01 Feb 2018 08:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xmYP/tp+X0rbv3201hQOHCnuavjxyqXudrz6xOx+u2A=; b=Wr6eV8hL1n+UrRWqqq3EOCfox3d0nvcM8o6lfqLmetPLQ8Lija0Vrpy4gTVbzr+RuO R7N8Z6QwvLc0oqg9PEwTvhkXvT24fEGHgAn/LbPRhtJn4SRFhmiI6KUbOoGXpHGQXJL6 6kZE8+Ulc/kPytLGaNyVMbUF7W43leQeY3rMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xmYP/tp+X0rbv3201hQOHCnuavjxyqXudrz6xOx+u2A=; b=dlEygKj5aKmWFAm1ZMFDmj8lyG8xMK+mbRrunon0QgJ6MYr8MHqbvH3uXp3VrdZKXi iAs27X+JftswuG29OMa2PlPU3BlWIbwbgwNYhTlfH8Db6x4dW6zZk5nAOKxYzOXOWq1v nk2FdCF6/VVMTIRY3wx3XC/uRil395UO8cHptjysv5/Om61etUyfynB3w/LIPuy9CVVZ lXvqphVks8QdyYyu85Q7jNEhsw7GSeWCbBwVGY8GaXXtnpw/aaeQY6zG1Xsw6GrvnaEV 5ekSTMBBO4gc5QmzUWTnbcfWeOGRLLt5USssD3pk4N81/Gfu6jsmQisEO1TECbKOP2l6 AHhw== X-Gm-Message-State: AKwxyteRUVXrEia6uN+n3nxAuezFLODm96dXz/Khz99VZOl7IpJ1BHK7 pmIG+JoMUqNwUGDxsCSAghodYQ== X-Received: by 10.36.138.134 with SMTP id v128mr41762528itd.153.1517503875640; Thu, 01 Feb 2018 08:51:15 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:14 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/7] cpuset: Rebuild root domain deadline accounting information Date: Thu, 1 Feb 2018 09:51:04 -0700 Message-Id: <1517503869-3179-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the topology of root domains is modified by CPUset or CPUhotplug operations information about the current deadline bandwidth held in the root domain is lost. This patch address the issue by recalculating the lost deadline bandwidth information by circling through the deadline tasks held in CPUsets and adding their current load to the root domain they are associated with. Signed-off-by: Mathieu Poirier --- include/linux/sched.h | 3 ++ include/linux/sched/deadline.h | 8 ++++++ kernel/cgroup/cpuset.c | 63 +++++++++++++++++++++++++++++++++++++++++- kernel/sched/deadline.c | 31 +++++++++++++++++++++ kernel/sched/sched.h | 3 -- kernel/sched/topology.c | 14 +++++++++- 6 files changed, 117 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/include/linux/sched.h b/include/linux/sched.h index d2588263a989..18d00914ae6c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -239,6 +239,9 @@ struct vtime { u64 gtime; }; +extern struct root_domain def_root_domain; +extern struct mutex sched_domains_mutex; + struct sched_info { #ifdef CONFIG_SCHED_INFO /* Cumulative counters: */ diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h index a5bc8728ead7..050961659b1d 100644 --- a/include/linux/sched/deadline.h +++ b/include/linux/sched/deadline.h @@ -29,4 +29,12 @@ static inline bool dl_time_before(u64 a, u64 b) return (s64)(a - b) < 0; } +#ifdef CONFIG_SMP + +struct root_domain; +extern void dl_add_task_root_domain(struct task_struct *p); +extern void dl_clear_root_domain(struct root_domain *rd); + +#endif /* CONFIG_SMP */ + #endif /* _LINUX_SCHED_DEADLINE_H */ diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index fbf40cbd37c9..fc5c709f99cf 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -812,6 +813,66 @@ static int generate_sched_domains(cpumask_var_t **domains, return ndoms; } +static void update_tasks_root_domain(struct cpuset *cs) +{ + struct css_task_iter it; + struct task_struct *task; + + css_task_iter_start(&cs->css, 0, &it); + + while ((task = css_task_iter_next(&it))) + dl_add_task_root_domain(task); + + css_task_iter_end(&it); +} + +/* + * Called with cpuset_mutex held (rebuild_sched_domains()) + * Called with hotplug lock held (rebuild_sched_domains_locked()) + * Called with sched_domains_mutex held (partition_and_rebuild_domains()) + */ +static void rebuild_root_domains(void) +{ + struct cpuset *cs = NULL; + struct cgroup_subsys_state *pos_css; + + rcu_read_lock(); + + /* + * Clear default root domain DL accounting, it will be computed again + * if a task belongs to it. + */ + dl_clear_root_domain(&def_root_domain); + + cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) { + + if (cpumask_empty(cs->effective_cpus)) { + pos_css = css_rightmost_descendant(pos_css); + continue; + } + + css_get(&cs->css); + + rcu_read_unlock(); + + update_tasks_root_domain(cs); + + rcu_read_lock(); + css_put(&cs->css); + } + rcu_read_unlock(); +} + +static void +partition_and_rebuild_sched_domains(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) +{ + mutex_lock(&sched_domains_mutex); + partition_sched_domains_locked(ndoms_new, doms_new, dattr_new); + rebuild_root_domains(); + mutex_unlock(&sched_domains_mutex); +} + /* * Rebuild scheduler domains. * @@ -844,7 +905,7 @@ static void rebuild_sched_domains_locked(void) ndoms = generate_sched_domains(&doms, &attr); /* Have scheduler rebuild the domains */ - partition_sched_domains(ndoms, doms, attr); + partition_and_rebuild_sched_domains(ndoms, doms, attr); out: put_online_cpus(); } diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 2473736c7616..1a5c42e7b076 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2208,6 +2208,37 @@ void __init init_sched_dl_class(void) GFP_KERNEL, cpu_to_node(i)); } +void dl_add_task_root_domain(struct task_struct *p) +{ + unsigned long flags; + struct rq_flags rf; + struct rq *rq; + struct dl_bw *dl_b; + + rq = task_rq_lock(p, &rf); + if (!dl_task(p)) + goto unlock; + + dl_b = &rq->rd->dl_bw; + raw_spin_lock_irqsave(&dl_b->lock, flags); + + dl_b->total_bw += p->dl.dl_bw; + + raw_spin_unlock_irqrestore(&dl_b->lock, flags); + +unlock: + task_rq_unlock(rq, p, &rf); +} + +void dl_clear_root_domain(struct root_domain *rd) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&rd->dl_bw.lock, flags); + rd->dl_bw.total_bw = 0; + raw_spin_unlock_irqrestore(&rd->dl_bw.lock, flags); +} + #endif /* CONFIG_SMP */ static void switched_from_dl(struct rq *rq, struct task_struct *p) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index b19552a212de..d369b748c5a1 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -659,9 +659,6 @@ struct root_domain { unsigned long max_cpu_capacity; }; -extern struct root_domain def_root_domain; -extern struct mutex sched_domains_mutex; - extern void init_defrootdomain(void); extern int sched_init_domains(const struct cpumask *cpu_map); extern void rq_attach_root(struct rq *rq, struct root_domain *rd); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 892e1f9c78f0..371468593f4a 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -3,6 +3,7 @@ * Scheduler topology setup/handling methods */ #include +#include #include #include #include @@ -1875,8 +1876,19 @@ void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], for (i = 0; i < ndoms_cur; i++) { for (j = 0; j < n && !new_topology; j++) { if (cpumask_equal(doms_cur[i], doms_new[j]) - && dattrs_equal(dattr_cur, i, dattr_new, j)) + && dattrs_equal(dattr_cur, i, dattr_new, j)) { + struct root_domain *rd; + + /* + * This domain won't be destroyed and as such + * its dl_bw->total_bw needs to be cleared. It + * will be recomputed in function + * update_tasks_root_domain(). + */ + rd = cpu_rq(cpumask_any(doms_cur[i]))->rd; + dl_clear_root_domain(rd); goto match1; + } } /* No match - a current sched domain not in new doms_new[] */ detach_destroy_domains(doms_cur[i]); From patchwork Thu Feb 1 16:51:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126561 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1879694ljc; Thu, 1 Feb 2018 08:53:27 -0800 (PST) X-Google-Smtp-Source: AH8x225LGpUou6XgH4+CFHmahhEOqMpbLoN5kbi3BfeXJGcnuedu8J5HKBwwGMDmZfcgXBtjhyI4 X-Received: by 10.98.8.206 with SMTP id 75mr37753454pfi.172.1517504006935; Thu, 01 Feb 2018 08:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517504006; cv=none; d=google.com; s=arc-20160816; b=BwhmsJfhzmz4UA35q1fCR6M1wnMVfMHQtALGJQ7lEVfTVaZzYPUJkWJnfXXQZ0SNyA V2J/lmlGBXS3lEEGuRepEhRhZWX0hOzvk6khJnvaNgd2IvixkS9MY1kkX4wvMWWsA06V up6LBQwmzny8xxB9OKWNh2c7232++azphmR0FoXAl7/HNqGx2DlqPI9YbCflR57k3Emp LvDfWj9zYR68GePSjaEqQPsSMg8sZv8MXXF3uNKSZM9uaXnIloamSDeJmCUyoDAWoS3V BZvdx1grKywMtvM+z/t36W93Bl3R+o4iu+zyLExK1+zTxTdyD0t1GGqsqs3gpm+DQHmv KapQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=NxYLTeQbcQ5hyZ7derb2NJjcJRu5QkrT4Vhd7FbcLYc=; b=GOaEVpZE3Z3DVlLR3LlHgEBTK4H/WC4mFGcrKa0d5POx34PDhTrZyftlekkkbtF+HE io5bz8HSG/gw+p4OhMUBql0R/EEfH6I9b4FjDvuwjEwx5ZdyxEV/UH5TNNJOAp31tT1H Q4FcVNb9lJeuVAw80z66TyQWDsU7aOr+WDfseA/EOCA2ckmoMZtBaK2aPlcXCEJzAFRN x10jhXKXEOhHtZS7xEC9HMRzXCg348lLhfs95iDOUnNq0NpRj3+LUakmHnRRuKktOA6n lzzu6V8CIBnDrMS/NudOKtivZlldc/vgdpRPUkTxaMZNgUF1fcgCV+4ibNB4ybDFqXh4 AkHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RqnlaL2z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f64si2139920pfa.364.2018.02.01.08.53.26; Thu, 01 Feb 2018 08:53:26 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=RqnlaL2z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961AbeBAQxZ (ORCPT + 28 others); Thu, 1 Feb 2018 11:53:25 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:38559 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752772AbeBAQvS (ORCPT ); Thu, 1 Feb 2018 11:51:18 -0500 Received: by mail-it0-f66.google.com with SMTP id k6so4551730ita.3 for ; Thu, 01 Feb 2018 08:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NxYLTeQbcQ5hyZ7derb2NJjcJRu5QkrT4Vhd7FbcLYc=; b=RqnlaL2zFBVTsHKCa37XwgxCzkh9O8IMiKocBvz0DAI9WCzB6AsVPDgBt7jSrbYJ4v W8IvChaYlMDrXhVaTJZKBbtpxT8iDsPR0SyERAXHy3gEdJojiciU3s87Gd/VYAcmndw+ +ac2Z7RQFb/Srm+VyoT8w8wFYvLhe1vYVq/e4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NxYLTeQbcQ5hyZ7derb2NJjcJRu5QkrT4Vhd7FbcLYc=; b=atgSXJhoXI0DLuSjFAjCq2z14PLj4ZP5M5n+5JwBA92s+cPPSLeWrvMJztD/r5AYoQ TPWj85n5iZHBoVJTGZ3Wf8nc9wLZPMaqt89VYUK0J8j1goSiJm2eWo/Tq1BxoS5vExyk uMVK7jySfOzs7bC+dWrHl3VHfEKP+QCKb/MClovG517WtZVKK8yLj1J6TAdwb5i4MFGS IjvELpy3pS1CJH8LzFP2/r6P8c/kpCXqGPi0SyPmU6QQxMl98mC+h9PMUf89OM0x1HUp 1U6r3inqpxOVtfHQF5YCqn5T/+yTKtZdLyPcr/1g8mz1DD4OA13R6dL91ao4936K2nbf MvaQ== X-Gm-Message-State: AKwxytfMMcb7KgJVFa9s8epZQutq0opdTOI4ZoKcI/zVX3lo+msPi4di NvGBREmgIVMrmH6fUsAimjdHUdUHL9w= X-Received: by 10.36.23.78 with SMTP id 75mr39665514ith.24.1517503877456; Thu, 01 Feb 2018 08:51:17 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:16 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 3/7] sched/deadline: Keep new DL task within root domain's boundary Date: Thu, 1 Feb 2018 09:51:05 -0700 Message-Id: <1517503869-3179-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When considering to move a task to the DL policy we need to make sure the CPUs it is allowed to run on matches the CPUs of the root domains of the runqueue it is currently assigned to. Otherwise the task will be allowed to roam on CPUs outside of this root domain, something that will skew system deadline statistics and potentially lead to over selling DL bandwidth. For example say we have a 4 core system split in 2 cpuset: set1 has CPU 0 and 1 while set2 has CPU 2 and 3. This results in 3 cpuset - the default set that has all 4 CPUs along with set1 and set2 as just depicted. We also have task A that hasn't been assigned to any CPUset and as such, is part of the default CPUset. At the time we want to move task A to a DL policy it has been assigned to CPU1. Since CPU1 is part of set1 the root domain will have 2 CPUs in it and the bandwidth constraint checked against the current DL bandwidth allotment of those 2 CPUs. If task A is promoted to a DL policy it's 'cpus_allowed' mask is still equal to the CPUs in the default CPUset, making it possible for the scheduler to move it to CPU2 and CPU3, which could also be running DL tasks of their own. This patch makes sure that a task's cpus_allowed mask matches the CPUs in the root domain associated to the runqueue it has been assigned to. Signed-off-by: Mathieu Poirier --- include/linux/cpuset.h | 6 ++++++ kernel/cgroup/cpuset.c | 23 +++++++++++++++++++++++ kernel/sched/core.c | 22 ++++++++++++++++++++++ 3 files changed, 51 insertions(+) -- 2.7.4 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 1b8e41597ef5..61a405ffc3b1 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -57,6 +57,7 @@ extern void cpuset_update_active_cpus(void); extern void cpuset_wait_for_hotplug(void); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); extern void cpuset_cpus_allowed_fallback(struct task_struct *p); +extern bool cpuset_cpus_match_task(struct task_struct *tsk); extern nodemask_t cpuset_mems_allowed(struct task_struct *p); #define cpuset_current_mems_allowed (current->mems_allowed) void cpuset_init_current_mems_allowed(void); @@ -186,6 +187,11 @@ static inline void cpuset_cpus_allowed_fallback(struct task_struct *p) { } +bool cpuset_cpus_match_task(struct task_struct *tsk) +{ + return true; +} + static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) { return node_possible_map; diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index fc5c709f99cf..6942c4652f31 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2517,6 +2517,29 @@ void cpuset_cpus_allowed_fallback(struct task_struct *tsk) */ } +/** + * cpuset_cpus_match_task - return whether a task's cpus_allowed mask matches + * that of the cpuset it is assigned to. + * @tsk: pointer to the task_struct from which tsk->cpus_allowd is obtained. + * + * Description: Returns 'true' if the cpus_allowed mask of a task is the same + * as the cpus_allowed of the cpuset the task belongs to. This is useful in + * situation where both cpuset and DL tasks are used. + */ +bool cpuset_cpus_match_task(struct task_struct *tsk) +{ + bool ret; + unsigned long flags; + + spin_lock_irqsave(&callback_lock, flags); + rcu_read_lock(); + ret = cpumask_equal((task_cs(tsk))->cpus_allowed, &tsk->cpus_allowed); + rcu_read_unlock(); + spin_unlock_irqrestore(&callback_lock, flags); + + return ret; +} + void __init cpuset_init_current_mems_allowed(void) { nodes_setall(current->mems_allowed); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a7bf32aabfda..1a64aad1b9dc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4188,6 +4188,28 @@ static int __sched_setscheduler(struct task_struct *p, } /* + * If setscheduling to SCHED_DEADLINE we need to make sure the task + * is constrained to run within the root domain it is associated with, + * something that isn't guaranteed when using cpusets. + * + * Speaking of cpusets, we also need to assert that a task's + * cpus_allowed mask equals its cpuset's cpus_allowed mask. Otherwise + * a DL task could be assigned to a cpuset that has more CPUs than the + * root domain it is associated with, a situation that yields no + * benefits and greatly complicate the management of DL task when + * cpusets are present. + */ + if (dl_policy(policy)) { + struct root_domain *rd = cpu_rq(task_cpu(p))->rd; + + if (!cpumask_equal(&p->cpus_allowed, rd->span) || + !cpuset_cpus_match_task(p)) { + task_rq_unlock(rq, p, &rf); + return -EBUSY; + } + } + + /* * If setscheduling to SCHED_DEADLINE (or changing the parameters * of a SCHED_DEADLINE task) we need to check if enough bandwidth * is available. From patchwork Thu Feb 1 16:51:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126557 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1878127ljc; Thu, 1 Feb 2018 08:51:30 -0800 (PST) X-Google-Smtp-Source: AH8x224RNRHV04TpOf6T0RGf7hNEKMlZAQQ+Ffa6koU6BTZBhg/tjkCFL8DMKUjBUwTstTqrpKto X-Received: by 2002:a17:902:5a8c:: with SMTP id r12-v6mr15994744pli.87.1517503890694; Thu, 01 Feb 2018 08:51:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503890; cv=none; d=google.com; s=arc-20160816; b=PzKtxdnKFN5dnORD6AcE1iZPbU923vXWOYQfHdZvTpEugFR3VXt/Fpu7IItk7e2s7R 4XE9KRMl1YI/ECggL5jH+DPq+bqdfsMHWZDeLhbZPdWyYYNG3cY8RdIcHtBvvnAolLAW 2rCfTReEXX7n2WkGuUHbgwC6Ddwq/y9JOf9surZewG0BEf1GP+GNFspkx1blNhAONDCK uuC45B5TfGpSCrhs1aoSAHDREc8IfONjtXHSMLJNZppS31zcRLaAUXw0/uoMQeqmXk4/ riSuirOrbgeLRg+xH7niB6W0jbnoiOT6TgwXUJmmJAQfp+y5ZbxPsSWJOzPw4ZFIhrju n+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=V//kdI3WH+mWZEDeznJVIv7RJ7NLlJ52gNLFJllNrSg=; b=DaaFhIyr5iW8/HP6LAAmEz5ByuHto43jlaQcEtYZPaNHH3Up3JEVSR5YAlFq4ZXYFq 1rpR5Jr6v6qDknW+nX50NRx74fFlt+nCC2vC5MesgRTXzQyyaYOmTx7bc1SbdCdzP/Nc ZPQBjBBFhdSUPMyAcuOYp9sKoJtl3aW/Fj5WwTWbOatfc4AuRHRKpUHrCBkxTceLqsdB NJ+hqgQeuAoPGP7MTOIqee7Za7AwUebrzt0m1NpZOgH564pFYDUPQUnzwjZhwDd4VNkx woJ40terAfVYm3QdwJUTxTj26aX4WtgLSi/GPVC5cekxgniUQ0O1guERXa7Eh8G/ADPT Es+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZQNgjP1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si2108303pll.485.2018.02.01.08.51.30; Thu, 01 Feb 2018 08:51:30 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=MZQNgjP1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752833AbeBAQv2 (ORCPT + 28 others); Thu, 1 Feb 2018 11:51:28 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:53485 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752782AbeBAQvU (ORCPT ); Thu, 1 Feb 2018 11:51:20 -0500 Received: by mail-it0-f65.google.com with SMTP id b5so4992567itc.3 for ; Thu, 01 Feb 2018 08:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V//kdI3WH+mWZEDeznJVIv7RJ7NLlJ52gNLFJllNrSg=; b=MZQNgjP1d+ldoO57fcZE6UIhjPSGyeoz/YViqCMwd97eCQEuz5BDtdkIR+wJAufNJw Ll+RD02wFIuqIwvB8MaZGEIHvDXCqIz2f+MXM4F53Ya3InN+la2iSvjLbUbg3qBN3Jr3 gIDxiUwVzpZ/m4hXqhU0hRx/sqCfSGTcVxEsw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V//kdI3WH+mWZEDeznJVIv7RJ7NLlJ52gNLFJllNrSg=; b=Y6k/Pg4rE45DIgRe6paq5ZIgmwZGFHF3wLzcVUHvaqFavoZKf8N7PrgxAP4XtBy7DB yvjj2LASqpadp/JcFk/2wGJtSGA68JjUWMsrPd0XvE+Wh/L1rtoJcWpjzoVoiqLOVI07 sTqZUIBgPKG+u3RrBV3lOTMEZT1Aod339Pv6p7Tm7/r7Qck6YTDlINV3+JAkupXOI9zO F+MRVPKMVdcbk3o4M1z5e/gzYZpMktXXs8B8jmcrmPG8zQfaP3AJtf/bduRKzgdJPtht J72RNCIUWwe3Dc48yvK5773KFZUG3yC5kf/OOlvpo9K/dJaP5pOxKj1a1eS8oHPkD1+E qCbg== X-Gm-Message-State: AKwxytc+FILjMD4z0GlOZwZTJQgI1KXnNIGcv5LPQNtGzp3gPFXVGa75 dz7XICsrdUcL/NdGc0NYPamMAQ== X-Received: by 10.36.250.195 with SMTP id v186mr19418039ith.151.1517503879328; Thu, 01 Feb 2018 08:51:19 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:18 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 4/7] cgroup: Constrain 'sched_load_balance' flag when DL tasks are present Date: Thu, 1 Feb 2018 09:51:06 -0700 Message-Id: <1517503869-3179-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch prevents the 'sched_load_balance' flag from being set to 0 when DL tasks are present in a CPUset. Otherwise we end up with the DL tasks using CPUs belonging to different root domains, something that breaks the mathematical model behind DL bandwidth management. For example on a 4 core system CPUset "set1" has been created and CPUs 0 and 1 assigned to it. A DL task has also been spun off. By default the DL task can use all the CPUs in the default CPUset. If we set the base CPUset's cpuset.sched_load_balance to 0, CPU 0 and 1 are added to a newly created root domain while CPU 2 and 3 endup in the default root domain. But the DL task is still part of the base CPUset and as such can use CPUs 0 to 3, spanning at the same time more than one root domain. Signed-off-by: Mathieu Poirier --- kernel/cgroup/cpuset.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) -- 2.7.4 diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 6942c4652f31..daa1b2bc7e11 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -458,6 +458,106 @@ static void free_trial_cpuset(struct cpuset *trial) kfree(trial); } +static bool cpuset_has_dl_tasks(struct cpuset *cs) +{ + bool dl_tasks = false; + struct css_task_iter it; + struct task_struct *task; + + /* Go through each task in @cs looking for a DL task */ + css_task_iter_start(&cs->css, 0, &it); + + while (!dl_tasks && (task = css_task_iter_next(&it))) { + if (dl_task(task)) + dl_tasks = true; + } + + css_task_iter_end(&it); + + return dl_tasks; +} + +/* + * Assumes RCU read lock and cpuset_mutex are held. + */ +static int +validate_change_load_balance(struct cpuset *cur, struct cpuset *trial) +{ + bool populated = false, dl_tasks = false; + int ret = -EBUSY; + struct cgroup_subsys_state *pos_css; + struct cpuset *cs; + + /* Bail out if nothing has changed. */ + if (is_sched_load_balance(cur) == + is_sched_load_balance(trial)) { + ret = 0; + goto out; + } + + /* + * First deal with the generic case that applies when + * cpuset.sched_load_balance gets flipped on a cpuset, + * regardless of the value. + */ + cpuset_for_each_descendant_pre(cs, pos_css, cur) { + if (cpuset_has_dl_tasks(cs)) + dl_tasks = true; + + /* Skip the top cpuset since it obviously exists */ + if (cs == cur) + continue; + + /* Children without CPUs are not important */ + if (cpumask_empty(cs->cpus_allowed)) { + pos_css = css_rightmost_descendant(pos_css); + continue; + } + + /* CPUs have been assigned to this cpuset. */ + populated = true; + + /* + * Go no further if both conditions are true so that we + * don't end up in a situation where a DL task is + * spanning more than one root domain or only assigned + * to a subset of the CPUs in a root domain. + */ + if (populated && dl_tasks) + goto out; + } + + /* + * Things get very complicated when dealing with children cpuset, + * resulting in hard to maintain code and low confidence that + * all cases are handled properly. As such prevent the + * cpuset.sched_load_balance from being modified on children cpuset + * where DL tasks have been assigned (or any of its children). + */ + if (dl_tasks && parent_cs(cur)) + goto out; + + ret = 0; +out: + return ret; +} + +/* + * Assumes RCU read lock and cpuset_mutex are held. + */ +static int +validate_dl_change(struct cpuset *cur, struct cpuset *trial) +{ + int ret = 0; + + /* Check if the sched_load_balance flag has been changed */ + ret = validate_change_load_balance(cur, trial); + if (ret) + return ret; + + return ret; +} + /* * validate_change() - Used to validate that any proposed cpuset change * follows the structural rules for cpusets. @@ -492,6 +592,10 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial) if (!is_cpuset_subset(c, trial)) goto out; + /* Make sure changes are compatible with deadline scheduling class */ + if (validate_dl_change(cur, trial)) + goto out; + /* Remaining checks don't apply to root cpuset */ ret = 0; if (cur == &top_cpuset) From patchwork Thu Feb 1 16:51:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126560 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1879107ljc; Thu, 1 Feb 2018 08:52:42 -0800 (PST) X-Google-Smtp-Source: AH8x224UkFG/UxMCzAPiBka0bZ+Z/yihgEqyDNYMLxwK5mTwRgk8lTk5Ni11/9ve+hNVVdfaqAJK X-Received: by 2002:a17:902:b595:: with SMTP id a21-v6mr12168687pls.253.1517503962420; Thu, 01 Feb 2018 08:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503962; cv=none; d=google.com; s=arc-20160816; b=AM7di/jgRwREq1+QuKT/T/hK3Aw0AjlNbW2rldFdhANTPLDH25sPSWAoS051JKXNb1 1rJQkyZwlmCgHyjlDUiPYyPpsG8i4Bk53eJfOlzUUXzUTVsSJ1Px79sbx17gayMvZWjg +Yk80QMtaCBZ5oHpUTj/iGQwcr0Jt0x5PB/nzKrwuQCzSvWq40Ih/y3/ubWAtxj4KKZK cejTU5H92L1L//tmOPxSjywp2BNS69Rx06skuE3Mp8FyqFvMIz4yKX3VevEhw1KUZ7+/ /cVhym0WJqQ5lGGxfOgUjLEh4X0XVNat0DyFYKBmJzYK2VOXrYS/N/3tDTuQtJmbm6b0 g2/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=E3/l3qaIHVNvvwCkSVFxDR1ltO2nXjxvm+6TXtxZcrE=; b=vN5U2ed8bjzDsZJ8IavUm47SRjC76PBExOF01YeY0LecHkLOniPizR0e0BgkY2lp9Y YSbYhLAOk9kKM2+cp3D0LD9NGW/5/F8oX0VlO/SbNznggC/n37r6emrCex/Kw5iXJ2IS NT1Mcy+Y/Y0DCt3oxw/KuvZpFuf2ySKGlNRnQXGdtE879iz+pp0gNwnYI4+Kppj3J0Ii EDAIGzqduHNowiwYYrKHDOVt7ZT+tK1x00PQ3rMLGlqxDfxuwqKVZ3BkzxEnruxn2II8 fzvwXNyzRp9CnTu9BWy4g3EfMUlefDw/OWNZDXHrj563+/Trhp+qff120BssVrpOU4T5 K8lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZFo4wvL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si1575810pgn.564.2018.02.01.08.52.42; Thu, 01 Feb 2018 08:52:42 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=MZFo4wvL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752638AbeBAQwl (ORCPT + 28 others); Thu, 1 Feb 2018 11:52:41 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:33709 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752789AbeBAQvV (ORCPT ); Thu, 1 Feb 2018 11:51:21 -0500 Received: by mail-it0-f68.google.com with SMTP id u12-v6so536027ite.0 for ; Thu, 01 Feb 2018 08:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E3/l3qaIHVNvvwCkSVFxDR1ltO2nXjxvm+6TXtxZcrE=; b=MZFo4wvLbhRVrZrxhH0SM3QROum/1iXpXMxbduVeWDMRelR6vIbl1NZvgmp8fHptN1 KcZrQQYg3DtVW/q+wa20bqnZ6wdnNrt5c5g5BHiAnAkzJ2iWgn/T4ecyYtcy6WpV0Ao9 mgyqNKPh/7o8SQvnzrVZgWM/lU7TQCw6Qf8kM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E3/l3qaIHVNvvwCkSVFxDR1ltO2nXjxvm+6TXtxZcrE=; b=hdW63qGoQYTUEefl9fliZiyXClfUcRNKep8rOjRBAFQUm6jKE7hFW827y8zwMbXrqq k0U+GjO7FIPwRv9Z5PCjZjfx1XjfjHbXyJRUd4l5TVvY8R7hRaK+mh0Bpju65TB2wFWc w+9rR51ikwb4UQcT+Eh/p6q0l9EJtWSi02nr0mam7YkzNJzdS+jb+hgGbO29Z2donYV2 01z2Gk/nrhfzVgG513yV2pjFFFuUZ6+Qy6tKL0qhCHEGF3+YNkMLy4UNbhK7KpSJgaRa pyUARWkttw9zffCrUxMc1myyCGj+/id/UPBuTGT+YaPL6x2wB3gfeBZpU4G8ZnvMopIs Fd9w== X-Gm-Message-State: AKwxytcbS5J+vSMZHH+BPIr5iK91LjyWDj11BuW8P2ObXJqlBdkof7AH wnYl9vgrNRSZza8pBgt6U93RIg== X-Received: by 10.36.60.140 with SMTP id m134mr40316401ita.146.1517503881130; Thu, 01 Feb 2018 08:51:21 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:20 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/7] cgroup: Constrain the addition of CPUs to a new CPUset Date: Thu, 1 Feb 2018 09:51:07 -0700 Message-Id: <1517503869-3179-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Care must be taken when CPUs are added to a new CPUset. If an ancestor of that set has its sched_load_balance flag switch off then the CPUs in the new CPUset will be added to a new root domain. If the ancestor also had DL tasks those will end up covering more than one root domain, breaking at the same time the DL integrity model. This patch prevents adding CPUs to a new CPUset if one of its ancestor had its sched_load_balance flag off and had DL tasks assigned to it. Signed-off-by: Mathieu Poirier --- kernel/cgroup/cpuset.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index daa1b2bc7e11..6ae4ad995e9e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -481,6 +481,43 @@ static bool cpuset_has_dl_tasks(struct cpuset *cs) * Assumes RCU read lock and cpuset_mutex are held. */ static int +validate_change_cpus(struct cpuset *cur, struct cpuset *trial) +{ + int ret = 0; + + /* + * CPUs are being added to a CPUset. If any parent of @trial has its + * sched_load_balance flag switched off this operation will create a + * new root domain spanning trial->cpus_allowed. At the same time + * if any parent of @trial has a DL task, that task will end up + * spanning more than one root domain and break the deadline integrity + * model. + */ + if (cpumask_weight(cur->cpus_allowed) < + cpumask_weight(trial->cpus_allowed)) { + struct cpuset *parent; + + parent = parent_cs(trial); + /* Go up until we reach the top_cpuset */ + while (parent) { + if (cpuset_has_dl_tasks(parent) && + !is_sched_load_balance(parent)) { + ret = -EBUSY; + goto out; + } + + parent = parent_cs(parent); + } + } + +out: + return ret; +} + +/* + * Assumes RCU read lock and cpuset_mutex are held. + */ +static int validate_change_load_balance(struct cpuset *cur, struct cpuset *trial) { bool populated = false, dl_tasks = false; @@ -553,8 +590,13 @@ validate_dl_change(struct cpuset *cur, struct cpuset *trial) /* Check if the sched_load_balance flag has been changed */ ret = validate_change_load_balance(cur, trial); if (ret) - return ret; + goto out; + ret = validate_change_cpus(cur, trial); + if (ret) + goto out; + +out: return ret; } From patchwork Thu Feb 1 16:51:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126559 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1878985ljc; Thu, 1 Feb 2018 08:52:34 -0800 (PST) X-Google-Smtp-Source: AH8x225Ri6ZF3de+ZeFWQaSsKOewJyAZpq/K7QhYdBtLRfD69112h5ioBccy66tsm9HXI4dwSrOY X-Received: by 10.99.171.12 with SMTP id p12mr29752892pgf.304.1517503954834; Thu, 01 Feb 2018 08:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503954; cv=none; d=google.com; s=arc-20160816; b=kn+UnE2gajaevg0eG0SnktYBkMpUJ9FAi8G/ipAn0UKTXxFzIMUSN1G1pVC2tzhERD ZUUupldArkMwluaD1vo7wpvTVOCn3qrx6nWiFS/dj7616s7WCoBaf5pvzx5CSUsLpjSu 4OsOKtV4aQ5GPMViOpSY05YDv8SIsuzBQmvi7jo24R3YAy8xYgIVyljl1vInmK60Bai+ Wq2QuGQyh88L+Ly5Z0+z3ZT3iPcazKKMUfC3Dc/k9cOTr6LRVEoz0LnpdfOfktNMl2ip qF3xeadN0ZhNJUvaUHB91lmyz0ZJr5EGIPoATy/txlJsTEGIE8nzjw6XW7YmAldt+uVD EstA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=bbSpz/uy+1sO31tcIPzjYC71AHXRgGxlaVBZKzn4+Mw=; b=rNuf/glaj7jayxjdOnZS1KHMwVpudRrHsykvaflVRrKltKxH/QlOOAJ0kG0wgQBuP1 V6h0eJEKDM2NTZNtSpclcKSNzUSrorYXdcKqfrE72UrKYcQaTNi7ACinTG3sxuLCp+rt UMq5mk/g0sL67SRChnZ6w0t9tTFCVJzJJOyVh3qLO1uE7/gqe6EQW4PWH/4YF84fgr43 EXUTbtUvlkcRckGfQyrHuKZDB+kQelJEwNG0J/riodon3YE61KLyiGxI6QDP/OruP4eY BR43SkcGHYwkrPooSI/96DRYMUWjkm//ptZvbs6EFdk1Qf4LxFbnED9B3DPGvpq9BO+i OKFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T2oFwe9G; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 72-v6si1078ple.299.2018.02.01.08.52.34; Thu, 01 Feb 2018 08:52:34 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=T2oFwe9G; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752889AbeBAQwd (ORCPT + 28 others); Thu, 1 Feb 2018 11:52:33 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:40923 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752799AbeBAQvX (ORCPT ); Thu, 1 Feb 2018 11:51:23 -0500 Received: by mail-it0-f67.google.com with SMTP id 196so4544748iti.5 for ; Thu, 01 Feb 2018 08:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bbSpz/uy+1sO31tcIPzjYC71AHXRgGxlaVBZKzn4+Mw=; b=T2oFwe9GY8/f6yYxPY2NY8IED1Y8GGwu/W0XpqjBr8EQJaBuOBogxUKEqHBzhl3Z3j udyblpy/pXF2SGCzB02wx/4IhbcRz6rFH8CLYb5/XTt3HoMSzRRbMBWoe/s0OKopIYlO mFivFrZxVynj0kB016B9uWzOP4mul21Mvu5qI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bbSpz/uy+1sO31tcIPzjYC71AHXRgGxlaVBZKzn4+Mw=; b=WWRezoE1BE+UMHXYPju3kbx6fpVUL3Lc3nbpabnrMfM1boWPu75cFqEAHR2LBGe8QR 9ZO0KEjW/2xPqg8y/5XsVwwvbNLJ7CxDf+6V3jrnlUyGojF5svfG/bCZyHT8H6nwLFj0 8mZbUzC4L2PnVAgEHOGs0HNNgHr1SwMsto770X3Hf0S1DRu3X8Hvtcx1cXPXKSUw9hzF v2tDKSP75nvY5bqVsBILeLRGWQPaNA4N3/REIuqlpOZ/i4Dy0KNKk4NEOdpZvb9amwAv vr5YOouYuRen2JHJ44mae4bZj5KdW6zxpmrKzDQW6Ng/3yKaLMbP5+OhA+erRuuer52T 9spg== X-Gm-Message-State: AKwxytcVc3ryaxWzq9q0IcC7xl7isj6Y2lcGiU1lBGEO+jh6FaT1eCPh 2zYbFS7inEBOxNFxR+sglGp1jg== X-Received: by 10.36.73.69 with SMTP id z66mr38070440ita.98.1517503882891; Thu, 01 Feb 2018 08:51:22 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:22 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 6/7] sched/core: Don't change the affinity of DL tasks Date: Thu, 1 Feb 2018 09:51:08 -0700 Message-Id: <1517503869-3179-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we mandate that on creation, the ->cpus_allowed mask of a future DL task has to be equal to the rd->span of the root domain it will be associated with, changing the affinity of a DL task doesn't make sense anymore. Indeed, if we set the task to a smaller affinity set then we may be running out of CPU cycle. If we try to increase the size of the affinity set the new CPUs are necessarily part of another root domain where DL utilisation for the task won't be accounted for. As such simply refuse to change the affinity set of a DL task. Signed-off-by: Mathieu Poirier --- kernel/sched/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1a64aad1b9dc..2c9e54aac3cc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4694,15 +4694,15 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) cpumask_and(new_mask, in_mask, cpus_allowed); /* - * Since bandwidth control happens on root_domain basis, - * if admission test is enabled, we only admit -deadline - * tasks allowed to run on all the CPUs in the task's - * root_domain. + * Since bandwidth control happens on root_domain basis, if admission + * test is enabled we don't allow the task' CPUs to change. If + * @new_mask is smaller than we risk running out of cycles. If it is + * bigger than we may be using DL bandwidth allocated to other CPUs. */ #ifdef CONFIG_SMP if (task_has_dl_policy(p) && dl_bandwidth_enabled()) { rcu_read_lock(); - if (!cpumask_subset(task_rq(p)->rd->span, new_mask)) { + if (!cpumask_equal(task_rq(p)->rd->span, new_mask)) { retval = -EBUSY; rcu_read_unlock(); goto out_free_new_mask; From patchwork Thu Feb 1 16:51:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 126558 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1878299ljc; Thu, 1 Feb 2018 08:51:43 -0800 (PST) X-Google-Smtp-Source: AH8x226nLeAXBxasYg+Cs+EztUPW9guPPGDHDw+6/NWus6XzqsPik423W/USOJNTDPlhMM4tzJlg X-Received: by 10.101.92.129 with SMTP id a1mr29875810pgt.198.1517503903283; Thu, 01 Feb 2018 08:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517503903; cv=none; d=google.com; s=arc-20160816; b=MGX9Fz8ijeYImr9Y6EVEO9OPfgJKm3r1jBCLZl5EiQUBtvoi0ss82l9CNRdn3Tdsh5 wB/ur2oYaN95jQXFl/kCIT7pVTcD+1KsZceABtOihf/qiUhbb5AHbyjAtyJ2+oWa5nIf TS1TGAcZrS/Z8XjTptV6wojStYtBkJ16crL9eeoAB4iw3DCtmSpR3VfZLEHmzK+zvOXI qh1hAyM+oehWgiykz3+xBY601ncBmWj6wZZbBJQ2qNwUlJIs8GoPDpT8TnzYv3ok8uuq HK0lhnISSWUbl2eg9pbhPhq0uTlStedhw+6+6ZDuRJ4nics9vRza+Vnks+O2x9E3bUJ0 Q/ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=cw439ri7YDuH2p/A5GKIcVjp/mn2EguSohu8jazS960=; b=KneSbSqVcIh7F7mWXIF0CZ6PmiMs+dE1R/xzePS4aJml+ZSoDEceSnj60JCBoPCoLO YvtNnFf8msQdFO6G3lr8R5kD+Ex7GjmyheUuK9T62fakpxSMvDlqFEwcd2Qo9vSARAtQ EVo9xYmG26k9Dzo6lTgyPk26pVR2RzDvqNO1ysZ8j0Lrn4OnI5IpoBX6UmUQhekWeJUO 26IWbqatM5WXSlxGTX4808NKGaT0d4WNbqvm4VGFTlzya7fJuPNq6ucXBqv7MQxF/MWX a+qjA0Si/cVHk5vFKoT9f4akxWmsJPPX6R3zSceeHhmvErMN2qMpxeqAJNNiQ73otajP sVsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A3HJH55D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si1719499pgo.709.2018.02.01.08.51.43; Thu, 01 Feb 2018 08:51:43 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=A3HJH55D; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752847AbeBAQvl (ORCPT + 28 others); Thu, 1 Feb 2018 11:51:41 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:39810 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752808AbeBAQvZ (ORCPT ); Thu, 1 Feb 2018 11:51:25 -0500 Received: by mail-it0-f66.google.com with SMTP id 68so4558015ite.4 for ; Thu, 01 Feb 2018 08:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cw439ri7YDuH2p/A5GKIcVjp/mn2EguSohu8jazS960=; b=A3HJH55DrPpe7Fo7pb800pDW1wZFahzH0/pTqj91Df2ufY5FR2ENxgQmbGEJGEVBxX VAVfeUXgJNQ1+ufWdgQKOcKUOab7eqcPFEpe0M6tu6XfsH8mGtrGSELCagFjouTnHb9/ f9KIc8ycLuG1M0ChobTFfdjdlns6eiy/f06io= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cw439ri7YDuH2p/A5GKIcVjp/mn2EguSohu8jazS960=; b=LuFbK0EEv2XawfGpODzik2syYBJ0rQ4Cu1pb9ryckDKaZ2yIl6AJ+swi87C7PAbLMp gLwtAn7BG5hVbM1FclXzc0jFk1/caUo47vgtA9cV3o4Uv3UknH3hajXKzFYwUZL5RCUs NuL6xixYMtdt8GCpND3oyUS4GITYxVWadz5jq7CgpmExjweL8TzOi1ifwfsy+CL1XUWO ilURY7QFjb9r4m3HxSr4U46Ca0J5HPQ9xAgEETzzFwCCnCI9VQnJfIM9rptxEVKjU6et Lsmp9YmSAD+XzXIkqjWwDCUyU34Y5RNJl9FyI9EbbkrkMhjttK1G9RE+abLp/idycEwV YcMA== X-Gm-Message-State: AKwxytd25uSEuXmCdJOM8PjX5lXKesjEVRVbCjkhftL9TC0WkwuQFXkW jQ1Lcos5pukybpbqY4jFItnujg== X-Received: by 10.36.63.73 with SMTP id d70mr8859732ita.96.1517503884855; Thu, 01 Feb 2018 08:51:24 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id e83sm9270773iof.71.2018.02.01.08.51.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Feb 2018 08:51:23 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, linux-kernel@vger.kernel.org Subject: [PATCH V2 7/7] sched/deadline: Prevent CPU hotplug operation if DL task on CPU Date: Thu, 1 Feb 2018 09:51:09 -0700 Message-Id: <1517503869-3179-8-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> References: <1517503869-3179-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a DL task is assigned a CPU the "utilisation" (this_bw) and the "active utilisation" (running_bw) fields of rq->dl are incremented accordingly. If the CPU is hotplugged out the DL task is transferred to another CPU but the task's contribution to this_bw and running_bw isn't substracted from the outgoing CPU's rq nor added to the newly appointed CPU. In this example (where a kernel has been instrumented to output the relevant information) we have a 4 CPU system with one 6:10 DL task that has been assigned to CPU 2: root@dragon:/home/linaro/# cat /proc/rq_debug dl_rq[0]: .online : yes .dl_nr_running : 0 .running_bw : 0 .this_bw : 0 .rd->span : 0-3 .dl_nr_migratory : 0 .rd->dl_bw->bw : 3984588 .rd->dl_bw->total_bw : 629145 dl_rq[1]: .online : yes .dl_nr_running : 0 .running_bw : 0 .this_bw : 0 .rd->span: : 0-3 .dl_nr_migratory : 0 .rd->dl_bw->bw : 3984588 <-- RD capacity for 4 CPUs .rd->dl_bw->total_bw : 629145 dl_rq[2]: .online : yes .dl_nr_running : 1 <-- One task running .running_bw : 629145 <-- Normal behavior .this_bw : 629145 <-- Normal behavior .rd->span : 0-3 .dl_nr_migratory : 1 .rd->dl_bw->bw : 3984588 .rd->dl_bw->total_bw : 629145 dl_rq[3]: .online : yes .dl_nr_running : 0 .running_bw : 0 .this_bw : 0 .rd->span : 0-3 .dl_nr_migratory : 0 .rd->dl_bw->bw : 3984588 .rd->dl_bw->total_bw : 629145 At this point we hotplug out CPU2 and list the status again: root@dragon:/home/linaro/# echo 0 > /sys/devices/system/cpu/cpu2/online root@dragon:/home/linaro/# cat /proc/rq_debug dl_rq[0]: .online : yes .dl_nr_running : 1 <-- DL task was moved here .running_bw : 0 <-- Contribution not added .this_bw : 0 <-- Contribution not added .rd->span : 0-1,3 .dl_nr_migratory : 1 .rd->dl_bw->bw : 2988441 <-- RD capacity updated .rd->dl_bw->total_bw : 629145 dl_rq[1]: .online : yes .dl_nr_running : 0 .running_bw : 0 .this_bw : 0 .rd->span : 0-1,3 .dl_nr_migratory : 0 .rd->dl_bw->bw : 2988441 .rd->dl_bw->total_bw : 629145 dl_rq[2]: .online : no <-- runqueue no longer online .dl_nr_running : 0 <-- DL task was moved .running_bw : 629145 <-- Contribution not substracted .this_bw : 629145 <-- Contribution not substracted .rd->span : 2 .dl_nr_migratory : 0 .rd->dl_bw->bw : 996147 .rd->dl_bw->total_bw : 0 dl_rq[3]: .online : yes .dl_nr_running : 0 .running_bw : 0 .this_bw : 0 .rd->span : 0-1,3 .dl_nr_migratory : 0 .rd->dl_bw->bw : 2988441 .rd->dl_bw->total_bw: 629145 Upon rebooting the system a splat is also produced: [ 578.184789] ------------[ cut here ]------------ [ 578.184813] dl_rq->running_bw > old [ 578.184838] WARNING: CPU: 0 PID: 4076 at /home/mpoirier/work/linaro/deadline/kernel/kernel/sched/deadline.c:98 dequeue_task_dl+0x128/0x168 [ 578.191693] Modules linked in: [ 578.191705] CPU: 0 PID: 4076 Comm: burn Not tainted 4.15.0-00009-gf597fc1e5764-dirty #259 [ 578.191708] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT) [ 578.191713] pstate: 60000085 (nZCv daIf -PAN -UAO) [ 578.191718] pc : dequeue_task_dl+0x128/0x168 [ 578.191722] lr : dequeue_task_dl+0x128/0x168 [ 578.191724] sp : ffff8000383ebbf0 [ 578.191727] x29: ffff8000383ebbf0 x28: ffff800038288000 [ 578.191733] x27: 0000000000000009 x26: ffff800038890000 [ 578.191739] x25: ffff800038994e60 x24: ffff800038994e00 [ 578.191744] x23: 0000000000000000 x22: 0000000000000000 [ 578.191749] x21: 000000000000000e x20: ffff800038288000 [ 578.191755] x19: ffff80003d950aa8 x18: 0000000000000010 [ 578.191761] x17: 0000000000000001 x16: 0000000000002710 [ 578.191766] x15: 0000000000000006 x14: ffff0000892ed37f [ 578.191772] x13: ffff0000092ed38d x12: 0000000000000000 [ 578.191778] x11: ffff8000383eb840 x10: 0000000005f5e0ff [ 578.191784] x9 : 0000000000000034 x8 : 625f676e696e6e75 [ 578.191794] x7 : 723e2d71725f6c64 x6 : 000000000000016c [ 578.191800] x5 : 0000000000000000 x4 : 0000000000000000 [ 578.191806] x3 : ffffffffffffffff x2 : 000080003480f000 [ 578.191812] x1 : ffff800038288000 x0 : 0000000000000017 [ 578.191818] Call trace: [ 578.191824] dequeue_task_dl+0x128/0x168 [ 578.191830] sched_move_task+0xa8/0x150 [ 578.191837] sched_autogroup_exit_task+0x20/0x30 [ 578.191843] do_exit+0x2c4/0x9f8 [ 578.191847] do_group_exit+0x3c/0xa0 [ 578.191853] get_signal+0x2a4/0x568 [ 578.191860] do_signal+0x70/0x210 [ 578.191866] do_notify_resume+0xe0/0x138 [ 578.191870] work_pending+0x8/0x10 [ 578.191874] ---[ end trace 345388d10dc698fe ]--- As a stop-gap measure before the real solution is available this patch prevents users from carrying out a CPU hotplug operation if a DL task is running (or suspended) on said CPU. Signed-off-by: Mathieu Poirier --- kernel/sched/deadline.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 1a5c42e7b076..9fa9421bb23f 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2672,11 +2672,16 @@ bool dl_cpu_busy(unsigned int cpu) int cpus; rcu_read_lock_sched(); + overflow = !!(cpu_rq(cpu)->dl.this_bw); + if (overflow) + goto out; + dl_b = dl_bw_of(cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); cpus = dl_bw_cpus(cpu); overflow = __dl_overflow(dl_b, cpus, 0, 0); raw_spin_unlock_irqrestore(&dl_b->lock, flags); +out: rcu_read_unlock_sched(); return overflow; }