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 1wL5sK-001WWm-1P for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 21:03:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wL5sJ-0069wv-17 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 21:03:15 +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 1wL5sI-0069wn-31 for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 21:03:15 +0000 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wL5sG-00000000hRd-0Uaf for pgsql-hackers@postgresql.org; Thu, 07 May 2026 21:03:14 +0000 Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-506aa68065eso9094291cf.1 for ; Thu, 07 May 2026 14:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778187792; x=1778792592; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=DshBbeAfc8zyqhVURNDBG2oLr7wNEW/8ckHD8bS6hW4=; b=NxMen6EaIdqVZ7ATm8V99nTRZIvmfPs+mTkrK3zIpJJk7hAZouaEGlajxpisg5ZnAR gsWTz5wh2V/Qn4orAIfraDFq6wpdKXeD+f9zn13xsW/NdryEjYFBUbLAHJjng+9EmoNP Atsri89LqinK1xu8Ih6u9u7bcBHjOQz+TZY19RgXNfl6vsyw/K9cXX1IFwqW+JjD7Txb E8WGxzIooRbpLr6Zl6Yu27uTYRlgQdiNPZaCuxMZetexhDgbTLksKFCR9GSydjQqh/jk pfXMc2+JHH72WVrh4E0xEy0fxAbPU3ikIqx9BwWZpiDaq/LZZ5rwEmRsj9FNR/bBfMjS 2Gpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778187792; x=1778792592; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DshBbeAfc8zyqhVURNDBG2oLr7wNEW/8ckHD8bS6hW4=; b=RlcnGqw81PjmF4n+NyxaPU1olZl2p8DNK8bl6oFBRTHSwH5JYALq0XMAAB7GxrX7ws VRCOu+uQWAz+r2Cqukup62LJMzIqog1lNx2u/zO7WEpDJQQe06k9oMe9hHAP7Sshedto szB1mHEuqFmDRhmwUO2QfZSdUavAmIU7BEibP+0lBrEVKyiNPoLFtx5kcHFENA23ozhR sSSFxPLbQNQllfLlSrEnKssAEQ+xVEndYt1AAeup9Nhy5W7CWWiIGH4zRkAAekHPvTCu UzwFum+qNBKzLJTgNPv2sGtBVzUrkdN1dh7gEidm3YGlLDqQi6F9enF4rVIURqESTYJI h67w== X-Gm-Message-State: AOJu0YwOVWtoXMGavO1SRdYljoFFBEl1K8x2oBqObQiBWm2/UE9BBzov 07lmhaIS3/8N2UGAGKYKs3p0EfioVfCFCzTCXYZxNhvmCIwSqJC7NSkO X-Gm-Gg: AeBDievQGcQ8xuXDCWOtvSBqzFcyq0TUzh5Gmfel875YBGdZWQG3i66b20suPLtZrcA B7Rz87ztcg61khRdTpGqosHaL/C+HA6DMEKVGTR8U3VaqrxWfvLTmuhLyONmPTyoEZwh/fTOM4Q LRS/KbRnz0hgU9mA0zcsnW21Ux9Refcahqi5u6Ekx7NjeL3e1qcXVSJCHXob/Bx0FCuWmlcF6YS jq3v9tqbDGlFOJcGq4iavSy4hg1MmsLx595LM+88ETwqUWvIpQz61Bx3+DtsExCR+hrUlyBK1HN rJ3iUvXq2CsYMSHQIZugEwM5NYSFjw42Bqps54CNZ0W9GmNmV+6uu9SuexFof/YIsO81ySD3TCR IPjw+xnwcntGSA0mgD3fZZjFAH5ZMnMJRs4OzA+IyVfcQoWSlyvThMdkhzSviVzg5fjVRm51hQA DMxMulSvA9PkoVDPH/Lnf/qt6O9CWngeRRebZe6g0S0CrgUYb3ioMIP7HqNILaQaDjkVbFZK22c 6SJOl6ZOnN4Pisgr379Ug== X-Received: by 2002:a05:622a:408b:b0:50f:ade2:2d3 with SMTP id d75a77b69052e-51461faa8femr133137011cf.42.1778187791560; Thu, 07 May 2026 14:03:11 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-514851141ebsm7216201cf.13.2026.05.07.14.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 14:03:10 -0700 (PDT) Date: Thu, 7 May 2026 16:03:09 -0500 From: Nathan Bossart To: Kirill Reshke Cc: pgsql-hackers@postgresql.org Subject: Re: small cleanup for s_lock.h Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="JmXY/Yn6swRVDyih" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --JmXY/Yn6swRVDyih Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, May 05, 2026 at 03:20:46AM +0500, Kirill Reshke wrote: > This indeed looks like a dead code. I also noticed `tas.s` is present > in meson.build, gitignore and src/backend/Makefile > should we remove that too? I forgot to remove these in v3. Here's a new patch set with that taken care of. -- nathan --JmXY/Yn6swRVDyih Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v4-0001-Remove-fallback-declaration-for-tas.patch From 595bbb48a7de3dd191023d617dc2c7f4725ed2d0 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 4 May 2026 16:04:04 -0500 Subject: [PATCH v4 1/3] Remove fallback declaration for tas(). The last definition of tas() in s_lock.c was removed in commit 718aa43a4e, and the last tas.s file was removed in commit 25f36066dd, so this is dead code. --- src/backend/Makefile | 2 +- src/backend/port/.gitignore | 1 - src/backend/port/meson.build | 2 +- src/include/storage/s_lock.h | 7 ------- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 162d3f1f2a9..4bb76d3d397 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -301,7 +301,7 @@ endif distclean: clean # generated by configure - rm -f port/tas.s port/pg_sema.c port/pg_shmem.c + rm -f port/pg_sema.c port/pg_shmem.c ########################################################################## diff --git a/src/backend/port/.gitignore b/src/backend/port/.gitignore index 4ef36b82c77..6c5067a4a9f 100644 --- a/src/backend/port/.gitignore +++ b/src/backend/port/.gitignore @@ -1,3 +1,2 @@ /pg_sema.c /pg_shmem.c -/tas.s diff --git a/src/backend/port/meson.build b/src/backend/port/meson.build index e8b7da8d281..29e88ef3541 100644 --- a/src/backend/port/meson.build +++ b/src/backend/port/meson.build @@ -30,4 +30,4 @@ if host_system == 'windows' endif # autoconf generates the file there, ensure we get a conflict -generated_sources_ac += {'src/backend/port': ['pg_sema.c', 'pg_shmem.c', 'tas.s']} +generated_sources_ac += {'src/backend/port': ['pg_sema.c', 'pg_shmem.c']} diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index c9e52511990..dcfec8ce2af 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -697,13 +697,6 @@ extern void s_unlock(volatile slock_t *lock); #define SPIN_DELAY() ((void) 0) #endif /* SPIN_DELAY */ -#if !defined(TAS) -extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or - * s_lock.c */ - -#define TAS(lock) tas(lock) -#endif /* TAS */ - #if !defined(TAS_SPIN) #define TAS_SPIN(lock) TAS(lock) #endif /* TAS_SPIN */ -- 2.50.1 (Apple Git-155) --JmXY/Yn6swRVDyih Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v4-0002-Remove-HAS_TEST_AND_SET.patch From ea055e53d64b97e74a87b02d424dee48fc66333b Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 4 May 2026 16:24:30 -0500 Subject: [PATCH v4 2/3] Remove HAS_TEST_AND_SET. This is only set when TAS is defined, so we can just check whether TAS is defined directly instead. --- src/include/storage/s_lock.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index dcfec8ce2af..fb872edd2f0 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -124,7 +124,6 @@ #ifdef __i386__ /* 32-bit i386 */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -194,7 +193,6 @@ spin_delay(void) #ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -249,7 +247,6 @@ spin_delay(void) */ #if defined(__arm__) || defined(__arm) || defined(__aarch64__) #ifdef HAVE_GCC__SYNC_INT32_TAS -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -292,7 +289,6 @@ spin_delay(void) /* S/390 and S/390x Linux (32- and 64-bit zSeries) */ #if defined(__s390__) || defined(__s390x__) -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -321,7 +317,6 @@ tas(volatile slock_t *lock) * acquire/release semantics. The CPU will treat superfluous members as * NOPs, so it's just code space. */ -#define HAS_TEST_AND_SET typedef unsigned char slock_t; @@ -392,7 +387,6 @@ do \ /* PowerPC */ #if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -453,7 +447,6 @@ do \ #if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ -#define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -531,10 +524,9 @@ do \ * grounds that that's known to be more likely to work in the ARM ecosystem. * (But we dealt with ARM above.) */ -#if !defined(HAS_TEST_AND_SET) +#if !defined(TAS) #if defined(HAVE_GCC__SYNC_INT32_TAS) -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -549,7 +541,6 @@ tas(volatile slock_t *lock) #define S_UNLOCK(lock) __sync_lock_release(lock) #elif defined(HAVE_GCC__SYNC_CHAR_TAS) -#define HAS_TEST_AND_SET #define TAS(lock) tas(lock) @@ -565,7 +556,7 @@ tas(volatile slock_t *lock) #endif /* HAVE_GCC__SYNC_INT32_TAS */ -#endif /* !defined(HAS_TEST_AND_SET) */ +#endif /* !defined(TAS) */ /* @@ -592,12 +583,11 @@ tas(volatile slock_t *lock) * --------------------------------------------------------------------- */ -#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ +#if !defined(TAS) /* We didn't trigger above, let's try here */ #ifdef _MSC_VER typedef LONG slock_t; -#define HAS_TEST_AND_SET #define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) #define SPIN_DELAY() spin_delay() @@ -649,11 +639,11 @@ spin_delay(void) #endif -#endif /* !defined(HAS_TEST_AND_SET) */ +#endif /* !defined(TAS) */ /* Blow up if we didn't have any way to do spinlocks */ -#ifndef HAS_TEST_AND_SET +#ifndef TAS #error PostgreSQL does not have spinlock support on this platform. Please report this to pgsql-bugs@lists.postgresql.org. #endif -- 2.50.1 (Apple Git-155) --JmXY/Yn6swRVDyih Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v4-0003-Better-express-platform-requirements-in-s_lock.h.patch From cd371f840ff8965b1efb0b989be3059272520e7c Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 7 May 2026 15:32:50 -0500 Subject: [PATCH v4 3/3] Better express platform requirements in s_lock.h. --- src/include/storage/s_lock.h | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index fb872edd2f0..c4369ee4ff6 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -44,23 +44,16 @@ * atomic test-and-set only when it appears free. * * TAS() and TAS_SPIN() are NOT part of the API, and should never be called - * directly. - * - * CAUTION: on some platforms TAS() and/or TAS_SPIN() may sometimes report - * failure to acquire a lock even when the lock is not locked. For example, - * on Alpha TAS() will "fail" if interrupted. Therefore a retry loop must - * always be used, even if you are certain the lock is free. + * directly. If a platform-specific TAS() is defined, the platform must + * _not_ define its own S_LOCK(). Conversely, if a platform-specific + * S_LOCK() is defined, the platform must _not_ define its own TAS(), but + * it does need to define its own TAS_SPIN(). Currently, all supported + * platforms define TAS() and use the default S_LOCK() implementation, so + * that is probably a good place to start if adding a new one. * * It is the responsibility of these macros to make sure that the compiler * does not re-order accesses to shared memory to precede the actual lock - * acquisition, or follow the lock release. Prior to PostgreSQL 9.5, this - * was the caller's responsibility, which meant that callers had to use - * volatile-qualified pointers to refer to both the spinlock itself and the - * shared data being accessed within the spinlocked critical section. This - * was notationally awkward, easy to forget (and thus error-prone), and - * prevented some useful compiler optimizations. For these reasons, we - * now require that the macros themselves prevent compiler re-ordering, - * so that the caller doesn't need to take special precautions. + * acquisition, or follow the lock release. * * On platforms with weak memory ordering, the TAS(), TAS_SPIN(), and * S_UNLOCK() macros must further include hardware-level memory fence @@ -72,7 +65,7 @@ * * On most supported platforms, TAS() uses a tas() function written * in assembly language to execute a hardware atomic-test-and-set - * instruction. Equivalent OS-supplied mutex routines could be used too. + * instruction. Equivalent compiler intrinsics are another popular option. * * * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group @@ -642,20 +635,25 @@ spin_delay(void) #endif /* !defined(TAS) */ -/* Blow up if we didn't have any way to do spinlocks */ -#ifndef TAS -#error PostgreSQL does not have spinlock support on this platform. Please report this to pgsql-bugs@lists.postgresql.org. -#endif - - /* * Default Definitions - override these above as needed. */ -#if !defined(S_LOCK) +/* + * Make sure S_LOCK is defined, either explicitly for the platform or via a TAS + * macro for the platform. Exactly one of either S_LOCK or TAS should be + * defined for a supported platform at this point in the file. + */ +#if defined(S_LOCK) +#if defined(TAS) +#error Both TAS and S_LOCK defined on this platform. Please report this to pgsql-bugs@lists.postgresql.org. +#endif +#elif defined(TAS) #define S_LOCK(lock) \ (TAS(lock) ? s_lock((lock), __FILE__, __LINE__, __func__) : 0) -#endif /* S_LOCK */ +#else +#error Neither TAS nor S_LOCK defined on this platform. Please report this to pgsql-bugs@lists.postgresql.org. +#endif #if !defined(S_UNLOCK) /* @@ -687,9 +685,19 @@ extern void s_unlock(volatile slock_t *lock); #define SPIN_DELAY() ((void) 0) #endif /* SPIN_DELAY */ +/* + * We can only define TAS_SPIN if TAS was defined. Otherwise, the platform + * defined its own S_LOCK without TAS, and therefore is responsible for + * defining its own TAS_SPIN as well. (Note that we currently do not have any + * platforms that don't define TAS.) + */ #if !defined(TAS_SPIN) +#if defined(TAS) #define TAS_SPIN(lock) TAS(lock) -#endif /* TAS_SPIN */ +#else +#error Neither TAS nor TAS_SPIN defined on this platform. Please report this to pgsql-bugs@lists.postgresql.org. +#endif /* TAS */ +#endif /* ! TAS_SPIN */ /* -- 2.50.1 (Apple Git-155) --JmXY/Yn6swRVDyih--