From patchwork Tue Sep 12 10:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 138640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp849372vqx; Tue, 12 Sep 2023 21:37:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPChuGu+/FkCNMFSyPDNd9EQVk5YL/H/KR22wWOFy1aH3e6phZ5fGE4mcvWfJydzMtqsZl X-Received: by 2002:a17:902:e543:b0:1b7:f64b:379b with SMTP id n3-20020a170902e54300b001b7f64b379bmr2890947plf.17.1694579846958; Tue, 12 Sep 2023 21:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694579846; cv=none; d=google.com; s=arc-20160816; b=kzaIvEv+Qn0rZe+2Tn7ZAvi9FZs1E72Uz7X+Yb73awkbO1M3DwyIIMyeZv/2dHD8uZ YAJGG9cj9anV4tCema5lTB+qNmPQn+GY7Q/jw3ke68+VdfuFPYfkn+zV7It9IL9wF9Jx 5jd1SsOjEHJoFyPZU4Mb/mCEicFfunDIkXRkga+FYXiCJrweDuIqBmDVUnYFJxf6xGX5 KIu/ZFUbErIMpQZ05ZVI/WBguaOhTomFCXLFqWsrSIp0lXp5Sir/7AEDHlsnILvK0R/G 0oqkrMZMGV07GQFfpJElyUz8XjEzG3WH6g8xZV5kf/xYrpp2JLfKyp796NerVSKL7RF3 1H7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=p5U7F6+T7pg7uOdMmZPiE6ZBW3x7QTJymrki28T32QQ=; fh=H2MkSknZKy/XcUE0SNWlqZifRHvGVZQUr5cmv0Cbtz8=; b=n1SVhPKdWjZPztpK3KyJzNz2tDJbdby6J2Qn7kExSffchyAW7uo/YiYtEBzqLX9G+v z8v6sxkTV5wCKfUqfqL0476fDvVuWJ7VpIHFByqmjbGAQrFlxldOPS1/IF8u8RYhat3u ju6/OXtMjZ5A+mX4kyzLLxVHR5wMHKKP4Tc2khOHOQgVQXPcqVvHWs6+zF/1gv7wBpS9 su7Zmj/vFFqtJ4NXdXzxPZsMSY+4lzXYRCnemaLWIkgMzNnxfiXA5Yo0sSv5zrruALM6 +V/HjXCPUKh2cdtdaOVybky8mbmZB31laN2pV1o4QTQvLKXl5NOPO2OEt6YN49PPeJU9 jKgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LiWAbaLC; dkim=neutral (no key) header.i=@linutronix.de header.b=oS+deMDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k5-20020a170902c40500b001b9c34985e1si10148899plk.497.2023.09.12.21.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 21:37:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LiWAbaLC; dkim=neutral (no key) header.i=@linutronix.de header.b=oS+deMDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D73C0804597A; Tue, 12 Sep 2023 03:34:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234178AbjILKeV (ORCPT + 37 others); Tue, 12 Sep 2023 06:34:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234378AbjILKag (ORCPT ); Tue, 12 Sep 2023 06:30:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E1711722; Tue, 12 Sep 2023 03:29:00 -0700 (PDT) Date: Tue, 12 Sep 2023 10:28:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694514538; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p5U7F6+T7pg7uOdMmZPiE6ZBW3x7QTJymrki28T32QQ=; b=LiWAbaLCaKztbVHAXXtIrokBdlQSJ9g88A4+EBclOMHitSGQkWGbbDdYKEP4/rIm8ZUm5a 9VObRcRVi/AWtNI2baDmoV1DWECG3ZDtMTsC1AfV8i3QXm0mGAfhwZANSAYFYc0xCNnRxh lEuzqxIY0oIgEwa69pEJfvYfqZh/HnqiPAPevsHHXQwPv9SIKv5Iqhkouz12iG5OqX56B5 3MfbKcRtmuOtAgp3RVmxTDASQIjNbBJnYnXOtglxMHXEw6bMAu8gW59VULemwXdoqz+Hku aee+0BaYxSMy5kNpkdTlZEUOK9WsYMLRgmlTDyL2LQNVUnFcTykHhDAk6CS+7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694514538; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p5U7F6+T7pg7uOdMmZPiE6ZBW3x7QTJymrki28T32QQ=; b=oS+deMDj8GYGBfvSqDmpUBsXUdIS8dxiZvYLbwkZRD/mruPyLYGtXAm0GhGovc9BVlPcgV tssYdvb+rdno8rBg== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: Simplify sched_rr_get_interval() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169451453824.27769.10199012591700147218.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 03:34:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776895757620978016 X-GMAIL-MSGID: 1776895757620978016 The following commit has been merged into the sched/core branch of tip: Commit-ID: dc163158330c1bd1be33e54d37b09f10c0a8db07 Gitweb: https://git.kernel.org/tip/dc163158330c1bd1be33e54d37b09f10c0a8db07 Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 16:59:05 +02:00 Committer: root CommitterDate: Sat, 09 Sep 2023 15:10:16 +02:00 sched: Simplify sched_rr_get_interval() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/core.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e825839..acaab2d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9031,38 +9031,30 @@ SYSCALL_DEFINE1(sched_get_priority_min, int, policy) static int sched_rr_get_interval(pid_t pid, struct timespec64 *t) { - struct task_struct *p; - unsigned int time_slice; - struct rq_flags rf; - struct rq *rq; + unsigned int time_slice = 0; int retval; if (pid < 0) return -EINVAL; - retval = -ESRCH; - rcu_read_lock(); - p = find_process_by_pid(pid); - if (!p) - goto out_unlock; + scoped_guard (rcu) { + struct task_struct *p = find_process_by_pid(pid); + if (!p) + return -ESRCH; - retval = security_task_getscheduler(p); - if (retval) - goto out_unlock; + retval = security_task_getscheduler(p); + if (retval) + return retval; - rq = task_rq_lock(p, &rf); - time_slice = 0; - if (p->sched_class->get_rr_interval) - time_slice = p->sched_class->get_rr_interval(rq, p); - task_rq_unlock(rq, p, &rf); + scoped_guard (task_rq_lock, p) { + struct rq *rq = scope.rq; + if (p->sched_class->get_rr_interval) + time_slice = p->sched_class->get_rr_interval(rq, p); + } + } - rcu_read_unlock(); jiffies_to_timespec64(time_slice, t); return 0; - -out_unlock: - rcu_read_unlock(); - return retval; } /**