From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14909C4360F for ; Wed, 3 Apr 2019 08:48:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2DCF21473 for ; Wed, 3 Apr 2019 08:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729347AbfDCIsG (ORCPT ); Wed, 3 Apr 2019 04:48:06 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35315 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729071AbfDCIrP (ORCPT ); Wed, 3 Apr 2019 04:47:15 -0400 Received: by mail-wr1-f66.google.com with SMTP id w1so20215848wrp.2 for ; Wed, 03 Apr 2019 01:47:13 -0700 (PDT) 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=2zb2sfp3ECm64xrb0rL2N53J/j5P/++jhkiQsNZzpOE=; b=AIm+g8BipBuxH6P6m22IPlhIiG4g1GoTUkNGFCrdnbL9ntfuY7l0l8KLIRs1O6sDsY +znF0Zw/3XC/LqL/LQlrEDmzEzZDWERvHCJhTj0OPLE0Ke40qVN8wHXevToxsSbLEF21 yrJquZGdz8i+qTY+p+lAI6fuYReR2teFYBJGAQEt2atZDmUOmTOVydnfJcxp+gLETciA pYB21M/OpkklAQ43Dp79yYU7roEx5DP6UXU5+MKmalzP0n9AB90bT+1VIf+Kiyj7Xrgn boVUfGr9/nrFq1LBYuQ3m10vLFCEtmHUQRI4R9df6OWT6oXn9rtNKU0TXRBDZXcn9utk c7BA== X-Gm-Message-State: APjAAAVZ/qmZkXIDSjpdG1br/w5KMNcPwLa4lYhbKKkGN/vi0KPXrw16 Ep4/1hFah5LqwRY6IOouLiajaA== X-Google-Smtp-Source: APXvYqzJIWNuxZsjgFwfQwl9wHCx2fX6iuOkRNcY+teCsmejGlDDLPIqochFb+2XnnM1MWtAsXGRIg== X-Received: by 2002:a5d:6101:: with SMTP id v1mr25931989wrt.222.1554281233040; Wed, 03 Apr 2019 01:47:13 -0700 (PDT) Received: from localhost.localdomain.com ([151.29.174.33]) by smtp.gmail.com with ESMTPSA id o2sm12258081wrs.89.2019.04.03.01.47.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Apr 2019 01:47:12 -0700 (PDT) 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 v7 2/7] sched/core: Streamlining calls to task_rq_unlock() Date: Wed, 3 Apr 2019 10:46:45 +0200 Message-Id: <20190403084650.4414-3-juri.lelli@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190403084650.4414-1-juri.lelli@redhat.com> References: <20190403084650.4414-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(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ead464a0f2e5..98e835de1e7b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4274,8 +4274,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; } /* @@ -4291,8 +4291,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: @@ -4305,8 +4305,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 @@ -4321,8 +4321,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 @@ -4341,8 +4341,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; @@ -4398,6 +4398,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, -- 2.17.2