From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 1BC9833A029 for ; Fri, 6 Mar 2026 23:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772838219; cv=none; b=oOGZRq+tGOIZ2NP37u8AKpzkzCMAOdykFN9GVWyDIErIZr8OJicyDIPtai0dck/Ef1OjPOPXvXZ1wwWIfymIwRiNGxUjwJIIh6u9GuZ+GK0HaEUUjXjc9WAHyTaMJnsrWtCjWnNb529/IIibHNqLCsRxoGuw/QVfpMuAQPy0rXk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772838219; c=relaxed/simple; bh=MSba6/sAaO61r4LY9LfnocvfFDUogKipVFzaVtfPpEU=; h=Date:From:To:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m/GdtXpPq/OumeNF70ux+fJLjxHg3U70XKXvrbxTrA98iaYpKhtQaETkH8GWT6WhLotSzyprnBVABPaveCGl2/mRb21jFrl40nm3gADWa0ICQabpKEXswF83vU2LVx+YLSAFksqfEi/F10lJIBWMDi7qrXqfFzzjimxWctikg9o= 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=GxQ/UXZS; arc=none smtp.client-ip=209.85.128.49 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="GxQ/UXZS" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso80745195e9.1 for ; Fri, 06 Mar 2026 15:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772838216; x=1773443016; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=VL+Emgimqbbg8mOVUdkV71rafMv0sCsu5Z54ZleT/6c=; b=GxQ/UXZSDdEeCM45AtAXiGqaoV1ocVhiWGwtH9LYQDJsvYNGh2CdqJnIZf3Rj8n2tE kFESnKaIuhnFQRRLvmGkf+LtcaVIH4RuRlWaJN8o5ddixljPHVhoJcH1euDHl4v4h3Uw qzkGo1HeBJUYUMFZszYDj3y93B+Iow4J56qiLJumFGrrTczLYAXYFOjhZwlW0NvaEIxU nmljCesE3Hrqq8GpsX8p0KLkTqKjlfCaLsvwawsCXupEAd09KSyIjHI8tkYHTrQofyP0 4tUxZAxRHI7MiZC8kpVv50dxvWAhQXfknn9MvCobLI7SXmAxkORzeAKqUeYLHTMa8wfB Z7wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772838216; x=1773443016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VL+Emgimqbbg8mOVUdkV71rafMv0sCsu5Z54ZleT/6c=; b=RewMeiwoXdIh6eCjnHXGPzfxPfwLmA3pgA6FZxJ9WL0OKVIKt4G643Wzcgq0DJvjHE zEfWYvd8NvFRs66OKJu8jZ4+VyWesnT8BaOIEai1zpnKxEksWmFf6eg1q+DQ6RDmNbiW baO/0tptH7FEuKMoYycTusyfYPJMVSv964/BlcVKqET5GHUC7uvjHgIjH47pGcPSW1IM g+AHu7k9OBGvxSZdq7AUvaAuCe+ptF7woVvBQZG2IfOCZy/A/C4+x3zY2Gk/ifj/GNBZ MdyZ0P+2/+B2si1t8MAGCR5dih5kXOtebDlL80glalyJ6K9FezId9sfdJ4L6ZI91NSux KAZA== X-Forwarded-Encrypted: i=1; AJvYcCVU8wgYKyinaHisEcXKiJKp7SXK+Gp2XTIsibyIsFzgoIcD7b70n9mVwm3nbc2QsxRWRF2VkaCpGJ5kF3E=@vger.kernel.org X-Gm-Message-State: AOJu0YzXLhBoXJqgaYw7J+Ul7/bzN2/gJF72imbhziSTyHKEPlRORDkP Le86VfgxYOd7jfjmKo3/ecn64Vf0oMU4fVdRwDlctJxadljjXHOmAyWw X-Gm-Gg: ATEYQzyn3PVX/P/ct4xDb1HUt4abDwZxPtUhInQj9fR8NxPqNjnKQvVB+iLQK6Iluk9 USqxExObF2gEZXDK037xVaY6Dk6LWcano22SqkbKH+hTF3tqvOIhnbMjIynWFjraE4AxYH9AP9C gxOjOcnpGZJNG7qY17rlkLjNs8eCGO81z4MPPp7AeMZQigeeUu/75XviBtKF1lUp5mJ7LuDlMKi IXEKhA8Z4kXOQWIDAMlBPq9bBTKpTPSDA1KrmjgOk5CGQbJDWFEyhlWv503xkYF/hGE9MlWBZsQ qSNW3tU1+qByzYVHEBYM4dg2xhdOidd56mMZiB7es2RIrBlEG7h24EBCy0JK8JcPcopoV4x0+B+ bdsBvNKz0TrF0rc/ls8dT97cLRS8K7XMtklceh2bXrMvB1PcIU/x+2MwITvz+7VNc8Vg2i+w251 QylJf+ElUD1NR07zaT+fFaUcSmSi9JwFaNcUwNyoSK0bpsrnOLp9SuFsgMRDtM6c4B X-Received: by 2002:a05:600c:3483:b0:483:7783:5382 with SMTP id 5b1f17b1804b1-485269612d7mr60903635e9.27.1772838216338; Fri, 06 Mar 2026 15:03:36 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4852ad0ce60sm65107635e9.12.2026.03.06.15.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 15:03:36 -0800 (PST) Date: Fri, 6 Mar 2026 23:03:34 +0000 From: David Laight To: Waiman Long , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , linux-kernel@vger.kernel.org, Linus Torvalds , Yafang Shao , Steven Rostedt Subject: Re: [PATCH v3 next 3/5] Use node->prev_cpu instead of saving node->prev Message-ID: <20260306230334.7f8a039b@pumpkin> In-Reply-To: <20260306225150.93178-4-david.laight.linux@gmail.com> References: <20260306225150.93178-1-david.laight.linux@gmail.com> <20260306225150.93178-4-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 6 Mar 2026 22:51:48 +0000 david.laight.linux@gmail.com wrote: Apologies to Yafang for mistyping his address.... > 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;