Re: [PATCH] Fix ARM64/MSVC atomic memory ordering issues on Win11 by adding explicit DMB ​barriers

From: Greg Burd <greg(at)burd(dot)me>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Dave Cramer <davecramer(at)gmail(dot)com>
Subject: Re: [PATCH] Fix ARM64/MSVC atomic memory ordering issues on Win11 by adding explicit DMB ​barriers
Date: 2025-11-21 19:52:03
Message-ID: F83967FF-978A-4CC0-A6CB-752173E1F0F9@greg.burd.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Nov 20 2025, at 7:08 pm, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:

> On Fri, Nov 21, 2025 at 9:45 AM Greg Burd <greg(at)burd(dot)me> wrote:
>> Dave and I have been working together to get ARM64 with MSVC functional.
>> The attached patches accomplish that. Dave is the author of the first
>> which addresses some build issues and fixes the spin_delay() semantics,
>> I did the second which fixes some atomics in this combination.
>
> A couple of immediate thoughts:

Hey Thomas, I'm always interested in your thoughts. Thanks for taking a
look at this.

> https://learn.microsoft.com/en-us/cpp/intrinsics/interlockedexchangeadd-intrinsic-functions?view=msvc-170
>
> Doesn't seem to match your conclusion.
>
> + if cc.get_id() == 'msvc'
> + cdata.set('USE_ARMV8_CRC32C', false)
> + cdata.set('USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 1)
>
> USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK (pg_crc32c_armv8_choose.c) won't
> actually work on Windows, but I don't think we should waste time
> implementing it: vendor-supported versions of Windows 11 require
> ARMv8.1A to boot[1][2], and that has it, so I think we should probably
> just define USE_ARMV8_CRC32C.

I'll give that a go, I think your logic is sound.

> +static __forceinline void
> +spin_delay(void)
> +{
> + /* Reference:
> https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics#BarrierRestrictions
> */
> + __isb(_ARM64_BARRIER_SY);
> +}
>
> I don't doubt that barriers are missing in a few places, but how can
> this be the right place?

Well, with the compiler flag that Andres mentioned I need to reconsider
this change.

> If you have an environment set up so it's easy to test, I would also
> be very interested to know if my patch set[3] that nukes all this
> stuff and includes <stdatomic.h> instead, which is green on
> Windows/x86 CI, will just work™ there too.

I do, and I will as soon as I get this sorted.

> [1] https://en.wikipedia.org/wiki/Windows_11_version_history
> [2] https://learn.microsoft.com/en-us/lifecycle/products/windows-11-home-and-pro
> [3] https://stream.boxwatch.ru/message-id/flat/CA%2BhUKGKFvu3zyvv3aaj5hHs9VtWcjFAmisOwOc7aOZNc5AF3NA%40mail.gmail.com

best.

-greg

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2025-11-21 19:57:35 Re: Changing the state of data checksums in a running cluster
Previous Message Nico Williams 2025-11-21 19:52:01 Re: Optimize cardinality estimation when unique keys are fully covered