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 1vNHKQ-00FvIK-0q for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Nov 2025 21:09:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vNHKN-00FUs3-1I for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Nov 2025 21:08:59 +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 1vNHKM-00FUrv-38 for pgsql-hackers@lists.postgresql.org; Sun, 23 Nov 2025 21:08:59 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vNHKK-0015zV-1T for pgsql-hackers@lists.postgresql.org; Sun, 23 Nov 2025 21:08:57 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-340c2dfc1daso350068a91.2 for ; Sun, 23 Nov 2025 13:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763932136; x=1764536936; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vsCrxE71xUEGLutIp43dXqFMeQxBkLBQMMmiLO30A0Y=; b=hWsWmNVQtqbbf/nZPw/7uUuomUN9gzjuyApnxlxfKdofH6n6uCHqFiz7en2ew44wHu 9BAEfEC+hbfCQYpAgWZG0/bcS4wXaogRQ76BsryOUgoqOnK8qBEPjiT2iqj7j9prxtuA +ovi34NPahEPagI+FIYfUwB69qCk/BJGLsNvQALqyd9iOEA7ybYzrvllctWJ0s/druZ/ 2EtHZdFX0YJq/4d1XwwMfZWSUWg2IiAgKM5OrBHBmiZg6Aj7ShjhLJOi0DhG9wlYgXnQ S7JmZsQVdaa1wmel6qcmWYJYR6Zy74g4eAPbAozH9VTTMMWSoAdRwJsRzOa+N5EI8G42 M5bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763932136; x=1764536936; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vsCrxE71xUEGLutIp43dXqFMeQxBkLBQMMmiLO30A0Y=; b=w2pDA5sb0g4Y4zv8BMzZMmWDbEZlw1qIVUv09/QOvmDcDyGZXtMPSVmqWitjyFHR5n +Wbz+NPrjEtiklXFcEztl1GSFhzydAaEFr/ZhGFcQAUB2tDEtqh9Nc6JoexlpPSY0n97 U7dVz4DhbiWG7Ap2M7onVZrSpRayhiQ6jqQnXKqZOc/hSAvFDlWGnnEVgkScjaQEcLUJ orjDxjz+TO3ZJjnoFQwT908N7ENnxJjnVUw4Mq5noTkmglsm2R11eNRG2d+nI3a5RRtJ IDTna5SSCh7sle9QHKFKpKVs2ncAKQZyOdYLao6PTLWy8TILKrBTOEoFSnDIacqH+7Zj yN6Q== X-Gm-Message-State: AOJu0YwOEi0X5xLd5EcY0JkG1ekamj951eAKVVH/tC8p0sLwaPRuVksu sH1/xBIO8vIvovOo8CohNUb+6Pd1TNw0ADKz+/AA1M8MdMuLEUKmqFlRzxE1xHilFZLX+qgqpli 4sekUEoW2y7SeMfnudH1Q71wddH7V7CE= X-Gm-Gg: ASbGnctjGRHcyXqyp/17IxhZh8KNtd1XD1GADjqUG0yYtsmN2tQIsXfITJlgunafiLI vVDWCISDL59xc0JZ5kTjxkQrde+1TApZpwZPOBhDZ12peDriRilsT+LW8iB9PEN3lYRyiCIsNxB fYIoq2fJ92MMbOjVJEX2Deizp0Zy1Hl6g1O8oVZfCF25duCHwIkNn2pR66fvOdyn6TZFlW+BGI7 Vk1KGWroHiN/VyZl8+AIQ6XfhRCsMwIIrQ2lFM9q/Txd/AkVjTuFrvzScAmYax7Xkbiww0tE2K7 mTw8EgL+dF5lS8GNB63Mc6HzXGAGcleEVh0oNRhCxBoXPqXe/7Xp X-Google-Smtp-Source: AGHT+IE/ImAlYdX2Q3lxO6xb3RbpyMSIDeT5WZak3wJ/yAQOVsiGNn9Fx6XI9Op0Mh/IMfNBagRWSvV+TaY1MEP6ipk= X-Received: by 2002:a05:7301:e24:b0:2a4:3593:2c07 with SMTP id 5a478bee46e88-2a7243ec7b9mr4989813eec.0.1763932136145; Sun, 23 Nov 2025 13:08:56 -0800 (PST) MIME-Version: 1.0 References: <336c6acf-39ce-4a06-870e-3055400a5d8d@app.fastmail.com> In-Reply-To: <336c6acf-39ce-4a06-870e-3055400a5d8d@app.fastmail.com> From: Thomas Munro Date: Mon, 24 Nov 2025 10:08:19 +1300 X-Gm-Features: AWmQ_bn9yCeViImt5IyIYs_A3E9HB_0_F1eoUb79phU1f_6M_whUe66e3Sih1jM Message-ID: Subject: Re: Trying out To: Greg Burd Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Nov 24, 2025 at 4:23=E2=80=AFAM Greg Burd wrote: > As mentioned on a separate thread about fixing ARM64 support when buildin= g with MSVC on Win11 [1] I tried out this patch. The reply on that thread = had an issue with _mm_pause() in spin_delay(), it turns out we need to use = __yield() [2]. I went ahead and fixed that, so ignore that patch on the ot= her thread [1]. The new patch attached that layers on top of your work and= supports that platform, there was one minor change that was required: > > > #ifdef _MSC_VER > > /* > * If using Visual C++ on Win64, inline assembly is unavailable. = Use a > * _mm_pause intrinsic instead of rep nop. For ARM64, use the __y= ield() > * intrinsic which emits the YIELD instruction as a hint to the p= rocessor. > */ > #if defined(_M_ARM64) > __yield(); > #elif defined(_WIN64) > _mm_pause(); > #else > /* See comment for gcc code. Same code, MASM syntax */ > __asm rep nop; > #endif > #endif /* _MSC_VER */ That makes more intuitive sense... but I didn't know that people *do* sometimes prefer instruction synchronisation barriers for spinlock delays: https://stackoverflow.com/questions/70810121/why-does-hintspin-loop-use-isb= -on-aarch64 When reading your patch I was pretty confused by that, because it said it was fixing a barrier problem and apparently doing so in an unprincipled place. I guess we really need to research the best delay mechanism for our needs on this architecture, independently of the compiler being used, and then write matching GCC and Visual Studio versions of that? I think there were some threads about spinlock performance on Linux + Graviton with graphs and theories... > tests are passing, best. Great news! Thanks. It sounds like if I could supply the missing credible evidence of codegen quality on... all the computers, then I think we'd be down to just: when can we pull the trigger and require Visual Studio 2022 and do we trust /experimental:c11atomics? FTR I had earlier shared some version of this patch with Dave when he was trying to get his Windows/ARM system going, but I think my earlier version was probably too broken. Sorry Dave. At that stage I was also trying to do it as an option but keeping the existing stuff around. Since then we adopted C11, so this is the all-in version. I also hadn't understood a key part of the C11 memory model that your RISC-V animal taught me and that c5d34f4a fixed, and you can see in this patch set too, and I'm not sure if Visual Studio is like GCC or Clang in that respect. It crossed my mind that this might even be related to the problem you've noticed with barriers being missing, but I haven't looked into that. BTW I believe we could actually change our code NOT to rely on that, ie to follow the C11 memory model better and declare eg PgAioHandle::status as atomic_uint8 or whatever (other non-atomic access would be considered dependent and do the right thing IIUC), but I'm not sure if it's necessary and that research project can wait.