From patchwork Fri Sep 15 11:25:01 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: 140519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1152270vqi; Fri, 15 Sep 2023 09:03:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVsKkelcsBRQYhABpGVNDCa+4rjBr3XyAeG7ne2kfwGB4qVPhxM65ArbPtqyU7S8+5wKdy X-Received: by 2002:a17:903:491:b0:1c3:4444:3c9e with SMTP id jj17-20020a170903049100b001c344443c9emr1992603plb.58.1694793818078; Fri, 15 Sep 2023 09:03:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694793818; cv=none; d=google.com; s=arc-20160816; b=kKT4pu8BGMlFGmxf1JZSLfMBvmxYj0oSntKUa4c4DYeR3vZN924nexYFnPiP5B3RQo sSGjoYh0GSXmaWKUGaxMSmvawX5yeVZLStnDUspsjpISXTAp+LmbtT6RUOZF1KBgaGM/ 73vrojVq6jCIWk4Jae+IDQe9wR0Hs4tkEOmDXWad1OeH9JhyxHw5jMI6m8aZm157uhZ7 o9045KgRIbxwbBTAB/V05hbRh8iYzbpEha3HgbUtKbP6voecjWKmZUhvN1M+1SsAc+B+ uKJ3rQ1TeLbtgJBJyBsHV/RymmDt8k4AB5FwhHn3W278Ue202p5RzDMQVJ/z5MNBXsEk UrvA== 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=aFgNEf9KkosXtEXMOYUFxRfb/yHPUkGh+NbET7KpgyU=; fh=0ceVkAIoz2nvfKPaWOLMlEP+kUNWnCRRlalO2ise3Rk=; b=Ods5XDDZQx629VkEm/huY/F2PZlOg1SUGDKY9aaKwZnBACLMl2LSrg8Y5onZ75d2JU imyHSkeKbfUmHoyMdByYgh5smNz0wo0Z/KYhkK2ri2F1WJAZzVcF39CXjHrx0fKGI6c3 Vxx2SxeNZ2SP+Dw/MrhdHlSjYXHyM6cYHzjR4a4GXB6GdMrEZAL4FHeMYVq/tZOzSOwI XM175/yWgDZqwcE7mmLvXxSX57WnYY7NdZD6YbNBnlBAt3pZ63QOu2h+RIQYY6qfiCgq 4RfFo5967bJ1+9CBXEPrBMuLlHYo2M7psoBKMKT81mLAsBMuUGdEawzkX+ghzdlRsQsx Vleg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BxzqdzKL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b001b894687ec9si3734362plg.462.2023.09.15.09.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:03:38 -0700 (PDT) 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=BxzqdzKL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 BB82583B2D6C; Fri, 15 Sep 2023 04:25:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234305AbjIOLZN (ORCPT + 32 others); Fri, 15 Sep 2023 07:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234343AbjIOLZK (ORCPT ); Fri, 15 Sep 2023 07:25:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86781CC4; Fri, 15 Sep 2023 04:25:03 -0700 (PDT) Date: Fri, 15 Sep 2023 11:25:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694777102; 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=aFgNEf9KkosXtEXMOYUFxRfb/yHPUkGh+NbET7KpgyU=; b=BxzqdzKLCC1b/mn/ogPsTNMt3ljEdYQzXUokqdYIFGCn/MePX5+v5wvsraHgjr/DA8Rc6U KcsgJtXvNxz/FqrTg8yrNxRyCpAxxcyalC/QBts4p4oA7oEOsvPS6IWbuXyQCBQb0JK1Jo xzdDZCVbwIn1L53/aDg4Kui5XvQsvCfi3RCcR25mHY/YmZF4BAPUe2nea5Hzurx+GfpNuO /y0kCwJwXTV63JwFxNfettgbcthG42h7K/S3pXK3mDFk9aGTH9+0kMB51/K7C1jvOHrWpF 8elcT5tVHa1HsjSLfbo9zeGxal95iKIcHDwyKusuHpaNc2+bc523AIOB42GQ5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694777102; 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=aFgNEf9KkosXtEXMOYUFxRfb/yHPUkGh+NbET7KpgyU=; b=Ivms8OZDGOMcjNzHLUZrk6b5c+YZ9EMkUZqY6LJ3yy/ioxCYvk3OfWU3u3fAwRaNlNx3uD 8tTkrS+uDCXjL8AA== 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/asm] x86/percpu: Use raw_cpu_try_cmpxchg() in preempt_count_set() Cc: Uros Bizjak , Ingo Molnar , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230830151623.3900-2-ubizjak@gmail.com> References: <20230830151623.3900-2-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <169477710134.27769.4966191345863204187.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 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]); Fri, 15 Sep 2023 04:25:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777120122391506374 X-GMAIL-MSGID: 1777120122391506374 The following commit has been merged into the x86/asm branch of tip: Commit-ID: b8e3dfa16ec55f310dd95831614af3d24abf5ed5 Gitweb: https://git.kernel.org/tip/b8e3dfa16ec55f310dd95831614af3d24abf5ed5 Author: Uros Bizjak AuthorDate: Wed, 30 Aug 2023 17:13:57 +02:00 Committer: Ingo Molnar CommitterDate: Fri, 15 Sep 2023 13:19:22 +02:00 x86/percpu: Use raw_cpu_try_cmpxchg() in preempt_count_set() Use raw_cpu_try_cmpxchg() instead of raw_cpu_cmpxchg(*ptr, old, new) == old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after CMPXCHG (and related MOV instruction in front of CMPXCHG). Also, raw_cpu_try_cmpxchg() implicitly assigns old *ptr value to "old" when cmpxchg fails. There is no need to re-read the value in the loop. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20230830151623.3900-2-ubizjak@gmail.com --- arch/x86/include/asm/preempt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h index 2d13f25..4527e14 100644 --- a/arch/x86/include/asm/preempt.h +++ b/arch/x86/include/asm/preempt.h @@ -31,11 +31,11 @@ static __always_inline void preempt_count_set(int pc) { int old, new; + old = raw_cpu_read_4(pcpu_hot.preempt_count); do { - old = raw_cpu_read_4(pcpu_hot.preempt_count); new = (old & PREEMPT_NEED_RESCHED) | (pc & ~PREEMPT_NEED_RESCHED); - } while (raw_cpu_cmpxchg_4(pcpu_hot.preempt_count, old, new) != old); + } while (!raw_cpu_try_cmpxchg_4(pcpu_hot.preempt_count, &old, new)); } /*