From patchwork Wed Sep 13 13:11:12 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: 139088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp83627vqb; Wed, 13 Sep 2023 14:01:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsc6HWXfi3aRCjPLqoaa5APL+lC4NH2InQvWyxPDZ/h0rDyFFX+ZY3yL7rJrHtyDsgH/T4 X-Received: by 2002:a05:6a20:13cf:b0:153:6a8b:8f5d with SMTP id ho15-20020a056a2013cf00b001536a8b8f5dmr3053949pzc.23.1694638892678; Wed, 13 Sep 2023 14:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694638892; cv=none; d=google.com; s=arc-20160816; b=njXBKlx9ZDu9V5hnSLP05sxvibK4p673fylrMzT5KoUKRVLGePbOYHGPY1zwk2q4cs a/OnwPM/hDNK0bDmzsOvMFvxJ1NWfLLSCtSwKmWhdxBku3Zwn+wVzOfHzfOdvcdEg8hr QHERJqQK+2bEyuAJqthuG0SCaEw0wE9E30i3agjcfWZ2IAoJ4s3MPwFYaPZjlMmiyb11 dEFAMuHmfUPttnVPWmOky+al7FIDVmU0iuBtD865ltLqL4n2qdMQBmfQOuWTpgC6My8E EkRRj1CDO/79vvaLeJxqmFNATDgqoF3C5RdF8S6TPUWxU5BsxY0C1qsMyrNMjKj9AOJ/ IDKg== 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=WSH5DAuj9ryML7nV9EnMVKVgDWCcsxry1G0kCNpwZ8g=; fh=zdCoWWNwZujffrJhBueQUzngzidRSLRPEc3xeSuESio=; b=SeIifVxRqRF4tkqyduH9x+CuQX9WfCqTNB/5KU/cRawujBlpssTUGspWZIG2Hb7kOD 22BonCvWX1wL/BsqWDWP6Uw6G4SXxGyoOBswzDO8PTsmaSUmxaTAl4aBI78iwxR8TtT0 Gi1iA82wmrlK6nvSwGpHG9HWCRuQmZ7XjoCJPZ57U1BmeHog8xg0J3NHStMZz4B4rgL+ RYphnICnNSiUNbgETEL3adYVrMJPvaGg3D+P3GwRqu6ip2aIOAS77BF1GBLQwqLDEwau zXYlFhBim6H1VyqBOQI7fVw4duF+sMKOSkLK4lHDByJ99QjfUmPu0ZV/PsMIx+5Zy69D xp3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=S6pEA7mz; dkim=neutral (no key) header.i=@linutronix.de header.b="0L/IlosI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id q128-20020a632a86000000b00577568210a1si7512652pgq.539.2023.09.13.14.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:01:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=S6pEA7mz; dkim=neutral (no key) header.i=@linutronix.de header.b="0L/IlosI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 0188A82A1778; Wed, 13 Sep 2023 06:11:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240733AbjIMNL0 (ORCPT + 36 others); Wed, 13 Sep 2023 09:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240798AbjIMNLS (ORCPT ); Wed, 13 Sep 2023 09:11:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B38619BB; Wed, 13 Sep 2023 06:11:14 -0700 (PDT) Date: Wed, 13 Sep 2023 13:11:12 -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=WSH5DAuj9ryML7nV9EnMVKVgDWCcsxry1G0kCNpwZ8g=; b=S6pEA7mzLAfDCh05I+zis080r8h8Rw3UH01N7AG4YLHkT5aV7b4svnYOgfCK0YTxwCS5Mj 7GtPNggn2MOeBWmCOkRlD6YhPaZO5HuTXn03J+p0xeVFnZsS/IaA8VrTzfpJU5eizR1OYh hY1KhLycsoFbNGaRePhW5fR4Md8VOeupsCQ/+ww1x8jRpDTo4JymZTMPktctRlARYku3Me 2Yx/3o6u0MXIXcaLUFo7F5R48yaPbp/elVkYF/r18uTkNWFX8ri6LFJ3Lf1mFXS6yAlCbs 3q5ubRQT/WHnBIZmvOU4x7mFsN2pkAU4qyiCmZPfLJPXQtTFSXGwT3L+0cwifA== 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=WSH5DAuj9ryML7nV9EnMVKVgDWCcsxry1G0kCNpwZ8g=; b=0L/IlosIMIxS958oIIG+X6Tz3FszJtsrlJ12ESripnaz3+DvsAKW54LjHLoadYMz1hRMaY BWNYBvlB5RDfrFCA== 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 yield_to() Cc: "Peter Zijlstra (Intel)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169461067223.27769.6572821196325694466.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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 06:11:47 -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 morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776957671468060114 X-GMAIL-MSGID: 1776957671468060114 The following commit has been merged into the sched/core branch of tip: Commit-ID: 7a50f76674f8b6f4f30a1cec954179f10e20110c Gitweb: https://git.kernel.org/tip/7a50f76674f8b6f4f30a1cec954179f10e20110c Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 16:58:23 +02:00 Committer: Ingo Molnar CommitterDate: Wed, 13 Sep 2023 15:01:28 +02:00 sched: Simplify yield_to() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 67 +++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1d5cbb3..6c8c40a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8888,55 +8888,46 @@ int __sched yield_to(struct task_struct *p, bool preempt) { struct task_struct *curr = current; struct rq *rq, *p_rq; - unsigned long flags; int yielded = 0; - local_irq_save(flags); - rq = this_rq(); + scoped_guard (irqsave) { + rq = this_rq(); again: - p_rq = task_rq(p); - /* - * If we're the only runnable task on the rq and target rq also - * has only one task, there's absolutely no point in yielding. - */ - if (rq->nr_running == 1 && p_rq->nr_running == 1) { - yielded = -ESRCH; - goto out_irq; - } + p_rq = task_rq(p); + /* + * If we're the only runnable task on the rq and target rq also + * has only one task, there's absolutely no point in yielding. + */ + if (rq->nr_running == 1 && p_rq->nr_running == 1) + return -ESRCH; - double_rq_lock(rq, p_rq); - if (task_rq(p) != p_rq) { - double_rq_unlock(rq, p_rq); - goto again; - } + guard(double_rq_lock)(rq, p_rq); + if (task_rq(p) != p_rq) + goto again; - if (!curr->sched_class->yield_to_task) - goto out_unlock; + if (!curr->sched_class->yield_to_task) + return 0; - if (curr->sched_class != p->sched_class) - goto out_unlock; + if (curr->sched_class != p->sched_class) + return 0; - if (task_on_cpu(p_rq, p) || !task_is_running(p)) - goto out_unlock; + if (task_on_cpu(p_rq, p) || !task_is_running(p)) + return 0; - yielded = curr->sched_class->yield_to_task(rq, p); - if (yielded) { - schedstat_inc(rq->yld_count); - /* - * Make p's CPU reschedule; pick_next_entity takes care of - * fairness. - */ - if (preempt && rq != p_rq) - resched_curr(p_rq); + yielded = curr->sched_class->yield_to_task(rq, p); + if (yielded) { + schedstat_inc(rq->yld_count); + /* + * Make p's CPU reschedule; pick_next_entity + * takes care of fairness. + */ + if (preempt && rq != p_rq) + resched_curr(p_rq); + } } -out_unlock: - double_rq_unlock(rq, p_rq); -out_irq: - local_irq_restore(flags); - - if (yielded > 0) + if (yielded) schedule(); return yielded;