From 9b5e8922b7c603f902fecfb30e24a962b6c08176 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 10 Mar 2023 16:22:59 +1300
Subject: [PATCH 2/3] Use microsecond-based naps for vacuum_cost_delay sleep.

Now that we have microsecond support in the WaitEventSet API, we can use
the standard programming pattern to implement the high resolution sleep
in vacuum_delay_point().

XXX We wouldn't be able to do this until Linux 5.11 is in common stable
distributions, otherwise the sleep would lose precision when changing
from the pg_usleep() coding.

Reported-by: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/CAAKRu_b-q0hXCBUCAATh0Z4Zi6UkiC0k2DFgoD3nC-r3SkR3tg%40mail.gmail.com
---
 src/backend/commands/vacuum.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 2e12baf8eb..f379e60dca 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -2232,10 +2232,10 @@ vacuum_delay_point(void)
 		if (msec > VacuumCostDelay * 4)
 			msec = VacuumCostDelay * 4;
 
-		(void) WaitLatch(MyLatch,
-						 WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
-						 msec,
-						 WAIT_EVENT_VACUUM_DELAY);
+		(void) WaitLatchUs(MyLatch,
+						   WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
+						   msec * 1000,
+						   WAIT_EVENT_VACUUM_DELAY);
 		ResetLatch(MyLatch);
 
 		VacuumCostBalance = 0;
-- 
2.39.2

