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 1rMxhP-0081iP-Em for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 22:02:24 +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 1rMxhN-007sJo-JW for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 22:02:21 +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 1rMxhN-007sJf-3A for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2024 22:02:21 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMxhI-000Y05-3z for pgsql-hackers@postgresql.org; Mon, 08 Jan 2024 22:02:19 +0000 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7b7f2c72846so101713839f.2 for ; Mon, 08 Jan 2024 14:02:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704751335; x=1705356135; 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=efjmebNWBh3z2VKcQczioQCSSruRi+2a1TFRTjTRk1A=; b=IHdT+riXlaJInOJDOKjxMNraHe+OsR4N/UiNjNY4iVMPv4v8D34UduqWECppvLW+Iq nd5OgLEWuxAomPhFK68SWig7rWx2FMS0skSH6qPyQabBg2jT+1uoVuoxC6TUjjAHJnnL kocGSrQZMhhoJBkavT7rpy+nSg3GwETdxF6v7F9BLQxqgT06E7KMaWOJ/1ZzuMm24IQL 0FDEIFJoYBuM5bltGkd7f4+uxg3vR6Mf2YeYJXfPd3NoFbv7oFi6MxrGyDjtjAaLmzYr KQ7N8GEC/F9NAfzLVXaIwRWcPP6r5RPoCOczf7g0a1q3P4x21HlUc67pXMoTtUN/+UDR Zf1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704751335; x=1705356135; 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=efjmebNWBh3z2VKcQczioQCSSruRi+2a1TFRTjTRk1A=; b=I5g593g68+cY3cFXp3A2MTT4XOP7n9L2+15v7xXWR0oVLnVcprhVEhtPk/HB2+cVZ4 7IPXdRgEkpf9WNS4YCwHvPKWmfdrAbQmuLYEYWdY80yNvdFwyG7D9+kIlByKON9YQXyo JgjaS3JZQyL3IktdFsFhYlJPeGfWJ0+GAfU48NqrdPbvzGKhR6VuN12hvFnHu+QWSjL6 sOqHLrZl/vf9vVkbfWtcEMU3kZqwmDFCQEkQWKJz+MvYCW5CQrW9nWDSHpv7v6iwMl9H xvk9AOEYbH3Z+2+lxk9MENH+9DNX6GlmWZ2bw8Yn6aYAlWE4BXHLKoaGk7bRgM6VaEmq qUAA== X-Gm-Message-State: AOJu0YwssFehyIHXWTsyiqIk0UiK7Rmd7fwm1XdrieJGVw9NK1J+SgMK uDqgE1EtOpbcJPnP+DIOOWGwkeCaE7Q= X-Google-Smtp-Source: AGHT+IF2zKfp3Mp4jibPNdkXXDB0zMGXOK/gDDNevWe6r8msRGcCzV1jvNOEUKUAJtM2jp4lgzNg4g== X-Received: by 2002:a6b:ea0a:0:b0:7ba:9c13:2873 with SMTP id m10-20020a6bea0a000000b007ba9c132873mr4256168ioc.36.1704751335307; Mon, 08 Jan 2024 14:02:15 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id cp26-20020a056638481a00b0046df4943a5csm220810jab.148.2024.01.08.14.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 14:02:14 -0800 (PST) Date: Mon, 8 Jan 2024 16:02:12 -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: <20240108220212.GA2914881@nathanxps13> References: <20240105061144.GA2166447@nathanxps13> <20240105164203.GC2168314@nathanxps13> <20240105174620.GA2285561@nathanxps13> <20240106161852.GA2435448@nathanxps13> <20240108201130.GA2747735@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline In-Reply-To: <20240108201130.GA2747735@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sorry for the noise. I spent some more time tidying this up for commit, which I am hoping to do in the next day or two. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --3V7upXqbjpZ4EhLz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v6-0001-Cross-check-lists-of-predefined-LWLocks.patch" From 4e222c1a1fc1a2476746cb7b68c1d2a203816699 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 8 Jan 2024 15:44:44 -0600 Subject: [PATCH v6 1/1] Cross-check lists of predefined LWLocks. Both lwlocknames.txt and wait_event_names.txt contain a list of all the predefined LWLocks, i.e., those with predefined positions within MainLWLockArray. It is easy to miss one or the other, especially since the list in wait_event_names.txt omits the "Lock" suffix for all the LWLock wait events. This commit adds a cross- check of these lists to the script that generates lwlocknames.h. If the lists do not match exactly, building will fail. Suggested-by: Robert Haas Reviewed-by: Robert Haas, Michael Paquier, Bertrand Drouvot Discussion: https://postgr.es/m/20240102173120.GA1061678%40nathanxps13 --- src/backend/Makefile | 2 +- src/backend/storage/lmgr/Makefile | 4 +- .../storage/lmgr/generate-lwlocknames.pl | 49 +++++++++++++++++++ .../utils/activity/wait_event_names.txt | 12 +++++ src/include/storage/meson.build | 4 +- 5 files changed, 67 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..06401dbf01 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,40 @@ 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 - WaitEventLWLock$/) + { + $record_lwlocks = 1; + 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 +85,15 @@ 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" + 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)" + if $wait_event_lwlocks[$i] ne $lockname; + $i++; + while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; @@ -63,6 +107,11 @@ 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" + if scalar @wait_event_lwlocks ne $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..ad6bf0de84 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 (i.e., 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 (i.e., 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..666fb22408 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 --3V7upXqbjpZ4EhLz--