Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb79ab00

Browse files
committed
When LWLOCK_STATS is defined, count spindelays.
When LWLOCK_STATS is *not* defined, the only change is thatSpinLockAcquire now returns the number of delays.Patch by me, review by Jeff Janes.
1 parent7577736 commitb79ab00

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

‎src/backend/storage/lmgr/lwlock.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static intcounts_for_pid = 0;
9595
staticint*sh_acquire_counts;
9696
staticint*ex_acquire_counts;
9797
staticint*block_counts;
98+
staticint*spin_delay_counts;
9899
#endif
99100

100101
#ifdefLOCK_DEBUG
@@ -134,6 +135,7 @@ init_lwlock_stats(void)
134135

135136
sh_acquire_counts=calloc(numLocks,sizeof(int));
136137
ex_acquire_counts=calloc(numLocks,sizeof(int));
138+
spin_delay_counts=calloc(numLocks,sizeof(int));
137139
block_counts=calloc(numLocks,sizeof(int));
138140
counts_for_pid=MyProcPid;
139141
on_shmem_exit(print_lwlock_stats,0);
@@ -151,10 +153,10 @@ print_lwlock_stats(int code, Datum arg)
151153

152154
for (i=0;i<numLocks;i++)
153155
{
154-
if (sh_acquire_counts[i]||ex_acquire_counts[i]||block_counts[i])
155-
fprintf(stderr,"PID %d lwlock %d: shacq %u exacq %u blk %u\n",
156+
if (sh_acquire_counts[i]||ex_acquire_counts[i]||block_counts[i]||spin_delay_counts[i])
157+
fprintf(stderr,"PID %d lwlock %d: shacq %u exacq %u blk %u spindelay %u\n",
156158
MyProcPid,i,sh_acquire_counts[i],ex_acquire_counts[i],
157-
block_counts[i]);
159+
block_counts[i],spin_delay_counts[i]);
158160
}
159161

160162
LWLockRelease(0);
@@ -395,7 +397,11 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
395397
boolmustwait;
396398

397399
/* Acquire mutex. Time spent holding mutex should be short! */
400+
#ifdefLWLOCK_STATS
401+
spin_delay_counts[lockid]+=SpinLockAcquire(&lock->mutex);
402+
#else
398403
SpinLockAcquire(&lock->mutex);
404+
#endif
399405

400406
/* If retrying, allow LWLockRelease to release waiters again */
401407
if (retry)

‎src/backend/storage/lmgr/s_lock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ s_lock_stuck(volatile slock_t *lock, const char *file, int line)
4646
/*
4747
* s_lock(lock) - platform-independent portion of waiting for a spinlock.
4848
*/
49-
void
49+
int
5050
s_lock(volatileslock_t*lock,constchar*file,intline)
5151
{
5252
/*
@@ -155,6 +155,7 @@ s_lock(volatile slock_t *lock, const char *file, int line)
155155
if (spins_per_delay>MIN_SPINS_PER_DELAY)
156156
spins_per_delay=Max(spins_per_delay-1,MIN_SPINS_PER_DELAY);
157157
}
158+
returndelays;
158159
}
159160

160161

‎src/include/storage/s_lock.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
*void S_INIT_LOCK(slock_t *lock)
1313
*Initialize a spinlock (to the unlocked state).
1414
*
15-
*void S_LOCK(slock_t *lock)
15+
*int S_LOCK(slock_t *lock)
1616
*Acquire a spinlock, waiting if necessary.
1717
*Time out and abort() if unable to acquire the lock in a
1818
*"reasonable" amount of time --- typically ~ 1 minute.
19+
*Should return number of "delays"; see s_lock.c
1920
*
2021
*void S_UNLOCK(slock_t *lock)
2122
*Unlock a previously acquired lock.
@@ -978,10 +979,7 @@ extern inttas_sema(volatile slock_t *lock);
978979

979980
#if !defined(S_LOCK)
980981
#defineS_LOCK(lock) \
981-
do { \
982-
if (TAS(lock)) \
983-
s_lock((lock), __FILE__, __LINE__); \
984-
} while (0)
982+
(TAS(lock) ? s_lock((lock), __FILE__, __LINE__) : 0)
985983
#endif/* S_LOCK */
986984

987985
#if !defined(S_LOCK_FREE)
@@ -1015,7 +1013,7 @@ extern inttas(volatile slock_t *lock);/* in port/.../tas.s, or
10151013
/*
10161014
* Platform-independent out-of-line support routines
10171015
*/
1018-
externvoids_lock(volatileslock_t*lock,constchar*file,intline);
1016+
externints_lock(volatileslock_t*lock,constchar*file,intline);
10191017

10201018
/* Support for dynamic adjustment of spins_per_delay */
10211019
#defineDEFAULT_SPINS_PER_DELAY 100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp