Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp259420lqg; Fri, 1 Mar 2024 04:39:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVO4T08qObvEv2SfGgxkcAy7GCJqtsAua4UWmY1L8bo0IsreelCpGMu5FCATSe1bduyYexsOh/st074U+tZFjxpvLTjO6GjTOdG84fQAQ== X-Google-Smtp-Source: AGHT+IHeu4M9dAHFHDaesJpvkHkgkkWEAkCjR/d6tJZw4m8h91KXSsgaOiNF396CETufMY8bkvBw X-Received: by 2002:a05:6402:2267:b0:566:201e:c18d with SMTP id du7-20020a056402226700b00566201ec18dmr1490357edb.13.1709296744720; Fri, 01 Mar 2024 04:39:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709296744; cv=pass; d=google.com; s=arc-20160816; b=trXF6kxxix11QPmpGtb9pwaySfXquj+gTIemA0l9nnCT70e1hTL0ZeFtuTlgz8fBWn GQaLCijB7U+vsLiARFF7O7YGYRd9oQESMzlXbmMoIgMCRu99Acs9RGzAedkt3sHyKAvf ++Rx5YghK4GYmsHH/e8Isk1xdbG5jilH1SHD6506LzcXMjrTcV4/15cWhSdfZ2erfWiC PcKKKbtMXab0OWMPth+iVYc0X8d3E7TQoerj1izYB2aqIdvI2vna5Rckf2dchD0+HfQl 2ullPDX3p5EMnyljMpjvKwSbDcCjxoBVkG2ADeJFPsIw5Mpb1yhzz0DHoXe64B3W+8zk og2w== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88406-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l14-20020a056402254e00b005664895cd8fsi1420276edb.53.2024.03.01.04.39.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 04:39:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88406-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88406-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 70E9E1F21D93 for ; Fri, 1 Mar 2024 12:39:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D016B33CD0; Fri, 1 Mar 2024 12:38:53 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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