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 1rSdx1-00EzaK-O4 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 14:10:00 +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 1rSdx0-005CTi-Le for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jan 2024 14:09:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSdwy-005CTZ-QD for pgsql-hackers@lists.postgresql.org; Wed, 24 Jan 2024 14:09:58 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSdwv-0038ZI-QH for pgsql-hackers@lists.postgresql.org; Wed, 24 Jan 2024 14:09:55 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id EBF635C0090; Wed, 24 Jan 2024 09:09:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 24 Jan 2024 09:09:51 -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=1706105391; x= 1706191791; bh=adls+cowJwDnnl4zJyMsf7nO57KIy4dvOGETrd1anow=; b=l 9n0R9egv+J8nMHNc2ZAOnr4atvQhCSYMOz1YWqguXJzTg5zdRlYsJcs3pTiEkxMM fzhal1QMQlSnwdswiCOXOo1KGnzPHgjNNS0WQOcrbMhp7TAUK879LoY2j6MzlRL/ RlHevClUnHEpLdl22rem6werXjv+F4nPprrSTgqxzzVNUejg5ej0o9BzSZ9LdpdX vuMmn7/NYTNJCmdct/J6UxLosw/1fGN9ijHcwmhuiTV7gqfFQyrKV4m+HF/Tkuky tmK+h9AuaVFBMhMZPFzdIlYSA6PmiG+DyoBISSgGw80HNlYQ+VmCE8Co7o4C1PSh aOj64KGTOzDv1rdOZDT3g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeluddgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepveehveeuvdekkedvtddvhfdtjeejgeeujeeifeehhfej jefhteetfedvgfdtjefhnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh dpthifihhtthgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 24 Jan 2024 09:09:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1706105389; bh=LsvqG8NfaLOdPPAnI5m3N8JSHGcsIDmWjxB6QJE5pKM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=L9iag2hn/D6AghCbBWuLBUFXSUt4o6fnBMCoXMJ5M8pGCoLuiSCy+Bs4soq87HSEC swN5gpxJVkpssOknxhoBN/pdGapBL0u10AGTH690z1uZMfQQ8qVbiOYFUziXsCLgVD AF6H4Ef1pa39aMu+xl5tVsI/EYx+v26R+krsRSmt6ck8orhL/CkeZgSOowboToL3Qv 1Hs6esNpkmB1Kp332fqjB7sq0IUTbfB47lb4WQmVkiZ2aQPwMzVT8Oy2wkJWaSIz8r ypgkzr4BVEX3JxjAxADEF5Ih1oHOiHWyOjPu/JhZz+VHFtrUSxWwhLk+5fCLwa5Zij Bah+sPqT/0mEw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id DFDA698; Wed, 24 Jan 2024 15:09:49 +0100 (CET) Date: Wed, 24 Jan 2024 15:09:49 +0100 From: Alvaro Herrera To: Heikki Linnakangas Cc: Pg Hackers Subject: Re: make BuiltinTrancheNames less ugly Message-ID: <202401241409.hbphjzkly6b2@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="uhuzi24vtrru3fse" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202401231442.aldy4ap76psg@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --uhuzi24vtrru3fse Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 --uhuzi24vtrru3fse Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Remove-IndividualLWLockNames.patch" From 3d24b89855888a6650ec1aafb3579d810bfec5ac Mon Sep 17 00:00:00 2001 From: Alvaro Herrera 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 \"\"", $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 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 --uhuzi24vtrru3fse--