make BuiltinTrancheNames less ugly
This array of tranche names is looking pretty ugly these days, and it'll
get worse as we add more members to it. I propose to use C99 designated
initializers, like we've done for other arrays. Patch attached.
The way I've coded in this patch, it means the array will now have 52
NULL pointers at the beginning. I don't think this is a big deal and
makes the code prettier. I see two alternatives:
1. Avoid all those NULLs by making each definition uglier (subtract
NUM_INDIVIDUAL_LWLOCKS from each array index) _and_ the usage of the
array by subtracting the same amount. This saves 208 bytes at the
expense of making the code worse.
2. More invasively, rework generate-lwlocknames.pl so that both lwlocks
and these builtin tranche names appear in a single array. (We could do
so by #include'ing lwlocknames.c at the top of the array).
Now, having written this proposal, I'm leaning towards idea 2 myself,
but since the patch here is less invasive, it seems worth having as
evidence.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"People get annoyed when you try to debug them." (Larry Wall)
Attachments:
0001-Use-designated-initializers-for-BuiltinTrancheNames.patchtext/x-diff; charset=utf-8Download
From 037fc293b359fbe7dfffcdaf8d5816daa82c0ddd Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 23 Jan 2024 10:36:14 +0100
Subject: [PATCH] Use designated initializers for BuiltinTrancheNames
---
src/backend/storage/lmgr/lwlock.c | 97 +++++++++++--------------------
1 file changed, 33 insertions(+), 64 deletions(-)
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 2f2de5a562..98fa6035cc 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -132,72 +132,41 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
static const char *const BuiltinTrancheNames[] = {
- /* LWTRANCHE_XACT_BUFFER: */
- "XactBuffer",
- /* LWTRANCHE_COMMITTS_BUFFER: */
- "CommitTsBuffer",
- /* LWTRANCHE_SUBTRANS_BUFFER: */
- "SubtransBuffer",
- /* LWTRANCHE_MULTIXACTOFFSET_BUFFER: */
- "MultiXactOffsetBuffer",
- /* LWTRANCHE_MULTIXACTMEMBER_BUFFER: */
- "MultiXactMemberBuffer",
- /* LWTRANCHE_NOTIFY_BUFFER: */
- "NotifyBuffer",
- /* LWTRANCHE_SERIAL_BUFFER: */
- "SerialBuffer",
- /* LWTRANCHE_WAL_INSERT: */
- "WALInsert",
- /* LWTRANCHE_BUFFER_CONTENT: */
- "BufferContent",
- /* LWTRANCHE_REPLICATION_ORIGIN_STATE: */
- "ReplicationOriginState",
- /* LWTRANCHE_REPLICATION_SLOT_IO: */
- "ReplicationSlotIO",
- /* LWTRANCHE_LOCK_FASTPATH: */
- "LockFastPath",
- /* LWTRANCHE_BUFFER_MAPPING: */
- "BufferMapping",
- /* LWTRANCHE_LOCK_MANAGER: */
- "LockManager",
- /* LWTRANCHE_PREDICATE_LOCK_MANAGER: */
- "PredicateLockManager",
- /* LWTRANCHE_PARALLEL_HASH_JOIN: */
- "ParallelHashJoin",
- /* LWTRANCHE_PARALLEL_QUERY_DSA: */
- "ParallelQueryDSA",
- /* LWTRANCHE_PER_SESSION_DSA: */
- "PerSessionDSA",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPE: */
- "PerSessionRecordType",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPMOD: */
- "PerSessionRecordTypmod",
- /* LWTRANCHE_SHARED_TUPLESTORE: */
- "SharedTupleStore",
- /* LWTRANCHE_SHARED_TIDBITMAP: */
- "SharedTidBitmap",
- /* LWTRANCHE_PARALLEL_APPEND: */
- "ParallelAppend",
- /* LWTRANCHE_PER_XACT_PREDICATE_LIST: */
- "PerXactPredicateList",
- /* LWTRANCHE_PGSTATS_DSA: */
- "PgStatsDSA",
- /* LWTRANCHE_PGSTATS_HASH: */
- "PgStatsHash",
- /* LWTRANCHE_PGSTATS_DATA: */
- "PgStatsData",
- /* LWTRANCHE_LAUNCHER_DSA: */
- "LogicalRepLauncherDSA",
- /* LWTRANCHE_LAUNCHER_HASH: */
- "LogicalRepLauncherHash",
- /* LWTRANCHE_DSM_REGISTRY_DSA: */
- "DSMRegistryDSA",
- /* LWTRANCHE_DSM_REGISTRY_HASH: */
- "DSMRegistryHash",
+ [LWTRANCHE_XACT_BUFFER] = "XactBuffer",
+ [LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
+ [LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
+ [LWTRANCHE_MULTIXACTOFFSET_BUFFER] = "MultiXactOffsetBuffer",
+ [LWTRANCHE_MULTIXACTMEMBER_BUFFER] = "MultiXactMemberBuffer",
+ [LWTRANCHE_NOTIFY_BUFFER] = "NotifyBuffer",
+ [LWTRANCHE_SERIAL_BUFFER] = "SerialBuffer",
+ [LWTRANCHE_WAL_INSERT] = "WALInsert",
+ [LWTRANCHE_BUFFER_CONTENT] = "BufferContent",
+ [LWTRANCHE_REPLICATION_ORIGIN_STATE] = "ReplicationOriginState",
+ [LWTRANCHE_REPLICATION_SLOT_IO] = "ReplicationSlotIO",
+ [LWTRANCHE_LOCK_FASTPATH] = "LockFastPath",
+ [LWTRANCHE_BUFFER_MAPPING] = "BufferMapping",
+ [LWTRANCHE_LOCK_MANAGER] = "LockManager",
+ [LWTRANCHE_PREDICATE_LOCK_MANAGER] = "PredicateLockManager",
+ [LWTRANCHE_PARALLEL_HASH_JOIN] = "ParallelHashJoin",
+ [LWTRANCHE_PARALLEL_QUERY_DSA] = "ParallelQueryDSA",
+ [LWTRANCHE_PER_SESSION_DSA] = "PerSessionDSA",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPE] = "PerSessionRecordType",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPMOD] = "PerSessionRecordTypmod",
+ [LWTRANCHE_SHARED_TUPLESTORE] = "SharedTupleStore",
+ [LWTRANCHE_SHARED_TIDBITMAP] = "SharedTidBitmap",
+ [LWTRANCHE_PARALLEL_APPEND] = "ParallelAppend",
+ [LWTRANCHE_PER_XACT_PREDICATE_LIST] = "PerXactPredicateList",
+ [LWTRANCHE_PGSTATS_DSA] = "PgStatsDSA",
+ [LWTRANCHE_PGSTATS_HASH] = "PgStatsHash",
+ [LWTRANCHE_PGSTATS_DATA] = "PgStatsData",
+ [LWTRANCHE_LAUNCHER_DSA] = "LogicalRepLauncherDSA",
+ [LWTRANCHE_LAUNCHER_HASH] = "LogicalRepLauncherHash",
+ [LWTRANCHE_DSM_REGISTRY_DSA] = "DSMRegistryDSA",
+ [LWTRANCHE_DSM_REGISTRY_HASH] = "DSMRegistryHash",
};
StaticAssertDecl(lengthof(BuiltinTrancheNames) ==
- LWTRANCHE_FIRST_USER_DEFINED - NUM_INDIVIDUAL_LWLOCKS,
+ LWTRANCHE_FIRST_USER_DEFINED,
"missing entries in BuiltinTrancheNames[]");
/*
@@ -775,7 +744,7 @@ GetLWTrancheName(uint16 trancheId)
/* Built-in tranche? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
- return BuiltinTrancheNames[trancheId - NUM_INDIVIDUAL_LWLOCKS];
+ return BuiltinTrancheNames[trancheId];
/*
* It's an extension tranche, so look in LWLockTrancheNames[]. However,
--
2.39.2
On 23/01/2024 12:25, Alvaro Herrera wrote:
This array of tranche names is looking pretty ugly these days, and it'll
get worse as we add more members to it. I propose to use C99 designated
initializers, like we've done for other arrays. Patch attached.The way I've coded in this patch, it means the array will now have 52
NULL pointers at the beginning. I don't think this is a big deal and
makes the code prettier. I see two alternatives:1. Avoid all those NULLs by making each definition uglier (subtract
NUM_INDIVIDUAL_LWLOCKS from each array index) _and_ the usage of the
array by subtracting the same amount. This saves 208 bytes at the
expense of making the code worse.2. More invasively, rework generate-lwlocknames.pl so that both lwlocks
and these builtin tranche names appear in a single array. (We could do
so by #include'ing lwlocknames.c at the top of the array).Now, having written this proposal, I'm leaning towards idea 2 myself,
but since the patch here is less invasive, it seems worth having as
evidence.
Idea 2 seems pretty straightforward, +1 for that.
--
Heikki Linnakangas
Neon (https://neon.tech)
On 2024-Jan-23, Heikki Linnakangas wrote:
On 23/01/2024 12:25, Alvaro Herrera wrote:
2. More invasively, rework generate-lwlocknames.pl so that both lwlocks
and these builtin tranche names appear in a single array. (We could do
so by #include'ing lwlocknames.c at the top of the array).
Idea 2 seems pretty straightforward, +1 for that.
This is what I came up with. For the compilation framework (both
Makefile and meson) I mostly just copied what we do in src/backend/node,
which seems to have passed CI just fine, but maybe there are better ways
to achieve it.
... oh, actually FreeBSD failed with this strange problem while linking:
[11:39:43.550] ld: error: undefined symbol: __dtraceenabled_postgresql___lwlock__wait__start
[11:39:43.551] >>> referenced by lwlock.c:1277 (../src/backend/storage/lmgr/lwlock.c:1277)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockAcquire) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551] >>> referenced by lwlock.c:1442 (../src/backend/storage/lmgr/lwlock.c:1442)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockAcquireOrWait) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551] >>> referenced by lwlock.c:1660 (../src/backend/storage/lmgr/lwlock.c:1660)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockWaitForVar) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551]
[ further similar lines ]
https://cirrus-ci.com/task/5055489315176448?logs=build#L1091
I have no idea what this means or how is it related to what I'm doing.
IMO it would be less ugly to have the origin file lwlocknames.txt be not
a text file but a .h with a macro that can be defined by interested
parties so that they can extract what they want from the file, like
PG_CMDTAG or PG_KEYWORD. Using Perl for this seems dirty ...
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"In Europe they call me Niklaus Wirth; in the US they call me Nickel's worth.
That's because in Europe they call me by name, and in the US by value!"
On 2024-Jan-23, Alvaro Herrera wrote:
... oh, actually FreeBSD failed with this strange problem while linking:
[11:39:43.550] ld: error: undefined symbol: __dtraceenabled_postgresql___lwlock__wait__start
[11:39:43.551] >>> referenced by lwlock.c:1277 (../src/backend/storage/lmgr/lwlock.c:1277)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockAcquire) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551] >>> referenced by lwlock.c:1442 (../src/backend/storage/lmgr/lwlock.c:1442)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockAcquireOrWait) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551] >>> referenced by lwlock.c:1660 (../src/backend/storage/lmgr/lwlock.c:1660)
[11:39:43.551] >>> lwlock.a.p/lwlock.c.o:(LWLockWaitForVar) in archive src/backend/storage/lmgr/lwlock.a
[11:39:43.551]
So what's going on here is that lwlock.c is being compiled to a separate
archive (lwlock.a), and when linking it wants to see the dtrace symbols
(__dtraceenabled_postgresql___lwlock__wait__start et al) but it looks
like they're not defined.
I installed systemtap on my machine and reconfigured meson with it so
that it uses dtrace, and it compiles successfully. One interesting
point: on my ninja log, I see dtrace being invoked, which I do not in
the FreeBSD log.
I continue to not understand what is going on.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"El sabio habla porque tiene algo que decir;
el tonto, porque tiene que decir algo" (Platon).
On 2024-Jan-23, Alvaro Herrera wrote:
This is what I came up with.
Hm, I forgot the attachment, thanks Heikki for the reminder.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Las mujeres son como hondas: mientras más resistencia tienen,
más lejos puedes llegar con ellas" (Jonas Nightingale, Leap of Faith)
Attachments:
v2-0001-Use-designated-initializers-for-BuiltinTrancheNam.patchtext/x-diff; charset=utf-8Download
From 2f5185cdd37e3502520d85e5f6f565b58330e702 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 23 Jan 2024 10:36:14 +0100
Subject: [PATCH v2] Use designated initializers for BuiltinTrancheNames
---
src/backend/storage/lmgr/Makefile | 3 +-
.../storage/lmgr/generate-lwlocknames.pl | 10 +-
src/backend/storage/lmgr/lwlock.c | 110 ++++++------------
src/backend/storage/lmgr/meson.build | 10 +-
4 files changed, 49 insertions(+), 84 deletions(-)
diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 504480e847..81da6ee13a 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -12,13 +12,14 @@ subdir = src/backend/storage/lmgr
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
+override CPPFLAGS := -I. $(CPPFLAGS)
+
OBJS = \
condition_variable.o \
deadlock.o \
lmgr.o \
lock.o \
lwlock.o \
- lwlocknames.o \
predicate.o \
proc.o \
s_lock.o \
diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 7b93ecf6c1..a679a4ff54 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -10,7 +10,6 @@ use Getopt::Long;
my $output_path = '.';
my $lastlockidx = -1;
-my $continue = "\n";
GetOptions('outdir:s' => \$output_path);
@@ -29,8 +28,6 @@ print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
print $c $autogen, "\n";
-print $c "const char *const IndividualLWLockNames[] = {";
-
#
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
# cross-check those with the ones in lwlocknames.txt.
@@ -97,12 +94,10 @@ while (<$lwlocknames>)
while ($lastlockidx < $lockidx - 1)
{
++$lastlockidx;
- printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx;
- $continue = ",\n";
+ printf $c "[%s] = \"<unassigned:%d>\",\n", $lastlockidx, $lastlockidx;
}
- printf $c "%s \"%s\"", $continue, $trimmedlockname;
+ printf $c "[%s] = \"%s\",\n", $lockidx, $trimmedlockname;
$lastlockidx = $lockidx;
- $continue = ",\n";
print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n";
}
@@ -112,7 +107,6 @@ die
. "lwlocknames.txt"
if $i < scalar @wait_event_lwlocks;
-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 2f2de5a562..8aad9c6690 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -115,8 +115,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* There are three sorts of LWLock "tranches":
*
* 1. The individually-named locks defined in lwlocknames.h each have their
- * own tranche. The names of these tranches appear in IndividualLWLockNames[]
- * in lwlocknames.c.
+ * own tranche. The names of these tranches come from lwlocknames.c into
+ * BuiltinTranchNames[] below.
*
* 2. There are some predefined tranches for built-in groups of locks.
* These are listed in enum BuiltinTrancheIds in lwlock.h, and their names
@@ -129,75 +129,43 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* All these names are user-visible as wait event names, so choose with care
* ... and do not forget to update the documentation's list of wait events.
*/
-extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
-
static const char *const BuiltinTrancheNames[] = {
- /* LWTRANCHE_XACT_BUFFER: */
- "XactBuffer",
- /* LWTRANCHE_COMMITTS_BUFFER: */
- "CommitTsBuffer",
- /* LWTRANCHE_SUBTRANS_BUFFER: */
- "SubtransBuffer",
- /* LWTRANCHE_MULTIXACTOFFSET_BUFFER: */
- "MultiXactOffsetBuffer",
- /* LWTRANCHE_MULTIXACTMEMBER_BUFFER: */
- "MultiXactMemberBuffer",
- /* LWTRANCHE_NOTIFY_BUFFER: */
- "NotifyBuffer",
- /* LWTRANCHE_SERIAL_BUFFER: */
- "SerialBuffer",
- /* LWTRANCHE_WAL_INSERT: */
- "WALInsert",
- /* LWTRANCHE_BUFFER_CONTENT: */
- "BufferContent",
- /* LWTRANCHE_REPLICATION_ORIGIN_STATE: */
- "ReplicationOriginState",
- /* LWTRANCHE_REPLICATION_SLOT_IO: */
- "ReplicationSlotIO",
- /* LWTRANCHE_LOCK_FASTPATH: */
- "LockFastPath",
- /* LWTRANCHE_BUFFER_MAPPING: */
- "BufferMapping",
- /* LWTRANCHE_LOCK_MANAGER: */
- "LockManager",
- /* LWTRANCHE_PREDICATE_LOCK_MANAGER: */
- "PredicateLockManager",
- /* LWTRANCHE_PARALLEL_HASH_JOIN: */
- "ParallelHashJoin",
- /* LWTRANCHE_PARALLEL_QUERY_DSA: */
- "ParallelQueryDSA",
- /* LWTRANCHE_PER_SESSION_DSA: */
- "PerSessionDSA",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPE: */
- "PerSessionRecordType",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPMOD: */
- "PerSessionRecordTypmod",
- /* LWTRANCHE_SHARED_TUPLESTORE: */
- "SharedTupleStore",
- /* LWTRANCHE_SHARED_TIDBITMAP: */
- "SharedTidBitmap",
- /* LWTRANCHE_PARALLEL_APPEND: */
- "ParallelAppend",
- /* LWTRANCHE_PER_XACT_PREDICATE_LIST: */
- "PerXactPredicateList",
- /* LWTRANCHE_PGSTATS_DSA: */
- "PgStatsDSA",
- /* LWTRANCHE_PGSTATS_HASH: */
- "PgStatsHash",
- /* LWTRANCHE_PGSTATS_DATA: */
- "PgStatsData",
- /* LWTRANCHE_LAUNCHER_DSA: */
- "LogicalRepLauncherDSA",
- /* LWTRANCHE_LAUNCHER_HASH: */
- "LogicalRepLauncherHash",
- /* LWTRANCHE_DSM_REGISTRY_DSA: */
- "DSMRegistryDSA",
- /* LWTRANCHE_DSM_REGISTRY_HASH: */
- "DSMRegistryHash",
+#include "lwlocknames.c"
+ [LWTRANCHE_XACT_BUFFER] = "XactBuffer",
+ [LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
+ [LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
+ [LWTRANCHE_MULTIXACTOFFSET_BUFFER] = "MultiXactOffsetBuffer",
+ [LWTRANCHE_MULTIXACTMEMBER_BUFFER] = "MultiXactMemberBuffer",
+ [LWTRANCHE_NOTIFY_BUFFER] = "NotifyBuffer",
+ [LWTRANCHE_SERIAL_BUFFER] = "SerialBuffer",
+ [LWTRANCHE_WAL_INSERT] = "WALInsert",
+ [LWTRANCHE_BUFFER_CONTENT] = "BufferContent",
+ [LWTRANCHE_REPLICATION_ORIGIN_STATE] = "ReplicationOriginState",
+ [LWTRANCHE_REPLICATION_SLOT_IO] = "ReplicationSlotIO",
+ [LWTRANCHE_LOCK_FASTPATH] = "LockFastPath",
+ [LWTRANCHE_BUFFER_MAPPING] = "BufferMapping",
+ [LWTRANCHE_LOCK_MANAGER] = "LockManager",
+ [LWTRANCHE_PREDICATE_LOCK_MANAGER] = "PredicateLockManager",
+ [LWTRANCHE_PARALLEL_HASH_JOIN] = "ParallelHashJoin",
+ [LWTRANCHE_PARALLEL_QUERY_DSA] = "ParallelQueryDSA",
+ [LWTRANCHE_PER_SESSION_DSA] = "PerSessionDSA",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPE] = "PerSessionRecordType",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPMOD] = "PerSessionRecordTypmod",
+ [LWTRANCHE_SHARED_TUPLESTORE] = "SharedTupleStore",
+ [LWTRANCHE_SHARED_TIDBITMAP] = "SharedTidBitmap",
+ [LWTRANCHE_PARALLEL_APPEND] = "ParallelAppend",
+ [LWTRANCHE_PER_XACT_PREDICATE_LIST] = "PerXactPredicateList",
+ [LWTRANCHE_PGSTATS_DSA] = "PgStatsDSA",
+ [LWTRANCHE_PGSTATS_HASH] = "PgStatsHash",
+ [LWTRANCHE_PGSTATS_DATA] = "PgStatsData",
+ [LWTRANCHE_LAUNCHER_DSA] = "LogicalRepLauncherDSA",
+ [LWTRANCHE_LAUNCHER_HASH] = "LogicalRepLauncherHash",
+ [LWTRANCHE_DSM_REGISTRY_DSA] = "DSMRegistryDSA",
+ [LWTRANCHE_DSM_REGISTRY_HASH] = "DSMRegistryHash",
};
StaticAssertDecl(lengthof(BuiltinTrancheNames) ==
- LWTRANCHE_FIRST_USER_DEFINED - NUM_INDIVIDUAL_LWLOCKS,
+ LWTRANCHE_FIRST_USER_DEFINED,
"missing entries in BuiltinTrancheNames[]");
/*
@@ -769,13 +737,9 @@ LWLockReportWaitEnd(void)
static const char *
GetLWTrancheName(uint16 trancheId)
{
- /* Individual LWLock? */
- if (trancheId < NUM_INDIVIDUAL_LWLOCKS)
- return IndividualLWLockNames[trancheId];
-
- /* Built-in tranche? */
+ /* Individual LWLock or built-in tranche? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
- return BuiltinTrancheNames[trancheId - NUM_INDIVIDUAL_LWLOCKS];
+ return BuiltinTrancheNames[trancheId];
/*
* It's an extension tranche, so look in LWLockTrancheNames[]. However,
diff --git a/src/backend/storage/lmgr/meson.build b/src/backend/storage/lmgr/meson.build
index da32198f78..16a004202d 100644
--- a/src/backend/storage/lmgr/meson.build
+++ b/src/backend/storage/lmgr/meson.build
@@ -5,11 +5,17 @@ backend_sources += files(
'deadlock.c',
'lmgr.c',
'lock.c',
- 'lwlock.c',
'predicate.c',
'proc.c',
's_lock.c',
'spin.c',
)
-generated_backend_sources += lwlocknames[1]
+# this includes a .c file generated. Is there a better way?
+lwlock = static_library('lwlock',
+ files('lwlock.c'),
+ dependencies: [backend_code],
+ include_directories: include_directories('../../../include/storage'),
+ kwargs: internal_lib_args,
+ )
+backend_link_with += lwlock
--
2.39.2
On 2024-Jan-23, Alvaro Herrera wrote:
... oh, actually FreeBSD failed with this strange problem while linking:
I figured this out. For dtrace support, we need to run dtrace on all
the objects produced by the compilation step, but because I took
lwlock.o out of the objects used to produce the backend into its own
"library", it needs to be included explicitly. (I think this is not a
problem for things like nodes/copyfuncs.c only because those files don't
have any use of TRACE macros).
So here's v3, which now passes fully in CI.
I'm a total newbie to Meson, so it's likely that there are better ways
to implement this. I'll leave this here for a little bit in case
anybody wants to comment.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"El sudor es la mejor cura para un pensamiento enfermo" (Bardia)
Attachments:
v3-0001-Use-designated-initializers-for-BuiltinTrancheNam.patchtext/x-diff; charset=utf-8Download
From 97e86277ec9a406fc625141b59d81757d4358a93 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 23 Jan 2024 10:36:14 +0100
Subject: [PATCH v3] Use designated initializers for BuiltinTrancheNames
---
src/backend/meson.build | 5 +-
src/backend/storage/lmgr/Makefile | 3 +-
.../storage/lmgr/generate-lwlocknames.pl | 10 +-
src/backend/storage/lmgr/lwlock.c | 110 ++++++------------
src/backend/storage/lmgr/meson.build | 12 +-
5 files changed, 55 insertions(+), 85 deletions(-)
diff --git a/src/backend/meson.build b/src/backend/meson.build
index 8767aaba67..6ce6292ea1 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -127,7 +127,10 @@ backend_objs = [postgres_lib.extract_all_objects(recursive: false)]
if dtrace.found() and host_system != 'darwin'
backend_input += custom_target(
'probes.o',
- input: ['utils/probes.d', postgres_lib.extract_objects(backend_sources, timezone_sources)],
+ input: ['utils/probes.d',
+ postgres_lib.extract_objects(backend_sources, timezone_sources),
+ lwlock_lib.extract_objects(lwlock_source)
+ ],
output: 'probes.o',
command: [dtrace, '-C', '-G', '-o', '@OUTPUT@', '-s', '@INPUT@'],
install: false,
diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 504480e847..81da6ee13a 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -12,13 +12,14 @@ subdir = src/backend/storage/lmgr
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
+override CPPFLAGS := -I. $(CPPFLAGS)
+
OBJS = \
condition_variable.o \
deadlock.o \
lmgr.o \
lock.o \
lwlock.o \
- lwlocknames.o \
predicate.o \
proc.o \
s_lock.o \
diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 7b93ecf6c1..a679a4ff54 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -10,7 +10,6 @@ use Getopt::Long;
my $output_path = '.';
my $lastlockidx = -1;
-my $continue = "\n";
GetOptions('outdir:s' => \$output_path);
@@ -29,8 +28,6 @@ print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
print $c $autogen, "\n";
-print $c "const char *const IndividualLWLockNames[] = {";
-
#
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
# cross-check those with the ones in lwlocknames.txt.
@@ -97,12 +94,10 @@ while (<$lwlocknames>)
while ($lastlockidx < $lockidx - 1)
{
++$lastlockidx;
- printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx;
- $continue = ",\n";
+ printf $c "[%s] = \"<unassigned:%d>\",\n", $lastlockidx, $lastlockidx;
}
- printf $c "%s \"%s\"", $continue, $trimmedlockname;
+ printf $c "[%s] = \"%s\",\n", $lockidx, $trimmedlockname;
$lastlockidx = $lockidx;
- $continue = ",\n";
print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n";
}
@@ -112,7 +107,6 @@ die
. "lwlocknames.txt"
if $i < scalar @wait_event_lwlocks;
-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 2f2de5a562..8aad9c6690 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -115,8 +115,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* There are three sorts of LWLock "tranches":
*
* 1. The individually-named locks defined in lwlocknames.h each have their
- * own tranche. The names of these tranches appear in IndividualLWLockNames[]
- * in lwlocknames.c.
+ * own tranche. The names of these tranches come from lwlocknames.c into
+ * BuiltinTranchNames[] below.
*
* 2. There are some predefined tranches for built-in groups of locks.
* These are listed in enum BuiltinTrancheIds in lwlock.h, and their names
@@ -129,75 +129,43 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* All these names are user-visible as wait event names, so choose with care
* ... and do not forget to update the documentation's list of wait events.
*/
-extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
-
static const char *const BuiltinTrancheNames[] = {
- /* LWTRANCHE_XACT_BUFFER: */
- "XactBuffer",
- /* LWTRANCHE_COMMITTS_BUFFER: */
- "CommitTsBuffer",
- /* LWTRANCHE_SUBTRANS_BUFFER: */
- "SubtransBuffer",
- /* LWTRANCHE_MULTIXACTOFFSET_BUFFER: */
- "MultiXactOffsetBuffer",
- /* LWTRANCHE_MULTIXACTMEMBER_BUFFER: */
- "MultiXactMemberBuffer",
- /* LWTRANCHE_NOTIFY_BUFFER: */
- "NotifyBuffer",
- /* LWTRANCHE_SERIAL_BUFFER: */
- "SerialBuffer",
- /* LWTRANCHE_WAL_INSERT: */
- "WALInsert",
- /* LWTRANCHE_BUFFER_CONTENT: */
- "BufferContent",
- /* LWTRANCHE_REPLICATION_ORIGIN_STATE: */
- "ReplicationOriginState",
- /* LWTRANCHE_REPLICATION_SLOT_IO: */
- "ReplicationSlotIO",
- /* LWTRANCHE_LOCK_FASTPATH: */
- "LockFastPath",
- /* LWTRANCHE_BUFFER_MAPPING: */
- "BufferMapping",
- /* LWTRANCHE_LOCK_MANAGER: */
- "LockManager",
- /* LWTRANCHE_PREDICATE_LOCK_MANAGER: */
- "PredicateLockManager",
- /* LWTRANCHE_PARALLEL_HASH_JOIN: */
- "ParallelHashJoin",
- /* LWTRANCHE_PARALLEL_QUERY_DSA: */
- "ParallelQueryDSA",
- /* LWTRANCHE_PER_SESSION_DSA: */
- "PerSessionDSA",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPE: */
- "PerSessionRecordType",
- /* LWTRANCHE_PER_SESSION_RECORD_TYPMOD: */
- "PerSessionRecordTypmod",
- /* LWTRANCHE_SHARED_TUPLESTORE: */
- "SharedTupleStore",
- /* LWTRANCHE_SHARED_TIDBITMAP: */
- "SharedTidBitmap",
- /* LWTRANCHE_PARALLEL_APPEND: */
- "ParallelAppend",
- /* LWTRANCHE_PER_XACT_PREDICATE_LIST: */
- "PerXactPredicateList",
- /* LWTRANCHE_PGSTATS_DSA: */
- "PgStatsDSA",
- /* LWTRANCHE_PGSTATS_HASH: */
- "PgStatsHash",
- /* LWTRANCHE_PGSTATS_DATA: */
- "PgStatsData",
- /* LWTRANCHE_LAUNCHER_DSA: */
- "LogicalRepLauncherDSA",
- /* LWTRANCHE_LAUNCHER_HASH: */
- "LogicalRepLauncherHash",
- /* LWTRANCHE_DSM_REGISTRY_DSA: */
- "DSMRegistryDSA",
- /* LWTRANCHE_DSM_REGISTRY_HASH: */
- "DSMRegistryHash",
+#include "lwlocknames.c"
+ [LWTRANCHE_XACT_BUFFER] = "XactBuffer",
+ [LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
+ [LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
+ [LWTRANCHE_MULTIXACTOFFSET_BUFFER] = "MultiXactOffsetBuffer",
+ [LWTRANCHE_MULTIXACTMEMBER_BUFFER] = "MultiXactMemberBuffer",
+ [LWTRANCHE_NOTIFY_BUFFER] = "NotifyBuffer",
+ [LWTRANCHE_SERIAL_BUFFER] = "SerialBuffer",
+ [LWTRANCHE_WAL_INSERT] = "WALInsert",
+ [LWTRANCHE_BUFFER_CONTENT] = "BufferContent",
+ [LWTRANCHE_REPLICATION_ORIGIN_STATE] = "ReplicationOriginState",
+ [LWTRANCHE_REPLICATION_SLOT_IO] = "ReplicationSlotIO",
+ [LWTRANCHE_LOCK_FASTPATH] = "LockFastPath",
+ [LWTRANCHE_BUFFER_MAPPING] = "BufferMapping",
+ [LWTRANCHE_LOCK_MANAGER] = "LockManager",
+ [LWTRANCHE_PREDICATE_LOCK_MANAGER] = "PredicateLockManager",
+ [LWTRANCHE_PARALLEL_HASH_JOIN] = "ParallelHashJoin",
+ [LWTRANCHE_PARALLEL_QUERY_DSA] = "ParallelQueryDSA",
+ [LWTRANCHE_PER_SESSION_DSA] = "PerSessionDSA",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPE] = "PerSessionRecordType",
+ [LWTRANCHE_PER_SESSION_RECORD_TYPMOD] = "PerSessionRecordTypmod",
+ [LWTRANCHE_SHARED_TUPLESTORE] = "SharedTupleStore",
+ [LWTRANCHE_SHARED_TIDBITMAP] = "SharedTidBitmap",
+ [LWTRANCHE_PARALLEL_APPEND] = "ParallelAppend",
+ [LWTRANCHE_PER_XACT_PREDICATE_LIST] = "PerXactPredicateList",
+ [LWTRANCHE_PGSTATS_DSA] = "PgStatsDSA",
+ [LWTRANCHE_PGSTATS_HASH] = "PgStatsHash",
+ [LWTRANCHE_PGSTATS_DATA] = "PgStatsData",
+ [LWTRANCHE_LAUNCHER_DSA] = "LogicalRepLauncherDSA",
+ [LWTRANCHE_LAUNCHER_HASH] = "LogicalRepLauncherHash",
+ [LWTRANCHE_DSM_REGISTRY_DSA] = "DSMRegistryDSA",
+ [LWTRANCHE_DSM_REGISTRY_HASH] = "DSMRegistryHash",
};
StaticAssertDecl(lengthof(BuiltinTrancheNames) ==
- LWTRANCHE_FIRST_USER_DEFINED - NUM_INDIVIDUAL_LWLOCKS,
+ LWTRANCHE_FIRST_USER_DEFINED,
"missing entries in BuiltinTrancheNames[]");
/*
@@ -769,13 +737,9 @@ LWLockReportWaitEnd(void)
static const char *
GetLWTrancheName(uint16 trancheId)
{
- /* Individual LWLock? */
- if (trancheId < NUM_INDIVIDUAL_LWLOCKS)
- return IndividualLWLockNames[trancheId];
-
- /* Built-in tranche? */
+ /* Individual LWLock or built-in tranche? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
- return BuiltinTrancheNames[trancheId - NUM_INDIVIDUAL_LWLOCKS];
+ return BuiltinTrancheNames[trancheId];
/*
* It's an extension tranche, so look in LWLockTrancheNames[]. However,
diff --git a/src/backend/storage/lmgr/meson.build b/src/backend/storage/lmgr/meson.build
index da32198f78..a12064ae8a 100644
--- a/src/backend/storage/lmgr/meson.build
+++ b/src/backend/storage/lmgr/meson.build
@@ -5,11 +5,19 @@ backend_sources += files(
'deadlock.c',
'lmgr.c',
'lock.c',
- 'lwlock.c',
'predicate.c',
'proc.c',
's_lock.c',
'spin.c',
)
-generated_backend_sources += lwlocknames[1]
+# this includes a .c file generated. Is there a better way?
+lwlock_source = files('lwlock.c')
+
+lwlock_lib = static_library('lwlock',
+ lwlock_source,
+ dependencies: [backend_code],
+ include_directories: include_directories('../../../include/storage'),
+ kwargs: internal_lib_args,
+ )
+backend_link_with += lwlock_lib
--
2.39.2
On 2024-Jan-23, Alvaro Herrera wrote:
I'm a total newbie to Meson, so it's likely that there are better ways
to implement this. I'll leave this here for a little bit in case
anybody wants to comment.
OK, I pushed the array definition, and here's the other bits as a
followup patch. I'll add it to the next commitfest, though I hope to
get it committed before then, either in this form or whatever different
Meson trickery is recommended.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Every machine is a smoke machine if you operate it wrong enough."
https://twitter.com/libseybieda/status/1541673325781196801
Attachments:
0001-Remove-IndividualLWLockNames.patchtext/x-diff; charset=utf-8Download
From 3d24b89855888a6650ec1aafb3579d810bfec5ac Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 23 Jan 2024 10:36:14 +0100
Subject: [PATCH] Remove IndividualLWLockNames
We can just merge the lwlock names into the BuiltinTrancheNames array.
This requires that Meson compiles the file with -I. in CPPFLAGS, which
in turn requires some additional contortions for DTrace support in
FreeBSD.
---
src/backend/meson.build | 4 +++-
src/backend/storage/lmgr/Makefile | 3 ++-
src/backend/storage/lmgr/generate-lwlocknames.pl | 10 ++--------
src/backend/storage/lmgr/lwlock.c | 13 ++++---------
src/backend/storage/lmgr/meson.build | 12 ++++++++++--
5 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/src/backend/meson.build b/src/backend/meson.build
index 8767aaba67..57a52c37e0 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -127,7 +127,9 @@ backend_objs = [postgres_lib.extract_all_objects(recursive: false)]
if dtrace.found() and host_system != 'darwin'
backend_input += custom_target(
'probes.o',
- input: ['utils/probes.d', postgres_lib.extract_objects(backend_sources, timezone_sources)],
+ input: ['utils/probes.d',
+ postgres_lib.extract_objects(backend_sources, timezone_sources),
+ lwlock_lib.extract_objects(lwlock_source)],
output: 'probes.o',
command: [dtrace, '-C', '-G', '-o', '@OUTPUT@', '-s', '@INPUT@'],
install: false,
diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 504480e847..81da6ee13a 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -12,13 +12,14 @@ subdir = src/backend/storage/lmgr
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
+override CPPFLAGS := -I. $(CPPFLAGS)
+
OBJS = \
condition_variable.o \
deadlock.o \
lmgr.o \
lock.o \
lwlock.o \
- lwlocknames.o \
predicate.o \
proc.o \
s_lock.o \
diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 7b93ecf6c1..a679a4ff54 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -10,7 +10,6 @@ use Getopt::Long;
my $output_path = '.';
my $lastlockidx = -1;
-my $continue = "\n";
GetOptions('outdir:s' => \$output_path);
@@ -29,8 +28,6 @@ print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
print $c $autogen, "\n";
-print $c "const char *const IndividualLWLockNames[] = {";
-
#
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
# cross-check those with the ones in lwlocknames.txt.
@@ -97,12 +94,10 @@ while (<$lwlocknames>)
while ($lastlockidx < $lockidx - 1)
{
++$lastlockidx;
- printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx;
- $continue = ",\n";
+ printf $c "[%s] = \"<unassigned:%d>\",\n", $lastlockidx, $lastlockidx;
}
- printf $c "%s \"%s\"", $continue, $trimmedlockname;
+ printf $c "[%s] = \"%s\",\n", $lockidx, $trimmedlockname;
$lastlockidx = $lockidx;
- $continue = ",\n";
print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n";
}
@@ -112,7 +107,6 @@ die
. "lwlocknames.txt"
if $i < scalar @wait_event_lwlocks;
-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 98fa6035cc..8aad9c6690 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -115,8 +115,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* There are three sorts of LWLock "tranches":
*
* 1. The individually-named locks defined in lwlocknames.h each have their
- * own tranche. The names of these tranches appear in IndividualLWLockNames[]
- * in lwlocknames.c.
+ * own tranche. The names of these tranches come from lwlocknames.c into
+ * BuiltinTranchNames[] below.
*
* 2. There are some predefined tranches for built-in groups of locks.
* These are listed in enum BuiltinTrancheIds in lwlock.h, and their names
@@ -129,9 +129,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* All these names are user-visible as wait event names, so choose with care
* ... and do not forget to update the documentation's list of wait events.
*/
-extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
-
static const char *const BuiltinTrancheNames[] = {
+#include "lwlocknames.c"
[LWTRANCHE_XACT_BUFFER] = "XactBuffer",
[LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
[LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
@@ -738,11 +737,7 @@ LWLockReportWaitEnd(void)
static const char *
GetLWTrancheName(uint16 trancheId)
{
- /* Individual LWLock? */
- if (trancheId < NUM_INDIVIDUAL_LWLOCKS)
- return IndividualLWLockNames[trancheId];
-
- /* Built-in tranche? */
+ /* Individual LWLock or built-in tranche? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
return BuiltinTrancheNames[trancheId];
diff --git a/src/backend/storage/lmgr/meson.build b/src/backend/storage/lmgr/meson.build
index da32198f78..a12064ae8a 100644
--- a/src/backend/storage/lmgr/meson.build
+++ b/src/backend/storage/lmgr/meson.build
@@ -5,11 +5,19 @@ backend_sources += files(
'deadlock.c',
'lmgr.c',
'lock.c',
- 'lwlock.c',
'predicate.c',
'proc.c',
's_lock.c',
'spin.c',
)
-generated_backend_sources += lwlocknames[1]
+# this includes a .c file generated. Is there a better way?
+lwlock_source = files('lwlock.c')
+
+lwlock_lib = static_library('lwlock',
+ lwlock_source,
+ dependencies: [backend_code],
+ include_directories: include_directories('../../../include/storage'),
+ kwargs: internal_lib_args,
+ )
+backend_link_with += lwlock_lib
--
2.39.2
On Wed Jan 24, 2024 at 8:09 AM CST, Alvaro Herrera wrote:
From 3d24b89855888a6650ec1aafb3579d810bfec5ac Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 23 Jan 2024 10:36:14 +0100
Subject: [PATCH] Remove IndividualLWLockNamesWe can just merge the lwlock names into the BuiltinTrancheNames array.
This requires that Meson compiles the file with -I. in CPPFLAGS, which
in turn requires some additional contortions for DTrace support in
FreeBSD.
---
src/backend/meson.build | 4 +++-
src/backend/storage/lmgr/Makefile | 3 ++-
src/backend/storage/lmgr/generate-lwlocknames.pl | 10 ++--------
src/backend/storage/lmgr/lwlock.c | 13 ++++---------
src/backend/storage/lmgr/meson.build | 12 ++++++++++--
5 files changed, 21 insertions(+), 21 deletions(-)diff --git a/src/backend/meson.build b/src/backend/meson.build index 8767aaba67..57a52c37e0 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -127,7 +127,9 @@ backend_objs = [postgres_lib.extract_all_objects(recursive: false)] if dtrace.found() and host_system != 'darwin' backend_input += custom_target( 'probes.o', - input: ['utils/probes.d', postgres_lib.extract_objects(backend_sources, timezone_sources)], + input: ['utils/probes.d', + postgres_lib.extract_objects(backend_sources, timezone_sources), + lwlock_lib.extract_objects(lwlock_source)], output: 'probes.o', command: [dtrace, '-C', '-G', '-o', '@OUTPUT@', '-s', '@INPUT@'], install: false, diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile index 504480e847..81da6ee13a 100644 --- a/src/backend/storage/lmgr/Makefile +++ b/src/backend/storage/lmgr/Makefile @@ -12,13 +12,14 @@ subdir = src/backend/storage/lmgr top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global+override CPPFLAGS := -I. $(CPPFLAGS) + OBJS = \ condition_variable.o \ deadlock.o \ lmgr.o \ lock.o \ lwlock.o \ - lwlocknames.o \ predicate.o \ proc.o \ s_lock.o \ diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index 7b93ecf6c1..a679a4ff54 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -10,7 +10,6 @@ use Getopt::Long; my $output_path = '.';my $lastlockidx = -1;
-my $continue = "\n";GetOptions('outdir:s' => \$output_path);
@@ -29,8 +28,6 @@ print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
print $c $autogen, "\n";-print $c "const char *const IndividualLWLockNames[] = {"; - # # First, record the predefined LWLocks listed in wait_event_names.txt. We'll # cross-check those with the ones in lwlocknames.txt. @@ -97,12 +94,10 @@ while (<$lwlocknames>) while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; - printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx; - $continue = ",\n"; + printf $c "[%s] = \"<unassigned:%d>\",\n", $lastlockidx, $lastlockidx; } - printf $c "%s \"%s\"", $continue, $trimmedlockname; + printf $c "[%s] = \"%s\",\n", $lockidx, $trimmedlockname; $lastlockidx = $lockidx; - $continue = ",\n";print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n";
}
@@ -112,7 +107,6 @@ die
. "lwlocknames.txt"
if $i < scalar @wait_event_lwlocks;-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 98fa6035cc..8aad9c6690 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -115,8 +115,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS, * There are three sorts of LWLock "tranches": * * 1. The individually-named locks defined in lwlocknames.h each have their - * own tranche. The names of these tranches appear in IndividualLWLockNames[] - * in lwlocknames.c. + * own tranche. The names of these tranches come from lwlocknames.c into + * BuiltinTranchNames[] below. * * 2. There are some predefined tranches for built-in groups of locks. * These are listed in enum BuiltinTrancheIds in lwlock.h, and their names @@ -129,9 +129,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS, * All these names are user-visible as wait event names, so choose with care * ... and do not forget to update the documentation's list of wait events. */ -extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */ - static const char *const BuiltinTrancheNames[] = { +#include "lwlocknames.c" [LWTRANCHE_XACT_BUFFER] = "XactBuffer", [LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer", [LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer", @@ -738,11 +737,7 @@ LWLockReportWaitEnd(void) static const char * GetLWTrancheName(uint16 trancheId) { - /* Individual LWLock? */ - if (trancheId < NUM_INDIVIDUAL_LWLOCKS) - return IndividualLWLockNames[trancheId]; - - /* Built-in tranche? */ + /* Individual LWLock or built-in tranche? */ if (trancheId < LWTRANCHE_FIRST_USER_DEFINED) return BuiltinTrancheNames[trancheId];diff --git a/src/backend/storage/lmgr/meson.build b/src/backend/storage/lmgr/meson.build index da32198f78..a12064ae8a 100644 --- a/src/backend/storage/lmgr/meson.build +++ b/src/backend/storage/lmgr/meson.build @@ -5,11 +5,19 @@ backend_sources += files( 'deadlock.c', 'lmgr.c', 'lock.c', - 'lwlock.c', 'predicate.c', 'proc.c', 's_lock.c', 'spin.c', )-generated_backend_sources += lwlocknames[1] +# this includes a .c file generated. Is there a better way? +lwlock_source = files('lwlock.c')
I don't understand this comment. Could you explain it a bit more?
+ +lwlock_lib = static_library('lwlock', + lwlock_source, + dependencies: [backend_code], + include_directories: include_directories('../../../include/storage'), + kwargs: internal_lib_args, + )
Move the paren to the beginning of the line.
+backend_link_with += lwlock_lib
Earlier in the thread you had said this:
IMO it would be less ugly to have the origin file lwlocknames.txt be
not a text file but a .h with a macro that can be defined by
interested parties so that they can extract what they want from the
file, like PG_CMDTAG or PG_KEYWORD. Using Perl for this seems dirty...
I really like this idea, and would definitely be more inclined to see
a solution like this.
--
Tristan Partin
Neon (https://neon.tech)
On 12/02/2024 19:01, Tristan Partin wrote:
On Wed Jan 24, 2024 at 8:09 AM CST, Alvaro Herrera wrote:
IMO it would be less ugly to have the origin file lwlocknames.txt be
not a text file but a .h with a macro that can be defined by
interested parties so that they can extract what they want from the
file, like PG_CMDTAG or PG_KEYWORD. Using Perl for this seems dirty...I really like this idea, and would definitely be more inclined to see
a solution like this.
+1 to that idea from me too. Seems pretty straightforward.
--
Heikki Linnakangas
Neon (https://neon.tech)
On 2024-Feb-23, Heikki Linnakangas wrote:
On 12/02/2024 19:01, Tristan Partin wrote:
On Wed Jan 24, 2024 at 8:09 AM CST, Alvaro Herrera wrote:
IMO it would be less ugly to have the origin file lwlocknames.txt be
not a text file but a .h with a macro that can be defined by
interested parties so that they can extract what they want from the
file, like PG_CMDTAG or PG_KEYWORD. Using Perl for this seems dirty...I really like this idea, and would definitely be more inclined to see
a solution like this.+1 to that idea from me too. Seems pretty straightforward.
OK, here's a patch that does it. I have not touched Meson yet.
I'm pretty disappointed of not being able to remove
generate-lwlocknames.pl (it now generates the .h, no longer the .c
file), but I can't find a way to do the equivalent #defines in CPP ...
it'd require invoking the C preprocessor twice. Maybe an intermediate
.h file would solve the problem, but I have no idea how would that work
with Meson. I guess I'll do it in Make and let somebody suggest a Meson
way.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"El hombre nunca sabe de lo que es capaz hasta que lo intenta" (C. Dickens)
Attachments:
0001-Rework-lwlocknames.txt-to-become-lwlocklist.h.patchtext/x-diff; charset=utf-8Download
From c70ae4eff6ec8e8965207d6e0d6d8fcdcd91cf16 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 1 Mar 2024 13:03:10 +0100
Subject: [PATCH] Rework lwlocknames.txt to become lwlocklist.h
This saves some code and some space in BuiltinTrancheNames, as foreseen
in commit 74a730631065.
---
src/backend/Makefile | 4 +-
src/backend/storage/lmgr/.gitignore | 1 -
src/backend/storage/lmgr/Makefile | 9 +-
.../storage/lmgr/generate-lwlocknames.pl | 52 ++++++------
src/backend/storage/lmgr/lwlock.c | 15 ++--
src/backend/storage/lmgr/lwlocknames.txt | 60 --------------
.../utils/activity/wait_event_names.txt | 8 +-
src/include/storage/lwlocklist.h | 82 +++++++++++++++++++
8 files changed, 124 insertions(+), 107 deletions(-)
delete mode 100644 src/backend/storage/lmgr/lwlocknames.txt
create mode 100644 src/include/storage/lwlocklist.h
diff --git a/src/backend/Makefile b/src/backend/Makefile
index d66e2a4b9f..34bb6393c4 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -110,8 +110,8 @@ $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
parser/gram.h: parser/gram.y
$(MAKE) -C parser gram.h
-storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt utils/activity/wait_event_names.txt
- $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
+storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl $(top_srcdir)/src/include/storage/lwlocklist.h utils/activity/wait_event_names.txt
+ $(MAKE) -C storage/lmgr lwlocknames.h
utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt
$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c
diff --git a/src/backend/storage/lmgr/.gitignore b/src/backend/storage/lmgr/.gitignore
index dab4c3f580..8e5b734f15 100644
--- a/src/backend/storage/lmgr/.gitignore
+++ b/src/backend/storage/lmgr/.gitignore
@@ -1,3 +1,2 @@
-/lwlocknames.c
/lwlocknames.h
/s_lock_test
diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 1aef423384..9d7dbe5abd 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -18,7 +18,6 @@ OBJS = \
lmgr.o \
lock.o \
lwlock.o \
- lwlocknames.o \
predicate.o \
proc.o \
s_lock.o \
@@ -35,11 +34,7 @@ s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/s
$(TASPATH) -L $(top_builddir)/src/common -lpgcommon \
-L $(top_builddir)/src/port -lpgport -lm -o s_lock_test
-# see notes in src/backend/parser/Makefile
-lwlocknames.c: lwlocknames.h
- touch $@
-
-lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt generate-lwlocknames.pl
+lwlocknames.h: $(top_srcdir)/src/include/storage/lwlocklist.h $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt generate-lwlocknames.pl
$(PERL) $(srcdir)/generate-lwlocknames.pl $^
check: s_lock_test
@@ -47,4 +42,4 @@ check: s_lock_test
clean:
rm -f s_lock_test
- rm -f lwlocknames.h lwlocknames.c
+ rm -f lwlocknames.h
diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 7b93ecf6c1..f46634a180 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# Generate lwlocknames.h and lwlocknames.c from lwlocknames.txt
+# Generate lwlocknames.h from lwlocklist.h
# Copyright (c) 2000-2024, PostgreSQL Global Development Group
use strict;
@@ -14,26 +14,22 @@ my $continue = "\n";
GetOptions('outdir:s' => \$output_path);
-open my $lwlocknames, '<', $ARGV[0] or die;
+open my $lwlocklist, '<', $ARGV[0] or die;
open my $wait_event_names, '<', $ARGV[1] or die;
# Include PID in suffix in case parallel make runs this multiple times.
my $htmp = "$output_path/lwlocknames.h.tmp$$";
-my $ctmp = "$output_path/lwlocknames.c.tmp$$";
open my $h, '>', $htmp or die "Could not open $htmp: $!";
-open my $c, '>', $ctmp or die "Could not open $ctmp: $!";
my $autogen =
- "/* autogenerated from src/backend/storage/lmgr/lwlocknames.txt, do not edit */\n";
+ "/* autogenerated from src/backend/storage/lmgr/lwlocklist.h, do not edit */\n";
print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
-print $c $autogen, "\n";
-print $c "const char *const IndividualLWLockNames[] = {";
#
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
-# cross-check those with the ones in lwlocknames.txt.
+# cross-check those with the ones in lwlocklist.h.
#
my @wait_event_lwlocks;
my $record_lwlocks = 0;
@@ -64,17 +60,30 @@ while (<$wait_event_names>)
push(@wait_event_lwlocks, $waiteventname . "Lock");
}
+my $in_comment = 0;
my $i = 0;
-while (<$lwlocknames>)
+while (<$lwlocklist>)
{
chomp;
- # Skip comments
- next if /^#/;
+ # Skip uniline C comments and empty lines
+ next if m{^\s*/\*.*\*/$};
next if /^\s*$/;
- die "unable to parse lwlocknames.txt"
- unless /^(\w+)\s+(\d+)$/;
+ # skip multiline C comments
+ if ($in_comment == 1)
+ {
+ $in_comment = 0 if m{\*/};
+ next;
+ }
+ elsif (m{^\s*/\*})
+ {
+ $in_comment = 1;
+ next;
+ }
+
+ die "unable to parse lwlocklist.h line \"$_\""
+ unless /^PG_LWLOCK\((\w+),\s+(\d+)\)$/;
(my $lockname, my $lockidx) = ($1, $2);
@@ -82,25 +91,23 @@ while (<$lwlocknames>)
$trimmedlockname =~ s/Lock$//;
die "lock names must end with 'Lock'" if $trimmedlockname eq $lockname;
- die "lwlocknames.txt not in order" if $lockidx < $lastlockidx;
- die "lwlocknames.txt has duplicates" if $lockidx == $lastlockidx;
+ die "lwlocklist.h not in order" if $lockidx < $lastlockidx;
+ die "lwlocklist.h has duplicates" if $lockidx == $lastlockidx;
- die "$lockname defined in lwlocknames.txt but missing from "
+ die "$lockname defined in lwlocklist.h but missing from "
. "wait_event_names.txt"
if $i >= scalar @wait_event_lwlocks;
die "lists of predefined LWLocks do not match (first mismatch at "
. "$wait_event_lwlocks[$i] in wait_event_names.txt and $lockname in "
- . "lwlocknames.txt)"
+ . "lwlocklist.h)"
if $wait_event_lwlocks[$i] ne $lockname;
$i++;
while ($lastlockidx < $lockidx - 1)
{
++$lastlockidx;
- printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx;
$continue = ",\n";
}
- printf $c "%s \"%s\"", $continue, $trimmedlockname;
$lastlockidx = $lockidx;
$continue = ",\n";
@@ -109,18 +116,15 @@ while (<$lwlocknames>)
die
"$wait_event_lwlocks[$i] defined in wait_event_names.txt but missing from "
- . "lwlocknames.txt"
+ . "lwlocklist.h"
if $i < scalar @wait_event_lwlocks;
-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;
close $h;
-close $c;
rename($htmp, "$output_path/lwlocknames.h")
|| die "rename: $htmp to $output_path/lwlocknames.h: $!";
-rename($ctmp, "$output_path/lwlocknames.c") || die "rename: $ctmp: $!";
-close $lwlocknames;
+close $lwlocklist;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index d405c61b21..1112389af5 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -115,8 +115,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* There are three sorts of LWLock "tranches":
*
* 1. The individually-named locks defined in lwlocknames.h each have their
- * own tranche. The names of these tranches appear in IndividualLWLockNames[]
- * in lwlocknames.c.
+ * own tranche. We absorb the names of these tranches from there into
+ * BuiltinTrancheNames here.
*
* 2. There are some predefined tranches for built-in groups of locks.
* These are listed in enum BuiltinTrancheIds in lwlock.h, and their names
@@ -129,9 +129,10 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* All these names are user-visible as wait event names, so choose with care
* ... and do not forget to update the documentation's list of wait events.
*/
-extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
-
static const char *const BuiltinTrancheNames[] = {
+#define PG_LWLOCK(lockname, id) [id] = CppAsString(lockname),
+#include "storage/lwlocknames.h"
+#undef PG_LWLOCK
[LWTRANCHE_XACT_BUFFER] = "XactBuffer",
[LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
[LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
@@ -745,11 +746,7 @@ LWLockReportWaitEnd(void)
static const char *
GetLWTrancheName(uint16 trancheId)
{
- /* Individual LWLock? */
- if (trancheId < NUM_INDIVIDUAL_LWLOCKS)
- return IndividualLWLockNames[trancheId];
-
- /* Built-in tranche? */
+ /* Built-in tranche or individual LWLock? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
return BuiltinTrancheNames[trancheId];
diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt
deleted file mode 100644
index 284d168f77..0000000000
--- a/src/backend/storage/lmgr/lwlocknames.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-# Some commonly-used locks have predefined positions within MainLWLockArray;
-# these are defined here. If you add a lock, add it to the end to avoid
-# renumbering the existing locks; if you remove a lock, consider leaving a gap
-# in the numbering sequence for the benefit of DTrace and other external
-# debugging scripts. Also, do not forget to update the section
-# WaitEventLWLock of src/backend/utils/activity/wait_event_names.txt.
-
-# 0 is available; was formerly BufFreelistLock
-ShmemIndexLock 1
-OidGenLock 2
-XidGenLock 3
-ProcArrayLock 4
-SInvalReadLock 5
-SInvalWriteLock 6
-WALBufMappingLock 7
-WALWriteLock 8
-ControlFileLock 9
-# 10 was CheckpointLock
-# 11 was XactSLRULock
-# 12 was SubtransSLRULock
-MultiXactGenLock 13
-# 14 was MultiXactOffsetSLRULock
-# 15 was MultiXactMemberSLRULock
-RelCacheInitLock 16
-CheckpointerCommLock 17
-TwoPhaseStateLock 18
-TablespaceCreateLock 19
-BtreeVacuumLock 20
-AddinShmemInitLock 21
-AutovacuumLock 22
-AutovacuumScheduleLock 23
-SyncScanLock 24
-RelationMappingLock 25
-#26 was NotifySLRULock
-NotifyQueueLock 27
-SerializableXactHashLock 28
-SerializableFinishedListLock 29
-SerializablePredicateListLock 30
-# 31 was SerialSLRULock
-SyncRepLock 32
-BackgroundWorkerLock 33
-DynamicSharedMemoryControlLock 34
-AutoFileLock 35
-ReplicationSlotAllocationLock 36
-ReplicationSlotControlLock 37
-#38 was CommitTsSLRULock
-CommitTsLock 39
-ReplicationOriginLock 40
-MultiXactTruncationLock 41
-# 42 was OldSnapshotTimeMapLock
-LogicalRepWorkerLock 43
-XactTruncationLock 44
-# 45 was XactTruncationLock until removal of BackendRandomLock
-WrapLimitsVacuumLock 46
-NotifyQueueTailLock 47
-WaitEventExtensionLock 48
-WALSummarizerLock 49
-DSMRegistryLock 50
-InjectionPointLock 51
-SerialControlLock 52
diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt
index ec2f31f82a..105ca977a5 100644
--- a/src/backend/utils/activity/wait_event_names.txt
+++ b/src/backend/utils/activity/wait_event_names.txt
@@ -279,9 +279,9 @@ Extension "Waiting in an extension."
# This class of wait events has its own set of C structure, so these are
# only used for the documentation.
#
-# NB: Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be
+# NB: Predefined LWLocks (i.e., those declared in lwlocknames.h) must be
# listed in the top section of locks and must be listed in the same order as in
-# lwlocknames.txt.
+# lwlocknames.h.
#
Section: ClassName - WaitEventLWLock
@@ -332,9 +332,9 @@ SerialControl "Waiting to read or update shared <filename>pg_serial</filename> s
#
# END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE)
#
-# Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be listed
+# Predefined LWLocks (i.e., those declared in lwlocknames.h) must be listed
# in the section above and must be listed in the same order as in
-# lwlocknames.txt. Other LWLocks must be listed in the section below.
+# lwlocknames.h. Other LWLocks must be listed in the section below.
#
XactBuffer "Waiting for I/O on a transaction status SLRU buffer."
diff --git a/src/include/storage/lwlocklist.h b/src/include/storage/lwlocklist.h
new file mode 100644
index 0000000000..3396eed58e
--- /dev/null
+++ b/src/include/storage/lwlocklist.h
@@ -0,0 +1,82 @@
+/*-------------------------------------------------------------------------
+ *
+ * lwlocklist.h
+ *
+ * The predefined LWLock list is kept in its own source file for use by
+ * automatic tools. The exact representation of a keyword is determined by
+ * the PG_LWLOCK macro, which is not defined in this file; it can be
+ * defined by the caller for special purposes.
+ *
+ * Also, generate-lwlock-names.pl processes this file.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * IDENTIFICATION
+ * src/include/storage/lwlocklist.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*
+ * Some commonly-used locks have predefined positions within MainLWLockArray;
+ * these are defined here. If you add a lock, add it to the end to avoid
+ * renumbering the existing locks; if you remove a lock, consider leaving a gap
+ * in the numbering sequence for the benefit of DTrace and other external
+ * debugging scripts. Also, do not forget to update the section
+ * WaitEventLWLock of src/backend/utils/activity/wait_event_names.txt.
+ */
+
+/* 0 is available; was formerly BufFreelistLock */
+PG_LWLOCK(ShmemIndexLock, 1)
+PG_LWLOCK(OidGenLock, 2)
+PG_LWLOCK(XidGenLock, 3)
+PG_LWLOCK(ProcArrayLock, 4)
+PG_LWLOCK(SInvalReadLock, 5)
+PG_LWLOCK(SInvalWriteLock, 6)
+PG_LWLOCK(WALBufMappingLock, 7)
+PG_LWLOCK(WALWriteLock, 8)
+PG_LWLOCK(ControlFileLock, 9)
+/* 10 was CheckpointLock */
+/* 11 was XactSLRULock */
+/* 12 was SubtransSLRULock */
+PG_LWLOCK(MultiXactGenLock, 13)
+/* 14 was MultiXactOffsetSLRULock */
+/* 15 was MultiXactMemberSLRULock */
+PG_LWLOCK(RelCacheInitLock, 16)
+PG_LWLOCK(CheckpointerCommLock, 17)
+PG_LWLOCK(TwoPhaseStateLock, 18)
+PG_LWLOCK(TablespaceCreateLock, 19)
+PG_LWLOCK(BtreeVacuumLock, 20)
+PG_LWLOCK(AddinShmemInitLock, 21)
+PG_LWLOCK(AutovacuumLock, 22)
+PG_LWLOCK(AutovacuumScheduleLock, 23)
+PG_LWLOCK(SyncScanLock, 24)
+PG_LWLOCK(RelationMappingLock, 25)
+/* 26 was NotifySLRULock */
+PG_LWLOCK(NotifyQueueLock, 27)
+PG_LWLOCK(SerializableXactHashLock, 28)
+PG_LWLOCK(SerializableFinishedListLock, 29)
+PG_LWLOCK(SerializablePredicateListLock, 30)
+/* 31 was SerialSLRULock */
+PG_LWLOCK(SyncRepLock, 32)
+PG_LWLOCK(BackgroundWorkerLock, 33)
+PG_LWLOCK(DynamicSharedMemoryControlLock, 34)
+PG_LWLOCK(AutoFileLock, 35)
+PG_LWLOCK(ReplicationSlotAllocationLock, 36)
+PG_LWLOCK(ReplicationSlotControlLock, 37)
+/* 38 was CommitTsSLRULock */
+PG_LWLOCK(CommitTsLock, 39)
+PG_LWLOCK(ReplicationOriginLock, 40)
+PG_LWLOCK(MultiXactTruncationLock, 41)
+/* 42 was OldSnapshotTimeMapLock */
+PG_LWLOCK(LogicalRepWorkerLock, 43)
+PG_LWLOCK(XactTruncationLock, 44)
+/* 45 was XactTruncationLock until removal of BackendRandomLock */
+PG_LWLOCK(WrapLimitsVacuumLock, 46)
+PG_LWLOCK(NotifyQueueTailLock, 47)
+PG_LWLOCK(WaitEventExtensionLock, 48)
+PG_LWLOCK(WALSummarizerLock, 49)
+PG_LWLOCK(DSMRegistryLock, 50)
+PG_LWLOCK(InjectionPointLock, 51)
+PG_LWLOCK(SerialControlLock, 52)
--
2.39.2
On Fri Mar 1, 2024 at 8:00 AM CST, Alvaro Herrera wrote:
On 2024-Feb-23, Heikki Linnakangas wrote:
On 12/02/2024 19:01, Tristan Partin wrote:
On Wed Jan 24, 2024 at 8:09 AM CST, Alvaro Herrera wrote:
IMO it would be less ugly to have the origin file lwlocknames.txt be
not a text file but a .h with a macro that can be defined by
interested parties so that they can extract what they want from the
file, like PG_CMDTAG or PG_KEYWORD. Using Perl for this seems dirty...I really like this idea, and would definitely be more inclined to see
a solution like this.+1 to that idea from me too. Seems pretty straightforward.
OK, here's a patch that does it. I have not touched Meson yet.
I'm pretty disappointed of not being able to remove
generate-lwlocknames.pl (it now generates the .h, no longer the .c
file), but I can't find a way to do the equivalent #defines in CPP ...
it'd require invoking the C preprocessor twice. Maybe an intermediate
.h file would solve the problem, but I have no idea how would that work
with Meson. I guess I'll do it in Make and let somebody suggest a Meson
way.
I can help you with Meson if you get the Make implementation done.
--
Tristan Partin
Neon (https://neon.tech)
On 2024-Mar-01, Tristan Partin wrote:
On Fri Mar 1, 2024 at 8:00 AM CST, Alvaro Herrera wrote:
I'm pretty disappointed of not being able to remove
generate-lwlocknames.pl (it now generates the .h, no longer the .c
file), but I can't find a way to do the equivalent #defines in CPP ...
it'd require invoking the C preprocessor twice. Maybe an intermediate
.h file would solve the problem, but I have no idea how would that work
with Meson. I guess I'll do it in Make and let somebody suggest a Meson
way.I can help you with Meson if you get the Make implementation done.
Actually I realized that we need to keep the Perl script anyway because
we want to be able to cross-check the wait_event_names.txt files to
ensure we generate the correct documentation. Since it was simple
enough, I added the Meson support already.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Essentially, you're proposing Kevlar shoes as a solution for the problem
that you want to walk around carrying a loaded gun aimed at your foot.
(Tom Lane)
Attachments:
v2-0001-Rework-lwlocknames.txt-to-become-lwlocklist.h.patchtext/x-diff; charset=utf-8Download
From 6359348fafbefb391aad89e47e5e443eb8ab8e29 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 1 Mar 2024 13:03:10 +0100
Subject: [PATCH v2] Rework lwlocknames.txt to become lwlocklist.h
This saves some code and some space in BuiltinTrancheNames, as foreseen
in commit 74a730631065.
We still have to build lwlocknames.h using Perl code, which initially I
wanted to avoid, but it gives us the chance to cross-check
wait_event_names.txt.
Discussion: https://postgr.es/m/202401231025.gbv4nnte5fmm@alvherre.pgsql
---
src/backend/Makefile | 4 +-
src/backend/storage/lmgr/.gitignore | 1 -
src/backend/storage/lmgr/Makefile | 9 +-
.../storage/lmgr/generate-lwlocknames.pl | 60 ++++++-------
src/backend/storage/lmgr/lwlock.c | 15 ++--
src/backend/storage/lmgr/lwlocknames.txt | 60 -------------
src/backend/storage/lmgr/meson.build | 2 -
.../utils/activity/wait_event_names.txt | 8 +-
src/include/storage/lwlock.h | 4 +-
src/include/storage/lwlocklist.h | 85 +++++++++++++++++++
src/include/storage/meson.build | 12 ++-
src/tools/pginclude/headerscheck | 1 +
12 files changed, 136 insertions(+), 125 deletions(-)
delete mode 100644 src/backend/storage/lmgr/lwlocknames.txt
create mode 100644 src/include/storage/lwlocklist.h
diff --git a/src/backend/Makefile b/src/backend/Makefile
index d66e2a4b9f..79a12dfd1e 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -110,8 +110,8 @@ $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
parser/gram.h: parser/gram.y
$(MAKE) -C parser gram.h
-storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt utils/activity/wait_event_names.txt
- $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
+storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl ../include/storage/lwlocklist.h utils/activity/wait_event_names.txt
+ $(MAKE) -C storage/lmgr lwlocknames.h
utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt
$(MAKE) -C utils/activity wait_event_types.h pgstat_wait_event.c wait_event_funcs_data.c
diff --git a/src/backend/storage/lmgr/.gitignore b/src/backend/storage/lmgr/.gitignore
index dab4c3f580..8e5b734f15 100644
--- a/src/backend/storage/lmgr/.gitignore
+++ b/src/backend/storage/lmgr/.gitignore
@@ -1,3 +1,2 @@
-/lwlocknames.c
/lwlocknames.h
/s_lock_test
diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile
index 1aef423384..3f89548bde 100644
--- a/src/backend/storage/lmgr/Makefile
+++ b/src/backend/storage/lmgr/Makefile
@@ -18,7 +18,6 @@ OBJS = \
lmgr.o \
lock.o \
lwlock.o \
- lwlocknames.o \
predicate.o \
proc.o \
s_lock.o \
@@ -35,11 +34,7 @@ s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/s
$(TASPATH) -L $(top_builddir)/src/common -lpgcommon \
-L $(top_builddir)/src/port -lpgport -lm -o s_lock_test
-# see notes in src/backend/parser/Makefile
-lwlocknames.c: lwlocknames.h
- touch $@
-
-lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt generate-lwlocknames.pl
+lwlocknames.h: ../../../include/storage/lwlocklist.h ../../utils/activity/wait_event_names.txt generate-lwlocknames.pl
$(PERL) $(srcdir)/generate-lwlocknames.pl $^
check: s_lock_test
@@ -47,4 +42,4 @@ check: s_lock_test
clean:
rm -f s_lock_test
- rm -f lwlocknames.h lwlocknames.c
+ rm -f lwlocknames.h
diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 7b93ecf6c1..eaddd9d3b9 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# Generate lwlocknames.h and lwlocknames.c from lwlocknames.txt
+# Generate lwlocknames.h from lwlocklist.h
# Copyright (c) 2000-2024, PostgreSQL Global Development Group
use strict;
@@ -14,26 +14,22 @@ my $continue = "\n";
GetOptions('outdir:s' => \$output_path);
-open my $lwlocknames, '<', $ARGV[0] or die;
+open my $lwlocklist, '<', $ARGV[0] or die;
open my $wait_event_names, '<', $ARGV[1] or die;
# Include PID in suffix in case parallel make runs this multiple times.
my $htmp = "$output_path/lwlocknames.h.tmp$$";
-my $ctmp = "$output_path/lwlocknames.c.tmp$$";
open my $h, '>', $htmp or die "Could not open $htmp: $!";
-open my $c, '>', $ctmp or die "Could not open $ctmp: $!";
my $autogen =
- "/* autogenerated from src/backend/storage/lmgr/lwlocknames.txt, do not edit */\n";
+ "/* autogenerated from src/include/storage/lwlocklist.h, do not edit */\n";
print $h $autogen;
print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
-print $c $autogen, "\n";
-print $c "const char *const IndividualLWLockNames[] = {";
#
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
-# cross-check those with the ones in lwlocknames.txt.
+# cross-check those with the ones in lwlocklist.h.
#
my @wait_event_lwlocks;
my $record_lwlocks = 0;
@@ -61,66 +57,70 @@ while (<$wait_event_names>)
# Record the LWLock.
(my $waiteventname, my $waitevendocsentence) = split(/\t/, $_);
- push(@wait_event_lwlocks, $waiteventname . "Lock");
+ push(@wait_event_lwlocks, $waiteventname);
}
+my $in_comment = 0;
my $i = 0;
-while (<$lwlocknames>)
+while (<$lwlocklist>)
{
chomp;
- # Skip comments
- next if /^#/;
+ # Skip single-line C comments and empty lines
+ next if m{^\s*/\*.*\*/$};
next if /^\s*$/;
- die "unable to parse lwlocknames.txt"
- unless /^(\w+)\s+(\d+)$/;
+ # skip multiline C comments
+ if ($in_comment == 1)
+ {
+ $in_comment = 0 if m{\*/};
+ next;
+ }
+ elsif (m{^\s*/\*})
+ {
+ $in_comment = 1;
+ next;
+ }
- (my $lockname, my $lockidx) = ($1, $2);
+ die "unable to parse lwlocklist.h line \"$_\""
+ unless /^PG_LWLOCK\((\d+),\s+(\w+)\)$/;
- my $trimmedlockname = $lockname;
- $trimmedlockname =~ s/Lock$//;
- die "lock names must end with 'Lock'" if $trimmedlockname eq $lockname;
+ (my $lockidx, my $lockname) = ($1, $2);
- die "lwlocknames.txt not in order" if $lockidx < $lastlockidx;
- die "lwlocknames.txt has duplicates" if $lockidx == $lastlockidx;
+ die "lwlocklist.h not in order" if $lockidx < $lastlockidx;
+ die "lwlocklist.h has duplicates" if $lockidx == $lastlockidx;
- die "$lockname defined in lwlocknames.txt but missing from "
+ die "$lockname defined in lwlocklist.h but missing from "
. "wait_event_names.txt"
if $i >= scalar @wait_event_lwlocks;
die "lists of predefined LWLocks do not match (first mismatch at "
. "$wait_event_lwlocks[$i] in wait_event_names.txt and $lockname in "
- . "lwlocknames.txt)"
+ . "lwlocklist.h)"
if $wait_event_lwlocks[$i] ne $lockname;
$i++;
while ($lastlockidx < $lockidx - 1)
{
++$lastlockidx;
- printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx;
$continue = ",\n";
}
- printf $c "%s \"%s\"", $continue, $trimmedlockname;
$lastlockidx = $lockidx;
$continue = ",\n";
- print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n";
+ print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
}
die
"$wait_event_lwlocks[$i] defined in wait_event_names.txt but missing from "
- . "lwlocknames.txt"
+ . "lwlocklist.h"
if $i < scalar @wait_event_lwlocks;
-printf $c "\n};\n";
print $h "\n";
printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1;
close $h;
-close $c;
rename($htmp, "$output_path/lwlocknames.h")
|| die "rename: $htmp to $output_path/lwlocknames.h: $!";
-rename($ctmp, "$output_path/lwlocknames.c") || die "rename: $ctmp: $!";
-close $lwlocknames;
+close $lwlocklist;
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 30f3a09a4c..83992725de 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -112,8 +112,8 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* There are three sorts of LWLock "tranches":
*
* 1. The individually-named locks defined in lwlocknames.h each have their
- * own tranche. The names of these tranches appear in IndividualLWLockNames[]
- * in lwlocknames.c.
+ * own tranche. We absorb the names of these tranches from there into
+ * BuiltinTrancheNames here.
*
* 2. There are some predefined tranches for built-in groups of locks.
* These are listed in enum BuiltinTrancheIds in lwlock.h, and their names
@@ -126,9 +126,10 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
* All these names are user-visible as wait event names, so choose with care
* ... and do not forget to update the documentation's list of wait events.
*/
-extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */
-
static const char *const BuiltinTrancheNames[] = {
+#define PG_LWLOCK(id, lockname) [id] = CppAsString(lockname) "Lock",
+#include "storage/lwlocklist.h"
+#undef PG_LWLOCK
[LWTRANCHE_XACT_BUFFER] = "XactBuffer",
[LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer",
[LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer",
@@ -742,11 +743,7 @@ LWLockReportWaitEnd(void)
static const char *
GetLWTrancheName(uint16 trancheId)
{
- /* Individual LWLock? */
- if (trancheId < NUM_INDIVIDUAL_LWLOCKS)
- return IndividualLWLockNames[trancheId];
-
- /* Built-in tranche? */
+ /* Built-in tranche or individual LWLock? */
if (trancheId < LWTRANCHE_FIRST_USER_DEFINED)
return BuiltinTrancheNames[trancheId];
diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt
deleted file mode 100644
index 284d168f77..0000000000
--- a/src/backend/storage/lmgr/lwlocknames.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-# Some commonly-used locks have predefined positions within MainLWLockArray;
-# these are defined here. If you add a lock, add it to the end to avoid
-# renumbering the existing locks; if you remove a lock, consider leaving a gap
-# in the numbering sequence for the benefit of DTrace and other external
-# debugging scripts. Also, do not forget to update the section
-# WaitEventLWLock of src/backend/utils/activity/wait_event_names.txt.
-
-# 0 is available; was formerly BufFreelistLock
-ShmemIndexLock 1
-OidGenLock 2
-XidGenLock 3
-ProcArrayLock 4
-SInvalReadLock 5
-SInvalWriteLock 6
-WALBufMappingLock 7
-WALWriteLock 8
-ControlFileLock 9
-# 10 was CheckpointLock
-# 11 was XactSLRULock
-# 12 was SubtransSLRULock
-MultiXactGenLock 13
-# 14 was MultiXactOffsetSLRULock
-# 15 was MultiXactMemberSLRULock
-RelCacheInitLock 16
-CheckpointerCommLock 17
-TwoPhaseStateLock 18
-TablespaceCreateLock 19
-BtreeVacuumLock 20
-AddinShmemInitLock 21
-AutovacuumLock 22
-AutovacuumScheduleLock 23
-SyncScanLock 24
-RelationMappingLock 25
-#26 was NotifySLRULock
-NotifyQueueLock 27
-SerializableXactHashLock 28
-SerializableFinishedListLock 29
-SerializablePredicateListLock 30
-# 31 was SerialSLRULock
-SyncRepLock 32
-BackgroundWorkerLock 33
-DynamicSharedMemoryControlLock 34
-AutoFileLock 35
-ReplicationSlotAllocationLock 36
-ReplicationSlotControlLock 37
-#38 was CommitTsSLRULock
-CommitTsLock 39
-ReplicationOriginLock 40
-MultiXactTruncationLock 41
-# 42 was OldSnapshotTimeMapLock
-LogicalRepWorkerLock 43
-XactTruncationLock 44
-# 45 was XactTruncationLock until removal of BackendRandomLock
-WrapLimitsVacuumLock 46
-NotifyQueueTailLock 47
-WaitEventExtensionLock 48
-WALSummarizerLock 49
-DSMRegistryLock 50
-InjectionPointLock 51
-SerialControlLock 52
diff --git a/src/backend/storage/lmgr/meson.build b/src/backend/storage/lmgr/meson.build
index da32198f78..05ac41e809 100644
--- a/src/backend/storage/lmgr/meson.build
+++ b/src/backend/storage/lmgr/meson.build
@@ -11,5 +11,3 @@ backend_sources += files(
's_lock.c',
'spin.c',
)
-
-generated_backend_sources += lwlocknames[1]
diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt
index c08e00d1d6..b0ab833602 100644
--- a/src/backend/utils/activity/wait_event_names.txt
+++ b/src/backend/utils/activity/wait_event_names.txt
@@ -280,9 +280,9 @@ Extension "Waiting in an extension."
# This class of wait events has its own set of C structure, so these are
# only used for the documentation.
#
-# NB: Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be
+# NB: Predefined LWLocks (i.e., those declared in lwlocknames.h) must be
# listed in the top section of locks and must be listed in the same order as in
-# lwlocknames.txt.
+# lwlocknames.h.
#
Section: ClassName - WaitEventLWLock
@@ -333,9 +333,9 @@ SerialControl "Waiting to read or update shared <filename>pg_serial</filename> s
#
# END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE)
#
-# Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be listed
+# Predefined LWLocks (i.e., those declared in lwlocknames.h) must be listed
# in the section above and must be listed in the same order as in
-# lwlocknames.txt. Other LWLocks must be listed in the section below.
+# lwlocknames.h. Other LWLocks must be listed in the section below.
#
XactBuffer "Waiting for I/O on a transaction status SLRU buffer."
diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h
index 10bea8c595..3479b4cf52 100644
--- a/src/include/storage/lwlock.h
+++ b/src/include/storage/lwlock.h
@@ -19,6 +19,7 @@
#endif
#include "port/atomics.h"
+#include "storage/lwlocknames.h"
#include "storage/proclist_types.h"
struct PGPROC;
@@ -82,9 +83,6 @@ typedef struct NamedLWLockTranche
extern PGDLLIMPORT NamedLWLockTranche *NamedLWLockTrancheArray;
extern PGDLLIMPORT int NamedLWLockTrancheRequests;
-/* Names for fixed lwlocks */
-#include "storage/lwlocknames.h"
-
/*
* It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
* here, but we need them to figure out offsets within MainLWLockArray, and
diff --git a/src/include/storage/lwlocklist.h b/src/include/storage/lwlocklist.h
new file mode 100644
index 0000000000..85f6568b9e
--- /dev/null
+++ b/src/include/storage/lwlocklist.h
@@ -0,0 +1,85 @@
+/*-------------------------------------------------------------------------
+ *
+ * lwlocklist.h
+ *
+ * The predefined LWLock list is kept in its own source file for use by
+ * automatic tools. The exact representation of a keyword is determined by
+ * the PG_LWLOCK macro, which is not defined in this file; it can be
+ * defined by the caller for special purposes.
+ *
+ * Also, generate-lwlocknames.pl processes this file to create lwlocknames.h.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * IDENTIFICATION
+ * src/include/storage/lwlocklist.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*
+ * Some commonly-used locks have predefined positions within MainLWLockArray;
+ * these are defined here. If you add a lock, add it to the end to avoid
+ * renumbering the existing locks; if you remove a lock, consider leaving a gap
+ * in the numbering sequence for the benefit of DTrace and other external
+ * debugging scripts. Also, do not forget to update the section
+ * WaitEventLWLock of src/backend/utils/activity/wait_event_names.txt.
+ *
+ * Note that the names here don't include the Lock suffix, to appease the
+ * C preprocessor; it's added elsewhere.
+ */
+
+/* 0 is available; was formerly BufFreelistLock */
+PG_LWLOCK(1, ShmemIndex)
+PG_LWLOCK(2, OidGen)
+PG_LWLOCK(3, XidGen)
+PG_LWLOCK(4, ProcArray)
+PG_LWLOCK(5, SInvalRead)
+PG_LWLOCK(6, SInvalWrite)
+PG_LWLOCK(7, WALBufMapping)
+PG_LWLOCK(8, WALWrite)
+PG_LWLOCK(9, ControlFile)
+/* 10 was CheckpointLock */
+/* 11 was XactSLRULock */
+/* 12 was SubtransSLRULock */
+PG_LWLOCK(13, MultiXactGen)
+/* 14 was MultiXactOffsetSLRULock */
+/* 15 was MultiXactMemberSLRULock */
+PG_LWLOCK(16, RelCacheInit)
+PG_LWLOCK(17, CheckpointerComm)
+PG_LWLOCK(18, TwoPhaseState)
+PG_LWLOCK(19, TablespaceCreate)
+PG_LWLOCK(20, BtreeVacuum)
+PG_LWLOCK(21, AddinShmemInit)
+PG_LWLOCK(22, Autovacuum)
+PG_LWLOCK(23, AutovacuumSchedule)
+PG_LWLOCK(24, SyncScan)
+PG_LWLOCK(25, RelationMapping)
+/* 26 was NotifySLRULock */
+PG_LWLOCK(27, NotifyQueue)
+PG_LWLOCK(28, SerializableXactHash)
+PG_LWLOCK(29, SerializableFinishedList)
+PG_LWLOCK(30, SerializablePredicateList)
+/* 31 was SerialSLRULock */
+PG_LWLOCK(32, SyncRep)
+PG_LWLOCK(33, BackgroundWorker)
+PG_LWLOCK(34, DynamicSharedMemoryControl)
+PG_LWLOCK(35, AutoFile)
+PG_LWLOCK(36, ReplicationSlotAllocation)
+PG_LWLOCK(37, ReplicationSlotControl)
+/* 38 was CommitTsSLRULock */
+PG_LWLOCK(39, CommitTs)
+PG_LWLOCK(40, ReplicationOrigin)
+PG_LWLOCK(41, MultiXactTruncation)
+/* 42 was OldSnapshotTimeMapLock */
+PG_LWLOCK(43, LogicalRepWorker)
+PG_LWLOCK(44, XactTruncation)
+/* 45 was XactTruncationLock until removal of BackendRandomLock */
+PG_LWLOCK(46, WrapLimitsVacuum)
+PG_LWLOCK(47, NotifyQueueTail)
+PG_LWLOCK(48, WaitEventExtension)
+PG_LWLOCK(49, WALSummarizer)
+PG_LWLOCK(50, DSMRegistry)
+PG_LWLOCK(51, InjectionPoint)
+PG_LWLOCK(52, SerialControl)
diff --git a/src/include/storage/meson.build b/src/include/storage/meson.build
index 666fb22408..f889093117 100644
--- a/src/include/storage/meson.build
+++ b/src/include/storage/meson.build
@@ -1,10 +1,10 @@
# Copyright (c) 2022-2024, PostgreSQL Global Development Group
-lwlocknames = custom_target('lwlocknames',
+lwlocknames_h = custom_target('lwlocknames_h',
input: files(
- '../../backend/storage/lmgr/lwlocknames.txt',
+ '../../include/storage/lwlocklist.h',
'../../backend/utils/activity/wait_event_names.txt'),
- output: ['lwlocknames.h', 'lwlocknames.c'],
+ output: ['lwlocknames.h'],
command: [
perl, files('../../backend/storage/lmgr/generate-lwlocknames.pl'),
'-o', '@OUTDIR@',
@@ -12,12 +12,10 @@ lwlocknames = custom_target('lwlocknames',
],
build_by_default: true,
install: true,
- install_dir: [dir_include_server / 'storage', false],
+ install_dir: dir_include_server / 'storage',
)
-lwlocknames_h = lwlocknames[0]
-
generated_backend_headers += lwlocknames_h
# autoconf generates the file there, ensure we get a conflict
-generated_sources_ac += {'src/backend/storage/lmgr': ['lwlocknames.c', 'lwlocknames.h']}
+generated_sources_ac += {'src/backend/storage/lmgr': ['lwlocknames.h']}
diff --git a/src/tools/pginclude/headerscheck b/src/tools/pginclude/headerscheck
index 5c12ab99b8..13b9735f84 100755
--- a/src/tools/pginclude/headerscheck
+++ b/src/tools/pginclude/headerscheck
@@ -133,6 +133,7 @@ do
test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
test "$f" = src/include/regex/regerrs.h && continue
+ test "$f" = src/include/storage/lwlocklist.h && continue
test "$f" = src/include/tcop/cmdtaglist.h && continue
test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue
test "$f" = src/pl/plpython/spiexceptions.h && continue
--
2.39.2