Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVUM1-004O6S-1p for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 12:40:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVUM0-006S60-1Q for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 12:40:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVUM0-006S5s-0U for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 12:40:36 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVULz-000xrJ-1e for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 12:40:36 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id AA7C87A01A6; Tue, 16 Dec 2025 07:40:34 -0500 (EST) Received: from phl-imap-14 ([10.202.2.87]) by phl-compute-02.internal (MEProxy); Tue, 16 Dec 2025 07:40:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burd.me; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1765888834; x=1765975234; bh=Fp+QkgtiUgciz+ZSCk+6FWbF9jb+fCvv9GRYpn4a4ZI=; b= J9RHa3vCl5h/L8ynrD8ZnlYjhmNCPOzhAHmozr9Ws7PaH/43uQEOqRfV0ykoOK2X pYj4OREzX8UON63Qr8lm00OIprUwyb5PZSKKA1MxATn7TeDf26dI5wWjY/jjYsoV 6Ci8OkvfRwVCg+E/+tjL3kzcRDtau0xYhORL6gA3QQAVdctka5GnLXOfJa4pK2QE JPDl3yXQsBCvQaTEBCSbMr7RXQrbnXiBQNxpUWn64vdZZRQv/aHwdJByxAj7ugz0 G0KtzR2Y2u7RTfBnA1kK2hyhDYyvMYvfm5U//9j8dVuTgXPHHZyCgGya7T95wIg1 QGz2nCL2XPCGy4kLG/xMig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1765888834; x= 1765975234; bh=Fp+QkgtiUgciz+ZSCk+6FWbF9jb+fCvv9GRYpn4a4ZI=; b=o arkEHW78WvKbXKNi11dWfq+gVRmPSNtHLlcxu3A8jI9VGOBmHM3PK98qb66tE+GD l2CCdPpIJdx2TyZZhB6c2sa7aACbMCu4DIbvB3hipUzkYxbLlaDtXHDZsvakO8Zx 3KXRTH/Eq6EYX+ugT7sK70HIcyjU74bZZInrqIgM8BWCkROCUl3WsWGzWvYVBfvJ 5+b627qMrImCammVQ8yS3jpxSr2wZY0eXjP44SaounN5Z+moDUOpI91i1QA+GYC5 YZDP5k4kEv2npXLvjv6SfukUq8YFA8DM7Hl9RlloMUehL2xSmY7utWErxsbeuwJ+ CI3fJ5LLlzjHzEGSJ1tWA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefleejudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfirhgvghcu uehurhgufdcuoehgrhgvghessghurhgurdhmvgeqnecuggftrfgrthhtvghrnhepvdeuhf fftddvveeuffetheehfeelveetvdeftdeufeffieejfeduleevfedtffdunecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsegsuhhrug drmhgvpdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphhtthho pegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtthhopehpvghtvghrsegvih hsvghnthhrrghuthdrohhrghdprhgtphhtthhopegurghvvggtrhgrmhgvrhesghhmrghi lhdrtghomhdprhgtphhtthhopehnrghthhgrnhgusghoshhsrghrthesghhmrghilhdrtg homhdprhgtphhtthhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgt phhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlh drohhrgh X-ME-Proxy: Feedback-ID: i675e48f3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 113F6C4006F; Tue, 16 Dec 2025 07:40:34 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: Atr_W4N1XYlB Date: Tue, 16 Dec 2025 07:40:13 -0500 From: "Greg Burd" To: "Andres Freund" , "Nathan Bossart" Cc: "Thomas Munro" , "PostgreSQL Hackers" , "Peter Eisentraut" , "Dave Cramer" Message-Id: In-Reply-To: References: <5e169c16-9e54-4325-8027-1f52a5bb5c1e@app.fastmail.com> <1c2a29b8-5b1e-44f7-a871-71ec5fefc120@app.fastmail.com> <8e926f26-0a97-434f-a665-8bb6f9159b08@app.fastmail.com> <6646f9f4-3609-41e2-8d9f-dcd63e9f915e@app.fastmail.com> Subject: Re: [PATCH] Fix ARM64/MSVC atomic memory ordering issues on Win11 by adding explicit DMB ?barriers Content-Type: text/plain Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Dec 15, 2025, at 5:32 PM, Andres Freund wrote: > Hi, > > On 2025-12-15 15:38:49 -0600, Nathan Bossart wrote: >> +++ b/meson.build >> @@ -2523,7 +2523,8 @@ int main(void) >> } >> ''' >> >> - if cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc', >> + if (host_cpu == 'aarch64' and cc.get_id() == 'msvc') or \ >> + cc.links(prog, name: '__crc32cb, __crc32ch, __crc32cw, and __crc32cd without -march=armv8-a+crc', >> args: test_c_args) >> # Use ARM CRC Extension unconditionally >> cdata.set('USE_ARMV8_CRC32C', 1) > > I still think this should have a comment explaining that we can > unconditionally rely on crc32 support due to window's baseline requirements. > > >> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h >> index 7f8f566bd40..e62141abf0a 100644 >> --- a/src/include/storage/s_lock.h >> +++ b/src/include/storage/s_lock.h >> @@ -602,13 +602,21 @@ typedef LONG slock_t; >> >> #define SPIN_DELAY() spin_delay() >> >> -/* If using Visual C++ on Win64, inline assembly is unavailable. >> - * Use a _mm_pause intrinsic instead of rep nop. >> - */ >> -#if defined(_WIN64) >> +#ifdef _M_ARM64 >> +static __forceinline void >> +spin_delay(void) >> +{ >> + /* Research indicates ISB is better than __yield() on AArch64. */ >> + __isb(_ARM64_BARRIER_SY); > > It'd be good to link the research in some form or another. Otherwise it's > harder to evolve the code in the future, because we don't know if the research > was "I liked the color better" or "one is catastrophically slower than the > other". > >> +} >> +#elif defined(_WIN64) >> static __forceinline void >> spin_delay(void) >> { >> + /* >> + * If using Visual C++ on Win64, inline assembly is unavailable. >> + * Use a _mm_pause intrinsic instead of rep nop. >> + */ >> _mm_pause(); >> } >> #else >> @@ -621,12 +629,19 @@ spin_delay(void) >> #endif >> >> #include >> +#ifdef _M_ARM64 >> +#pragma intrinsic(_InterlockedExchange) >> + >> +/* _ReadWriteBarrier() is insufficient on non-TSO architectures. */ >> +#define S_UNLOCK(lock) _InterlockedExchange(lock, 0) >> +#else >> #pragma intrinsic(_ReadWriteBarrier) >> >> #define S_UNLOCK(lock) \ >> do { _ReadWriteBarrier(); (*(lock)) = 0; } while (0) >> >> #endif >> +#endif > > The newline placement looks odd here. I'd add newlines around the #else. Hey Andres, thanks for chiming in! I agree with your suggestions and it looks like Nathan has already addressed them to your satisfaction. I've applied v11 on my "unicorn" Win11 ARM64 MSVC system and it's testing now. best. -greg > Greetings, > > Andres Freund