Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp609674rdb; Thu, 30 Nov 2023 13:16:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPdJRb9Fn10t7qg9yC1bl+0KiGLVc3YALoQdGAFcRkhSwPJvv/j2oV8YAuanu7pNUUWeaw X-Received: by 2002:a05:6a20:9e4d:b0:188:1281:8994 with SMTP id mt13-20020a056a209e4d00b0018812818994mr28139050pzb.35.1701379018890; Thu, 30 Nov 2023 13:16:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701379018; cv=none; d=google.com; s=arc-20160816; b=uvwV70SnNWglcyditfUdu1jwS0GyNyfcpY44I13kkqvMf6ck+FlB8aglKFHgJQncgd crxDYCdE0QcsuL05q7xZC/3VS4R9aTucWj3Tpx8Pf5/trvo654UCBAiHYYE6CpFItdnG ITmYstnsvens3gNw8O2/LtCk5/11LJFnwq02J2goBlqZOrH9Fz4KYjfnHULPBEdmBUwg 2yNYnlbNDaTbW0ONBLl+1BYYGDLDS7o+W8Cd/EWuphb4MnHl7FbVi0f/VDmJYYCkWp3g PgGUuw3OcV866+5OdYUDONSdb5yJLYfVnD2hu7V1sBd97CbeynG514QZqCN3cUlucLKi MFeg== 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=PtG/pJNQ7Od6jW99MrxTBwU7p8L9C5Q2DPh/DamRQNY=; fh=lC3L+tLu9jMrTwLXdci/D+zTDmYl6oRylGrfIkeVy60=; b=fQMJJCJWYSA6yVmFDHo6Zt+NJb/9vvSwxLoS638AMuxnKeW812J4ZSyihzhhtpzZII +C7GZulUGGUHhWomaKT3yo3mshyR20y1SxNG/u5s9flsv23nlEF8YY0iLMCyNFPXErLh DbHBqRl89K+EqPY6LSk/MHKD5LZrZxKr0dG2MIhi4706e8fRKEfOb/8J7U37dGZL37cV YAuvqEmbPUArysRcahrH6TLPacMMCNrq2cKe7hGKuSBkaKVPa+xDcCPKo/nM9+qdQ+rU /3yMCRWv0Xq1IRsF/fZtB9gr6wfK4MjKjf3ebvBUNNwFDnsV/QaWXxgl8gL9G9mK0SRi Iz8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2gelQeEc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UOv04alI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cw5-20020a056a00450500b006cbfe297885si2114726pfb.110.2023.11.30.13.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:16:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2gelQeEc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=UOv04alI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 C2BCD82F2C65; Thu, 30 Nov 2023 13:16:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376830AbjK3VQ0 (ORCPT + 99 others); Thu, 30 Nov 2023 16:16:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376829AbjK3VQ0 (ORCPT ); Thu, 30 Nov 2023 16:16:26 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC40DC4; Thu, 30 Nov 2023 13:16:31 -0800 (PST) Date: Thu, 30 Nov 2023 21:16:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701378989; 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=PtG/pJNQ7Od6jW99MrxTBwU7p8L9C5Q2DPh/DamRQNY=; b=2gelQeEcnPGYDIKblA3e0q2C3luQCLUh8zslN9yEdngo/cHsxyIO1q1fAGiI93xkmjvLdG RJyt18grKlYW+PO+Ws/NRoKKODfFF3q/34grzfTlBh8gt7XDfRo3RDX+3eSMWhAamy4vLN pQtethRjqdhdk4JIWBRnbwC0A5QsGb2k5jKVqt0RmTEm3iL1b3PE1VyGpD4NT66Kd/Pw2y j0eMTRk7CVGyJNW3UR/vJsTpjCskgVMjASXnRO0x6RVlvYaqS3OXuAg7oe26bxvtfIONVu 8xgSwsgkYNjckaqWkWG9v7u/R9SGs9NDa42b8SYC3T6nztACB4B7vpyu7DFYpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701378989; 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=PtG/pJNQ7Od6jW99MrxTBwU7p8L9C5Q2DPh/DamRQNY=; b=UOv04alInXHYPKlrEmzLQUaWcsmSx+/WpEfbSE2S/3meQjCAvXJkUCpMMCXoGm3CAdMdCQ 1C/Uk3RTm0RHa8CA== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/percpu] x86/smp: Use atomic_try_cmpxchg in native_stop_other_cpus() Cc: Uros Bizjak , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231123203605.3474745-2-ubizjak@gmail.com> References: <20231123203605.3474745-2-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <170137898888.398.2140410650044568209.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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]); Thu, 30 Nov 2023 13:16:51 -0800 (PST) The following commit has been merged into the x86/percpu branch of tip: Commit-ID: 9e9d673b2c84719937db5d6ab1d8cbcd7d45e974 Gitweb: https://git.kernel.org/tip/9e9d673b2c84719937db5d6ab1d8cbcd7d45e974 Author: Uros Bizjak AuthorDate: Thu, 23 Nov 2023 21:34:23 +01:00 Committer: Ingo Molnar CommitterDate: Thu, 30 Nov 2023 20:25:09 +01:00 x86/smp: Use atomic_try_cmpxchg in native_stop_other_cpus() Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old. X86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after the CMPXCHG. Tested by building a native Fedora-38 kernel and rebooting a 12-way SMP system using "shutdown -r" command some 100 times. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20231123203605.3474745-2-ubizjak@gmail.com --- arch/x86/kernel/smp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c index 65dd44e..1bb7952 100644 --- a/arch/x86/kernel/smp.c +++ b/arch/x86/kernel/smp.c @@ -148,15 +148,16 @@ static int register_stop_handler(void) static void native_stop_other_cpus(int wait) { - unsigned int this_cpu; + unsigned int old_cpu, this_cpu; unsigned long flags, timeout; if (reboot_force) return; /* Only proceed if this is the first CPU to reach this code */ + old_cpu = -1; this_cpu = smp_processor_id(); - if (atomic_cmpxchg(&stopping_cpu, -1, this_cpu) != -1) + if (!atomic_try_cmpxchg(&stopping_cpu, &old_cpu, this_cpu)) return; /* For kexec, ensure that offline CPUs are out of MWAIT and in HLT */