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 1wKJws-000qkA-26 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 17:52:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKJwr-00D52W-05 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 May 2026 17:52:45 +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 1wKJwq-00D51l-1y for pgsql-hackers@lists.postgresql.org; Tue, 05 May 2026 17:52:44 +0000 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKJwo-00000000LoL-0Uft for pgsql-hackers@postgresql.org; Tue, 05 May 2026 17:52:43 +0000 Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-8aca4e14411so55201496d6.3 for ; Tue, 05 May 2026 10:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778003562; x=1778608362; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=YBYOKNdY6UY/i+ZHPzFdTw5/QiWCPxn7jKWarm9pFOI=; b=jE61DKOhpoVB9rVnMk26oHUncP2B+OL6783uSITXL/QoNRunW4Tt7gMRXC8RPRu43I Z0YULdw1bk6aLMS0ndcc+Cd+s5p4Z5n+zvNMlk9w/ta2gHlQXVAZ7+MEFrBu71luvyg7 8qpMndP40OIeNxzpcCsgtaWKunAM2+/ZkN0aq+z6VbUj+l6weJpwZG1Lg+HilTGyctUq oY09Lqzk07TIkBNDjqHL2lHAQGdEMonQb6mKNSs8YAGC3L5OxpUp2EIS/hIjsiXIubDu KZ5NTgBH0uEWyWwhWtgIfo+atUsUrXKyxlGHmV1cwN4uTgyNavlXXwTf1nRr6jXEGXvs Dzxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778003562; x=1778608362; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YBYOKNdY6UY/i+ZHPzFdTw5/QiWCPxn7jKWarm9pFOI=; b=JNkKE2gd7rMsahUCJbDP6m2Za2iLNK/QO/cauNfpyYKv9JKhOuilC9V9k3/EpMmaWV AkN/cHTAVt5755oOKe5dXtiKkWNIqtUpzDAI7rsWwanbJ6qcefz1LwcQ/UGWyJp1MhGl nnDtmqcqEcQo9Vijx4JjfLXaGA+WnhCW6eWtB+TsdfxOh8tGVVN5P7iK9byXNMQbdz5G qJorWrvQxJUTU77pYKKpzGdyeqDFQZcGchn09mkjFKHvB/diVM7efHlGDP5xNC1oPJvG D8gDuzfCL0fOv4L621KERTIuRW5hC5nd+Zyui6XbnCUSyKLL6UlWOs4zotOnEaUQaC+Y fpEg== X-Gm-Message-State: AOJu0YwhpY0/uD/JBINPJrTuwTNU5StjshQmxSlGnYHb9FIezVN8b3I2 esxX41zuw79xT2ELROjmFeuuXqz5f/AVFyb21Dh2RmbCdvpBm+IJ3ELGar8JxQ== X-Gm-Gg: AeBDiesAzdJJG2tIpHl8dHxjK5Os+9PviJWODiK1sB8R/Buak5ubkNu29Ofat0mQB7a NNgUqErfYuu566FZigkINAZCw2+RUzUepNV2a903fefJbkFs57Mp6ETDlCMTbpq4HNee9ecaMyu jZhJ2daDbe3zHYPDMJuiqhEascpOzaXLppiq9y7oOijYHf+qiZLxPGl9uvvvbOj/m1xe6SS1Y2g eSDbRw047XzkJaYc693ZGKq0aaotfg25QdWCR8+7poogiijReST5NICwxuzsTvcwXrxihdDHVJF QazH2gqvkebN7eJu+wJNGDeVAdFuf/TWLslWXgDm7Pl+BvMwNxRWcKo7KHQgj/J/xtg2trmxeF3 c2HVUuD6otojOfAviAw24X4UrR2KROtxifibApmhDe4KwS/Nm/HgyNm7CEp2vsbw/3dYCu6FM5/ I5HNAqrOyGk5bFfthQ3b30FEEouO3EZD8G36081SUW94WjxgUcpvDiZUzgCvMyrNCJqd9tkS5eC pOYHzMu6mHjRTDg3M9FeJ0HqChQa6zx X-Received: by 2002:a05:6214:5342:b0:8ac:b1ad:3a1a with SMTP id 6a1803df08f44-8b668a1faf0mr252777256d6.36.1778003561584; Tue, 05 May 2026 10:52:41 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b53cd827c5sm182625596d6.40.2026.05.05.10.52.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 10:52:39 -0700 (PDT) Date: Tue, 5 May 2026 12:52:37 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: remove pg_spin_delay() from atomics code Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9wPlq30DMLxbhZ5y" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --9wPlq30DMLxbhZ5y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline While inspecting what 32-bit optimizations we had, I noticed this line in atomics/arch-x86.h: #elif defined(_MSC_VER) && defined(__x86_64__) ...which led me to rediscover what Thomas Munro had found a while back [0], i.e., we aren't using the right x86_64 macro for MSVC in lots of places. Upon further inspection, all of this pg_spin_delay() stuff seems to have been unused since it was added in commit b64d92f1a5, so I'm guessing it's just an implementation artifact that didn't get cleaned up. Here's a patch to remove that dead code. [0] https://postgr.es/m/CA%2BhUKGL8Hs-phHPugrWM%3D5dAkcT897rXyazYzLw-Szxnzgx-rA%40mail.gmail.com -- nathan --9wPlq30DMLxbhZ5y Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-remove-pg_spin_delay.patch From 588685e23134c1916ff9640b7c9eca155434e346 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 5 May 2026 12:37:50 -0500 Subject: [PATCH v1 1/1] remove pg_spin_delay() --- src/include/port/atomics.h | 5 --- src/include/port/atomics/arch-x86.h | 54 ----------------------------- src/include/port/atomics/generic.h | 6 ---- 3 files changed, 65 deletions(-) diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h index d8b1d20fe60..c50d95d29e2 100644 --- a/src/include/port/atomics.h +++ b/src/include/port/atomics.h @@ -154,11 +154,6 @@ #define pg_read_barrier() pg_read_barrier_impl() #define pg_write_barrier() pg_write_barrier_impl() -/* - * Spinloop delay - Allow CPU to relax in busy loops - */ -#define pg_spin_delay() pg_spin_delay_impl() - /* * pg_atomic_init_flag - initialize atomic flag. * diff --git a/src/include/port/atomics/arch-x86.h b/src/include/port/atomics/arch-x86.h index bd6f4f56ca2..b317cf7a188 100644 --- a/src/include/port/atomics/arch-x86.h +++ b/src/include/port/atomics/arch-x86.h @@ -76,60 +76,6 @@ typedef struct pg_atomic_uint64 } pg_atomic_uint64; #endif /* __x86_64__ */ -#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ - -#if !defined(PG_HAVE_SPIN_DELAY) -/* - * This sequence is equivalent to the PAUSE instruction ("rep" is - * ignored by old IA32 processors if the following instruction is - * not a string operation); the IA-32 Architecture Software - * Developer's Manual, Vol. 3, Section 7.7.2 describes why using - * PAUSE in the inner loop of a spin lock is necessary for good - * performance: - * - * The PAUSE instruction improves the performance of IA-32 - * processors supporting Hyper-Threading Technology when - * executing spin-wait loops and other routines where one - * thread is accessing a shared lock or semaphore in a tight - * polling loop. When executing a spin-wait loop, the - * processor can suffer a severe performance penalty when - * exiting the loop because it detects a possible memory order - * violation and flushes the core processor's pipeline. The - * PAUSE instruction provides a hint to the processor that the - * code sequence is a spin-wait loop. The processor uses this - * hint to avoid the memory order violation and prevent the - * pipeline flush. In addition, the PAUSE instruction - * de-pipelines the spin-wait loop to prevent it from - * consuming execution resources excessively. - */ -#if defined(__GNUC__) || defined(__INTEL_COMPILER) -#define PG_HAVE_SPIN_DELAY -static inline void -pg_spin_delay_impl(void) -{ - __asm__ __volatile__(" rep; nop \n"); -} -#elif defined(_MSC_VER) && defined(__x86_64__) -#define PG_HAVE_SPIN_DELAY -static __forceinline void -pg_spin_delay_impl(void) -{ - _mm_pause(); -} -#elif defined(_MSC_VER) -#define PG_HAVE_SPIN_DELAY -static __forceinline void -pg_spin_delay_impl(void) -{ - /* See comment for gcc code. Same code, MASM syntax */ - __asm rep nop; -} -#endif -#endif /* !defined(PG_HAVE_SPIN_DELAY) */ - - -#if defined(__GNUC__) || defined(__INTEL_COMPILER) - #define PG_HAVE_ATOMIC_TEST_SET_FLAG static inline bool pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr) diff --git a/src/include/port/atomics/generic.h b/src/include/port/atomics/generic.h index fd64b6cbd86..daa772e9a6d 100644 --- a/src/include/port/atomics/generic.h +++ b/src/include/port/atomics/generic.h @@ -28,12 +28,6 @@ # define pg_write_barrier_impl pg_memory_barrier_impl #endif -#ifndef PG_HAVE_SPIN_DELAY -#define PG_HAVE_SPIN_DELAY -#define pg_spin_delay_impl() ((void)0) -#endif - - /* provide fallback */ #if !defined(PG_HAVE_ATOMIC_FLAG_SUPPORT) && defined(PG_HAVE_ATOMIC_U32_SUPPORT) #define PG_HAVE_ATOMIC_FLAG_SUPPORT -- 2.50.1 (Apple Git-155) --9wPlq30DMLxbhZ5y--