From patchwork Thu Nov 30 21:16:28 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: 172126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp690712vqy; Thu, 30 Nov 2023 13:16:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZbXZq4WXJiwec7Va5NQTBpQoVvd4UExWZrbJB5tkhgY39trwrJSNhmtlhICydZWv3v80M X-Received: by 2002:a17:902:ee4d:b0:1d0:4be4:8dcc with SMTP id 13-20020a170902ee4d00b001d04be48dccmr1073210plo.9.1701379006168; Thu, 30 Nov 2023 13:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701379006; cv=none; d=google.com; s=arc-20160816; b=siROP6nPmIddd1URicSH/67N6p7IJpo1kkGZ9FslnR+p2yo/MynPuyKGRVE66y2Nf5 STsTqdIxL1E5cSVdT0WRmcHLCrraECB8CDfqgFKe4y6GbskOCiVY7GtlMrL/+kYN3pDZ P7M6EEP/T7onKNA8g1EVUXK2xKFURx+4C4/Hhv/uIFay7Ni4QCEckA+g4GRSdhQ3NdHH 7NaYQuQm1WPpiThq0RSgEFV/5J6QpZFpY3rD5Db+HPBX/OgkdHH83pPpFqluoK5ligcw 16nLYzoyAF5JU2zrOj04O1pux+mQsHF00P4HWKu5tRgNTQDUwzd7uOJBPvPP0LG89ggW AsZA== 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.b=UOv04alI; 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 j17-20020a170902da9100b001cfc170c11asi1962555plx.475.2023.11.30.13.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:16:46 -0800 (PST) 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=2gelQeEc; dkim=neutral (no key) header.i=@linutronix.de header.b=UOv04alI; 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 6C1C382E877A; Thu, 30 Nov 2023 13:16:39 -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 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:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783388527401061689 X-GMAIL-MSGID: 1784025192673521466 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 */