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 1rLdQw-00991G-FP for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 06:11:54 +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 1rLdQu-000nYY-Pv for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 06:11:52 +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 1rLdQu-000nYQ-F1 for pgsql-hackers@lists.postgresql.org; Fri, 05 Jan 2024 06:11:52 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rLdQr-00Fd12-E8 for pgsql-hackers@postgresql.org; Fri, 05 Jan 2024 06:11:51 +0000 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7bbe90357d8so57107139f.2 for ; Thu, 04 Jan 2024 22:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704435107; x=1705039907; 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=j+CK3o/7jnUV9xvBCVeTJehV7BnbfDuw7zByNMPAnl4=; b=CxFQtvDIbIyzgrusYl/2r8FExGaGVjaUlIWgOrRH2PhqjgOgTWdeNLVyHT8VJHytqN kdGQzDQpT2wNq/LggxL2I3O+7mUtNNXCgSeAErVV0HnVo+91dm3HymF7+gJFfRC0COAY qE/083SrjHPEDFmPSQ/Y4OZo9BF77V+d+qRouasm+cjrdXav0pr5sWqcxgkiUj6jCOW/ Fcc/JwLMpqYQ2fL6d7DbvIxSeQHBOKHq6wyfF9Nc6wGbnnioDaP6hZp70avSfP5sR9pr NgvexGP2W4fVj71tb2iPp7eCQ8I466DfV3GKsoBImFeTvM8gilhTo3Yn2g7p/cDLB8cc 4D0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704435107; x=1705039907; 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=j+CK3o/7jnUV9xvBCVeTJehV7BnbfDuw7zByNMPAnl4=; b=YrDmEfgUICGq2QB5miE7rW2u9YB0Gw1ocVNdomGvRMGCPY74++ATSZBQDLX27ALY+D 7/aivNMOut8hCmry+10AVH86sUGbU3QPcEJIvYmzMGfAQsPaIqEpM/NKxT71/kzgLmOH rmGAPkKGTteRAFsqfCai2zeM05ScljmGEGDo68oIUGkhQO1rSuzDLdKl2FQsU84TvYyj fXCyVcVYUsmDWEvFWzDIEwRQuEJPGOvrTKCUm6kX453tl7wMqWP84DpbYM7F99+ta9w2 srVda4zuO6VvjXIy55Uhd/wRfGOl6/Sl6fd+30h/trUPMLQdtlu75G5aJdWhU+L3GuBH Krow== X-Gm-Message-State: AOJu0YzJwOZ0U+59w1Gj3phNjrIURJaEvlfd/s8Q0NeKBPbFV6eqerj2 HB4kTO1yhCGhwEAK70aQ6F+YuXsGKMI= X-Google-Smtp-Source: AGHT+IH+80abFwD+JxHHNkHTctmNfz3rmYEhuCbZdBpe2y9GEtTV+9mMbk+yR6nSPKzqDvTC2ASuig== X-Received: by 2002:a6b:fb18:0:b0:7bb:c573:cc40 with SMTP id h24-20020a6bfb18000000b007bbc573cc40mr1844481iog.33.1704435106785; Thu, 04 Jan 2024 22:11:46 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id b11-20020a5d894b000000b007baabfc9a3dsm240276iot.54.2024.01.04.22.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 22:11:46 -0800 (PST) Date: Fri, 5 Jan 2024 00:11:44 -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: <20240105061144.GA2166447@nathanxps13> References: <20240102173120.GA1061678@nathanxps13> <20240102214544.GA1063425@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="envbJBWh7q8WU6mo" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jan 03, 2024 at 07:59:45AM +0000, Bertrand Drouvot wrote: > +1 to add a test and put in a place that would produce failures at build time. > I think that having the test in the script that generates the header file is more > appropriate (as building the documentation looks less usual to me when working on > a patch). Okay, I did that in v2. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --envbJBWh7q8WU6mo Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-verify-lists-of-predefined-LWLocks-in-lwlocknames.patch" From 587f6a2c108fc7496fcb3d5764ca06ac5fb21326 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 5 Jan 2024 00:07:40 -0600 Subject: [PATCH v2 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 | 63 +++++++++++++++++++ .../utils/activity/wait_event_names.txt | 10 +++ src/include/storage/meson.build | 2 +- 5 files changed, 77 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..9afee7984b 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,59 @@ 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 $found_lwlock_section = 0; +my $recording_lwlocks = 0; + +while (<$wait_event_names>) +{ + chomp; + + # Skip comments + next if /^#/; + + # Skip empty lines + if (/^\s*$/) + { + # + # If we encounter an empty line while recording the LWLocks listed in + # wait_event_names.txt, we are done. + # + last if $recording_lwlocks; + + # + # Begin recording the LWLocks listed in wait_event_names.txt following + # the empty line after the WaitEventLWLock section declaration. + # + $recording_lwlocks = 1 if $found_lwlock_section; + next; + } + + # + # Prepare to record the LWLocks when we find the WaitEventLWLock section + # declaration. + # + if (/^Section: ClassName(.*)/) + { + my $section_name = $_; + $section_name =~ s/^.*- //; + $found_lwlock_section = 1 if $section_name eq "WaitEventLWLock"; + next; + } + + # Go to the next line if we are not yet recording LWLocks. + next if not $recording_lwlocks; + + # Record the LWLock. + (my $waiteventname, my $waitevendocsentence) = split(/\t/, $_); + push(@wait_event_lwlocks, $waiteventname . "Lock"); +} + +my $i = 0; while (<$lwlocknames>) { chomp; @@ -50,6 +104,12 @@ 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 in lwlocknames.txt and wait_event_names.txt do not match" + unless $wait_event_lwlocks[$i] eq $lockname; + $i++; + while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; @@ -63,6 +123,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..fed50079fd 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,12 @@ 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." +# +# 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..8df8b404f5 100644 --- a/src/include/storage/meson.build +++ b/src/include/storage/meson.build @@ -1,7 +1,7 @@ # 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'), files('../../backend/utils/activity/wait_event_names.txt')], output: ['lwlocknames.h', 'lwlocknames.c'], command: [ perl, files('../../backend/storage/lmgr/generate-lwlocknames.pl'), -- 2.25.1 --envbJBWh7q8WU6mo--