From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEDD135AC2D for ; Fri, 6 Mar 2026 22:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772837519; cv=none; b=kih6dgipIHYnKuuHKrfulkVUpICn/vYYMR7C+uVfw7R4y0ZREEc4yQCjYJisnlJd5twhcOqNqcrvkLr46OIT/kzzLbheejAC6Mpz70SlW+0OruStNqkfeZ3sjIS40sRTPyys67a0+mRcYEtrEg1TW2ONV7+3gdBB1vSpGZr7TqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772837519; c=relaxed/simple; bh=kBmrmMgLNdyt4E9Zugo/Q64IQu7gAlgFQJUnp65MRdI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XtKc9AGKlTOTxEXHWYJ4ejsC3iowquhuYc6SbHtcBZFr70jFe4Koj3HZhgGlLkYLETMq78qgrFXog+FN5SOC5wU03QCy3BCoOyV56UGPQeCuAYY8KFcDpXjVGXAVpuK3DehIfm87/CXgrnIvw3Yxf4d16IlPoTDac0VTjBaMEng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bdN2szU3; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bdN2szU3" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-439b790af67so3759071f8f.0 for ; Fri, 06 Mar 2026 14:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772837516; x=1773442316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XC9jtm4WiIgFtvh7yHCK73pPr3f6g+wj+j5SOjMROmk=; b=bdN2szU3PpsLfs4rXfy8WRIeN+xFNwcEu/x/OdAEUG6GDRA2loVVBo3KKC5SmK8P+e Z4HfRilH60zECKfJo7VB/KLqjcay9+bL+3kS8Jvi411905SJMst2Z74E6mjMDhGZhD3J knw854LFsQhqLMiI5cYEcP9NQe5fR43PRvSpGP06aFma0zv8fY4/IY5jAU2gkXXAQgzY nJw77VSt+TdvNU8z0E/A7kXqlMFUvlZkUpR+pdroHmF2AgbjY4JlCu39uA5zRcxszUG2 UzADUN/sz9Q7jjeFtJ2LNBl4AKMDzkWpM8CFtEDvVJsh2M1QzrGsXCqbXpLXxuiknfRe LCUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772837516; x=1773442316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XC9jtm4WiIgFtvh7yHCK73pPr3f6g+wj+j5SOjMROmk=; b=VvZSkZ9bnSV0U3ggh+wMiDcFfPBB7AimdW4afc5WMBFqkwTEOxHiQ16DIuYGWEnc2x 4syjlbKQIirFDA+OfLIF48d8erDhLsSw8YkLRwQXdcOQVXnjugcO9uazi8NaJeTRFz3Q 0YrpPaMVKYJaAlbvm60Cw65ZItIFD4TtO7H2+pdCN3lQkG4MUFdVQkYvr3e1OYMqkvsZ HzZSpmT+ThDbVk3d9H1hP6G4iyhSriFe5kK0DbNUE1ByTDGBI/uRF/vogU1EvHAqRgMV B13+eBGJqNh1a9CGyDjRL1IIjvRdr4n12PBwLC3vnClPe9RTVf59Ua3xpt5wgvE5zP73 2/Hw== X-Forwarded-Encrypted: i=1; AJvYcCVjhAjhZZ1W3rjhBzn+8wOmY85MXS4LnWc0hYzD4USuITIv9BSyxguDG8EkO1o3KklVGZROsLlkixuaJSo=@vger.kernel.org X-Gm-Message-State: AOJu0YyHeIHabgzaNCRx2QgaNvQZGatcbQg2No2Xt/YCdtXnHrN84dFo 3l22KgsBZe91rmZdMORlwJW2GvwNIyQMz26lSz5wZF6ssSYWmUtMOGAB X-Gm-Gg: ATEYQzxxaJwUhx0jafgfM9XfmFStGLH5VOYfAVPsvYW1Q+QI4vqGncolaKARdUytWwG f4npUAYkbd2w65opoFWWO8ycoGUxxrwZ7fRilbuHxliN6PqJ9uRLWpxk4dvqfMfI5RyBJHGX5wS xn2M+lRKGeVDw55tz1WemSGTz+QZBDScJomFR2Ryght5GXCbvY0Z4Za/HetojVwLN4wrtdJOhlT sLMonVh837Jm7eOrB0vqGZSt/ifBLb2OMApfQ+mEv17WqSBtSg1gvdQzYbVER7SdH+Jh+LgJxuW N5VGqBkN6/Anq4MpLoG34l5LHC8RZs8Q7l+/Am51yvpo3BzanvTu7aNHa0LmpZd50X2vcXRwSa5 AEZEuWGUebRUWoD5lHVL7E+6ik15D5Wixx2+DZFy5w2vD9yIxxOVDNFsdAN/wfaLP97bjBPONSb rYMsRfniP9FSjyTqC55nX3BYEJAe9OqNPPCenE7lkPcpUIp+m27DQWQj1wzqT1UDbJ1aDqXoMqy 5TpFLBtliOh X-Received: by 2002:a05:600c:1e88:b0:479:13e9:3d64 with SMTP id 5b1f17b1804b1-48526759d12mr71041765e9.15.1772837516297; Fri, 06 Mar 2026 14:51:56 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dae57c05sm6160845f8f.39.2026.03.06.14.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 14:51:56 -0800 (PST) From: david.laight.linux@gmail.com To: Waiman Long , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Linus Torvalds , Yafang Shao , Steven Rostedt Cc: David Laight Subject: [PATCH v3 next 3/5] Use node->prev_cpu instead of saving node->prev Date: Fri, 6 Mar 2026 22:51:48 +0000 Message-Id: <20260306225150.93178-4-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260306225150.93178-1-david.laight.linux@gmail.com> References: <20260306225150.93178-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight node->prev is only used to update 'prev' in the unlikely case of concurrent unqueues. The new 'prev' pointer can be obtained from prev_cpu. node->cpu (or more particularly) prev->cpu is only used for the osq_wait_next() call in the unqueue path. Normally this is exactly the value that the initial xchg() read from lock->tail (used to obtain 'prev'), but can get updated by concurrent unqueues. Both the 'prev' and 'cpu' members of optimistic_spin_node are now unused and can be deleted. Signed-off-by: David Laight --- kernel/locking/osq_lock.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c index 0e1c7d11b6c0..5dd7e08d4fda 100644 --- a/kernel/locking/osq_lock.c +++ b/kernel/locking/osq_lock.c @@ -13,9 +13,8 @@ */ struct optimistic_spin_node { - struct optimistic_spin_node *next, *prev; + struct optimistic_spin_node *next; int locked; /* 1 if lock acquired */ - int cpu; /* encoded CPU # + 1 value */ int prev_cpu; /* encoded CPU # + 1 value */ }; @@ -96,10 +95,9 @@ bool osq_lock(struct optimistic_spin_queue *lock) struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); struct optimistic_spin_node *prev, *next; int curr = encode_cpu(smp_processor_id()); - int old; + int prev_cpu; node->next = NULL; - node->cpu = curr; /* * We need both ACQUIRE (pairs with corresponding RELEASE in @@ -107,23 +105,22 @@ bool osq_lock(struct optimistic_spin_queue *lock) * the node fields we just initialised) semantics when updating * the lock tail. */ - old = atomic_xchg(&lock->tail, curr); - if (old == OSQ_UNLOCKED_VAL) + prev_cpu = atomic_xchg(&lock->tail, curr); + if (prev_cpu == OSQ_UNLOCKED_VAL) return true; - WRITE_ONCE(node->prev_cpu, old); - prev = decode_cpu(old); - node->prev = prev; + WRITE_ONCE(node->prev_cpu, prev_cpu); + prev = decode_cpu(prev_cpu); node->locked = 0; /* * osq_lock() unqueue * - * node->prev = prev osq_wait_next() + * node->prev_cpu = prev_cpu osq_wait_next() * WMB MB - * prev->next = node next->prev = prev // unqueue-C + * prev->next = node next->prev_cpu = prev_cpu // unqueue-C * - * Here 'node->prev' and 'next->prev' are the same variable and we need + * Here 'node->prev_cpu' and 'next->prev_cpu' are the same variable and we need * to ensure these stores happen in-order to avoid corrupting the list. */ smp_wmb(); @@ -179,9 +176,10 @@ bool osq_lock(struct optimistic_spin_queue *lock) /* * Or we race against a concurrent unqueue()'s step-B, in which - * case its step-C will write us a new @node->prev pointer. + * case its step-C will write us a new @node->prev_cpu value. */ - prev = READ_ONCE(node->prev); + prev_cpu = READ_ONCE(node->prev_cpu); + prev = decode_cpu(prev_cpu); } /* @@ -191,7 +189,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) * back to @prev. */ - next = osq_wait_next(lock, node, prev->cpu); + next = osq_wait_next(lock, node, prev_cpu); if (!next) return false; @@ -203,8 +201,7 @@ bool osq_lock(struct optimistic_spin_queue *lock) * it will wait in Step-A. */ - WRITE_ONCE(next->prev_cpu, prev->cpu); - WRITE_ONCE(next->prev, prev); + WRITE_ONCE(next->prev_cpu, prev_cpu); WRITE_ONCE(prev->next, next); return false; -- 2.39.5