From patchwork Mon Aug 14 15:08:06 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: 135499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2814126vqi; Mon, 14 Aug 2023 08:19:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFETvbYGmHLYJ6kdpEQUfAH3X7txrg6qqQxSNQe9wFrqsanxf4YXEaIeUkQD5dJkBhQa0Hf X-Received: by 2002:a2e:9bd6:0:b0:2b6:da64:734f with SMTP id w22-20020a2e9bd6000000b002b6da64734fmr7772203ljj.47.1692026355899; Mon, 14 Aug 2023 08:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692026355; cv=none; d=google.com; s=arc-20160816; b=XC5VUZTXLKl9AX87I2yTtZeJSmxvyIsbTCL3MkszNO87yyFUmWtA30coj3+XXP2D/z v1Bnbt4fScjUlMCO8rndzSG2qSc5UNaoAAZiY/v4R0/6U4YdQdfvmjmPGb1B4Xs20o+T H2g9lOrLeuw6sWXAYV69hwJcFwb9fNZIyZes3WNykFSH8ofFBuoeulIQAJmkbfApBLmN 0iD+YaRQ2lINsk5kCiYGMtaDQ6bGY8M1t8kLxX6HNnpcLIH3RyfLs5lRtz0q4HfBSBpM PJc7YBa8FuxYqOrEflYFp3FpaZSYtDIllp4bDF67nU0cPzzhFF3Ee3ADuOgeQpb/MLas M4QA== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=YMGiIB3ZRF9xDuzowmKuMGbuFtNeEa/dk8I9+QRM62A=; fh=utQzrRGpdyneC53QA2zUro1rWgCYMKhBZhFdjXY/HTE=; b=GGG4DEayShc4YuL4JESYqpi6IdPrA4pqCUeJ30B9Q09CcqYjghfJnikL5P0j4Kd20E OBGjia6UAkGGR9XwxC/4vJWM41GryqksEXIHTzG+TByj8DfVzawocVFtYjWPAB3LbNTu GuzozWEk8uZY/vNODT3ShNl6NUu/7+Oby0iGj7IplISQXd6gD+w8IHHpPAJ/N5buROPh EHKuE/xq2i/Lw2SA6Frg0gcB2mzGtcJCAWEzjJEY286Lb8d4CObSfCV8eJPXcwHpfez1 dxPQw0sHopDDcEbkvyn98Z9+sWKNOhiVDZAXF37mN2h6/D5wy4Rvu3xRrCS2tP7pCMN6 ZA4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=crm6U1Y1; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uz11-20020a170907118b00b0099b4985e4d5si8635795ejb.451.2023.08.14.08.18.35; Mon, 14 Aug 2023 08:19:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=crm6U1Y1; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232789AbjHNPIn (ORCPT + 99 others); Mon, 14 Aug 2023 11:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232673AbjHNPIL (ORCPT ); Mon, 14 Aug 2023 11:08:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 129A010DB; Mon, 14 Aug 2023 08:08:08 -0700 (PDT) Date: Mon, 14 Aug 2023 15:08:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692025686; 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: in-reply-to:in-reply-to:references:references; bh=YMGiIB3ZRF9xDuzowmKuMGbuFtNeEa/dk8I9+QRM62A=; b=crm6U1Y1puA8N68rUT3sEX9cqlewdFVZZCBRq2kQaq148y6iT29NohOJBl3R4JHIw97woh 7xHjXBayhMJk0NQ6r2W9ofkoLF7OEcAiReaWFOniBQ5nqt2iimWiIbAH0DttzvEUiw7Mbg e97CsAddUSTLIjegT3Gdvo5aoefxj0bEZOU/zvX3Ay3ML/Ifaxn0JAfz6udZTyWn3Aw3Me zG2Usu7G3Aul7UwVzJjMaZtJFROmUuySvRsOxWtjiy4Flml/EzC7OMEF28GsCM6N5hecsf TM+1B8Y3FcBMkRMEElHo9uvvhVwNsDabcRAxgS3sXMSCbVQZV7uy+et2T7FZSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692025686; 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: in-reply-to:in-reply-to:references:references; bh=YMGiIB3ZRF9xDuzowmKuMGbuFtNeEa/dk8I9+QRM62A=; b=A/v8uHIc6YkhrKwX4WgWj9AyS0n/YfPYLmkYO4r+DX+PvdR7DsEfNOJZKJtSJ7fiNpVY+S IuudXucGLZYvuDCQ== 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: migrate_swap_stop() Cc: "Peter Zijlstra (Intel)" , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230801211811.964370836@infradead.org> References: <20230801211811.964370836@infradead.org> MIME-Version: 1.0 Message-ID: <169202568621.27769.9047614343930343004.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773065352895588712 X-GMAIL-MSGID: 1774218228223257305 The following commit has been merged into the sched/core branch of tip: Commit-ID: 5bb76f1ddf2a7dd98f5a89d7755600ed1b4a7fcd Gitweb: https://git.kernel.org/tip/5bb76f1ddf2a7dd98f5a89d7755600ed1b4a7fcd Author: Peter Zijlstra AuthorDate: Tue, 01 Aug 2023 22:41:24 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 14 Aug 2023 17:01:25 +02:00 sched: Simplify: migrate_swap_stop() Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Link: https://lore.kernel.org/r/20230801211811.964370836@infradead.org --- kernel/sched/core.c | 23 +++++++---------------- kernel/sched/sched.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6e8a8e9..66478a6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3433,7 +3433,6 @@ static int migrate_swap_stop(void *data) { struct migration_swap_arg *arg = data; struct rq *src_rq, *dst_rq; - int ret = -EAGAIN; if (!cpu_active(arg->src_cpu) || !cpu_active(arg->dst_cpu)) return -EAGAIN; @@ -3441,33 +3440,25 @@ static int migrate_swap_stop(void *data) src_rq = cpu_rq(arg->src_cpu); dst_rq = cpu_rq(arg->dst_cpu); - double_raw_lock(&arg->src_task->pi_lock, - &arg->dst_task->pi_lock); - double_rq_lock(src_rq, dst_rq); + guard(double_raw_spinlock)(&arg->src_task->pi_lock, &arg->dst_task->pi_lock); + guard(double_rq_lock)(src_rq, dst_rq); if (task_cpu(arg->dst_task) != arg->dst_cpu) - goto unlock; + return -EAGAIN; if (task_cpu(arg->src_task) != arg->src_cpu) - goto unlock; + return -EAGAIN; if (!cpumask_test_cpu(arg->dst_cpu, arg->src_task->cpus_ptr)) - goto unlock; + return -EAGAIN; if (!cpumask_test_cpu(arg->src_cpu, arg->dst_task->cpus_ptr)) - goto unlock; + return -EAGAIN; __migrate_swap_task(arg->src_task, arg->dst_cpu); __migrate_swap_task(arg->dst_task, arg->src_cpu); - ret = 0; - -unlock: - double_rq_unlock(src_rq, dst_rq); - raw_spin_unlock(&arg->dst_task->pi_lock); - raw_spin_unlock(&arg->src_task->pi_lock); - - return ret; + return 0; } /* diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 9c5035c..c299a58 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2614,6 +2614,12 @@ static inline void double_rq_clock_clear_update(struct rq *rq1, struct rq *rq2) static inline void double_rq_clock_clear_update(struct rq *rq1, struct rq *rq2) {} #endif +#define DEFINE_LOCK_GUARD_2(name, type, _lock, _unlock, ...) \ +__DEFINE_UNLOCK_GUARD(name, type, _unlock, type *lock2; __VA_ARGS__) \ +static inline class_##name##_t class_##name##_constructor(type *lock, type *lock2) \ +{ class_##name##_t _t = { .lock = lock, .lock2 = lock2 }, *_T = &_t; \ + _lock; return _t; } + #ifdef CONFIG_SMP static inline bool rq_order_less(struct rq *rq1, struct rq *rq2) @@ -2743,6 +2749,16 @@ static inline void double_raw_lock(raw_spinlock_t *l1, raw_spinlock_t *l2) raw_spin_lock_nested(l2, SINGLE_DEPTH_NESTING); } +static inline void double_raw_unlock(raw_spinlock_t *l1, raw_spinlock_t *l2) +{ + raw_spin_unlock(l1); + raw_spin_unlock(l2); +} + +DEFINE_LOCK_GUARD_2(double_raw_spinlock, raw_spinlock_t, + double_raw_lock(_T->lock, _T->lock2), + double_raw_unlock(_T->lock, _T->lock2)) + /* * double_rq_unlock - safely unlock two runqueues * @@ -2800,6 +2816,10 @@ static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2) #endif +DEFINE_LOCK_GUARD_2(double_rq_lock, struct rq, + double_rq_lock(_T->lock, _T->lock2), + double_rq_unlock(_T->lock, _T->lock2)) + extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq); extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq);