From patchwork Tue Sep 12 10:29:00 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: 138734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp975381vqx; Wed, 13 Sep 2023 03:08:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6RHeY4nbUN9FVo5QocAW1Xhk9KsoybXcuNEAkLkPmd/10jub1fOd1unsGYDC0BCQbS+8P X-Received: by 2002:a17:90a:b902:b0:273:f51f:1626 with SMTP id p2-20020a17090ab90200b00273f51f1626mr1492234pjr.35.1694599694038; Wed, 13 Sep 2023 03:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694599694; cv=none; d=google.com; s=arc-20160816; b=RsnRurEfHZNF19LR3ukYxp7E7M/QZtC+PZHAe0UpeFEndk635GfH6oaeQHqfvOtCsg 826u3QUAK0Pm+cWQAoHsadwyy7vtTaWeUfbHKkGwLFWHsa5wcbqRvzqcdA9Iq8kZCEdZ n8mTSO/Q4acPtVsLkdpvSLbAcwkp+oOhDeK2HMud1pEdJdFVk8scGRi5gCfj8bERTky+ WgKLBw3uRlxsY8Wl3g3apNFLNifUXfcCqj94nxGWbrvSMY3Yul3SkfU90JoL49bWIyFk +HT7Z5wOsPSsVvBZUec8qbr5gJ4II2tBSvrPOjspO7VdjHB6Hfh1ayFQFRUK1EgxxVBM P4mg== 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=iEujX5toaF9pezhF/bbHRVvwipV/jeRcb51TpsPRK+U=; fh=H2MkSknZKy/XcUE0SNWlqZifRHvGVZQUr5cmv0Cbtz8=; b=V7M6Lm3VfxIY9TzgD+kq1BkyHhuDmNnw4KTqL8siXOKY01FnkUAUw5yL9wpjsiR4qd vce61H8Tw26cewFWICCOsPch06ptxV6GbYEKYKxjZaIWB7Hhh1ACqwRRGFSAf3QmJD2E 6mN2Lo7oyO9MVkkybfxe9Ee0L6AO7ZsI4pph5tYrHyeM1puUN6kzXp1mliuvHixQE/sV KzrnOEIbNBBRNlXkSZv/SAKuei5C/T5v6VXLmrgb9aqQUbZNHNyuxaPdvS6hQSxaEFay 8HTRkNkFz//G47JVcVyrWfywO5PEwZpoCGG4/r+Vg4CcvzJOgCsLMicLmM3kTNEq5s7T Xmuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DJ9ytuG7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id d64-20020a17090a6f4600b0026efcf5357csi1274050pjk.126.2023.09.13.03.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 03:08:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DJ9ytuG7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 8716B83F0284; Tue, 12 Sep 2023 03:34:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234311AbjILKef (ORCPT + 37 others); Tue, 12 Sep 2023 06:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234407AbjILKal (ORCPT ); Tue, 12 Sep 2023 06:30:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B8051726; Tue, 12 Sep 2023 03:29:02 -0700 (PDT) Date: Tue, 12 Sep 2023 10:29:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694514540; 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=iEujX5toaF9pezhF/bbHRVvwipV/jeRcb51TpsPRK+U=; b=DJ9ytuG7th25rPLKF57KrifS1Qp2+vEY4itK8tf/ujxzii2bJIrQJcecqs2ImsDM94Ncxj RBWm12jxn8gy+WNitKauRqI+QnlytgJvp5nm9PcD1cZ8i28vXUU/OdAHF+k9QAS7ykWslk +stmwOMLXlwnP2+YgurRmV9qQ+2AIdnhLt+oJB2sOMXO+/xhwj7lI/kBwWdXiIZjC55AvV foeFZM5iuK1j1NxtEutUNos6K2RQKRk27/wTnpip/d6zAb+m0CFjXhJS0Fskr2qBAQsx3K eQms6hKra1gBOlTrdbh1xVoovT539YavkSA1vaipMidm6+UwM65oA+Hnmm6pSg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694514540; 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=iEujX5toaF9pezhF/bbHRVvwipV/jeRcb51TpsPRK+U=; b=Ei1vaT7u2G8VL9DdvLSGxiBvkImS3BWULl1XGLrv+pO/uAdLJoRPTGf/xcLbOtLJrIB5Mv suhOfkHGqdyR58CA== 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 set_user_nice() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169451454033.27769.14330488410812815255.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 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 03:34:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776916568716133435 X-GMAIL-MSGID: 1776916568716133435 The following commit has been merged into the sched/core branch of tip: Commit-ID: 7db0c4c81425e6e0d69dcb56e8c5e99d63f4ef07 Gitweb: https://git.kernel.org/tip/7db0c4c81425e6e0d69dcb56e8c5e99d63f4ef07 Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 20:52:55 +02:00 Committer: root CommitterDate: Sat, 09 Sep 2023 15:10:14 +02:00 sched: Simplify set_user_nice() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/core.c | 13 ++++++------- kernel/sched/sched.h | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index efe3848..e4d8b7a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7188,9 +7188,8 @@ static inline int rt_effective_prio(struct task_struct *p, int prio) void set_user_nice(struct task_struct *p, long nice) { bool queued, running; - int old_prio; - struct rq_flags rf; struct rq *rq; + int old_prio; if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE) return; @@ -7198,7 +7197,9 @@ void set_user_nice(struct task_struct *p, long nice) * We have to be careful, if called from sys_setpriority(), * the task might be in the middle of scheduling on another CPU. */ - rq = task_rq_lock(p, &rf); + CLASS(task_rq_lock, rq_guard)(p); + rq = rq_guard.rq; + update_rq_clock(rq); /* @@ -7209,8 +7210,9 @@ void set_user_nice(struct task_struct *p, long nice) */ if (task_has_dl_policy(p) || task_has_rt_policy(p)) { p->static_prio = NICE_TO_PRIO(nice); - goto out_unlock; + return; } + queued = task_on_rq_queued(p); running = task_current(rq, p); if (queued) @@ -7233,9 +7235,6 @@ void set_user_nice(struct task_struct *p, long nice) * lowered its priority, then reschedule its CPU: */ p->sched_class->prio_changed(rq, p, old_prio); - -out_unlock: - task_rq_unlock(rq, p, &rf); } EXPORT_SYMBOL(set_user_nice); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 3a01b7a..62013c4 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1657,6 +1657,11 @@ task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf) raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags); } +DEFINE_LOCK_GUARD_1(task_rq_lock, struct task_struct, + _T->rq = task_rq_lock(_T->lock, &_T->rf), + task_rq_unlock(_T->rq, _T->lock, &_T->rf), + struct rq *rq; struct rq_flags rf) + static inline void rq_lock_irqsave(struct rq *rq, struct rq_flags *rf) __acquires(rq->lock)