From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 E68A135F8B2 for ; Fri, 6 Mar 2026 22:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772837981; cv=none; b=ZUj8377gtlIAWXWfbJH2V41UTdwiJ34FXaBa1h7ZzvluPSqx0cQQRCzg53HA5BjF1ofeEFb3ZVdPqrx00sTjz5OMiwXs5zc+4UHCyVehH6bjg81en0BhHlKBU14ImZcjkHuyqAvGgLdY1gd+gdUqFmDRJVjdeDvI+08dIG/E7ng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772837981; c=relaxed/simple; bh=1lZWHWT+6ccuuSbCVvAubclNB/5k50qaDbwyPFvx16A=; h=Date:From:To:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PudWSKCi3lvqW6lXfhvsVuUrcqqp7Eo7883JzWRwyTxQtiOFB2P0W9mBvTL0uw2UvaoTuZIGOVZWVDvQ75vg0cqXQQ3aWwRZVtIuSzvtpqNEkPNmsqtcaAov94LE2PNJ4NhyFPc9DExYxu9fhiLoX8qnQjyj8pyo6U2JVzDrwFU= 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=jF3kBquj; arc=none smtp.client-ip=209.85.128.47 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="jF3kBquj" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4836f4cbe0bso84838305e9.3 for ; Fri, 06 Mar 2026 14:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772837978; x=1773442778; 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=E6PZ6ZyecKgmNbwaYlo8339OHOhNN0mwoDsV7e4udiQ=; b=jF3kBqujTtJHYSxUktOLNs5v2krhHAq/orZFp4fulgD8I5r9uV2W/qlhR206tjquKD hncTsfdlLlH0DwSePmcK1ttUPSSogTSERMnoJScmDe7Su8PESxEHOj2fvbO2udoPKFtr fVswQwBx0kWJUCWhwoMgc7vWkItFnp9WviVR0+9z6fkW7CgDMBiWHxZcVsQWFyqIHwfc raO6LzsfzOitRJd2As16lFMA4DxzuNp5CS3PNGfowMTCF4moDjUQfXdSjVBh+gTDSUg8 5d3A/6OLH8YrGPtKvgVDvYYhuNgbnvE3Xz7hxxs9vIQalH7UAal5MG8dBOBOJ2sHHFVl h7eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772837978; x=1773442778; 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=E6PZ6ZyecKgmNbwaYlo8339OHOhNN0mwoDsV7e4udiQ=; b=dCq70mC3UIvHLs2D44K55a2o7gfc+/HupxekQHKyv7rXBp5CbV5T08i9kFBQuwoF1N 8YYtcaExcowI8eTvH+AYFSP6D0tnodZKvH9/cWfSJgDXY2MMcy/nP+TnqNd00vVh7HcA 2KAtjPuiC4oByq8NFKnni5DNldr9AcO/jD2jwXW3+VPuTwykRG3AIUQ73C8r9u0MMztl 4oJss2pVhwlOhBAjS1CRuqPEKIj1YVVXT7K/pzYU4WYmX/EwqvysySkMElJ9u41VpQdB /WJDssX5qYLBEidlL83Gf8dKvoD6UgyU4YYXZYD/7QwE+hAjln1TFMfX46zt4qHRAQOL 6mkQ== X-Forwarded-Encrypted: i=1; AJvYcCW3y+VpwjjRIVi/DSOSpiEYNisWykIaY0o/1Kti6pnWJLU8H+V4SXHxRdvvfnh9SVbPsEkiKNBfg/ryGf0=@vger.kernel.org X-Gm-Message-State: AOJu0YxfDiXhO+Yq+LiK3GzsREiFjazN9azV6s7DlBrbO9+u5jhoLe11 iKM/IgAClz7EkY8thfGDAbVPTl6qkiOjhbu+A5VIgS5S7W6HxLbeeRJ6wv54uf3k X-Gm-Gg: ATEYQzxOHBmPm63Z4aSVf+nn1OW4lRWlLgCEzHcuYUrEZunqziOQ+i8f7qwKDSBFh88 AE69+EqqypbbcsSUMsEdUzRMs9w0FKIv+1XsKLLDiIXMnhs1W9VPwl1i+zBotf+uxXeE10bOPz1 TQU8qqGPL8+Trg40OgLgQW+quhw+lkyfE4t5fv1O0UGg/ylYSXBR/vwAotugACutQpaAyMhcUps flICF1Xag9dBeHiX1JnSkM9I7KFg1vNWhJ85JvvEPXjj45czdTSFAQ6/mUATeTSW9tms+wnxxcT xHe3zrYYuRfrr8oEr4JAwfm1RcqDEj13xeIidyEx4+W6paEySe/NPd5BYr3052TTwxLoF3x3dnH qZF+JZFnWZR4knMpMvy72HQQ79PJYBEw79NQoTCZLt/Fpl7LDtkhQ5gguSjHqql5VscVmRSOtsz zayMcadEGYS9AiN2aIPGs6rf6in02/9zyVAKiuzAuNcZjG1aeyrkMF8v7V/xX+iZI3mseh9e9Vm CM= X-Received: by 2002:a05:600d:8446:10b0:485:2ce2:4c85 with SMTP id 5b1f17b1804b1-4852ce24f01mr11280915e9.35.1772837978167; Fri, 06 Mar 2026 14:59:38 -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 ffacd0b85a97d-439dad8dbb3sm6050346f8f.4.2026.03.06.14.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 14:59:37 -0800 (PST) Date: Fri, 6 Mar 2026 22:59:36 +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 0/5] locking/osq_lock: Optimisations to osq_lock code Message-ID: <20260306225936.6445f9ca@pumpkin> In-Reply-To: <20260306225150.93178-1-david.laight.linux@gmail.com> References: <20260306225150.93178-1-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:45 +0000 david.laight.linux@gmail.com wrote: Apologies to Yafang for mistyping his address.... > From: David Laight > > This is a slightly edited copy of v2 from 2 years ago. > I've re-read the comments (on v1 and v2). > Patch #3 now unconditionally calls decode_cpu() when stabilizing @prev > (I'm not at all sure the cpu number can ever be unchanged.) > Patch #5 now converts almost all the cpu numbers to 'unsigned int'. > > Fot patch #2 I've found a note that: > kernel test robot noticed a 10.7% improvement of stress-ng.netlink-task.ops_per_sec > > Notes from v2: > Patch #1 is the node->locked part of v1's patch #2. > > Patch #2 removes the pretty much guaranteed cache line reload getting > the cpu number (from node->prev) for the vcpu_is_preempted() check. > It is (basically) the old #5 with the addition of a READ_ONCE() > and leaving the '+ 1' offset (for patch 3). > > Patch #3 ends up removing both node->cpu and node->prev. > This saves issues initialising node->cpu. > Basically node->cpu was only ever read as node->prev->cpu in the unqueue code. > Most of the time it is the value read from lock->tail that was used to > obtain 'prev' in the first place. > The only time it is different is in the unlock race path where 'prev' > is re-read from node->prev - updated right at the bottom of osq_lock(). > So the updated node->prev_cpu can used (and prev obtained from it) without > worrying about only one of node->prev and node->prev-cpu being updated. > > Linus did suggest just saving the cpu numbers instead of pointers. > It actually works for 'prev' but not 'next'. > > Patch #4 removes the unnecessary node->next = NULL > assignment from the top of osq_lock(). > > Patch #5 just stops gcc using two separate instructions to decrement > the offset cpu number and then convert it to 64 bits. > Linus got annoyed with it, and I'd spotted it as well. > I don't seem to be able to get gcc to convert __per_cpu_offset[cpu - 1] > to (__per_cpu_offset - 1)[cpu] (cpu is offset by one) but, in any case, > it would still need zero extending in the common case. > > David Laight (5): > Defer clearing node->locked until the slow osq_lock() path. > Optimise vcpu_is_preempted() check. > Use node->prev_cpu instead of saving node->prev. > Optimise decode_cpu() and per_cpu_ptr(). > Avoid writing to node->next in the osq_lock() fast path. > > kernel/locking/osq_lock.c | 56 +++++++++++++++++++-------------------- > 1 file changed, 27 insertions(+), 29 deletions(-) >