Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6720206rdb; Tue, 2 Jan 2024 10:55:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEoeOY0b1L2QigFMB8NrS1biJwMw8J6AyWV9gioNotqGOuFzDZ+2VahhTNGShdCvPsVC4E5 X-Received: by 2002:a05:6359:4c06:b0:172:f31a:6bfb with SMTP id kj6-20020a0563594c0600b00172f31a6bfbmr22126168rwc.51.1704221714325; Tue, 02 Jan 2024 10:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704221714; cv=none; d=google.com; s=arc-20160816; b=V7QEs+od42PKYPxcXsiCH0g1H6e7VHZ5H7l9HSROkyrxSrz0i610oRkPEWP0nI1MPT alfMAY3xGuUmlFUP7xFd9z6GCicDnFclvl8cP0MUwZ0tJU+/BNcfn1FPpiJXD6QZv+ZL zDunTXOB4Nml1k/zOisHfB+Boan55jhsod6V9EnLd06ZXxN8nh0IiA6dTyNQRr4aP9n3 fB5Tg4YPj8SQZOd7CHkdGSLTSWtHDl7q2CkLD/rG9OgbgNuPnmDcUipH9pfC15HOUkhu smfoZy0FyZ/MG6C0eoMysssdDtuQombTWQA4WN+ByTaatThnYt5zUwN+1BO59izb+NMl drXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=7+SZED/A1h752GveqQ8KwOCCj8k8UMoXQ0xqbzwkRoU=; fh=dyt8kZs0HTY3EhIgOso4+LiWpKlg/tJ357ZbxRedKZQ=; b=wS2hLMSj3Tfc0PuEQ/Yhj6G3YQ4MxqX14PlVa439vGN+WtEd4vJluq8l1CNNRuBSJN RggaTWPrKb8qUdrF94k6yV8XMW770RR33dVEpmto+YZnfIF1u8oVnR58ytev16m6rey+ MVIyQJ+Lvm48Nc2jx0dC0V5PmQCQ/wQbBKyian6yAcB7lcAyWxax9PtJJZ7UCCf7GF2V KbJ1LE/Js7w5UYv+8bU8gb/4zH3MLdzIkMRZjYt9PZhIW7h52FSWgKXRmvFu+QI6p8qK NcctBB148Rh5QGAaAHiwZAnP7iQ8iQWsbx4vxOvoQNx2JXJEvWJS0EPTFOO4RzZ3DQxv a6hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lhR5yFOT; spf=pass (google.com: domain of linux-kernel+bounces-14747-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y36-20020a056a001ca400b006d9cc854bc8si13192347pfw.205.2024.01.02.10.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:55:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14747-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=@gmail.com header.s=20230601 header.b=lhR5yFOT; spf=pass (google.com: domain of linux-kernel+bounces-14747-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 848EE2827F7 for ; Tue, 2 Jan 2024 18:55:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98B8215AD2; Tue, 2 Jan 2024 18:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lhR5yFOT" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 8621B15AEA for ; Tue, 2 Jan 2024 18:54:48 +0000 (UTC) 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 Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-67f9fac086bso73777716d6.3 for ; Tue, 02 Jan 2024 10:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704221687; x=1704826487; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=7+SZED/A1h752GveqQ8KwOCCj8k8UMoXQ0xqbzwkRoU=; b=lhR5yFOTiLUAAHu6YCrTOF2hQRsWg1hRIe0FQ0hbFv39fBpGCAcLGch5RIt/3r97Xo VbwEVkb2vSbikzdbMRNl1Lzh7mFIic5jf1cXjNwxsprnIlv64GDB3DQacLCYBLWz7NCj Et/yetRbIOsDNPmduRKKg6UxltcRBf29lgVMGU4zRw6foEn6ChkqBRnOA53cJHIjNYae HldDg3IOB7fjrcxqSAuKHPGbPvZ/gzXvqRLGpUvS3LIkxX9SeVcpFLZbumAk7OKrRKUP qPRa5dWt96jxDHdSU/o2+/jY+QbLb1Vd6rMXcGraSGsazsv1WbcfHngIKzxOMyd28OHO pWnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704221687; x=1704826487; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+SZED/A1h752GveqQ8KwOCCj8k8UMoXQ0xqbzwkRoU=; b=urDK3sdFcjWFWNTZO9PhoKkAoV3Hn6tQDif7EJ0UJx5IRIjXLWALzkDsc9hWe3HjYv 0Rl0boJzzszljxcE7DCB3BxZtqGV13EU4gL5pCQeYn33mFFe99RLlwEFnwYwX65htrh1 iawFNHJPUUy54DxkdzDZ1jvSoxxsp5Opo1Q9KsgmME6Lr28r64HG88R9iyXJmQUEX5LG 8IzNQTfoAgx3EJtlvARRiJm5/lF6/ce1Nr945AQ5PcXa34x3pkywp/7o1Kt4jEmkzJqD 1iCXXZuM37G/iWtFxYMp3/3beNJcSfwc4g2yEvWpC0CKk7tkRvxG9OgKDnVrmuhEX4bX Fogg== X-Gm-Message-State: AOJu0YxGO3LYZkmqvfYcAYPqh4bGzf5nu+tsSky3vr5W6UaktvoOiMRi /HXdcwmkPoZ54lSE+/aeWXs= X-Received: by 2002:a05:6214:2388:b0:680:b8bf:f844 with SMTP id fw8-20020a056214238800b00680b8bff844mr3313901qvb.102.1704221687335; Tue, 02 Jan 2024 10:54:47 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id v7-20020a0cf907000000b00680b1947dbbsm1771086qvn.111.2024.01.02.10.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:54:47 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 5EDBD27C005A; Tue, 2 Jan 2024 13:54:46 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 02 Jan 2024 13:54:46 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdegfedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtrodttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeeitdefvefhteeklefgtefhgeelkeefffelvdevhfehueektdevhfettddv teevvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jan 2024 13:54:44 -0500 (EST) Date: Tue, 2 Jan 2024 10:53:43 -0800 From: Boqun Feng To: David Laight Cc: 'Waiman Long' , "'linux-kernel@vger.kernel.org'" , "'peterz@infradead.org'" , "'mingo@redhat.com'" , "'will@kernel.org'" , 'Linus Torvalds' , "'xinhui.pan@linux.vnet.ibm.com'" , "'virtualization@lists.linux-foundation.org'" , 'Zeng Heng' Subject: Re: [PATCH next 2/5] locking/osq_lock: Avoid dirtying the local cpu's 'node' in the osq_lock() fast path. Message-ID: References: <73a4b31c9c874081baabad9e5f2e5204@AcuMS.aculab.com> <835f65d9-a041-4956-b89d-7cd3660c3ab8@redhat.com> 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-Disposition: inline In-Reply-To: On Sat, Dec 30, 2023 at 03:49:52PM +0000, David Laight wrote: [...] > I don't completely understand the 'acquire'/'release' semantics (they didn't > exist when I started doing SMP kernel code in the late 1980s). > But it looks odd that osq_unlock()'s fast path uses _release but the very > similar code in osq_wait_next() uses _acquire. > The _release in osq_unlock() is needed since unlocks are needed to be RELEASE so that lock+unlock can be a critical section (i.e. no memory accesses can escape). When osq_wait_next() is used in non unlock cases, the RELEASE is not required. As for the case where osq_wait_next() is used in osq_unlock(), there is a xchg() preceding it, which provides a full barrier, so things are fine. /me wonders whether we can relax the _acquire in osq_wait_next() into a _relaxed. > Indeed, apart from some (assumed) optimisations, I think osq_unlock() > could just be: > next = osq_wait_next(lock, this_cpu_ptr(&osq_node), 0); > if (next) > next->locked = 1; > If so we need to provide some sort of RELEASE semantics for the osq_unlock() in all the cases. Regards, Boqun > I don't think the order of the tests for lock->tail and node->next > matter in osq_wait_next(). > If they were swapped the 'Second most likely case' code from osq_unlock() > could be removed. > (The 'uncontended case' doesn't need to load the address of 'node'.) > > David > > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)