From patchwork Wed Aug 16 21:20:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 110284 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1324139qge; Wed, 16 Aug 2017 14:21:51 -0700 (PDT) X-Received: by 10.99.37.6 with SMTP id l6mr2763535pgl.407.1502918511581; Wed, 16 Aug 2017 14:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502918511; cv=none; d=google.com; s=arc-20160816; b=DA0Vf+yjBSIir602dQXiFxm+y5ox1YhrgTL1Ggta+a39M6cY3GNMD4L5gM74KBpq4J kr4xRnbgQ04GE5Pjm2lP0MSGIr49dMHE6jTKIjbp07nY9FHDGDwOzlxGyXYD1zZh/hSE pcgZRNEinjGFQGbP0ZbrphMOGC1xG2IWfyutDaOB8Fv9fpArliINS3VpBZTyWiNqznh/ R0ApEnnWjPU/Tpoiiq+NHkD0WdGBUPM9x1UuzXfFuUDHQVAo9FbD6iFwJqkfqFUTGNy+ ZtZA6P6LnX5kKCwl2TbamGMWh5bFO8swTzqV6Gg+dpLRUgmqcfvLKWZJ+VuCdm9tvUE4 4o5w== 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=K8/rSTPEOkMaV2XKAw16f6bLQEjuL/boke6ZWKVKJfY=; b=CNOQMRtxgdfpOQ/LWA8x0pFEoNzANssDTURilWHHGYud34WcHpZ3zCIp6FewrSj6M5 ZvrqySzE1XV0XS/7UIlkziyfVQCDgkX2HUH218mJR7MT9WyASykAAe4UPJm04TMPTpMp OuUEdeK0+kQ8iv0oiRvt/1nUYk4J3cgwMbBgKKNJiGuB0Ei3JUwgmh2qkijTEtP8d7Xq S32MQQhq/YYFz5NsfVtCPe/9vezeUuYiSE/Y3MbmYghgmgEY64MLjKroLnBPAeXylN+e BW6y6FDwOJCczb0M8xKBpx4TX8b0KysUGOW7UESYi5vBjm9sX9T2R/ZHT8vulcq7xaAW 4zgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZW4cjS3E; 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 r13si1113480plj.167.2017.08.16.14.21.51; Wed, 16 Aug 2017 14:21:51 -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; dkim=pass header.i=@linaro.org header.s=google header.b=ZW4cjS3E; 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 S1752666AbdHPVVt (ORCPT + 26 others); Wed, 16 Aug 2017 17:21:49 -0400 Received: from mail-io0-f180.google.com ([209.85.223.180]:35593 "EHLO mail-io0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752495AbdHPVU4 (ORCPT ); Wed, 16 Aug 2017 17:20:56 -0400 Received: by mail-io0-f180.google.com with SMTP id m88so17262455iod.2 for ; Wed, 16 Aug 2017 14:20:55 -0700 (PDT) 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=K8/rSTPEOkMaV2XKAw16f6bLQEjuL/boke6ZWKVKJfY=; b=ZW4cjS3EuCjZ+ZjkSRmXrFLdjj2sGnV/XOXYFtmhfk76XBt4vKOMCRY65v2DupQhbw M0cUrhXiW0cullQJWNmNaoTSf3EV8kCuhVhreV1rWreA4KZdoaMQxAxpgK1PMMnCqq68 wa9ZMMtIRDivaodfAGDu4cyRMSjHVbaomUle4= 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=K8/rSTPEOkMaV2XKAw16f6bLQEjuL/boke6ZWKVKJfY=; b=JbYw184jBCje3etYwdQkRPJIdpXMUYhRe+9kCI90d4bcIZXE81A2X7DRqDlFVc3Ekh TPmB0MCLgUfEj7nQuKl+ZzgbKf+3FO9wFco/rvwf0OLdM/GWnfaw0dH9SJBvcbPL84zz PBk7jblzz4roHUcF4DsSk2fEIPe2Rryk92Dfyxrvze+uoQ2twmC3FGR07mPlcG8lTtAT QjqXroLxsw2TVnKUe/Pxc55XKrodZRjlL5TpP5nJqtgXW4l5wTDfrSVauHmB8bP9Pj0O Xpfojg5glgoDim0qOugdqYCK2hEzUjJ8OUUp/rtlT+F7eHr5rNGFlZkQy1EuOhTy2xBm 3hpQ== X-Gm-Message-State: AHYfb5h0Iur6IBxLv/kZf168N0bVwwTmmSRNAPTVMKXYSQnePLw1xFxp MgMDdw9OWYJu/He9 X-Received: by 10.107.53.40 with SMTP id c40mr2923443ioa.289.1502918455510; Wed, 16 Aug 2017 14:20:55 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 80sm918281itk.11.2017.08.16.14.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Aug 2017 14:20:54 -0700 (PDT) From: Mathieu Poirier To: mingo@redhat.com, peterz@infradead.org Cc: tj@kernel.org, vbabka@suse.cz, lizefan@huawei.com, akpm@linux-foundation.org, weiyongjun1@huawei.com, juri.lelli@arm.com, rostedt@goodmis.org, claudio@evidence.eu.com, luca.abeni@santannapisa.it, bristot@redhat.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org Subject: [PATCH 4/7] cgroup: Constrain 'sched_load_balance' flag when DL tasks are present Date: Wed, 16 Aug 2017 15:20:40 -0600 Message-Id: <1502918443-30169-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502918443-30169-1-git-send-email-mathieu.poirier@linaro.org> References: <1502918443-30169-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 fippled off 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 | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) -- 2.7.4 diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index f6d1e485dc2d..18df143b4013 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -447,6 +447,85 @@ 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, &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_dl_change(struct cpuset *cur, struct cpuset *trial) +{ + bool populated = false, dl_tasks = false; + int ret = -EBUSY; + struct cgroup_subsys_state *pos_css; + struct cpuset *cs; + + /* + * The cpuset.sched_load_balance flag is flipped off on + * the current cpuset. + */ + if (is_sched_load_balance(cur) && + !is_sched_load_balance(trial)) { + /* See if at least one descendant cpuset is populated */ + cpuset_for_each_descendant_pre(cs, pos_css, cur) { + /* Skip over ourselve */ + if (cs == cur) + continue; + + /* Empty cpusets are of no interest */ + if (cpumask_empty(cs->cpus_allowed)) { + pos_css = css_rightmost_descendant(pos_css); + continue; + } + + /* + * @cur has at least one children and CPUs have been + * assigned to it - there is no need to go further. + */ + populated = true; + break; + } + + dl_tasks = cpuset_has_dl_tasks(cur); + + /* + * This CPUset has a children that is populated by (at least) + * one CPU. When the sched_load_balance flag gets flipped off + * it will create a new root domain for the children CPUset, + * and that new root domain will include the CPUs assigned to + * the CPUset. + * + * Since the tasks in the current CPUset have not been assigned + * to the children CPUset they will simply stay here and use + * all the CPUs available in this set. For DL tasks this can't + * be allowed since they will be executing on CPUs associated to + * more than one root domains. + */ + if (populated && dl_tasks) + goto out; + } + + ret = 0; +out: + return ret; +} + /* * validate_change() - Used to validate that any proposed cpuset change * follows the structural rules for cpusets. @@ -481,6 +560,9 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial) if (!is_cpuset_subset(c, trial)) goto out; + if (validate_dl_change(cur, trial)) + goto out; + /* Remaining checks don't apply to root cpuset */ ret = 0; if (cur == &top_cpuset)