From patchwork Wed Sep 13 13:11:11 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: 139541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp310396vqi; Thu, 14 Sep 2023 05:27:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkWYhZv3qQVa2DeceE6V3LFGp5GU1JRT8Hxvl9Ye7Q3uFYZz8EwF2onk3YIKfuV6trgd64 X-Received: by 2002:a05:6870:d154:b0:19e:fa1f:fc2f with SMTP id f20-20020a056870d15400b0019efa1ffc2fmr5234554oac.38.1694694460592; Thu, 14 Sep 2023 05:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694694460; cv=none; d=google.com; s=arc-20160816; b=Jilg0g5GoB6f4+fBg8QkgBOm92ysk3EAAE/PaCS8FB8XcUkYQ0nORP8HKrI5H3oAZA 8Sr14QQPTPNtdj0ocOzwcuOO6ctNoRgQTCAfRAC2ArVI4/bc2i6c58wXQmSaHRycs2LZ YKezcHpPqeMEKpD3PGJKPZlZPmXh8e355yeUMBZ9dkYCa5/FR5OrODnQdQvcMnvGXHYr Xgo6lQdzFXLt1DO3tCO1tE4Irm/HNlWvbSZxN6bXH26jmUHc8O37acYvwmloUBXFEiJ8 FpgsJeR6UnyB4hbQ8RBRG15+snFe2I5HHEkDgYH9KIoJmpehOxh6/MXNAO4boMBxuLUj a7jQ== 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=XNT5aV5paLg1iK4+47E6rr7mjK+RF8y6ODrB8EBjWdI=; fh=zdCoWWNwZujffrJhBueQUzngzidRSLRPEc3xeSuESio=; b=HzuL0WGlUbQemAidf/9sFchKUjbWfDv+3JamEwtaaAVdNdtzKYmv7u3afNSdUC0DZB PVwpGgpOpzqIFSgUDMjj3MA3zA9U8ZhEeGA3BvO1lW4fFQSjcexPFYlMp3vLcVfN3sNf iZe2Y4hTTKOcsiyDm8BCADDQi6FHissMDE9rJhJ2pQwiyjhc/3gyXMqQZaw97qsJGBNw /ORzd0nNsDVfAaIns2SMO68ousZgBY4n83tw/aWp2NTZ4oyMXqdEM3Mq5JRm2KUy/RsD yJ41Vpdkvt0L4l1N2CEAWf/0kft685iJR5sPLyMQ1z7QAgPIQ9IhJOQC/5LYkOwpFuUe YhNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=M7sPWgqU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id m9-20020a654389000000b00565e39e7b80si1349432pgp.678.2023.09.14.05.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:27:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=M7sPWgqU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 0E76F811874A; Wed, 13 Sep 2023 06:11:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240828AbjIMNL3 (ORCPT + 36 others); Wed, 13 Sep 2023 09:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240791AbjIMNLR (ORCPT ); Wed, 13 Sep 2023 09:11:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADADA19B4; Wed, 13 Sep 2023 06:11:13 -0700 (PDT) Date: Wed, 13 Sep 2023 13:11:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694610672; 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=XNT5aV5paLg1iK4+47E6rr7mjK+RF8y6ODrB8EBjWdI=; b=M7sPWgqUI0hVrNqiUhkvhaTJoH6vtD5TTZiKcowuWCXWq10XC1Qm4ZgyMqe9SRFkDgfTSs m84px/iTUXA9ZaPDUaqQGgxiN2fQM8THkawIDM3Mxmb+hNkVElCoY2LFbd1T5Lwtmz+tjs Pf5JxNptbvwaNQW9b9QgOBQDuNdaTir7cUmzzxVDcxiTUQq285GsLZ/F8Z8xYITRSog3kg XFwyUTrZiEMNrVY43pg1KjLUScOAKaFoK60eV3NR0mSsuHRK1yrTPZg2cTMswMRQWucuwg I6BZ+RMmTRek9Iu6vLVg6bxQe1TuupApRBXxvV0nVMnZeRyYQyaZS7YrOonuPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694610672; 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=XNT5aV5paLg1iK4+47E6rr7mjK+RF8y6ODrB8EBjWdI=; b=SW+iMqWr2rDi5NerpslOi+y8Ypp1SFU6moh2lfgHSCLdqlOU9CiCe07OSuMIl6QZa576Yu nJFYSsDqBYJZ4ZBQ== 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)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169461067174.27769.5481930955867667911.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 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 06:11:44 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777015938821756511 X-GMAIL-MSGID: 1777015938821756511 The following commit has been merged into the sched/core branch of tip: Commit-ID: af7c5763f5e8bc1b3f827354a283ccaf6a8c8098 Gitweb: https://git.kernel.org/tip/af7c5763f5e8bc1b3f827354a283ccaf6a8c8098 Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 16:59:05 +02:00 Committer: Ingo Molnar CommitterDate: Wed, 13 Sep 2023 15:01:33 +02:00 sched: Simplify sched_rr_get_interval() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar --- 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 6c8c40a..d298176 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9030,38 +9030,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; } /**