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,