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 1rM9O6-0034UB-LP for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Jan 2024 16:19:07 +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 1rM9O4-00AAVb-2T for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Jan 2024 16:19:04 +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 1rM9O3-00AAVT-NX for pgsql-hackers@lists.postgresql.org; Sat, 06 Jan 2024 16:19:03 +0000 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rM9O0-000Awq-U3 for pgsql-hackers@postgresql.org; Sat, 06 Jan 2024 16:19:03 +0000 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7b7f2c72846so29917839f.2 for ; Sat, 06 Jan 2024 08:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704557939; x=1705162739; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RoyG8C9v6F0JNGXZKiRAP2pww/7vLefVVVraxFRqdNg=; b=Q8CuflZzsYKCt+HMtsnWNlxlKUQ14A+64leuC/V73icFnF6nepHPdqf5EUExfTzOdw kt10bw9opHiX8HIwudB9lKvn2+zR/9AjBzqfNPqGBH3kUg6KWvT2yNKYQyBlvU2uDCuI oZHcLeMGqX7PWS35uk/1rtp7QXVkDGeu1wFOqGwnMRihWK/rI3i+3QtbuuwReATtMpSB O9zeH2ovbIh908YEK7QYunRk+XsURR85acXOtrDDqnkDpKYKfUjT3GqX9DuBt70Bh6Cb SNFaI6FFe3Nqi+kiySnsc9DUH6ly3kFX/micivH+f18rkLgv39tGfEXMIoHh2RqK1MHU xqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704557939; x=1705162739; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RoyG8C9v6F0JNGXZKiRAP2pww/7vLefVVVraxFRqdNg=; b=AL3X3JjHbYcj0s6Y1asoEZGjQF+0Nc76KldlBoNK5xetZSTuJiMq7/TpF5zpFziboZ 1kQeBoqbPY3/9A+o1Q6hVn4105JgcBN+6LSRVRaB0f3C6N44VbvL/qeSEeOtIj2E/F0V 3OFQ1QymllE3sbjLHoElpWkPyAcaL4EDK6sCSmQhdG1Gx6cEhk5M9RqfNnXXKKoj7VjV oDvdRPsjJmgLQ9EGB2vyb9+nvGE44LyDgWFSw7doXF1BLgB/GRbthE4U0wx0Ea3GjG3Z 8ClDkrZCfkTamh26MbargJ6JfqsEIc/4UpZ/Z7UsPZT4zveINMkbacnQzFvIqpELog3W sAqQ== X-Gm-Message-State: AOJu0Yx33rEbog16tslaesmXbZNRPIo+Ks/1nZUjjpy9j0/VBSWj8VD4 9ElPwD4ICIxYbNcVHIal9A0= X-Google-Smtp-Source: AGHT+IFrH+hCEFCB0NSppOKacPvdGIO9hSigtStVN4veRkBLVRDVRhRoFbDoNfil7hdlVCZI57rkQA== X-Received: by 2002:a05:6e02:12c5:b0:35f:b148:c24c with SMTP id i5-20020a056e0212c500b0035fb148c24cmr1728835ilm.1.1704557938885; Sat, 06 Jan 2024 08:18:58 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ck19-20020a056e02371300b0035fec699584sm1373790ilb.13.2024.01.06.08.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 08:18:58 -0800 (PST) Date: Sat, 6 Jan 2024 10:18:52 -0600 From: Nathan Bossart To: Bertrand Drouvot Cc: Robert Haas , "pgsql-hackers@postgresql.org" , Michael Paquier Subject: Re: verify predefined LWLocks have entries in wait_event_names.txt Message-ID: <20240106161852.GA2435448@nathanxps13> References: <20240102173120.GA1061678@nathanxps13> <20240102214544.GA1063425@nathanxps13> <20240105061144.GA2166447@nathanxps13> <20240105164203.GC2168314@nathanxps13> <20240105174620.GA2285561@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Jan 06, 2024 at 09:03:52AM +0000, Bertrand Drouvot wrote: > Sorry, I missed this in my first review, but instead of: > > - input: files('../../backend/storage/lmgr/lwlocknames.txt'), > + input: [files('../../backend/storage/lmgr/lwlocknames.txt'), files('../../backend/utils/activity/wait_event_names.txt')], > > what about? > > input: files( > '../../backend/storage/lmgr/lwlocknames.txt', > '../../backend/utils/activity/wait_event_names.txt', > ), > > It's done that way in doc/src/sgml/meson.build for example. I fixed this in v4. > Except for the above, the patch looks good to me. Thanks for reviewing! -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --IS0zKkzwUGydFO0o Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-verify-lists-of-predefined-LWLocks-in-lwlocknames.patch" From 35a744e0114c38e3ffb48e446360b252bb7b17b4 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 5 Jan 2024 00:07:40 -0600 Subject: [PATCH v4 1/1] verify lists of predefined LWLocks in lwlocknames.txt and wait_event_names.txt match --- src/backend/Makefile | 2 +- src/backend/storage/lmgr/Makefile | 4 +- .../storage/lmgr/generate-lwlocknames.pl | 48 +++++++++++++++++++ .../utils/activity/wait_event_names.txt | 12 +++++ src/include/storage/meson.build | 4 +- 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 816461aa17..7d2ea7d54a 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -130,7 +130,7 @@ $(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 +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 utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile index c48ba943c4..504480e847 100644 --- a/src/backend/storage/lmgr/Makefile +++ b/src/backend/storage/lmgr/Makefile @@ -39,8 +39,8 @@ s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/s lwlocknames.c: lwlocknames.h touch $@ -lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt generate-lwlocknames.pl - $(PERL) $(srcdir)/generate-lwlocknames.pl $< +lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt generate-lwlocknames.pl + $(PERL) $(srcdir)/generate-lwlocknames.pl $^ check: s_lock_test ./s_lock_test diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index bef5e16e11..237c3b9678 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -15,6 +15,7 @@ my $continue = "\n"; GetOptions('outdir:s' => \$output_path); open my $lwlocknames, '<', $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$$"; @@ -30,6 +31,42 @@ 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. +# +my @wait_event_lwlocks; +my $record_lwlocks = 0; + +while (<$wait_event_names>) +{ + chomp; + + # Check for end marker. + last if /^# END OF PREDEFINED LWLOCKS/; + + # Skip comments and empty lines. + next if /^#/; + next if /^\s*$/; + + # Start recording LWLocks when we find the WaitEventLWLock section. + if (/^Section: ClassName(.*)/) + { + my $section_name = $_; + $section_name =~ s/^.*- //; + $record_lwlocks = 1 if $section_name eq "WaitEventLWLock"; + next; + } + + # Go to the next line if we are not yet recording LWLocks. + next if not $record_lwlocks; + + # Record the LWLock. + (my $waiteventname, my $waitevendocsentence) = split(/\t/, $_); + push(@wait_event_lwlocks, $waiteventname . "Lock"); +} + +my $i = 0; while (<$lwlocknames>) { chomp; @@ -50,6 +87,14 @@ while (<$lwlocknames>) die "lwlocknames.txt not in order" if $lockidx < $lastlockidx; die "lwlocknames.txt has duplicates" if $lockidx == $lastlockidx; + die $lockname . " defined in lwlocknames.txt but missing from wait_event_names.txt" + unless $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)" + unless $wait_event_lwlocks[$i] eq $lockname; + $i++; + while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; @@ -63,6 +108,9 @@ while (<$lwlocknames>) print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n"; } +die $wait_event_lwlocks[$i] . " defined in wait_event_names.txt but missing from lwlocknames.txt" + unless scalar(@wait_event_lwlocks) eq $i; + printf $c "\n};\n"; print $h "\n"; printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1; diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt index 088eb977d4..4d70e84103 100644 --- a/src/backend/utils/activity/wait_event_names.txt +++ b/src/backend/utils/activity/wait_event_names.txt @@ -276,6 +276,10 @@ 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 locks (those declared in lwlocknames.txt) must be listed in +# the top section of locks and must be listed in the same order as in +# lwlocknames.txt. +# Section: ClassName - WaitEventLWLock @@ -326,6 +330,14 @@ NotifyQueueTail "Waiting to update limit on NOTIFY message st WaitEventExtension "Waiting to read or update custom wait events information for extensions." WALSummarizer "Waiting to read or update WAL summarization state." +# +# END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE) +# +# Predefined LWLocks (those declared in lwlocknames.txt) 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. +# + XactBuffer "Waiting for I/O on a transaction status SLRU buffer." CommitTsBuffer "Waiting for I/O on a commit timestamp SLRU buffer." SubtransBuffer "Waiting for I/O on a sub-transaction SLRU buffer." diff --git a/src/include/storage/meson.build b/src/include/storage/meson.build index 2a88248464..7f1ce38566 100644 --- a/src/include/storage/meson.build +++ b/src/include/storage/meson.build @@ -1,7 +1,9 @@ # Copyright (c) 2022-2024, PostgreSQL Global Development Group lwlocknames = custom_target('lwlocknames', - input: files('../../backend/storage/lmgr/lwlocknames.txt'), + input: [files( + '../../backend/storage/lmgr/lwlocknames.txt', + '../../backend/utils/activity/wait_event_names.txt')], output: ['lwlocknames.h', 'lwlocknames.c'], command: [ perl, files('../../backend/storage/lmgr/generate-lwlocknames.pl'), -- 2.25.1 --IS0zKkzwUGydFO0o--