From patchwork Fri Mar 1 12:38:48 2024 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: 208816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1046968dyb; Fri, 1 Mar 2024 04:39:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrv0OJTjapVnya9UrFSCPGpMFrZg1zBUeEXuFLHtdVL5qCdhbsUyIcIFw7T/S5Atnr7OBKoJtVVDTVZ7EpHoIH6DKhrA== X-Google-Smtp-Source: AGHT+IG3DV8NgLuwx3bD5NTBMp8Tys20dOMmeCJzFnd9gNdSD0nnlAvsgdAbiE7ufXbaZlTZoDZV X-Received: by 2002:a05:6358:c97:b0:17b:f6d6:2d54 with SMTP id o23-20020a0563580c9700b0017bf6d62d54mr1567810rwj.28.1709296758693; Fri, 01 Mar 2024 04:39:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709296758; cv=pass; d=google.com; s=arc-20160816; b=jWXZ+Ig0VzXvHQWEplkmYt9KLICvbIv024GsgoTkJ4qJikbSxaxx/ScS58Z17U4qm+ FtqelSbpyAkFAmOX4krCPPm+v1HZX/m78Kk98Be+84pkouBM1gkT1GQE/n13NDt8Mqyo XWxPjbjABH9iVZ/iJ2M4mQTRNg9KyNFBebR3C4XuzdsHgTIZGzu3PcBMJe57zdbszAIx ewg508moIMOgx1XvweS8MLqfFZEdHAID83Z7X35QzJQW9YRHc1xW0ntwLH4hrc3Wwogr EYslUSmLuki/+9zVMTlvRpP3JilJzLUUlZ00maqt4lkroNtZOBefg1Pi397kGzCC0+Ze cDUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=jGBPuh9xFafhzrpJQWBTrjACe5BJAQKU5ZVCsVAxxOM=; fh=w49Ka2fdMuS29shJHiVCJ0jkpJk8gLVm/hnrhq3Ospg=; b=LHvGLeQhqm5OQ2PlCvHd1aP/bxBAbIcOLoXXxXxXOJw/6Rqlprmq2iulL7rpEptkBA aOMJ8F0JbR4IrUhX9YXjqAL5IiZPIgD1E1siqMJcIdAgH/JWokk3NvW2/h9LBh0yxPKt +dftVPQ7p8F5DZitBCxpTDdeoCPISmLsNDeS0ZmnJw1lFoxDjrQ2sDdKEKyKa4HD+Hye 0qFWrQMC1rbiCdbiMJoWuvYvNF9d3kAdQSDaelkov+9mT8aBKkPvk3csG1x2OnAWgpjE LUqYEYCuy3xvVK9AbFw/SPGQXU1SYrVJLCkRaplOfLFIXfTIkiwZvzZTMkdfBS4XkQYg NeTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F3hhs45w; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-88406-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88406-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u12-20020ad45aac000000b0068fb7e2785dsi3545441qvg.517.2024.03.01.04.39.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 04:39:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88406-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F3hhs45w; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-88406-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88406-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 79AD91C225E7 for ; Fri, 1 Mar 2024 12:39:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA3B840BE2; Fri, 1 Mar 2024 12:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F3hhs45w"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LbjSABXx" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D5D03FB84; Fri, 1 Mar 2024 12:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709296733; cv=none; b=FcoRPlqzpp/WnaQ4GjzvmraLcKVYSOCi/2yCupRw3Oj6cV2GgqpFD1bOfgEy3iMKkOk5cuW5FK805eOn6PcLsvjK5PfsD04FyT7fCtAIaLV5AdKkPcQRifJ6Yqjqz9Px/Ss6un27RDx0Vvwood3SqVfELmBvhuU+0pC0pZ/zqVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709296733; c=relaxed/simple; bh=qSeqRDVTN9dpiUTvX40r7xH4MdiIS3SY62kiEFe6taU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=QMI+nZm5OsU3aWY/SdmMh6/rgKULQWYW6Yhzgrdnu9PluEWhvQpXcWF4ARNTt5aYLQNrkibY7j68tSF8RjsGk9JwGJ06Bp+OYgv8VWjgLKnnptzVJxTAFja5AWwhHqv0uiQGV5RDIjOuOdh5yETQIU9i7afcvCdclYcrLaokPd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=F3hhs45w; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LbjSABXx; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 01 Mar 2024 12:38:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709296729; 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=jGBPuh9xFafhzrpJQWBTrjACe5BJAQKU5ZVCsVAxxOM=; b=F3hhs45wcVeznJ/JyywwwVaFb3zeOWqGuhI7ENKPLFww1zlHlM4mdtgmqRbpdkLhX+lxmx 6ueGkVjsxVBy47X7r8I9RDAjVqxwUqhIqLhIHiK56lfJc323/fbxrFyRLCqfqb1CEpyvdc /T+BUIQj2YuXJ3/OFCp4qrNw2pPR5JfWj7+llV4Trq95tTC7hoA6nO43mPDVTrgJKvWC9d 2F8Mgw+XZtYCXbvrJb/XL1meYzXZ45UrmahJ05ljDrGCL+bMOpfnCdKUh/Mc+nPsXc0fEi OjVW4UOZXzkJHeRuByNl3DLOeIunu2EDXCiAt0/QfUzOXkJLzfUjtx0NYqt2ew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709296729; 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=jGBPuh9xFafhzrpJQWBTrjACe5BJAQKU5ZVCsVAxxOM=; b=LbjSABXxLR9vJzYEFeJeuTSCLot5dQ81SLuVKiWtkr/kMXA3alXERY3XwX0Oo7O5oFrcgk 4eceQRnGdF2sAmBw== 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: locking/core] locking/x86: Implement local_xchg() using CMPXCHG without the LOCK prefix Cc: Uros Bizjak , Ingo Molnar , Peter Zijlstra , Waiman Long , Will Deacon , Thomas Gleixner , Linus Torvalds , "Paul E. McKenney" , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240124105816.612670-1-ubizjak@gmail.com> References: <20240124105816.612670-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170929672897.398.5127033798711557434.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792327558026353996 X-GMAIL-MSGID: 1792327558026353996 The following commit has been merged into the locking/core branch of tip: Commit-ID: e807c2a37044a51de89d6d4f8a1f5ecfb3752f36 Gitweb: https://git.kernel.org/tip/e807c2a37044a51de89d6d4f8a1f5ecfb3752f36 Author: Uros Bizjak AuthorDate: Wed, 24 Jan 2024 11:58:16 +01:00 Committer: Ingo Molnar CommitterDate: Fri, 01 Mar 2024 12:54:25 +01:00 locking/x86: Implement local_xchg() using CMPXCHG without the LOCK prefix Implement local_xchg() using the CMPXCHG instruction without the LOCK prefix. XCHG is expensive due to the implied LOCK prefix. The processor cannot prefetch cachelines if XCHG is used. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Peter Zijlstra Cc: Waiman Long Cc: Will Deacon Cc: Thomas Gleixner Cc: Linus Torvalds Cc: Paul E. McKenney Cc: "H. Peter Anvin" Link: https://lore.kernel.org/r/20240124105816.612670-1-ubizjak@gmail.com --- arch/x86/include/asm/local.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h index 73dba8b..59aa966 100644 --- a/arch/x86/include/asm/local.h +++ b/arch/x86/include/asm/local.h @@ -131,8 +131,20 @@ static inline bool local_try_cmpxchg(local_t *l, long *old, long new) (typeof(l->a.counter) *) old, new); } -/* Always has a lock prefix */ -#define local_xchg(l, n) (xchg(&((l)->a.counter), (n))) +/* + * Implement local_xchg using CMPXCHG instruction without the LOCK prefix. + * XCHG is expensive due to the implied LOCK prefix. The processor + * cannot prefetch cachelines if XCHG is used. + */ +static __always_inline long +local_xchg(local_t *l, long n) +{ + long c = local_read(l); + + do { } while (!local_try_cmpxchg(l, &c, n)); + + return c; +} /** * local_add_unless - add unless the number is already a given value