Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp399211lqg; Thu, 11 Apr 2024 06:34:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKB5VIqAzWCcjPXtpMffG6oYSAb2ngjqsjZHg9iE9c7ySbdjj47HlqNzZN6NY4m22fiwHPdvEp/P260yKffSvrYLCoDCugq9Ash2GDZA== X-Google-Smtp-Source: AGHT+IFuYSEKZMXarbYlzZzqO2+us/chrkioQM3ozg6L5P6jA8rAQm/vW+/KdVSPfOkGLE5JGUE3 X-Received: by 2002:a05:6a20:96cc:b0:1a9:8152:511c with SMTP id hq12-20020a056a2096cc00b001a98152511cmr1385310pzc.62.1712842448701; Thu, 11 Apr 2024 06:34:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712842448; cv=pass; d=google.com; s=arc-20160816; b=a6blrYkPby4phLLTOjNzC0yq/dA9mzuK15kiAPCCsVGijt1bVPQZBX8wND32ggHtZS Yg8T1gWCErtPAfskBP2cjm36zjpIQvDJ3uZNL6g0t3tdsz78tItOhYCbaRx8wWtuYrAQ 6Y01UTL1qB+HmXd6CWxvzjq020NSEGcQSdRzw6BRXJPsV//TxK4ycce0YWYWZkHICkS3 jdcvG4vsagYNTqejlrM86k4thDVgvRN+iK8a0bbGf3avxqC2XxFniYwDXVQdthkSFRRi 0VUEpZp7eOqXBKJ/ZakGzWIOGMjgTt8k70EibWHaWJ+qj92ifapfv6yxGZFCs3lo0tfg uA7Q== 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=WNqR9Y5JGQ4CxyKKvoYHU90nk2eqTzymbAxs2+eiH6A=; fh=Ud94Q6dWpSSu3/GJgsQezWkHqhtq6g8OS0jJFkPGhUA=; b=CsdAGf4aKCoDa4obElZWm7CkqytWsGKXJRKGsEx1g5fMPDlvajX/dimWHutUjVo29t 5+A8c0UFg+WXCIEKNqBTJLgRDWKTGC03UqKD9qyDHrMK7YlNemmKQcSrF4Wxu2g8TCA7 mrksV2oC0R/H6dOetVnB5aJlnLKxRqJjvgNFQTWh0kIeyMzneWRxwu4v1fUQxt1hfHpF fspbwfzPgirEQq8A+qJ46xvB6/rEi0JreGamGPq7FODYDa/i443m0OSQMAPymKBVyBKK 4/lX0zalWyOjiGWpQln+97FI6sbkmkF4GbuUeq1Zp6A9j4aoSii7dFMMN63D1TecL2ai xdtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ylU+1+Wr; 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-140513-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bz38-20020a056a02062600b005dc3e74657csi1354609pgb.478.2024.04.11.06.34.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 06:34:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140513-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ylU+1+Wr; 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-140513-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140513-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3C9A22866D9 for ; Thu, 11 Apr 2024 13:34:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFF371514C0; Thu, 11 Apr 2024 13:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ylU+1+Wr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jxOaslzx" 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 75F9B14F13C; Thu, 11 Apr 2024 13:33:46 +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=1712842427; cv=none; b=BBTZprAdwEkL2wkwxVDhBKqUbFwJ9J83GnxqGMHceZ/LVtEQowA1RKwepqT5Qk1IJThmLZRxCNoWsfOFCscG/TPoMWIqQp9yigRwcAg+9DikL7OaRzwLEdHhIIxEz5cAu9qGyXlIqt05jUI2VkdKRJY28MHcxx2Vg/+UFyMRKC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712842427; c=relaxed/simple; bh=CTsZ3geEpyeUBeF8httS+4YkKLB1Eb9XdorTHopdmCc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=lHLowZEeikZJwDcBOdhQc05AEMcvGWdf0sntjn1V64M9kqXW2SythQoXMBdwe09HlMqXu+TYGeyFdR6gYBOTF27f7xrKc9T/HmPKf4ymbbJkcMNytbzL5CdgI6GyaTAgB1TFMxl32yJSlJlfwtthjo+O5gG59jgcZVQGjlS7+Wg= 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=ylU+1+Wr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jxOaslzx; 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: Thu, 11 Apr 2024 13:33:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712842421; 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=WNqR9Y5JGQ4CxyKKvoYHU90nk2eqTzymbAxs2+eiH6A=; b=ylU+1+WrvMf5/yZvF5uuF7u3q+k5yokybOyi/Y9FspYg1l9MnGeKXpLh0tY4SxglsuXeDM SdPu1J2PwK9412z1wLHgvhK+Qpgk7mwjcKymnigeMmanxJadfyCyMK4f2t6bOeASoyop92 9tDnj3HjnPmPC6i0HRT0wWZw7cnumUR2748r69At9z3SSezasdZf9ZCUeGUUPtfOtooz0V IQMA3kaK9vII58cqOYC0ChnWtqUdOSFxVT3LQO5dqY3fJko2xVvic7sMXkovxnMY85OPWO Z+v6bRGjPaHQeY+XZj6LIpO/qXyMRh7iSu0EBrIbOfb6wqGDmC+6yGEuQ42zvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712842421; 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=WNqR9Y5JGQ4CxyKKvoYHU90nk2eqTzymbAxs2+eiH6A=; b=jxOaslzxHo+/x/OO53FDxfxmgkMHXAJ+zcqWj8aHIJ7mNhYwpj+gq+Ly5VnOow3+WxwgVM TGUCPb8ZNP29qeCA== 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/pvqspinlock: Use try_cmpxchg_acquire() in trylock_clear_pending() Cc: Uros Bizjak , Ingo Molnar , Waiman Long , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240325140943.815051-1-ubizjak@gmail.com> References: <20240325140943.815051-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: <171284242025.10875.1534973785149780371.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: 7316aec453e4f5cb7bd0d7b856c01ed71d64eafc Gitweb: https://git.kernel.org/tip/7316aec453e4f5cb7bd0d7b856c01ed71d64eafc Author: Uros Bizjak AuthorDate: Mon, 25 Mar 2024 15:09:32 +01:00 Committer: Ingo Molnar CommitterDate: Thu, 11 Apr 2024 15:19:08 +02:00 locking/pvqspinlock: Use try_cmpxchg_acquire() in trylock_clear_pending() Use try_cmpxchg_acquire(*ptr, &old, new) instead of cmpxchg_relaxed(*ptr, old, new) == old in trylock_clear_pending(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after CMPXCHG. Also change the return type of the function to bool. No functional change intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Reviewed-by: Waiman Long Cc: Linus Torvalds Link: https://lore.kernel.org/r/20240325140943.815051-1-ubizjak@gmail.com --- kernel/locking/qspinlock_paravirt.h | 31 +++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h index 169950f..77ba80b 100644 --- a/kernel/locking/qspinlock_paravirt.h +++ b/kernel/locking/qspinlock_paravirt.h @@ -116,11 +116,12 @@ static __always_inline void set_pending(struct qspinlock *lock) * barrier. Therefore, an atomic cmpxchg_acquire() is used to acquire the * lock just to be sure that it will get it. */ -static __always_inline int trylock_clear_pending(struct qspinlock *lock) +static __always_inline bool trylock_clear_pending(struct qspinlock *lock) { + u16 old = _Q_PENDING_VAL; + return !READ_ONCE(lock->locked) && - (cmpxchg_acquire(&lock->locked_pending, _Q_PENDING_VAL, - _Q_LOCKED_VAL) == _Q_PENDING_VAL); + try_cmpxchg_acquire(&lock->locked_pending, &old, _Q_LOCKED_VAL); } #else /* _Q_PENDING_BITS == 8 */ static __always_inline void set_pending(struct qspinlock *lock) @@ -128,27 +129,21 @@ static __always_inline void set_pending(struct qspinlock *lock) atomic_or(_Q_PENDING_VAL, &lock->val); } -static __always_inline int trylock_clear_pending(struct qspinlock *lock) +static __always_inline bool trylock_clear_pending(struct qspinlock *lock) { - int val = atomic_read(&lock->val); - - for (;;) { - int old, new; - - if (val & _Q_LOCKED_MASK) - break; + int old, new; + old = atomic_read(&lock->val); + do { + if (old & _Q_LOCKED_MASK) + return false; /* * Try to clear pending bit & set locked bit */ - old = val; - new = (val & ~_Q_PENDING_MASK) | _Q_LOCKED_VAL; - val = atomic_cmpxchg_acquire(&lock->val, old, new); + new = (old & ~_Q_PENDING_MASK) | _Q_LOCKED_VAL; + } while (!atomic_try_cmpxchg_acquire (&lock->val, &old, new)); - if (val == old) - return 1; - } - return 0; + return true; } #endif /* _Q_PENDING_BITS == 8 */