From patchwork Tue Feb 13 20:32:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128301 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp34094ljc; Tue, 13 Feb 2018 12:35:32 -0800 (PST) X-Google-Smtp-Source: AH8x227PCKjzdKRuZoaMeACs3C2ySr5Xbc0pJNqx9Mbd/q33LrubXgpckOlkahr6NTNOQXyUpJS0 X-Received: by 2002:a17:902:7485:: with SMTP id h5-v6mr2263394pll.236.1518554131902; Tue, 13 Feb 2018 12:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554131; cv=none; d=google.com; s=arc-20160816; b=meAllWWcJbgEY0jE2wDkAYAw3PNijmwJvMDjlflY+N+GKYbCugS/6BpflcEp+tCMZG q+F49Mf26HspgC5nqeXJlWfDdlBQfSFnKuENAG+46wjXGOZ4lJ/Z/KvNP4p/bsZqr/ck ke3AXH+m7961DqzDZWS5AHTdvgjP+l1FS8prQVcqnuin0hZhRdhVmmRpwXJCBAseVPeW sjh7gnowmHDFQ70RNMk0OpEPiTQ2c1T/VGN+TyDl03GdDSKN7fYizAvMC6XrZqx2WJRG mYnta2K/r66y58KiHWUREOJJOrr0NEug9URZ73HLuvKI5Rz6Sd0n7Q13x83dzG/reQ3b nH7w== 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=EN03PbsrZiRRqe4tJq7u3W330XNNPxoiJqtHTysQnFs=; b=HapwvnGiJGckru1kUVNSRB/cJ+j7HWxyDPQPVBDXauXfLCS0CqffCKCN4zB3GRDS+W m7OK26WgnE7zMMdegqWHukhZLNRQOp4mzSDqq18iRJ8B7hr6mtSN6N+bGcLL/yYB78ZT ALHtf5A/MBxjocZ/GHzHDcdmpAXUSBjeMVvqCwIKqnXeGTFODTdlTFJGL7npD83enUN4 tqIUTRUHdNXb7RBQTaEFrrywczjFV5Q+zWSFzE05zSriCPBROsG0K1zo/GnzaO6908hx zTh5RNhAdiikQfn3A011zn+E99e4HUnCauY41LPvFBcILUT0vtHe4TAyEbsfhEkUG+86 P8EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dcOKRsEo; 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 n129si108109pga.260.2018.02.13.12.35.31; Tue, 13 Feb 2018 12:35:31 -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=dcOKRsEo; 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 S965876AbeBMUf1 (ORCPT + 28 others); Tue, 13 Feb 2018 15:35:27 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:39649 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965634AbeBMUcw (ORCPT ); Tue, 13 Feb 2018 15:32:52 -0500 Received: by mail-pg0-f65.google.com with SMTP id w17so670778pgv.6 for ; Tue, 13 Feb 2018 12:32:52 -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=EN03PbsrZiRRqe4tJq7u3W330XNNPxoiJqtHTysQnFs=; b=dcOKRsEoc1JKX6Br+4wnJstQv600hGAlsAcCP2/+h0WJurO14ocItmm21QqUPsSd9D tUteljV0oeogOyCJDl3e2eD3PL/2T6jpxQav4TviqavnrbInaTyP8BZ9OIwnKBOH0jQr Ec03h9IxEhLwYf8NikCJppXuQr1VoFByI0ePE= 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=EN03PbsrZiRRqe4tJq7u3W330XNNPxoiJqtHTysQnFs=; b=dmNfw8grkirEiyTvBWG8Wzf1RX20H+lM1GykNrIVy6pDu1G9GsB0pEYjmJ9T3b2yWE 85Wr/D2XmVMbarngt4AuyTAtXzZ9awQDg2O2G5OyQ2e+ewonmg1tNNEROkU6BEt4ycvy Ai7Zt6bwQneXLnSvP+Rfb1RjP7nS/ekUw8pclDJlW3YXmiwV0aBhIh74XYlwshEeydTv RZQgKLMm+ee93fjm4EUeDCdBlgT9cWLIwCayO327T4ZQHrhjNGbtn7upXamqZulYpS3J emDS5x/rjvVoKDxCr4BUCSkS+GYh6hMwDLNrOoyXGL/0EfX6s8HZP+r0kSLG/pa8Alrj iIdg== X-Gm-Message-State: APf1xPDmugiP1c0N/Kz0XgopJE0D/jRy7B7ULYbOWrGvxNPspXJTdPlO hvdwx/keDy/RRp7CKxyPhWKZzQ== X-Received: by 10.101.68.82 with SMTP id e18mr1909353pgq.329.1518553971987; Tue, 13 Feb 2018 12:32:51 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:51 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 01/10] sched/topology: Add check to backup comment about hotplug lock Date: Tue, 13 Feb 2018 13:32:38 -0700 Message-Id: <1518553967-20656-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 The comment above function partition_sched_domains() clearly state that the cpu_hotplug_lock should be held but doesn't mandate one to abide to it. Adding an explicit check backs that comment and make it impossible for anyone to miss the requirement. Suggested-by: Juri Lelli Signed-off-by: Mathieu Poirier --- kernel/sched/topology.c | 1 + 1 file changed, 1 insertion(+) -- 2.7.4 diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8010c2974d30..7c744c7425ec 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1863,6 +1863,7 @@ void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], int i, j, n; int new_topology; + lockdep_assert_cpus_held(); mutex_lock(&sched_domains_mutex); /* Always unregister in case we don't destroy any domains: */ From patchwork Tue Feb 13 20:32:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128292 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp32349ljc; Tue, 13 Feb 2018 12:33:05 -0800 (PST) X-Google-Smtp-Source: AH8x227cFjxXJyas409d1m7JRKwvklIG4MrOWI9//Qq1Itto/a9uIGwfwVIEjJ+B0aUCKhBfSbnO X-Received: by 10.98.110.202 with SMTP id j193mr2407635pfc.19.1518553985824; Tue, 13 Feb 2018 12:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518553985; cv=none; d=google.com; s=arc-20160816; b=etufRXnNVUg1/tspzdhlCCvRdhEm/SrQ4EmHf1Qg9tj3LTO135liYu5iKcaWBL8LxK pjoAFJXV7u1g7WKXRPFySltzY/orDOOLdtpHgw8KwDSQjO3J+Z+gD3DWdsuoU9cg1y7X 8gGriak4pgry1aUH5ZVoPv2AMg7KE4X0kKKNs5hhc14fq2QTNTW5TFMqyfOabYOmaViX vrTGrpJj+RWrNORzc0vi1lJeBVPTiLds0QPfH++TQEnnGWZYUaFIYvte3NluvI1p+LWN nKc4kR4BdM3+pdl+5c+oU1pQu8hwuoZbGel/xOStaSV383wzE8ROzniolG+v4QWWaBu9 G/bw== 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=aqfOKIUd8Y1UwyLRij4d9JL0cKxu3qmny5GvLSDwxsk=; b=vojJGtYLr5Tzb0NNI09FxjxbiF6JWzN8dZGS6iz6mdsl9HwZTaoL/n65ZMIK8VMz1U cHxXz/nNMHjFZJ5srIa2vJC9C0/2696whrv5gpbi+12m1DCt2zFBms+UliqCuPvItr4p IBr0BgfrbJxJk9URNDj/CDcobFxPE5FYlc9aWaO5TpQEcxi4n+fzyIP7N8gEPfvLfBt2 qcJ2V7TK+W8AM34KABfCFxlkhlqT/726/zDv5Emfh2uargRpl2zubZcBYT9D8zpHNNAJ RvTJrc91bbq/UaVExWarpVVlfYfZn/GsHTcoAMvLd6gsJcyiUKnI6oPBH81qsWbRQKYo 7yjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IM6PVvBL; 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 d19si2185203pfk.194.2018.02.13.12.33.05; Tue, 13 Feb 2018 12:33:05 -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=IM6PVvBL; 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 S965831AbeBMUdA (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:00 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42031 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965789AbeBMUcy (ORCPT ); Tue, 13 Feb 2018 15:32:54 -0500 Received: by mail-pg0-f68.google.com with SMTP id y8so666150pgr.9 for ; Tue, 13 Feb 2018 12:32:54 -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=aqfOKIUd8Y1UwyLRij4d9JL0cKxu3qmny5GvLSDwxsk=; b=IM6PVvBLeFKzmTSnH0hsMPEmeFYJ0QV/o1Q7Q3q+5C3TkrfcamuQ8B5akP9QDC4lt8 yRJVz+xLv27O8nYAai8SyvEv8/5MAXJl8y5/gjRVZlTcZNrFW7+xLE68GfQs1QN5kpgF VSnTsJBwe1Fhb6yr+ELcLcyFW7AHol4dilZdI= 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=aqfOKIUd8Y1UwyLRij4d9JL0cKxu3qmny5GvLSDwxsk=; b=bb/A/RNDPKJkT3UlkFF9VdIbzeXth/PiGmjvX+9shp7rE7SxdvjkwvrTzJn9fFmgom u/TF0/crza4HpqdSzcKspqSnxOW2d6Okuo+tFZhUUQFK/QcijbkkzsCQdRxxcdY+++uJ PjaO5y2JCIcMZUEgNxXhKhi5vZBlOa9Kjj2wLjwQv8sJSnwaztGvsB2SyLzSlFPK6Lov DwCUBakb0ez8sqXHCIrNNAEV0BZeS3FH23RA3E09kjCyYp6KqtRKuhGglfPai4YG1aRK 3M3KOl/x3t7yPyBE+drxl0zJKKx3IHjQL6RA6/wXqWRlcfkqbX1xOqMN6ADFQY6z85l0 S/PQ== X-Gm-Message-State: APf1xPCaPdOEjNsQCews9UnExsnp29RQ4y6ii6J5TVFLp9P5vhiNtUNW Ppeo1r+D5HXroFbQqkodwyn/Vg== X-Received: by 10.99.123.79 with SMTP id k15mr1954390pgn.173.1518553973609; Tue, 13 Feb 2018 12:32:53 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:52 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 02/10] sched/topology: Adding function partition_sched_domains_locked() Date: Tue, 13 Feb 2018 13:32:39 -0700 Message-Id: <1518553967-20656-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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. No change of functionality is introduced by this patch. Signed-off-by: Mathieu Poirier --- include/linux/sched/topology.h | 10 ++++++++++ kernel/sched/topology.c | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index 26347741ba50..57997caf61b6 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -162,6 +162,10 @@ 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 +211,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 7c744c7425ec..eee721da40fb 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1855,16 +1855,16 @@ 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; lockdep_assert_cpus_held(); - 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(); @@ -1929,7 +1929,17 @@ 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) +{ + lockdep_assert_cpus_held(); + mutex_lock(&sched_domains_mutex); + partition_sched_domains_locked(ndoms_new, doms_new, dattr_new); mutex_unlock(&sched_domains_mutex); } From patchwork Tue Feb 13 20:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128299 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp33484ljc; Tue, 13 Feb 2018 12:34:47 -0800 (PST) X-Google-Smtp-Source: AH8x224ms/B+TuruA0NXbVfSgm48mBqwoUk7bz4JPO67mnnwfq5kUDoXLuwUuyzdFT6wB4I/e+50 X-Received: by 10.98.80.89 with SMTP id e86mr2391179pfb.46.1518554087600; Tue, 13 Feb 2018 12:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554087; cv=none; d=google.com; s=arc-20160816; b=zg4RAaGSmfsQUOupreF7FpfhLS+t4ww8k1EnlhRWccDGUOf5o9H+ojjR8FMQLs35rj t4saZ9GZOEsZaAJ8ITaZ/euivWzEE/P8fVN3Z3qCofqRsJO/7eRjNSEwndG9OT76SCQg 49sJGkdNCyhL0iApU12CSYTndj9QUnFZwZg408AlNMjiyyx/igjmpH3Hg9PAvubGPiB5 lf1O5wzfSGqPouN1p/S3sNfszMJRFuchde6C7v3CQ5gcFFkUi6k+IcVTR83Es0EazrfU LZaxDgosqrUUAohwZZoyaS2PPpvV43lfEyhe0cK+OrQefxlUttk3wuG+AjmRlq8yhLHa gkjA== 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=S3I4UClItunArMEru3vMQ88fmU6Nz0gQ2VdpI9jpZQY=; b=akUbQyUc1M2XBbNBR8Ioz6ys3zXVph/j0lgUzZqASSGZ9EAAXQIaG4cjrWIk2lBb9h ccFIMpbrDoIya9Az3M7JanRz3pfulvtx87XZcCsFGnojCGonZdvR+Fw40fVjQWVGpSK2 2DzPI002fKNs9+3pRjCXIbuHbtAUw8F0AgWBAL1L6B1ycQRMXyLYnkUXAPbOthpbIeZO vXFBFei63SKrNSHUHDts+EshCpMVQWIKAh+FHNoEft2pL0OzIOkCiW/pEsrJGqlg/6iQ /QEkDnZKd/hEGeaNIlazFJOeOQgozw7fkUUA6mzWnYN5hUoR7vAe1N+htX83pFwvrkKH Pziw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FEG0+189; 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 r70si2219359pfk.198.2018.02.13.12.34.47; Tue, 13 Feb 2018 12:34:47 -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=FEG0+189; 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 S965813AbeBMUc6 (ORCPT + 28 others); Tue, 13 Feb 2018 15:32:58 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34889 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965790AbeBMUcz (ORCPT ); Tue, 13 Feb 2018 15:32:55 -0500 Received: by mail-pg0-f65.google.com with SMTP id l131so680129pga.2 for ; Tue, 13 Feb 2018 12:32:55 -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=S3I4UClItunArMEru3vMQ88fmU6Nz0gQ2VdpI9jpZQY=; b=FEG0+189JD6VN92BeoE8zOln/oYsEsbujAq+wLmMjvwxALcbnp1/LnfILBg+60W9pV iK3+6S8YBsEA5OMEi7gnZN7ndczKhp5K0tluAdkwOiO2G/+5/I8OTnBPWD4iYyLEjmri 2K2QUBOnEdGQT7f60KgJCy1rI+DNkhUkg4bUA= 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=S3I4UClItunArMEru3vMQ88fmU6Nz0gQ2VdpI9jpZQY=; b=ISHOoPDGu0ylWRaJh8XhiaViZRWpuZUpoeiHLSmhTL8Sh9PndiyHM1NE2YKy6hsupS w4RrTxq8NRzwCcdgDrMSMboSwLdrhJ8BgpGxVcZhTOW9hmRMwm88yom+3pDYOPGeAi7z E7Ac2xKxKzPbsQO5WjOo56c6DIP7FRH1IfnvoATnnAbtxqn/7PL/JCPSrz7vUQh/N2Ei EyvThJ+GrDS1h7HADVirHGPrUmf9JBN4y0HWN+5raRi+imLVZcJPuSnPuJ4HdsHwj3w5 YLkN49qeRw0bw/XLyV271fkidKcZO78SjzNYihHT+LpO0eEhue07u0OIraqovjzd11CZ 0eNg== X-Gm-Message-State: APf1xPB9F6Y9YkUI9vWpnuzpYg0KkV0V9i9iFfNUByuKajnfbXD2cdEq /L4mvAuCNgwVJM4dcK5ZLMe2WAdFTu4= X-Received: by 10.99.55.65 with SMTP id g1mr1964367pgn.284.1518553975246; Tue, 13 Feb 2018 12:32:55 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:54 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 03/10] sched/core: Streamlining calls to task_rq_unlock() Date: Tue, 13 Feb 2018 13:32:40 -0700 Message-Id: <1518553967-20656-4-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 Calls to task_rq_unlock() are done several times in function __sched_setscheduler(). This is fine when only the rq lock needs to be handled but not so much when other locks come into play. This patch streamline the release of the rq lock so that only one location need to be modified when dealing with more than one lock. No change of functionality is introduced by this patch. Signed-off-by: Mathieu Poirier --- kernel/sched/core.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/kernel/sched/core.c b/kernel/sched/core.c index bf724c1952ea..f727c3d0064c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4189,8 +4189,8 @@ static int __sched_setscheduler(struct task_struct *p, * Changing the policy of the stop threads its a very bad idea: */ if (p == rq->stop) { - task_rq_unlock(rq, p, &rf); - return -EINVAL; + retval = -EINVAL; + goto unlock; } /* @@ -4206,8 +4206,8 @@ static int __sched_setscheduler(struct task_struct *p, goto change; p->sched_reset_on_fork = reset_on_fork; - task_rq_unlock(rq, p, &rf); - return 0; + retval = 0; + goto unlock; } change: @@ -4220,8 +4220,8 @@ static int __sched_setscheduler(struct task_struct *p, if (rt_bandwidth_enabled() && rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0 && !task_group_is_autogroup(task_group(p))) { - task_rq_unlock(rq, p, &rf); - return -EPERM; + retval = -EPERM; + goto unlock; } #endif #ifdef CONFIG_SMP @@ -4236,8 +4236,8 @@ static int __sched_setscheduler(struct task_struct *p, */ if (!cpumask_subset(span, &p->cpus_allowed) || rq->rd->dl_bw.bw == 0) { - task_rq_unlock(rq, p, &rf); - return -EPERM; + retval = -EPERM; + goto unlock; } } #endif @@ -4256,8 +4256,8 @@ static int __sched_setscheduler(struct task_struct *p, * is available. */ if ((dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) { - task_rq_unlock(rq, p, &rf); - return -EBUSY; + retval = -EBUSY; + goto unlock; } p->sched_reset_on_fork = reset_on_fork; @@ -4313,6 +4313,10 @@ static int __sched_setscheduler(struct task_struct *p, preempt_enable(); return 0; + +unlock: + task_rq_unlock(rq, p, &rf); + return retval; } static int _sched_setscheduler(struct task_struct *p, int policy, From patchwork Tue Feb 13 20:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128300 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp33654ljc; Tue, 13 Feb 2018 12:35:00 -0800 (PST) X-Google-Smtp-Source: AH8x22566Le97uVWa8yRteNN57Ts24DFUIGjRlzwnqaZV3k9GLxQwMDmZqrBPUvoKWULtgWLRVHa X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr2223776pln.345.1518554100088; Tue, 13 Feb 2018 12:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554100; cv=none; d=google.com; s=arc-20160816; b=SD4XFuRhutkkUsT8nq52zd7JHJoX2tyIj/m2FemiLsKCFIbykBdjQsBMv0jSqVIHhp p45inj5yvs7QpJoGq3/NVFahKxufOAZ97aTlL3gNDoswBVbi6fz73LWxbvokRGnuXPjt WVPGmgsOpG41E3gaXCIZxjWIkXGZXFrOANd8SDtRr1KHyxkFdE+5OL5VPbJhY36vQASs hJ6zjfRBoaDkr0ahEhHIjkxN1Se8R/68f0VyJqiDmijnFSm/gay2uDb2ZGHqs8ajopb2 IlESJN0PNNNXlkc2bbvwGdHX1sfJjsVsateb1HK/ifmEO5OyGgYqXPPlbFuOqte9S9Vh s0bQ== 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=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=TZvCSOHTGRyHBBLdOlYTvXkTL5l66uTc/KHtsBO2bHI+5D03NEkvkz5DD/JdV6ddae yEbeztkfrgosy9f59ZUz6a1N3OAaeUOCZbORxb70aoEezapQYjjkqdgSTwwLsaQfuWLD CNw4eUxY0t3YnW1KaKFfwsQV7aDl0CG+xCF52mwvHHLejJe4n9S4r9ThDShrmkXSKWoP QUWPPjqynCtg+/Tm9QTtFwfMlFdAb5DTcnpMCSK9A5PJNMjIHsg4mymuZQ3Q2NXlKDW/ PhPYnxDB9KQ6WqqKUgYkCwLkno6ue+38Vudnid0LskeeGMhegd0uSCtcHGbVSS8qDu5M rpfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KeDDm7Th; 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 t133si281281pgc.158.2018.02.13.12.34.59; Tue, 13 Feb 2018 12:35:00 -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=KeDDm7Th; 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 S965918AbeBMUe5 (ORCPT + 28 others); Tue, 13 Feb 2018 15:34:57 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33687 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965795AbeBMUc5 (ORCPT ); Tue, 13 Feb 2018 15:32:57 -0500 Received: by mail-pg0-f66.google.com with SMTP id g12so684354pgs.0 for ; Tue, 13 Feb 2018 12:32:57 -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=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=KeDDm7ThA8dMcMlwVymErZqolbPxpadLCV0q56Uh098JOTh9Tzv+GCd8Xnqct8bd8r 10/e+HGlSwMcb/FmkhUis0NGuViB+I8jcQtjEzwquy7BzVKdYrEz1WO/+mDLLt6SDSML NbJgYPR06XBvz6mq6sOAY2dBUyqjQekR9NrZY= 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=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=k/OzTSoxFgFDowYAv228BNw+YijCM2oYuJJwyhzk4o3XtYE2GUo4RET1saGhtsT/kx wS6qF7jfjAse4dRjJ343dAiFGQfmB8Tm7MAR/q0BoC40uCwulTQLf3LUa8nTNZR6oT0F P3QP8w2W90fq0tm9ii7HzpcgvWMcMTgZ4d2s86YKfCr7jsNZuA4HUgzIoAhXXisg4UfP ESHM5r06lb9cOi1p2JNa7LkINqlnoVma9nX5/GvjGvhD01ZQoY51ywtJ9z8EwYvtctBX nxY2iEfkqM3rzccjtg/cqEcq3uEiFYrDBltH4Ga8/BSVq7Vre0lDme4j9JIsGk7w6NBv bwTA== X-Gm-Message-State: APf1xPAk2QQSU9zkVD3v+8V4gf3EJMhk+Rm+n2SHAS7g83nfnCMnwyJ3 zVryrJ2qBTX1TvfC7G29Lz9vIg== X-Received: by 10.101.88.205 with SMTP id e13mr1437491pgu.121.1518553977031; Tue, 13 Feb 2018 12:32:57 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:56 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 04/10] sched/core: Prevent race condition between cpuset and __sched_setscheduler() Date: Tue, 13 Feb 2018 13:32:41 -0700 Message-Id: <1518553967-20656-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 No synchronisation mechanism exist between the cpuset subsystem and calls to function __sched_setscheduler(). As such it is possible that new root domains are created on the cpuset side while a deadline acceptance test is carried out in __sched_setscheduler(), leading to a potential oversell of CPU bandwidth. By making available the cpuset_mutex to the core scheduler it is possible to prevent situations such as the one described above from happening. Signed-off-by: Mathieu Poirier --- include/linux/cpuset.h | 6 ++++++ kernel/cgroup/cpuset.c | 16 ++++++++++++++++ kernel/sched/core.c | 9 +++++++++ 3 files changed, 31 insertions(+) -- 2.7.4 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 934633a05d20..4bbb3f5a3020 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -55,6 +55,8 @@ extern void cpuset_init_smp(void); extern void cpuset_force_rebuild(void); extern void cpuset_update_active_cpus(void); extern void cpuset_wait_for_hotplug(void); +extern void cpuset_lock(void); +extern void cpuset_unlock(void); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); extern void cpuset_cpus_allowed_fallback(struct task_struct *p); extern nodemask_t cpuset_mems_allowed(struct task_struct *p); @@ -176,6 +178,10 @@ static inline void cpuset_update_active_cpus(void) static inline void cpuset_wait_for_hotplug(void) { } +static inline void cpuset_lock(void) { } + +static inline void cpuset_unlock(void) { } + static inline void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask) { diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d18c72e83de4..41f8391640e6 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2410,6 +2410,22 @@ void __init cpuset_init_smp(void) } /** + * cpuset_lock - Grab the cpuset_mutex from another subsysytem + */ +void cpuset_lock(void) +{ + mutex_lock(&cpuset_mutex); +} + +/** + * cpuset_unlock - Release the cpuset_mutex from another subsysytem + */ +void cpuset_unlock(void) +{ + mutex_unlock(&cpuset_mutex); +} + +/** * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed. * @pmask: pointer to struct cpumask variable to receive cpus_allowed set. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f727c3d0064c..0d8badcf1f0f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4176,6 +4176,13 @@ static int __sched_setscheduler(struct task_struct *p, } /* + * Make sure we don't race with the cpuset subsystem where root + * domains can be rebuilt or modified while operations like DL + * admission checks are carried out. + */ + cpuset_lock(); + + /* * Make sure no PI-waiters arrive (or leave) while we are * changing the priority of the task: * @@ -4247,6 +4254,7 @@ static int __sched_setscheduler(struct task_struct *p, if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) { policy = oldpolicy = -1; task_rq_unlock(rq, p, &rf); + cpuset_unlock(); goto recheck; } @@ -4316,6 +4324,7 @@ static int __sched_setscheduler(struct task_struct *p, unlock: task_rq_unlock(rq, p, &rf); + cpuset_unlock(); return retval; } From patchwork Tue Feb 13 20:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128298 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp33177ljc; Tue, 13 Feb 2018 12:34:19 -0800 (PST) X-Google-Smtp-Source: AH8x226iIE/ADUzUiLSO1xRGJ8OeiygNJhPqV5f6wdtze3gqdTuOwTNCCcNlMcQzIKS+Vo39Sc0X X-Received: by 2002:a17:902:bb8e:: with SMTP id m14-v6mr569604pls.423.1518554059740; Tue, 13 Feb 2018 12:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554059; cv=none; d=google.com; s=arc-20160816; b=CxBGM6SLRs+Th/o3PMGuDSVhj+wMfNKRbs064uWfV+ii/0RfibMWwvpUOZO+iH7WJN jwepk3ACe5LCUpLXXB63NTcrLMxuGIzDnRhOLcAov4kSUjSIFSyzAsWzu5jRsdud1A2E k6AtmezVLu+CYOE3bzU3K3/6lSgOjrXTuau/deYnb9OfH0MakqZIC52SqCeTN/0E8G1G EJEk9jPgblvAom+bi3Uc8m12vU8aIu30wlQOVHs827R6gp7tgYQ4TDsJ8qpdhC/rODS7 QRg3tgw0IP4yDi/KX6PzAZ+Gb7KBYOBk15yU4akxs6TBfn0XGwHw+itboQ0oWRb64Iva jYfQ== 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=RpRuSxilgCH4LvoCdF6+8SofEdCVGn9nDBpdua5XPeg=; b=okE2JBmvANDQIydiLB/Sgw8Jr2kpytxB9j2MUS88GsCn0n3B+VfVcjDMtTVfV8gyCw 9MFxOlhvmVb0nsitH1undXHoMwu36oxR48VQOFYXmudreEaGds7J+Ky5y7dn9H9W9zoN iI0gBePPs6ouk480lMPeiDwf2meVp0HaxguGStxEsh/e106olocSpCJXpBQkSuW1KEiT CMSB2TD7lAzpaKf+q98gDt2VKksh5cThvX6n4YH4XCxnUAzWo0lVv1AEOPMtYhQCsjFm T4xyZ+omA3jPmusqEZtbaMHFWKS6exz2X7/XifaBfmboTklgC28nImG6KYCiPtZJvFmv 1jbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZyuffiXf; 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 69-v6si7891058plc.814.2018.02.13.12.34.19; Tue, 13 Feb 2018 12:34:19 -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=ZyuffiXf; 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 S965914AbeBMUeQ (ORCPT + 28 others); Tue, 13 Feb 2018 15:34:16 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41843 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965816AbeBMUc7 (ORCPT ); Tue, 13 Feb 2018 15:32:59 -0500 Received: by mail-pg0-f67.google.com with SMTP id t4so667062pgp.8 for ; Tue, 13 Feb 2018 12:32:59 -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=RpRuSxilgCH4LvoCdF6+8SofEdCVGn9nDBpdua5XPeg=; b=ZyuffiXfo5iEz4uAcBgVh9AbjJH/5OUzhigoxN2CbbuxFHdrROm2U7MPr4IvGUJOk/ cTyZ7LxGXqGzrfnj4ITSxP8pzQb4/w4Ldb/Y9PLCnBEbcfNmliQ9PhH6wfw5+X4MXgKI lVY+kt6t1HwJFSh02q7haJn8rjheinsPeh9rk= 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=RpRuSxilgCH4LvoCdF6+8SofEdCVGn9nDBpdua5XPeg=; b=ehSUMK9h9M/SydciXR9COigyqn0fKZ74rfXllstajFoimSytxx/O7urZjhhpxDY6JL rE/FseKjUNqo4RIrpPvie2Y40FFq7tenGKDd5jFs/fL5BxEaky7WJFDPTt9TUh+8Hrch UavAbXDOMEre21dDrWOc7syilEa0R+F+vW19zncmNBzYM3VFkCpK+FSLouqjnPeRM0Q7 W4JfcUfi2gx1v8Iv0isnxVNFiucWGuU4sG6BD3Vl2eLtTahAIH/N70Z4ltP5truxPMdp 60o3HdZzPTNu+3y5WF/MUZ7/gNuRj2zQ1Q2k8+yqE4sXvjj2Te/05ACNfnstZN+EiSy6 g2SQ== X-Gm-Message-State: APf1xPDs3gui3NrtOq9vsbHN5AdadjXgKMs2WJuQBQlSTsi8wyHZGrFi AcIbqd/DV9gJZ7ZEohMsiTx+tQ== X-Received: by 10.98.103.83 with SMTP id b80mr2415502pfc.12.1518553978835; Tue, 13 Feb 2018 12:32:58 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:57 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 05/10] cpuset: Rebuild root domain deadline accounting information Date: Tue, 13 Feb 2018 13:32:42 -0700 Message-Id: <1518553967-20656-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 | 5 ++++ 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, 119 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/include/linux/sched.h b/include/linux/sched.h index b161ef8a902e..b9bd7da8dc85 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -239,6 +239,11 @@ struct vtime { u64 gtime; }; +#ifdef CONFIG_SMP +extern struct root_domain def_root_domain; +extern struct mutex sched_domains_mutex; +#endif + 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 41f8391640e6..d8108030b754 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 9bb0e0c412ec..8eb508cf1990 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2269,6 +2269,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 fb5fc458547f..8aba192d4d17 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -685,9 +685,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 eee721da40fb..3210ded386ba 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 @@ -1889,8 +1890,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 Tue Feb 13 20:32:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128293 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp32391ljc; Tue, 13 Feb 2018 12:33:09 -0800 (PST) X-Google-Smtp-Source: AH8x224o4vL1vyXSBCPKJAMNOcmh6iSoexyQAeJI1ozQ9UHfZm694LaLj3rVv4mrHTpiJwwwlMDl X-Received: by 10.98.224.24 with SMTP id f24mr2359696pfh.157.1518553989032; Tue, 13 Feb 2018 12:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518553989; cv=none; d=google.com; s=arc-20160816; b=iJCce96heL4WnF6vdkr8XNacUatCjunQPkWcrJxNpbnaNbIfmhU1uj4ET7Y3/TzfHm DzYTU6p8gOWripYqspBoQebMNKqAMGI79JFMWt8LDO8RVRFDdlCCsjgdXpw+xAMrwQlQ JQQZ/lbh0zx0UTT1iwDMILCZ7gmI9Scd0d5rmRpHUnCDIWf1gB7wh7b7prnKi/Pp/6Uy RVKUr97Qq2piWOos3wl9uDu7QN7iHV2MK+pzdxWHmDPDK9Rgy9YGuP+UfBvl+LswOyay Aa35mO1kKxxd14bat64Jo4U+r53FJV/NSwyL4TsLt3qptnmY9TXVdpHd3FG5rCXxIiEZ o7eQ== 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=UiNYSXlI7VQ3ceWY8eltwO5YQlhRrMN/ywnq3UC6geM=; b=eTkMCIET7YZj5KyDNMd2Vo4YoDFG51TF08nzw3joeJCWuyoDpquHs+aCJSfxzM0CIR CwQNUKjBFgNyJ3CmCHw/N3Y/08LBtrXYeYJtreQhRr+29apSR8jlvb1rYgZH8b4Lvmat zjHL3MHYqfzh++DRxOFfq4Zs0e6HXJ5q1LkHe6uLnofvD9tHaVqa/ID8lp+z5imddHPJ vJz/n/9FUdhhInewNo6dOHYnBvEcfpyTzfRWGbPFwD/077W68/ZgHOYLJmOP453LEpwb r4n5C3e6hIem9RpXROmxmNUoJ6JnXNcjrOEhT+dCYEngXcjRC/ZPgRvAqaWfF7GM1YuS iN3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fEsj0b4b; 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 i70si1599949pgc.148.2018.02.13.12.33.08; Tue, 13 Feb 2018 12:33:09 -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=fEsj0b4b; 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 S965851AbeBMUdE (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:04 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41848 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965789AbeBMUdB (ORCPT ); Tue, 13 Feb 2018 15:33:01 -0500 Received: by mail-pg0-f65.google.com with SMTP id t4so667122pgp.8 for ; Tue, 13 Feb 2018 12:33:00 -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=UiNYSXlI7VQ3ceWY8eltwO5YQlhRrMN/ywnq3UC6geM=; b=fEsj0b4bFOXf5b4A57cwUpm7uAXJ7n2KbBPx6KJIQNI3bss1EX3uLirSofvpXAC5Vi zenUEf4RfO87M1dImm43IQuGEYQRfe4yl1FMe/Im49A6/YoF5i2wMQFX8krpx0qPBhQ5 JCO21PlGdCu7BtQxtIxyS49YMytJWi3+Ot7KE= 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=UiNYSXlI7VQ3ceWY8eltwO5YQlhRrMN/ywnq3UC6geM=; b=NgYTVOrvXtqV4nTJPqCItS6zcuRMlKfpAWwevfIaA+AQPQ+2q6ly/tn10/vnslueHS 3V7c8mGPPDbBn4c1WGbrXjU9h6GfrmTFRdlDupj6qXfxptwXkX402adPqIQg0MFlFpt6 qskrJ99HHKyRCLW20CfY5HQoH7UWF3bj2U6oRclwScKqSM8qGeCsSTCfzWG+Hx1t1vXq KH4mIroHBNZ3ar+IhxePI8GbO8BbGyU/I2ySGJn0eoFpf/6OKNK2nzkEJxcsm9uSngC/ HLE+VGxUKM8CsVfTcE7K2V60YJyngC983YUmtK99qdoGtCNmb4EoI8ytJL7jsnSGMvYK FHew== X-Gm-Message-State: APf1xPCahK38sKyjX6KePL2vB7C0xx6XHBOsnNV3Ls9TUKslspWlfQbg aZbCEj6LYFK/qUe+c237Yo9sSdCHV+s= X-Received: by 10.98.214.153 with SMTP id a25mr2384379pfl.173.1518553980526; Tue, 13 Feb 2018 12:33:00 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:59 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 06/10] sched/deadline: Keep new DL task within root domain's boundary Date: Tue, 13 Feb 2018 13:32:43 -0700 Message-Id: <1518553967-20656-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 domain 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 we have a system where the cpuset.sched_load_balance flag of the root cpuset has been set to 0 and the 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, i.e, 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 (root) 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 of 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 | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+) -- 2.7.4 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 4bbb3f5a3020..f6a9051de907 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_lock(void); extern void cpuset_unlock(void); +extern bool cpuset_cpus_match_task(struct task_struct *tsk); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); extern void cpuset_cpus_allowed_fallback(struct task_struct *p); extern nodemask_t cpuset_mems_allowed(struct task_struct *p); @@ -182,6 +183,11 @@ static inline void cpuset_lock(void) { } static inline void cpuset_unlock(void) { } +static inline bool cpuset_cpus_match_task(struct task_struct *tsk) +{ + return true; +} + static inline void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask) { diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d8108030b754..45a5035ae601 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2487,6 +2487,29 @@ void cpuset_unlock(void) } /** + * 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; +} + +/** * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed. * @pmask: pointer to struct cpumask variable to receive cpus_allowed set. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0d8badcf1f0f..b930857f4d14 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4237,6 +4237,26 @@ static int __sched_setscheduler(struct task_struct *p, cpumask_t *span = rq->rd->span; /* + * 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 (!cpumask_equal(&p->cpus_allowed, span) || + !cpuset_cpus_match_task(p)) { + retval = -EPERM; + goto unlock; + } + + /* * Don't allow tasks with an affinity mask smaller than * the entire root_domain to become SCHED_DEADLINE. We * will also fail if there's no bandwidth available. From patchwork Tue Feb 13 20:32:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128297 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp33129ljc; Tue, 13 Feb 2018 12:34:15 -0800 (PST) X-Google-Smtp-Source: AH8x226Nvz12ftb5cTSLvC39h2DirAyA22xwvwZ9VbYX9pxps01u1wjswHuStZQ3/uRRm5O4mWgn X-Received: by 10.99.145.199 with SMTP id l190mr1854504pge.397.1518554055558; Tue, 13 Feb 2018 12:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554055; cv=none; d=google.com; s=arc-20160816; b=n3W9CQ0f1AYx2CSup5O39Du7z2H1ttbCctp+XYkSbDc4pOm6Ta1w/n3ELe9B8/z2y4 Bhi6BXCp9THIjh6x2AIj1jg01AKWh+16NWFodmHaDbYZ1cT4OBBzvl7WnJdtrBhJbUGG Yi8zU1qYD2LZtCxpVAcFt0Bp/+0WTBZPy4GjDbFqrAeVTPQUhaux0B4kJDukQUqMHsBS 9lNAU6IeRxNSdHxeuvm4XTryDJ1v+iNg7vMNQVStbgKEStIstjfKO7ksH/+uWEYLERU1 UdJsmpbelZz1BE8755hJdr633ZwrT3gb4cf4YJT4Ax957e4OOoZg8H1G7vTf1ep7Hum0 eZ5A== 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=uq46gIPTMMHr/Kat4X5lgfFhxL9zwh8U+r4MofJlGJE=; b=lzHfjASx0qzu9vzyZx+nShuvFsBfjAXSuYVU904sNnpD1Ey/QeaIc29keCM7TLLjvq JgiNEQnc070wjDkm6v7IyELCep1HZI4Beo0lZ3kWmucs0XaXfDljvAjKMSmmIcx1RjWJ fSxTs85lw7zGKIZ1eTQcV1/lTFFda/ZZ/S4p7WaOsc6QPL9kIuy1uoADZft1p1QpER+c bfyapybbvhQj1xERAenHTTXKkv6O02wUnUgb7TLQk+J4MBAlw3t1BI+qurwvigod5/Vq PWuhHJwMr6BMaPkQV58cISCJBlc5QBIh41YEfJy2fdr7WQSIOPVfJC6wEoVcYMUpKNZR QQpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BDHATBqF; 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 bj9-v6si342395plb.464.2018.02.13.12.33.59; Tue, 13 Feb 2018 12:34:15 -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=BDHATBqF; 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 S965906AbeBMUd4 (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:56 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34915 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965835AbeBMUdD (ORCPT ); Tue, 13 Feb 2018 15:33:03 -0500 Received: by mail-pg0-f68.google.com with SMTP id l131so680400pga.2 for ; Tue, 13 Feb 2018 12:33:02 -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=uq46gIPTMMHr/Kat4X5lgfFhxL9zwh8U+r4MofJlGJE=; b=BDHATBqFc0sPhc0T3pEQV4hcu+EyeElcrfCkPm8ZLX5bC+E8dC1qDaBXcPf3DIHcud Ncl6sQ6ipH+y05ptMPKTT0WUgMnsruggG5mWYb8VsWfFUkh9RHYV+qVuWzIZuL8Hx6EU f8iIOUx+ybCZkiFKDeOr2fIeQTGvsxYgvECeI= 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=uq46gIPTMMHr/Kat4X5lgfFhxL9zwh8U+r4MofJlGJE=; b=o4Ll36U6jCEM4zQPPtkFcZaeIyitTyaGbK58heHNyMIDQAv+/WK4o1z85mDPa6Jinb bhrksM1OiLgmG7iRoFsuk3iGt8gFdeezfxxqeNTHAGt0WdLJmkR2RI9IEeiOb/jvg5CX 8CFI4RG7K8lfvvnw5bpK0hmC1+45L4naA01H7VT0l+DmdDWPIG43sY0piXUDHOf23cRW uUOwFZrh5W8ePd4q+xCEEoix6qjdgGfcPEX1pngBGo7xv2owg3owApqld7/k3rmTjupb 96EAU+M9Y+IpprA5t1jpitOIKfUAgZU1Fdag5NY3aRmTYgI/oOH6OU96hzjSiL7kuzVs 1f/A== X-Gm-Message-State: APf1xPCO1tty/M82bJmZpRERKAfBADNbBoQHO1SKgGMhbhmoC75lcdLJ 2P60A7q528wo4/89ViDAaoRJLg== X-Received: by 10.98.204.75 with SMTP id a72mr2403665pfg.33.1518553982168; Tue, 13 Feb 2018 12:33:02 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.33.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:33:01 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 07/10] cgroup: Constrain 'sched_load_balance' flag when DL tasks are present Date: Tue, 13 Feb 2018 13:32:44 -0700 Message-Id: <1518553967-20656-8-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 45a5035ae601..4f5e8bac5337 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 Tue Feb 13 20:32:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128295 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp32493ljc; Tue, 13 Feb 2018 12:33:18 -0800 (PST) X-Google-Smtp-Source: AH8x227TwvGd8adbx2wl7zwVNtP0aNJ7/WihYsMUVk2IG6HoXWIxLnbsONadFTyT1DEXw7poDkX6 X-Received: by 2002:a17:902:a984:: with SMTP id bh4-v6mr2174479plb.95.1518553998012; Tue, 13 Feb 2018 12:33:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518553998; cv=none; d=google.com; s=arc-20160816; b=0vM3WmWCdGmA4QyeiCJndgUH48mtwB/eDYSQ1ZWLXkjA9npVnnOAwFvCOSYOQi7VDa cEzUXbN3MeIhV0lRR/eQ2cvsX6zISHgdxysLDUncenAruf16kIbRuM11b9FgRRMFbTDa rWMG5d+6C4Za2OZrYm0SytO3+JLIZHHWZCL+zHSj1qibeWWzQu5E0O1IgbLlLbO06fCf fwuVC52f/K6vjKIRKQmnW9Yh3Yssa+Bp1oW40b/+xnOvCXZjMM+uRlRchKkJSAFFUDK0 I10Tqq5XSE93CIKUUn842x4Ckb+lMecvDecIOB/v0G2rxdral2tlqaGIcklQ3XNMXIXn /egg== 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=oUUAzyuPxc2AWJT2EOSXQAEFlSz5Oal6yF3Vntlh3d8=; b=kRXy88/Fd1JLzklmMsmlBUlWTQkX9RZuH1mXIShZ2t9ASmqmL1lc1cM8+IdY/iroIw BDCZMYqX4d3UL9srHIjcFaSMOkMgCRZ61TblsTr4Vqup5+QEJCUveOV2Xe/bfUZTWCHV 3+BU9dOtmVvgbTmtEADoG9H34Mtb7ibPaAPmtmvLFnioB4JHcUVIX6OI6vSuRPCqrmZ/ AbFaGiS0E2b5uyH+xO5R2EXU0d9blgNblOurAvVX5JzTttUV5+VKSJXrFw0hIDJu/4pz DOAqaqk3RkTAnMdnyZ/24PdhBtc8f1/tNGWoVr1Es7GepJbBZeBMA5hJtkg/Zqw5j2qg tqFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fhvNaP3V; 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 g5si171289pgp.433.2018.02.13.12.33.17; Tue, 13 Feb 2018 12:33:17 -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=fhvNaP3V; 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 S965882AbeBMUdM (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:12 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41680 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965846AbeBMUdE (ORCPT ); Tue, 13 Feb 2018 15:33:04 -0500 Received: by mail-pl0-f68.google.com with SMTP id k8so7191043pli.8 for ; Tue, 13 Feb 2018 12:33:04 -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=oUUAzyuPxc2AWJT2EOSXQAEFlSz5Oal6yF3Vntlh3d8=; b=fhvNaP3VFNS+rKp8IezXtyq1ExfwA0JvnoeHnWOcdBYWAd9+76CSseGsgm/PHlqzvn tNSinUrTQ8VDhzOO7GUN2aCMgi2/Q+otsAcU9nj3To93RM6I+47a/zTHyQKdlX88xfYw qatqfzmWizXlTGteL+xWX+9YeyDoaP800lQf0= 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=oUUAzyuPxc2AWJT2EOSXQAEFlSz5Oal6yF3Vntlh3d8=; b=o2NzcDhmPgdc5ctEPkCSqts7QGDW8F5iDnKA1LKMcAA+tnPfHkW+TbxemW6o5e5kvg I70+aJ2XOdhJJ2G8tErXH4QWwZScOEtpTuMozsFTdJ8NtzNhoTe4gnOJ4gA7GOGOced4 cKYj/E6wofJmCcBqqa6UtdeDroZUEp6VQlRmMkwLnt750qKk5R0NdILfD+RJZMBVmb/d O9mCN4qjgJYAZuA7ffHnSLyoGwOBMy1SRS3iMVholEVRNmybtX+jZj8Ec6nKZuZkrwmO b+DjTtMdqXDbwVyutIF/upF6osJ1VVh17v24RVxD7k5Kl9Ft/F0We6nCytxxqMC6joxA Ys3w== X-Gm-Message-State: APf1xPAtRjspqa7cVzqx18avgyigzTWqzluPfq/ulPO7D1qklehJFUvJ CIm+9E2pKcb72r+trpEJwKw5ng== X-Received: by 2002:a17:902:b484:: with SMTP id y4-v6mr2173272plr.89.1518553983767; Tue, 13 Feb 2018 12:33:03 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:33:03 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 08/10] cgroup: Constrain the addition of CPUs to a new CPUset Date: Tue, 13 Feb 2018 13:32:45 -0700 Message-Id: <1518553967-20656-9-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 4f5e8bac5337..4c1b71608c23 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,11 @@ 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); + +out: return ret; } From patchwork Tue Feb 13 20:32:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128294 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp32460ljc; Tue, 13 Feb 2018 12:33:13 -0800 (PST) X-Google-Smtp-Source: AH8x227zBOBzyyJwzevQr5BJoDKubUl2Fae8PbDY5M4nilCuVpWabg2iYOYzoRjvJ+Aq8Lg3pI0d X-Received: by 10.99.123.12 with SMTP id w12mr1848013pgc.405.1518553993739; Tue, 13 Feb 2018 12:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518553993; cv=none; d=google.com; s=arc-20160816; b=kfcqjU0IdbP24YbFb9hgTvmYruPp4dn+ToPKCY8UWGhhZcDeEznuJJaQRqfj6CVZ7B Hlz0tA6B67sR8MLSEtpX6jukrNGE/pZLdhwZP25q3UymA4rdCiZOsjpJDuk5Ky/AZk9j kwCPrBgE7K0ecSfo+RpSgQ9CiJZxAPnybu6tP0+v0LoEq4iCwZWxUFIJ8TnVk5ifDfkB DfLEM/vM2JmOR05iWOmafK67OsUWfR9fSpBq2bzdtnTRkVkEzfexaK6n8a6Z72qldFDu dmn1wdz/pjV5S9L2YhoB7LtQxi8joG1uOPG83Uub4lTWofe5/hldhskvrpkApjs6+PlT 4jAA== 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=oO7ETIAHJvP4bmC3XeX+DrkDkVpYJsA7c39rYbRV7Qc=; b=vUJGorfm4di0BTkKMVJCyEH7WiiwuZBlUpVR3oZjkWwmrhEp+3VsyLBtHA3yVBH4Md 8xMw+vHJhsCODsGf9sBc62fg84Q6OxD9A1lYKAiB4Lc3whELb6FZpKqOD2QGVJQuIWbK bIUHMkLLQdEogUdQscwhq4C61fozZIcIqsbm5xPjxzwGi+ZieDvlKkNYjepQGVtjMiVC Dk/Rww4aZB3yKTmvwp3QmCvWpHl6y5x51V10cmJVKcckhK8dN8AieQRgdR5J2xDO6Xtw zxlf1k+lf/BCzJisDs6Nrk5yqSasrAuwoq5YAjff4RbitP3YM7/8//i3qgeXHzSINdR7 SU5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXNG1elb; 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 b65si1113993pfl.179.2018.02.13.12.33.13; Tue, 13 Feb 2018 12:33:13 -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=PXNG1elb; 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 S965868AbeBMUdK (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:10 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44530 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965789AbeBMUdG (ORCPT ); Tue, 13 Feb 2018 15:33:06 -0500 Received: by mail-pl0-f67.google.com with SMTP id w21so205524plp.11 for ; Tue, 13 Feb 2018 12:33:05 -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=oO7ETIAHJvP4bmC3XeX+DrkDkVpYJsA7c39rYbRV7Qc=; b=PXNG1elbWSLD8EY662YNAvJfv6PKwdRA9rGyUddZR8bccgwb8lzZfcrKN0AQ0XAC6R FBhflkngS7BUBHqHF54ZekNLk03a5L+n7bYzpLNCQALygv7QuDlMbRcTWtcP00Zy/SnV 00du0m/PYo/DZBElLyo3Q0YUnB321xbV4vPtw= 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=oO7ETIAHJvP4bmC3XeX+DrkDkVpYJsA7c39rYbRV7Qc=; b=m6ltWxFIiusBdipMc2Mvqp7Z3SfEE9ya0e6PIo11jvI2kv3OHikg17QnZ/58ESOvDx QNwjQJGHULNFnKmL2t+aSVdS+kS/U6dCDBpXhTHd71GFdz7C2M2aTWty2UIUYOwkBu1m 540xpY5dP32xyYa9D/cV0Yp0mi+Pbdiwfw7pengTA+Megsjh1yBLpJzByvrUcKji9fuy EOLC5o9q3A0oH4UHSKr2rkRGnTVhtFfJVAcAV2bTDUNZkzLqXSiT5/kpemwePvDZmFMb jAT760dc3PUzQn4S9EIVd3lBnmQgVi1CKTpxunJZgY+C+hHroAQV8NyTKoYOJthJ7/OF aBGw== X-Gm-Message-State: APf1xPCu19pPGKhtrg1hyyk8uo8OVBSduiO8xeuBdLs+3Oo9g8EvKy1S kFuLby2uENtrfvMFtZ9UpyGlJw== X-Received: by 2002:a17:902:6843:: with SMTP id f3-v6mr2183743pln.182.1518553985400; Tue, 13 Feb 2018 12:33:05 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.33.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:33:04 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 09/10] sched/core: Don't change the affinity of DL tasks Date: Tue, 13 Feb 2018 13:32:46 -0700 Message-Id: <1518553967-20656-10-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 b930857f4d14..7a265478d873 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4773,15 +4773,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 Tue Feb 13 20:32:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128296 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp32759ljc; Tue, 13 Feb 2018 12:33:42 -0800 (PST) X-Google-Smtp-Source: AH8x226xu2f3AKMvj4ZagFVAKLGYE1+qdXINGz6s8ZS6SkDRAJtHfaYhhHkqvXaUtyPdp3tjAPi+ X-Received: by 10.99.123.12 with SMTP id w12mr1848767pgc.405.1518554021907; Tue, 13 Feb 2018 12:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554021; cv=none; d=google.com; s=arc-20160816; b=qGmNXxelRDQuFdLNgWgPiDq3WCcbgXa0Ew8E10sN9tlE0ZUhjndXKFzO3NRdgUadNy 8HGn0RPJcCI7Z2UK5+5vB3RqBSZLjWodNfHqOVXZUooN3p1Em8TrI/dqhgeCR2ND1QJM PB/6uZxyGob/W53P2wmRPYYSczxfQQRVDiDvT3srL/TQ6Aztol8nyxXZft4KI4z0IxeP BAcbR+hzKaOl0eOvjK26W7fi6ItXryY3fBtpdIvOBHkvSQjQkFnGXFnDE/+9HXWuXnmW 3cRfHJh8Bhyy0gUrFfUqHi1NENCO17CYvUcJxFINtn8jEhXCiZFasTXNa/bjoysM5RR+ D1jw== 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=UbhPA4pshwFydxif8sqRTcHzvw2HfoMH+EbQHDwykcA=; b=HKlZRvO9TjYBuuWUrvXwi1bv58KDZt8OqDfMS6fxVtekzNWVOOFgR4pawFhDbwQq/1 m6uQibqLWmN1ZmaN3wLQKMqGQtEc+ogbCQa7q3uJ4l+AU/cjnnstj/BRPmrl79E2dHUP aTYkArEmYv4nEKdJkaLFSu2mt6XivYDTWydgjmDi+ad2dtHr+JnNonZnMCS3zhmRmPgH JnMkBtHvcVZUHjCUBkGvlxaZ+DVEQc78yPpcafZEbwaUa8OEGXmDuggzEsrJ27GE6Kxx x8tH32NDl2aU8GEjJUIz5fopdeitGRiXSa1QBI/JxkWwZQf0RsaTfC6WAJARkRD5D54r c2JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DVCvk9Zg; 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 71-v6si117407plc.713.2018.02.13.12.33.41; Tue, 13 Feb 2018 12:33:41 -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=DVCvk9Zg; 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 S965894AbeBMUdh (ORCPT + 28 others); Tue, 13 Feb 2018 15:33:37 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40195 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965854AbeBMUdH (ORCPT ); Tue, 13 Feb 2018 15:33:07 -0500 Received: by mail-pl0-f67.google.com with SMTP id g18so7202326plo.7 for ; Tue, 13 Feb 2018 12:33:07 -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=UbhPA4pshwFydxif8sqRTcHzvw2HfoMH+EbQHDwykcA=; b=DVCvk9ZgdcQD0+NZcisAYqDjgZApKtpzarE0SHhAEP+eCsvDNE7jRWw+vziFuo//fK Gqe9w9iZ9w/L7PwaNXVeK+be+4JCB81gW+QTZKEdFOiK0tvEGXbOFsjtuSClYkzJwE78 Elgeik8iROxXblraNm/mLY5KbNAQxq+8WSBu8= 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=UbhPA4pshwFydxif8sqRTcHzvw2HfoMH+EbQHDwykcA=; b=HssF45D2wVCLv9fyDC3p2bSe857UfsE1IhA3Ix+Cf7XxnBf1QXIf6RHM6ZCXftaCmb qD7dPNwOY/mHY2Ipb4fNpwjb+OjOTymIYAGSGoGPeyqT2KYhBWNlLAGdk1p/CR3De0F1 uLQSu/+NhRwBG5foRTmBaugsMUPKO2PlxnsDij11nNQzjGsuytxvgMQjI0+9uQiW7+n0 eNzS52XzikgUx617LIgUhH8VOTmR0sjxWGjXz4j0QPZb2wATyQAPSaGj/DEF/pWiCPhE T2J689ulDSmsJYqOwJcghiKw+9qI2pHTN3NxWCNQEg9mWwKWc9gydAtf9neldu0W+PGX l9Kw== X-Gm-Message-State: APf1xPC875uoIfmaWcjr46Zac8uLemw4cXM02foHeeKoE+nw2y2v0kJ3 IR/wNC4vNA8mCVrVAW5StbKMRw== X-Received: by 2002:a17:902:560f:: with SMTP id h15-v6mr2207318pli.302.1518553987193; Tue, 13 Feb 2018 12:33:07 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.33.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:33:06 -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, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 10/10] sched/deadline: Prevent CPU hotplug operation if DL task on CPU Date: Tue, 13 Feb 2018 13:32:47 -0700 Message-Id: <1518553967-20656-11-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-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 8eb508cf1990..c46aaa7c3569 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2741,11 +2741,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; }