mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
Extend framework from commit 53be0b1ad to report latch waits.
WaitLatch, WaitLatchOrSocket, and WaitEventSetWait now taken an additional wait_event_info parameter; legal values are defined in pgstat.h. This makes it possible to uniquely identify every point in the core code where we are waiting for a latch; extensions can pass WAIT_EXTENSION. Because latches were the major wait primitive not previously covered by this patch, it is now possible to see information in pg_stat_activity on a large number of important wait events not previously addressed, such as ClientRead, ClientWrite, and SyncRep. Unfortunately, many of the wait events added by this patch will fail to appear in pg_stat_activity because they're only used in background processes which don't currently appear in pg_stat_activity. We should fix this either by creating a separate view for such information, or else by deciding to include them in pg_stat_activity after all. Michael Paquier and Robert Haas, reviewed by Alexander Korotkov and Thomas Munro.
This commit is contained in:
@@ -3635,9 +3635,6 @@ LockBufferForCleanup(Buffer buffer)
|
||||
UnlockBufHdr(bufHdr, buf_state);
|
||||
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
|
||||
|
||||
/* Report the wait */
|
||||
pgstat_report_wait_start(WAIT_BUFFER_PIN, 0);
|
||||
|
||||
/* Wait to be signaled by UnpinBuffer() */
|
||||
if (InHotStandby)
|
||||
{
|
||||
@@ -3649,9 +3646,7 @@ LockBufferForCleanup(Buffer buffer)
|
||||
SetStartupBufferPinWaitBufId(-1);
|
||||
}
|
||||
else
|
||||
ProcWaitForSignal();
|
||||
|
||||
pgstat_report_wait_end();
|
||||
ProcWaitForSignal(WAIT_BUFFER_PIN);
|
||||
|
||||
/*
|
||||
* Remove flag marking us as waiter. Normally this will not be set
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#endif
|
||||
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "portability/instr_time.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/barrier.h"
|
||||
@@ -297,9 +298,11 @@ DisownLatch(volatile Latch *latch)
|
||||
* we return all of them in one call, but we will return at least one.
|
||||
*/
|
||||
int
|
||||
WaitLatch(volatile Latch *latch, int wakeEvents, long timeout)
|
||||
WaitLatch(volatile Latch *latch, int wakeEvents, long timeout,
|
||||
uint32 wait_event_info)
|
||||
{
|
||||
return WaitLatchOrSocket(latch, wakeEvents, PGINVALID_SOCKET, timeout);
|
||||
return WaitLatchOrSocket(latch, wakeEvents, PGINVALID_SOCKET, timeout,
|
||||
wait_event_info);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -316,7 +319,7 @@ WaitLatch(volatile Latch *latch, int wakeEvents, long timeout)
|
||||
*/
|
||||
int
|
||||
WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
|
||||
long timeout)
|
||||
long timeout, uint32 wait_event_info)
|
||||
{
|
||||
int ret = 0;
|
||||
int rc;
|
||||
@@ -344,7 +347,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
|
||||
AddWaitEventToSet(set, ev, sock, NULL, NULL);
|
||||
}
|
||||
|
||||
rc = WaitEventSetWait(set, timeout, &event, 1);
|
||||
rc = WaitEventSetWait(set, timeout, &event, 1, wait_event_info);
|
||||
|
||||
if (rc == 0)
|
||||
ret |= WL_TIMEOUT;
|
||||
@@ -863,7 +866,8 @@ WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event)
|
||||
*/
|
||||
int
|
||||
WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
WaitEvent *occurred_events, int nevents)
|
||||
WaitEvent *occurred_events, int nevents,
|
||||
uint32 wait_event_info)
|
||||
{
|
||||
int returned_events = 0;
|
||||
instr_time start_time;
|
||||
@@ -883,6 +887,8 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
cur_timeout = timeout;
|
||||
}
|
||||
|
||||
pgstat_report_wait_start(wait_event_info);
|
||||
|
||||
#ifndef WIN32
|
||||
waiting = true;
|
||||
#else
|
||||
@@ -960,6 +966,8 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
waiting = false;
|
||||
#endif
|
||||
|
||||
pgstat_report_wait_end();
|
||||
|
||||
return returned_events;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/bgworker.h"
|
||||
#include "storage/procsignal.h"
|
||||
#include "storage/shm_mq.h"
|
||||
@@ -894,7 +895,7 @@ shm_mq_send_bytes(shm_mq_handle *mqh, Size nbytes, const void *data,
|
||||
* at top of loop, because setting an already-set latch is much
|
||||
* cheaper than setting one that has been reset.
|
||||
*/
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0);
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0, WAIT_EVENT_MQ_SEND);
|
||||
|
||||
/* Reset the latch so we don't spin. */
|
||||
ResetLatch(MyLatch);
|
||||
@@ -991,7 +992,7 @@ shm_mq_receive_bytes(shm_mq *mq, Size bytes_needed, bool nowait,
|
||||
* loop, because setting an already-set latch is much cheaper than
|
||||
* setting one that has been reset.
|
||||
*/
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0);
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0, WAIT_EVENT_MQ_RECEIVE);
|
||||
|
||||
/* Reset the latch so we don't spin. */
|
||||
ResetLatch(MyLatch);
|
||||
@@ -1090,7 +1091,7 @@ shm_mq_wait_internal(volatile shm_mq *mq, PGPROC *volatile * ptr,
|
||||
}
|
||||
|
||||
/* Wait to be signalled. */
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0);
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0, WAIT_EVENT_MQ_INTERNAL);
|
||||
|
||||
/* Reset the latch so we don't spin. */
|
||||
ResetLatch(MyLatch);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "access/xlog.h"
|
||||
#include "access/xloginsert.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "storage/proc.h"
|
||||
@@ -389,7 +390,7 @@ ResolveRecoveryConflictWithLock(LOCKTAG locktag)
|
||||
}
|
||||
|
||||
/* Wait to be signaled by the release of the Relation Lock */
|
||||
ProcWaitForSignal();
|
||||
ProcWaitForSignal(WAIT_LOCK | locktag.locktag_type);
|
||||
|
||||
/*
|
||||
* Clear any timeout requests established above. We assume here that the
|
||||
@@ -469,7 +470,7 @@ ResolveRecoveryConflictWithBufferPin(void)
|
||||
}
|
||||
|
||||
/* Wait to be signaled by UnpinBuffer() */
|
||||
ProcWaitForSignal();
|
||||
ProcWaitForSignal(WAIT_BUFFER_PIN);
|
||||
|
||||
/*
|
||||
* Clear any timeout requests established above. We assume here that the
|
||||
|
||||
@@ -1676,7 +1676,6 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
set_ps_display(new_status, false);
|
||||
new_status[len] = '\0'; /* truncate off " waiting" */
|
||||
}
|
||||
pgstat_report_wait_start(WAIT_LOCK, locallock->tag.lock.locktag_type);
|
||||
|
||||
awaitedLock = locallock;
|
||||
awaitedOwner = owner;
|
||||
@@ -1724,7 +1723,6 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
/* In this path, awaitedLock remains set until LockErrorCleanup */
|
||||
|
||||
/* Report change to non-waiting status */
|
||||
pgstat_report_wait_end();
|
||||
if (update_process_title)
|
||||
{
|
||||
set_ps_display(new_status, false);
|
||||
@@ -1739,7 +1737,6 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
awaitedLock = NULL;
|
||||
|
||||
/* Report change to non-waiting status */
|
||||
pgstat_report_wait_end();
|
||||
if (update_process_title)
|
||||
{
|
||||
set_ps_display(new_status, false);
|
||||
|
||||
@@ -732,9 +732,9 @@ LWLockReportWaitStart(LWLock *lock)
|
||||
int lockId = T_ID(lock);
|
||||
|
||||
if (lock->tranche == 0)
|
||||
pgstat_report_wait_start(WAIT_LWLOCK_NAMED, (uint16) lockId);
|
||||
pgstat_report_wait_start(WAIT_LWLOCK_NAMED | (uint16) lockId);
|
||||
else
|
||||
pgstat_report_wait_start(WAIT_LWLOCK_TRANCHE, lock->tranche);
|
||||
pgstat_report_wait_start(WAIT_LWLOCK_TRANCHE | lock->tranche);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -750,7 +750,7 @@ LWLockReportWaitEnd(void)
|
||||
* Return an identifier for an LWLock based on the wait class and event.
|
||||
*/
|
||||
const char *
|
||||
GetLWLockIdentifier(uint8 classId, uint16 eventId)
|
||||
GetLWLockIdentifier(uint32 classId, uint16 eventId)
|
||||
{
|
||||
if (classId == WAIT_LWLOCK_NAMED)
|
||||
return MainLWLockNames[eventId];
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
#include "access/xact.h"
|
||||
#include "access/xlog.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/predicate.h"
|
||||
#include "storage/predicate_internals.h"
|
||||
@@ -1518,7 +1519,7 @@ GetSafeSnapshot(Snapshot origSnapshot)
|
||||
SxactIsROUnsafe(MySerializableXact)))
|
||||
{
|
||||
LWLockRelease(SerializableXactHashLock);
|
||||
ProcWaitForSignal();
|
||||
ProcWaitForSignal(WAIT_EVENT_SAFE_SNAPSHOT);
|
||||
LWLockAcquire(SerializableXactHashLock, LW_EXCLUSIVE);
|
||||
}
|
||||
MySerializableXact->flags &= ~SXACT_FLAG_DEFERRABLE_WAITING;
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "access/twophase.h"
|
||||
#include "access/xact.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/autovacuum.h"
|
||||
#include "replication/slot.h"
|
||||
#include "replication/syncrep.h"
|
||||
@@ -1212,7 +1213,8 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0);
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0,
|
||||
WAIT_LOCK | locallock->tag.lock.locktag_type);
|
||||
ResetLatch(MyLatch);
|
||||
/* check for deadlocks first, as that's probably log-worthy */
|
||||
if (got_deadlock_timeout)
|
||||
@@ -1722,9 +1724,9 @@ CheckDeadLockAlert(void)
|
||||
* wait again if not.
|
||||
*/
|
||||
void
|
||||
ProcWaitForSignal(void)
|
||||
ProcWaitForSignal(uint32 wait_event_info)
|
||||
{
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0);
|
||||
WaitLatch(MyLatch, WL_LATCH_SET, 0, wait_event_info);
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user