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,