Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5291284rdb; Sat, 30 Dec 2023 14:47:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IET0hn1P10/W93gQ8IsSPoijE2QlP+HcoRQIJ/vQ/JafVfGWyCYmrjVLa9HBBpOhGiZmkZA X-Received: by 2002:a05:600c:b91:b0:40d:86a3:e0fe with SMTP id fl17-20020a05600c0b9100b0040d86a3e0femr92061wmb.177.1703976469224; Sat, 30 Dec 2023 14:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703976469; cv=none; d=google.com; s=arc-20160816; b=OUVFYITKHH0FaJqhRX0fr1vIgEl2vHcUh+MPAy5FAqwWdwbj7D0liiRIwGQPxlksMR C5Q+N8iQPox6Rdoka8OFnDeAtwUPXLR1q3CivnY6F9uNojo2aAcc/Fmqx+vCrY6Q9s9x xa3mtgAqsawM0nCrzx6UgBRvv63rB0KHQrnEJ8u8h7DThY0aOBzRjaJ3i9QCj6TZP2xw UkFLhLq9rDYJT4xBo/lDOxoNPWvIwETqHIWe1IXkV8NH+ZpArQ+uNL8KsBDPHtIsYpRF BeBMR//zgBbHAyq+WeunZlXy07otf3kfd9ndQHbKXJy/gd0LP4LNzaMFDCe4DKEqbXxN J4QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=gi1a9/IBnu0WD4fd15eJFe8ImXiZkiaO2qiI8+au7tU=; fh=q1xPsa0s/xT+dnbQRpjw0/an1NH+vMCUSDgH5Nl8MDk=; b=QC0eW/j5i3+311lmkxcQBYJG91vuvkPtpL9+cPUrmh0lYyKPdEG+cKoTDWtdQWE5Rb xOlNvfIzkP3OjjD+LnA0E2e7LGKDXrk9CoxNJMAdCi+nR7IzhKOcNGkcVGx8CbY/4EnZ jVLyxKtMAieZ4qSlpD7HAIS1XCUb0ZwRCRSWq+L6jDfC5x4HcXixt8pe8KGfq7kTQyHv UK1/CKRjwv9iaTVn5Bi2oGexUfItE0DUZ7+sT7lhFJpR/WsQY8BqJ8Sqy832MMX3hzwC FsS+ygWhrk9qa9nMnL3MXp5WdpieolYO/9hQWqONQ46vmRNgaxPm7oQQ0M2+opIq/mOE 1ltA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-13605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y16-20020a170906525000b00a2352187e7dsi8580937ejm.998.2023.12.30.14.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 14:47:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-13605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.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 am.mirrors.kernel.org (Postfix) with ESMTPS id F2FE81F22501 for ; Sat, 30 Dec 2023 22:47:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51521F9CC; Sat, 30 Dec 2023 22:47:42 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (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 4E5B9E546 for ; Sat, 30 Dec 2023 22:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-44-HrekTaZ8MoaRuuAvFWTwrg-1; Sat, 30 Dec 2023 22:47:37 +0000 X-MC-Unique: HrekTaZ8MoaRuuAvFWTwrg-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 30 Dec 2023 22:47:19 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sat, 30 Dec 2023 22:47:19 +0000 From: David Laight To: 'Ingo Molnar' CC: "'linux-kernel@vger.kernel.org'" , "'peterz@infradead.org'" , "'longman@redhat.com'" , "'mingo@redhat.com'" , "'will@kernel.org'" , "'boqun.feng@gmail.com'" , 'Linus Torvalds' , "'xinhui.pan@linux.vnet.ibm.com'" , "'virtualization@lists.linux-foundation.org'" , 'Zeng Heng' Subject: RE: [PATCH next 4/5] locking/osq_lock: Optimise per-cpu data accesses. Thread-Topic: [PATCH next 4/5] locking/osq_lock: Optimise per-cpu data accesses. Thread-Index: Ado6mZUJWFdx4PkETd+mn/PWVjPd0AAxm5QAAARO0qA= Date: Sat, 30 Dec 2023 22:47:19 +0000 Message-ID: References: <73a4b31c9c874081baabad9e5f2e5204@AcuMS.aculab.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Ingo Molnar > Sent: 30 December 2023 20:38 >=20 > * David Laight wrote: >=20 > > bool osq_lock(struct optimistic_spin_queue *lock) > > { > > -=09struct optimistic_spin_node *node =3D this_cpu_ptr(&osq_node); > > +=09struct optimistic_spin_node *node =3D raw_cpu_read(osq_node.self); > > =09struct optimistic_spin_node *prev, *next; > > =09int old; > > > > -=09if (unlikely(node->cpu =3D=3D OSQ_UNLOCKED_VAL)) > > -=09=09node->cpu =3D encode_cpu(smp_processor_id()); > > +=09if (unlikely(!node)) { > > +=09=09int cpu =3D encode_cpu(smp_processor_id()); > > +=09=09node =3D decode_cpu(cpu); > > +=09=09node->self =3D node; > > +=09=09node->cpu =3D cpu; >=20 > This whole initialization sequence is suboptimal and needs to be > cleaned up first: the node->cpu field is constant once initialized, so > it should be initialized from appropriate init methods, not runtime in > osq_lock(), right? I thought that as well, but there would need to be a list of 'init' functions for the per-cpu data. I didn't spot one. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)