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 1rMvyE-007o21-0o for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 20:11:38 +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 1rMvyD-007Pjh-7e for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jan 2024 20:11:37 +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 1rMvyC-007PjZ-Px for pgsql-hackers@lists.postgresql.org; Mon, 08 Jan 2024 20:11:36 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMvy9-000XIX-US for pgsql-hackers@postgresql.org; Mon, 08 Jan 2024 20:11:35 +0000 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7bb982d0f12so84698839f.0 for ; Mon, 08 Jan 2024 12:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704744693; x=1705349493; 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=/sJdU6ixCRPQAULsNqlm4Rkz2zNopwWHvDmQc3fWguM=; b=jjmKATT6HJKxTPY4CltO5OCuzBEj40QL9pKZcesat72+guRmVWIqF5U1c5AQUaSejT LRgiVTyyahCXTl8sWdg96OMZQ2vsY3nTw7Ng/wd8HankYF4VHjRKnu8OFZZnB2vJ5NA7 f2qH6uN2e9i94woUVE2TQWgXgBm8P+fw9WT4dk9oRi4lDsWOe+lpWXQxCcEpARuMbhDX ByZNcBE6MllyKRVg/7SqqVomaXA1Xg3FegRYrtqSPZPbFkmG12RH/4yJHAxGbiaXSeMg +etgmlvkTnapjm7P1j7irRkBMnw0ICBCNCjj4UkdEMqZc+E2Xz2dz3vs7txyt+vLKTr0 HPlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704744693; x=1705349493; 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=/sJdU6ixCRPQAULsNqlm4Rkz2zNopwWHvDmQc3fWguM=; b=jC9xHCd8VD2blqugsF3ftjmNkC9R9r8EtDZxi+ZRaphA3rxSglBtAv6NBmeKyBwg9r zhN0tmRQRTyDC6O2ON4e+k9ePeQHZx436W2yuPy9I+HFbBxsQN8AwdVe03KAgwmuwK3z 0lRe3lPx/rasQXzRW0le4kLd0ZAeCk+2RehzyZGb7XT1/0QJbeBd/GlqlOctJ7/QOw/r oPSUvyvsy3uRy9SRnwZBJ0l60gUfG1VwuFmZ9MrOdVso2kCOgZpW5IZ31csnA1H2m/wf N5ew7Z2Yoy3xtUB/tw8hz9URkc+VUCHdv3Z6nA10qfsHqB/1HYE6acut0S61A5UXJhO0 kZkQ== X-Gm-Message-State: AOJu0YzLsn9OzB4r3ZfGdV6rIRtQoO8PaNIAXiw5ij5UyJ4N5nPaIfeh 7wiX1ViC8SNVKosFFgo7MDE= X-Google-Smtp-Source: AGHT+IE3qAh2gyZUX2T6/15cgn8dP7YZ19lAgEHVox5hTPImWk/n5rvKEuVQEXtOgflMP6zqaYn3cQ== X-Received: by 2002:a05:6e02:1d13:b0:35f:b666:bc5a with SMTP id i19-20020a056e021d1300b0035fb666bc5amr268649ila.7.1704744693010; Mon, 08 Jan 2024 12:11:33 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id j13-20020a056e02220d00b003606da052dcsm150967ilf.4.2024.01.08.12.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:11:32 -0800 (PST) Date: Mon, 8 Jan 2024 14:11:30 -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: <20240108201130.GA2747735@nathanxps13> References: <20240102214544.GA1063425@nathanxps13> <20240105061144.GA2166447@nathanxps13> <20240105164203.GC2168314@nathanxps13> <20240105174620.GA2285561@nathanxps13> <20240106161852.GA2435448@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 Mon, Jan 08, 2024 at 07:59:10AM +0000, Bertrand Drouvot wrote: > + input: [files( > + '../../backend/storage/lmgr/lwlocknames.txt', > + '../../backend/utils/activity/wait_event_names.txt')], > > I think the "[" and "]" are not needed here. D'oh! Fixed in v5. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --envbJBWh7q8WU6mo Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0001-verify-lists-of-predefined-LWLocks-in-lwlocknames.patch" From 53c492ac8b345eca1c5c245882073273ddde53c1 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 5 Jan 2024 00:07:40 -0600 Subject: [PATCH v5 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..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 --envbJBWh7q8WU6mo--