From patchwork Thu Jan 17 08:47:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 155804 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1699839jaa; Thu, 17 Jan 2019 00:48:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN7dnUR1YLF2/hqPg+r1PJw4ve8rVOrEUZ+vJtFp9xG5dHQlW0H1RMQMsbVU2vySODZOd1RP X-Received: by 2002:a62:7dcb:: with SMTP id y194mr14158191pfc.113.1547714882269; Thu, 17 Jan 2019 00:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547714882; cv=none; d=google.com; s=arc-20160816; b=acwdT1otPkF6pJTkB6pegwnCIde3pqJWlaHe6o8gLUsOpV8orpzz8h5A7YI2qIdyQF gmj/jkjFh5vqoZpVVuJIfHSB5ebwp0vGjega8DZ3ctEDPuYfsaJ6rbprL9chJBlA8szN P+v7trrIT/lpiYwZrE/arwBNGncgJ9fGSXK4CUrHnrjhBVsYBNUcZmNxZwlKozz+TTYG fcCSwgX5nYd4/QeLgHZVGf768A8drxWvb8BmvhL2mkEnvwFdb+WAuX327spucs+ehLQq 4HHTlAmrluWpCJnh9ltTYVTLc6K0SyPAQuihRS64h3HK4IUKhAaYFjzd++Pme7mHwP7w 8gKg== 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; bh=aOQfSRK6Cu00XkimRyJoEETFz42MVog205vqP9ZMoCo=; b=H3vRz0jOLZNKZEK2IeaxwUbG6St7RMijb79ibmTvR8TvIGeNynF7HRumyfPufNNeeF 0k1qkO8lYz021rXkoaUtjq66TISghoGBmVf8EEG86oRz90uuXag9YY0HSdJ2LUq1BDBn ThzERsISPgSlNv3wiEgvkGvXKxQo8ubV0zVkG2LgW1HD4TnN93ZpnBkQ8FMwGTySFbju 1pWQcd+i9dla3YULw16umMHw3R/3LJkBclQdY5ngByEckYQjuApGUUUtA3e6+r2OY/yt ixoZ/++XYldqBjgPsN/oNwPrw9Mi4HHgu0LpalHpJEKX70eKiVkDDBsdjJdRUIBwUamk pnDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si990099pgc.369.2019.01.17.00.48.02; Thu, 17 Jan 2019 00:48:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730783AbfAQIsA (ORCPT + 12 others); Thu, 17 Jan 2019 03:48:00 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:32828 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbfAQIr5 (ORCPT ); Thu, 17 Jan 2019 03:47:57 -0500 Received: by mail-wr1-f68.google.com with SMTP id c14so10063086wrr.0 for ; Thu, 17 Jan 2019 00:47:56 -0800 (PST) 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=aOQfSRK6Cu00XkimRyJoEETFz42MVog205vqP9ZMoCo=; b=j++Zb85NJtYEANAmbti21Y+bYkU7YyLixgxE0Apf2gHd9EQzW3LIIOxotb13jLmI6N xYVDyLCh2VTLwjZ5JWwJ/tRKOSiEWYlfqgdZZKtoqUJCBKfmMMMMCE+3+JALToLlzlm2 6zk7rcM3U40S91MJSITj8TjAl9ajexA59K9Sc2J0ojZIpYCNh/8xXhzgo7rpHzYNbP7J 4k4Kcqn2DlsGpUKmsDoDvB4XS5Vyv1QVDcaHvxdaiUZby8KOzrq9rnoccZMx5tCR87CF T7jtGc2cy7jBUP+FyzSLEEfYWnPdL7pGyWcqC/cCY/EWD1pEVfz6Hqz/vg5Kz8vawVZu wyFQ== X-Gm-Message-State: AJcUukcTbXC4n2f+eYPa2vHzkhV6a/Ao9zS3rhP8tyz+u8oPIoSmHBbZ TRMfxyJFiJS7ddbloMg1NvBCKA== X-Received: by 2002:a5d:61c4:: with SMTP id q4mr10532377wrv.308.1547714875758; Thu, 17 Jan 2019 00:47:55 -0800 (PST) Received: from localhost.localdomain.home ([151.15.254.62]) by smtp.gmail.com with ESMTPSA id 199sm41984992wmh.21.2019.01.17.00.47.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 00:47:55 -0800 (PST) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rostedt@goodmis.org, tj@kernel.org Cc: linux-kernel@vger.kernel.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, lizefan@huawei.com, cgroups@vger.kernel.org Subject: [PATCH v6 1/5] sched/topology: Adding function partition_sched_domains_locked() Date: Thu, 17 Jan 2019 09:47:35 +0100 Message-Id: <20190117084739.17078-2-juri.lelli@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190117084739.17078-1-juri.lelli@redhat.com> References: <20190117084739.17078-1-juri.lelli@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Poirier 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 Acked-by: Tejun Heo --- include/linux/sched/topology.h | 10 ++++++++++ kernel/sched/topology.c | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) -- 2.17.2 diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index 6b9976180c1e..d69e7d56253a 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); @@ -206,6 +210,12 @@ extern void set_sched_topology(struct sched_domain_topology_level *tl); struct sched_domain_attr; +static inline void +partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) +{ +} + static inline void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], struct sched_domain_attr *dattr_new) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8d7f15ba5916..dd94000cb378 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1929,15 +1929,15 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, * ndoms_new == 0 is a special case for destroying existing domains, * and it will not create the default domain. * - * Call with hotplug lock held + * Call with hotplug lock and sched_domains_mutex held */ -void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], - struct sched_domain_attr *dattr_new) +void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) { int i, j, n; int new_topology; - mutex_lock(&sched_domains_mutex); + lockdep_assert_held(&sched_domains_mutex); /* Always unregister in case we don't destroy any domains: */ unregister_sched_domain_sysctl(); @@ -2002,6 +2002,15 @@ void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], ndoms_cur = ndoms_new; register_sched_domain_sysctl(); +} +/* + * Call with hotplug lock held + */ +void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], + struct sched_domain_attr *dattr_new) +{ + mutex_lock(&sched_domains_mutex); + partition_sched_domains_locked(ndoms_new, doms_new, dattr_new); mutex_unlock(&sched_domains_mutex); } From patchwork Thu Jan 17 08:47:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 155805 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1700142jaa; Thu, 17 Jan 2019 00:48:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN53yZNotp/FUr0WQHJaRfUH+yV+y4e9OpmRYfC5/VTrQdoDCTjn/OWlq3mRrSY0mYveoS1U X-Received: by 2002:a63:af52:: with SMTP id s18mr12664630pgo.385.1547714901730; Thu, 17 Jan 2019 00:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547714901; cv=none; d=google.com; s=arc-20160816; b=Q51eN5/ZB/L6Y7h/u/6xKike1cWaD2Br3YB9CMEdYx5fKRzwKKj2q2grKZOHjQwuBN TpHdbcaIwG2HbcJdWfCGRT3Jo5VUTtDxhYClYKw4Vm2mqatNRTwvQLaR2uixNIwor6Pb yhDChVAUrzWSxm5l5OC9LXVaPXyo/KymVL9Ndmu2mAgGlsat4gjMcHiWKKXix720e+Ou AdU7ERMtNfZAZ7R8emGkYeV7Rinbbx6/qr6MQH/yDCTjuyDruENscmLtrbqzId7Adqx/ YMG2NHJWz0fxSVmqfx75p3KRhJrJtu1cbGx9tCWL8bRCmuRWDuN5w5dToaGtw+R6RyiH zOVw== 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; bh=goaAe7vGQCi5mRt58Lo1uF5caU1iA3IvOl0cay4wrr0=; b=UeY8cNv4xMllHgB+FumI0PGAatMi6GicWF0c/rl+zU3y0ijOU/vMzx/eIJGlw17afS Y6fV2Ljiwfp6D8sDcrZH+0mAQq/S0IF01EKPtaJzQcBzHADnVSSAnWr9TzgY8eDujyzE T+jkN+Z0elvU6UU2IbREp8YwHT7eulkCtHVOERPpXcx6CTUOrSjl888sFJYU9ZwNqAwa U/ZMiE6a7d2lWBQJ6yqozPS7E9hB+J/HUnj4fC1RdpHJ61y/hpspKvoWkfFUbfVLNb5/ Bjsf7H6C+72+xZ9OLRL0pmhtPuPXVHkKHxSKBA/cqYiLHlhaWb5KrJhL2UluqhN7GKMh y35Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si963199pgi.387.2019.01.17.00.48.21; Thu, 17 Jan 2019 00:48:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730847AbfAQIsU (ORCPT + 12 others); Thu, 17 Jan 2019 03:48:20 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43386 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725710AbfAQIr7 (ORCPT ); Thu, 17 Jan 2019 03:47:59 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10so9971716wrs.10 for ; Thu, 17 Jan 2019 00:47:57 -0800 (PST) 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=goaAe7vGQCi5mRt58Lo1uF5caU1iA3IvOl0cay4wrr0=; b=bhDWnnSqUqPjQFeSzA9hrAld+VXHYlUyyQWOqFF73m73Nif5m9iOpyHwm52wsfG0Ty F5BPUanRxvMsua04sopExJgRlqIzQJvuEtHn5sL4XCtoEjL1OdlLkKvxdNTWGrq22NVJ IH8tLxLoAntBzQUV2w+u1zHm7GZHNEkIvZsGYsJbni7Yvxd7BgTFYkqKCSSRjbRwv4FP YvtXVC7BEq9yvX6qSjPdbqxa44AJPKdExvrhz2r8JcrpUWnY4wht7a4YihyjaZzwnTQy 1LTEGyvjAd9aKlxFuZdiHT7DP/NqC3F3YF89uq0Nm897EOwwV/cNdxhT/o1+q0iWwEJY Vjlw== X-Gm-Message-State: AJcUukeaRPH6rNiNMSRBRLfh66SWs7rCiTYJ8Xv+gWl8SvtMCEOxYRMT Hqv39UjDxFYyt7Sul/krD/Zm6g== X-Received: by 2002:adf:c846:: with SMTP id e6mr10517656wrh.243.1547714877001; Thu, 17 Jan 2019 00:47:57 -0800 (PST) Received: from localhost.localdomain.home ([151.15.254.62]) by smtp.gmail.com with ESMTPSA id 199sm41984992wmh.21.2019.01.17.00.47.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 00:47:56 -0800 (PST) From: Juri Lelli To: peterz@infradead.org, mingo@redhat.com, rostedt@goodmis.org, tj@kernel.org Cc: linux-kernel@vger.kernel.org, luca.abeni@santannapisa.it, claudio@evidence.eu.com, tommaso.cucinotta@santannapisa.it, bristot@redhat.com, mathieu.poirier@linaro.org, lizefan@huawei.com, cgroups@vger.kernel.org Subject: [PATCH v6 2/5] sched/core: Streamlining calls to task_rq_unlock() Date: Thu, 17 Jan 2019 09:47:36 +0100 Message-Id: <20190117084739.17078-3-juri.lelli@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190117084739.17078-1-juri.lelli@redhat.com> References: <20190117084739.17078-1-juri.lelli@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Poirier 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 streamlines 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 Reviewed-by: Steven Rostedt (VMware) Acked-by: Tejun Heo --- kernel/sched/core.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 2.17.2 diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 091e089063be..f5263383170e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4228,8 +4228,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; } /* @@ -4245,8 +4245,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: @@ -4259,8 +4259,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 @@ -4275,8 +4275,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 @@ -4295,8 +4295,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; @@ -4352,6 +4352,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,