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

Commit9e0bc7c

Browse files
committed
Track spinlock delay in microsecond granularity.
On many platforms the OS will round the sleep time to millisecondresolution, but there is no reason for us to pre-emptively round theargument to pg_usleep.When the delay was measured in milliseconds and started from 1 ms, itsometimes took many attempts until the logic that increases the delay bymultiplying with a random value between 1 and 2 actually managed to bump itfrom 1 ms to 2 ms. That lead to a sequence of 1 ms waits until the delaystarted to increase. This wasn't really a problem but it looked odd if youobserved the waits. There is no measurable difference in performance, butit's more readable this way.Jeff Janes
1 parent9db4ad4 commit9e0bc7c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,12 @@ s_lock(volatile slock_t *lock, const char *file, int line)
8181
* so minutes.It seems better to fix the total number of tries (and thus
8282
* the probability of unintended failure) than to fix the total time
8383
* spent.
84-
*
85-
* The pg_usleep() delays are measured in milliseconds because 1 msec is a
86-
* common resolution limit at the OS level for newer platforms. On older
87-
* platforms the resolution limit is usually 10 msec, in which case the
88-
* total delay before timeout will be a bit more.
8984
*/
9085
#defineMIN_SPINS_PER_DELAY 10
9186
#defineMAX_SPINS_PER_DELAY 1000
9287
#defineNUM_DELAYS1000
93-
#defineMIN_DELAY_MSEC1
94-
#defineMAX_DELAY_MSEC1000
88+
#defineMIN_DELAY_USEC1000L
89+
#defineMAX_DELAY_USEC1000000L
9590

9691
intspins=0;
9792
intdelays=0;
@@ -109,9 +104,9 @@ s_lock(volatile slock_t *lock, const char *file, int line)
109104
s_lock_stuck(lock,file,line);
110105

111106
if (cur_delay==0)/* first time to delay? */
112-
cur_delay=MIN_DELAY_MSEC;
107+
cur_delay=MIN_DELAY_USEC;
113108

114-
pg_usleep(cur_delay*1000L);
109+
pg_usleep(cur_delay);
115110

116111
#if defined(S_LOCK_TEST)
117112
fprintf(stdout,"*");
@@ -122,8 +117,8 @@ s_lock(volatile slock_t *lock, const char *file, int line)
122117
cur_delay+= (int) (cur_delay*
123118
((double)random() / (double)MAX_RANDOM_VALUE)+0.5);
124119
/* wrap back to minimum delay when max is exceeded */
125-
if (cur_delay>MAX_DELAY_MSEC)
126-
cur_delay=MIN_DELAY_MSEC;
120+
if (cur_delay>MAX_DELAY_USEC)
121+
cur_delay=MIN_DELAY_USEC;
127122

128123
spins=0;
129124
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp