From patchwork Wed Sep 13 13:11:14 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: 139244 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp61548vqi; Wed, 13 Sep 2023 19:18:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfRQ/fi45jGbaXNTmtYt4GyYNCXqxGyYUoP9hQLjhuUbgCrdxisMC+LjdsBTOWZUmjj2NC X-Received: by 2002:a05:6870:9214:b0:1be:f46d:a26c with SMTP id e20-20020a056870921400b001bef46da26cmr5189277oaf.27.1694657932426; Wed, 13 Sep 2023 19:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694657932; cv=none; d=google.com; s=arc-20160816; b=PbDBfhVGU3NyiRoD1Vqi7oNgM/ZFls8uqeJHdBNRDVJ1TywAlUa9fERE+LqHeyYkd3 wECI5nvQyVz+8CDqd1oVvlwOdReHfDA+9vqXvk9KpjgJl9Zv588j8x2xp/vjouSm4tzM gc2YkraGZFbuYgT5NiwPjaH0qRG/S/QhvHqu/a3PmOdAynzNLqr+WziBjFv+YubTbIRB OlkZKV1LNx+EZaMDGngeyHQuyfelU+WKkJiU/Qe9e6wdXgSJ7IRw6E02mbDRrQ6TsLBB YUI5ioW9TxHEgVxwQg6mhZMihWiRikJc0/CzaOzFrwEkznDJh42WWHelpLKsvK/bwjun ykfw== 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=jjhk2NOlcOekS+9KNZbWh/C2ynHVx5QcKV0wX5xUGqg=; fh=zdCoWWNwZujffrJhBueQUzngzidRSLRPEc3xeSuESio=; b=ir52Z812zTNRjn8AwdkedSRgH99eY6ypTChNlw7v+IyVzxgTrLfY211DW1aH0i1jQx 7y9KgKfLxLAmQkAJh6S/HUw2/d345IqNZ01841A9WUIWCh6WmUuZ69bI4tIsHtLh/Xe7 zUAwc6iTJrtQJQfNqyiZOO6oFIb0IK4F+a8v+Ey3wPbX8tiBOX87tmSDI4ZocNZI/V7H bSnfcFsKEn5mip0QD+C3xm/yHJAtI7QC/V5CVNC/v4ig9kUjcMp2KdpXdL1NVft5+cZg nxeW7ze2s2YJzAHNC3vmULJWfCgKtxL5QEd78KiGwA2jQ2+FNrYquxQ9CHP+1YojLxUT TqKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JpLoIuaf; 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 s16-20020a656450000000b00574134c9ac9si468390pgv.521.2023.09.13.19.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 19:18:52 -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=JpLoIuaf; 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 36C33801DDB7; Wed, 13 Sep 2023 06:11:43 -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 S240854AbjIMNLj (ORCPT + 36 others); Wed, 13 Sep 2023 09:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240713AbjIMNLU (ORCPT ); Wed, 13 Sep 2023 09:11:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AB7619B9; Wed, 13 Sep 2023 06:11:16 -0700 (PDT) Date: Wed, 13 Sep 2023 13:11:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694610674; 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=jjhk2NOlcOekS+9KNZbWh/C2ynHVx5QcKV0wX5xUGqg=; b=JpLoIuafpG6wlsZAlyygKEsq3o8LUqUnVBJIA1KktQUNiDvbtfZC2w8wIzWe/tfY5aUvKa LWQUnQe0mr3npdMcNZhEkAhA2kArZDaO7vm24aE9E0C7PId9qQ+Y0gD8NVuwdUxLNqnaeU dKMitLDsQ8lB5RNQYfNw49aU885yydzXsLXEoJ9HCqtGFfI0M5X6vsv0WWhJW0q4p43JPZ Z3qc4U2iAo0Pl1skif2wr7yxx0rwh2BZmJMSXnjCaE+VfYl4MMNrx5hmoYuWhJROZIBUwI RPeJZlzHfnIJTWc7JMryOMobK4zHtOUCb25MrW08vacetBMe2qWbyFIy533zcA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694610674; 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=jjhk2NOlcOekS+9KNZbWh/C2ynHVx5QcKV0wX5xUGqg=; b=CNnzyjUFXMnwWN387i793lndxYBeU0NIdau+Jq+XrV7VhVrmABQTjfPRVxsNEbbVDu7FeK SrmVXPXC04z9VlCA== 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)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169461067423.27769.1239931915350058927.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]); Wed, 13 Sep 2023 06:11:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776977636204138827 X-GMAIL-MSGID: 1776977636204138827 The following commit has been merged into the sched/core branch of tip: Commit-ID: 94b548a15e8ec47dfbf6925bdfb64bb5657dce0c Gitweb: https://git.kernel.org/tip/94b548a15e8ec47dfbf6925bdfb64bb5657dce0c Author: Peter Zijlstra AuthorDate: Fri, 09 Jun 2023 20:52:55 +02:00 Committer: Ingo Molnar CommitterDate: Wed, 13 Sep 2023 15:01:14 +02:00 sched: Simplify set_user_nice() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar --- 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 2299a5c..fa57a56 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7187,9 +7187,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; @@ -7197,7 +7196,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); /* @@ -7208,8 +7209,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) @@ -7232,9 +7234,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 0484627..68768f4 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1658,6 +1658,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)