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.94.2) (envelope-from ) id 1rSGSz-00CVrj-Lz for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 13:05:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSGSx-00CrDJ-Qh for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 13:05:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSGSw-00CrDB-Cz for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 13:05:23 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSGSr-003Imi-JY for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 13:05:21 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6744A5C0153; Tue, 23 Jan 2024 08:05:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 23 Jan 2024 08:05:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1706015115; x= 1706101515; bh=lFGIfiLPsowQikEPLoQt2DEg0tYis/rnK2Y6KBAZmDg=; b=s z7C2WmyuHON9kJfY1AdLfCExV56seJ/TBnFMqAXKjrxnyTUgA0hqqivhLb1pCvGq T5dlu4lOF/Ra5ITGyKmBG3Jjxzh3e1YkRmvc9UWoWst2vAbCoLiC/TTX0Lzs2D7S JIy1DaU0sOkadEhyyqPiWWJRe4WFbhM53wU0UOOc9V02xDQGTv677jDmOCztexNV ga/6Yj/45WyIL3wKNnFvVNy9PzNrwlRsu1NefARFv0fhEUNHPFC3ONsbaWEXeBIW blc+EPsMC/FadXyKib4muVSk7beNoMfvmK2wk8z6KvBAM0QcHr28g9DWPMSb/rXC 8juXtO/hdtjSy6vlbeF8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekkedggeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudelkeekgfdttdettdekgfduvdeiffelteegjeeihfet heekveeftedtuddvhfeunecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 23 Jan 2024 08:05:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1706015113; bh=L8Xo+1ugpWkHvBe4ZJtuWqz3Vz8XOoSgtH+s+pLPe7s=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=OehHwXXSuMn1nAHRhm5JCpx7ZYYjD4etwc2OC8USO43IYwHK/2bLcm4Z9dA4hweei tb5gu2Bs9lAFj+QUUYqWtcSqUYq1NAdM2zzie8OQ1OvvSoHYk8fkdH7I9SKiBdSPch ufpf94XWe0olAGxtvHb9gi/Ovmy0jz6LEFeap7i9lQEWUDAgkZ1iaum9XpDX0lLRYm AnDxtsQFsgE0N8xLRR4OcMZphnTayRlrod0o6RD2jtuzbrAXafozOeZ1ijRdWKRESX GGKscqBeLnwnvoD3qjTbid6K1dfOsohYQrjInDQ6XK8P4N8IThEbYcgCT6kFRonhM2 5kgBJgvG1E4IQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 41A2498; Tue, 23 Jan 2024 14:05:13 +0100 (CET) Date: Tue, 23 Jan 2024 14:05:13 +0100 From: Alvaro Herrera To: Heikki Linnakangas Cc: Pg Hackers Subject: Re: make BuiltinTrancheNames less ugly Message-ID: <202401231305.57j4lgvlxgi3@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="divjqopgmirc6hbh" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202401231147.clytrnaysp43@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --divjqopgmirc6hbh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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) --divjqopgmirc6hbh Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v2-0001-Use-designated-initializers-for-BuiltinTrancheNam.patch" From 2f5185cdd37e3502520d85e5f6f565b58330e702 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera 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 \"\"", $continue, $lastlockidx; - $continue = ",\n"; + printf $c "[%s] = \"\",\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 --divjqopgmirc6hbh--