pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Introduce WAIT_EVENT_EXTENSION and WAIT_EVENT_BUFFER_PIN
Date: Wed, 17 May 2023 08:29:42 +0200
Message-ID: <a82c2660-64b4-1c59-3eef-bf82b86fb99a@gmail.com> (raw)
In-Reply-To: <ZGMf082u9mK3MX2z@paquier.xyz>
References: <c6f35117-4b20-4c78-1df5-d3056010dcf5@gmail.com>
	<ZGMf082u9mK3MX2z@paquier.xyz>

Hi,

On 5/16/23 8:16 AM, Michael Paquier wrote:
> On Mon, May 15, 2023 at 10:07:04AM +0200, Drouvot, Bertrand wrote:
>> This is preliminary work to autogenerate some wait events
>> code and documentation done in [1].
>>
>> The patch introduces 2 new "wait events" (WAIT_EVENT_EXTENSION
>> and WAIT_EVENT_BUFFER_PIN) and their associated functions
>> (pgstat_get_wait_extension() and pgstat_get_wait_bufferpin() resp.)
>>
>> Please note that that would not break extensions outside contrib
>> that make use of the existing PG_WAIT_EXTENSION.
> 
> I have looked at this one, and I think that's OK for what you are
> aiming at here (in addition to my previous message that I hope
> provides enough context about the whys and the hows).

Thanks!

Please find V2 attached, it adds WaitEventBufferPin and WaitEventExtension to
src/tools/pgindent/typedefs.list (that was done in [1]...).

[1]: https://www.postgresql.org/message-id/flat/77a86b3a-c4a8-5f5d-69b9-d70bbf2e9b98%40gmail.com

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

v2-0001-Introducing-WAIT_EVENT_EXTENSION-and-WAIT_EVENT_B.patch (text/plain, 10.5K) download From 4c9ca1389b0aa9f7eae34c3b72f15dbc7da39783 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Date: Sat, 13 May 2023 07:59:08 +0000 Subject: [PATCH v2] Introducing WAIT_EVENT_EXTENSION and WAIT_EVENT_BUFFER_PIN --- contrib/dblink/dblink.c | 4 +- contrib/pg_prewarm/autoprewarm.c | 4 +- contrib/postgres_fdw/connection.c | 6 +-- src/backend/storage/buffer/bufmgr.c | 2 +- src/backend/storage/ipc/standby.c | 2 +- src/backend/utils/activity/wait_event.c | 66 +++++++++++++++++++++--- src/include/utils/wait_event.h | 20 ++++++- src/test/modules/test_shm_mq/setup.c | 2 +- src/test/modules/test_shm_mq/test.c | 2 +- src/test/modules/worker_spi/worker_spi.c | 2 +- src/tools/pgindent/typedefs.list | 2 + 11 files changed, 93 insertions(+), 19 deletions(-) 8.8% contrib/dblink/ 4.6% contrib/pg_prewarm/ 9.3% contrib/postgres_fdw/ 3.4% src/backend/storage/buffer/ 3.2% src/backend/storage/ipc/ 47.9% src/backend/utils/activity/ 14.2% src/include/utils/ 4.5% src/test/modules/test_shm_mq/ 3.7% src/ diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 55f75eff36..f167cb71d4 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -203,7 +203,7 @@ dblink_get_conn(char *conname_or_str, dblink_connstr_check(connstr); /* OK to make connection */ - conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION); + conn = libpqsrv_connect(connstr, WAIT_EVENT_EXTENSION); if (PQstatus(conn) == CONNECTION_BAD) { @@ -293,7 +293,7 @@ dblink_connect(PG_FUNCTION_ARGS) dblink_connstr_check(connstr); /* OK to make connection */ - conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION); + conn = libpqsrv_connect(connstr, WAIT_EVENT_EXTENSION); if (PQstatus(conn) == CONNECTION_BAD) { diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c index 93835449c0..d0efc9e524 100644 --- a/contrib/pg_prewarm/autoprewarm.c +++ b/contrib/pg_prewarm/autoprewarm.c @@ -237,7 +237,7 @@ autoprewarm_main(Datum main_arg) (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, -1L, - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); } else { @@ -264,7 +264,7 @@ autoprewarm_main(Datum main_arg) (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, delay_in_ms, - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); } /* Reset the latch, loop. */ diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c index da32d503bc..25d0c43b64 100644 --- a/contrib/postgres_fdw/connection.c +++ b/contrib/postgres_fdw/connection.c @@ -530,7 +530,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user) /* OK to make connection */ conn = libpqsrv_connect_params(keywords, values, false, /* expand_dbname */ - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); if (!conn || PQstatus(conn) != CONNECTION_OK) ereport(ERROR, @@ -863,7 +863,7 @@ pgfdw_get_result(PGconn *conn, const char *query) WL_LATCH_SET | WL_SOCKET_READABLE | WL_EXIT_ON_PM_DEATH, PQsocket(conn), - -1L, PG_WAIT_EXTENSION); + -1L, WAIT_EVENT_EXTENSION); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); @@ -1567,7 +1567,7 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result, WL_LATCH_SET | WL_SOCKET_READABLE | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, PQsocket(conn), - cur_timeout, PG_WAIT_EXTENSION); + cur_timeout, WAIT_EVENT_EXTENSION); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 1fa689052e..c7c1782461 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -4895,7 +4895,7 @@ LockBufferForCleanup(Buffer buffer) SetStartupBufferPinWaitBufId(-1); } else - ProcWaitForSignal(PG_WAIT_BUFFER_PIN); + ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN); /* * Remove flag marking us as waiter. Normally this will not be set diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index ffe5e1563f..33188f829e 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -840,7 +840,7 @@ ResolveRecoveryConflictWithBufferPin(void) * SIGHUP signal handler, etc cannot do that because it uses the different * latch from that ProcWaitForSignal() waits on. */ - ProcWaitForSignal(PG_WAIT_BUFFER_PIN); + ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN); if (got_standby_delay_timeout) SendRecoveryConflictWithBufferPin(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN); diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c index 7940d64639..8572cf169e 100644 --- a/src/backend/utils/activity/wait_event.c +++ b/src/backend/utils/activity/wait_event.c @@ -28,7 +28,9 @@ static const char *pgstat_get_wait_activity(WaitEventActivity w); +static const char *pgstat_get_wait_bufferpin(WaitEventBufferPin w); static const char *pgstat_get_wait_client(WaitEventClient w); +static const char *pgstat_get_wait_extension(WaitEventExtension w); static const char *pgstat_get_wait_ipc(WaitEventIPC w); static const char *pgstat_get_wait_timeout(WaitEventTimeout w); static const char *pgstat_get_wait_io(WaitEventIO w); @@ -90,7 +92,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info) case PG_WAIT_LOCK: event_type = "Lock"; break; - case PG_WAIT_BUFFER_PIN: + case PG_WAIT_BUFFERPIN: event_type = "BufferPin"; break; case PG_WAIT_ACTIVITY: @@ -147,9 +149,13 @@ pgstat_get_wait_event(uint32 wait_event_info) case PG_WAIT_LOCK: event_name = GetLockNameFromTagType(eventId); break; - case PG_WAIT_BUFFER_PIN: - event_name = "BufferPin"; - break; + case PG_WAIT_BUFFERPIN: + { + WaitEventBufferPin w = (WaitEventBufferPin) wait_event_info; + + event_name = pgstat_get_wait_bufferpin(w); + break; + } case PG_WAIT_ACTIVITY: { WaitEventActivity w = (WaitEventActivity) wait_event_info; @@ -165,8 +171,12 @@ pgstat_get_wait_event(uint32 wait_event_info) break; } case PG_WAIT_EXTENSION: - event_name = "Extension"; - break; + { + WaitEventExtension w = (WaitEventExtension) wait_event_info; + + event_name = pgstat_get_wait_extension(w); + break; + } case PG_WAIT_IPC: { WaitEventIPC w = (WaitEventIPC) wait_event_info; @@ -254,6 +264,28 @@ pgstat_get_wait_activity(WaitEventActivity w) return event_name; } +/* ---------- + * pgstat_get_wait_bufferpin() - + * + * Convert WaitEventBufferPin to string. + * ---------- + */ +static const char * +pgstat_get_wait_bufferpin(WaitEventBufferPin w) +{ + const char *event_name = "unknown wait event"; + + switch (w) + { + case WAIT_EVENT_BUFFER_PIN: + event_name = "BufferPin"; + break; + /* no default case, so that compiler will warn */ + } + + return event_name; +} + /* ---------- * pgstat_get_wait_client() - * @@ -297,6 +329,28 @@ pgstat_get_wait_client(WaitEventClient w) return event_name; } +/* ---------- + * pgstat_get_wait_extension() - + * + * Convert WaitEventExtension to string. + * ---------- + */ +static const char * +pgstat_get_wait_extension(WaitEventExtension w) +{ + const char *event_name = "unknown wait event"; + + switch (w) + { + case WAIT_EVENT_EXTENSION: + event_name = "Extension"; + break; + /* no default case, so that compiler will warn */ + } + + return event_name; +} + /* ---------- * pgstat_get_wait_ipc() - * diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h index 518d3b0a1f..dc01d4e84d 100644 --- a/src/include/utils/wait_event.h +++ b/src/include/utils/wait_event.h @@ -17,7 +17,7 @@ */ #define PG_WAIT_LWLOCK 0x01000000U #define PG_WAIT_LOCK 0x03000000U -#define PG_WAIT_BUFFER_PIN 0x04000000U +#define PG_WAIT_BUFFERPIN 0x04000000U #define PG_WAIT_ACTIVITY 0x05000000U #define PG_WAIT_CLIENT 0x06000000U #define PG_WAIT_EXTENSION 0x07000000U @@ -50,6 +50,15 @@ typedef enum WAIT_EVENT_WAL_WRITER_MAIN } WaitEventActivity; +/* ---------- + * Wait Events - BUFFERPIN + * ---------- + */ +typedef enum +{ + WAIT_EVENT_BUFFER_PIN = PG_WAIT_BUFFERPIN +} WaitEventBufferPin; + /* ---------- * Wait Events - Client * @@ -70,6 +79,15 @@ typedef enum WAIT_EVENT_WAL_SENDER_WRITE_DATA, } WaitEventClient; +/* ---------- + * Wait Events - EXTENSION + * ---------- + */ +typedef enum +{ + WAIT_EVENT_EXTENSION = PG_WAIT_EXTENSION +} WaitEventExtension; + /* ---------- * Wait Events - IPC * diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c index bec5732e87..192e5cc2ab 100644 --- a/src/test/modules/test_shm_mq/setup.c +++ b/src/test/modules/test_shm_mq/setup.c @@ -280,7 +280,7 @@ wait_for_workers_to_become_ready(worker_state *wstate, /* Wait to be signaled. */ (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0, - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); /* Reset the latch so we don't spin. */ ResetLatch(MyLatch); diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c index 906e943e2d..d9be703350 100644 --- a/src/test/modules/test_shm_mq/test.c +++ b/src/test/modules/test_shm_mq/test.c @@ -232,7 +232,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS) * for us to do. */ (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0, - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); } diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c index ad491d7722..7227cfaa45 100644 --- a/src/test/modules/worker_spi/worker_spi.c +++ b/src/test/modules/worker_spi/worker_spi.c @@ -199,7 +199,7 @@ worker_spi_main(Datum main_arg) (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, worker_spi_naptime * 1000L, - PG_WAIT_EXTENSION); + WAIT_EVENT_EXTENSION); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 06da7cd428..dce1bcbfdf 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -2972,7 +2972,9 @@ WSANETWORKEVENTS WSAPROTOCOL_INFO WaitEvent WaitEventActivity +WaitEventBufferPin WaitEventClient +WaitEventExtension WaitEventIO WaitEventIPC WaitEventSet -- 2.34.1

view thread (25+ messages)  latest in thread

Message-ID: <a82c2660-64b4-1c59-3eef-bf82b86fb99a@gmail.com>
Permalink:  ../a82c2660-64b4-1c59-3eef-bf82b86fb99a@gmail.com/
Also on:    postgresql.org/message-id/a82c2660-64b4-1c59-3eef-bf82b86fb99a@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: bertranddrouvot.pg@gmail.com, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org
  Subject: Re: Introduce WAIT_EVENT_EXTENSION and WAIT_EVENT_BUFFER_PIN
  In-Reply-To: <a82c2660-64b4-1c59-3eef-bf82b86fb99a@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox