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

Commit80abbeb

Browse files
committed
Make init_spin_delay() C89 compliant and change stuck spinlock reporting.
The current definition of init_spin_delay (introduced recently in4835458) wasn't C89 compliant. It's not legal to refer to refer tonon-constant expressions, and the ptr argument was one. This, asreported by Tom, lead to a failure on buildfarm animal pademelon.The pointer, especially on system systems with ASLR, isn't super helpfulanyway, though. So instead of making init_spin_delay into an inlinefunction, make s_lock_stuck() report the function name in addition tofile:line and change init_spin_delay() accordingly. While not a directreplacement, the function name is likely more useful anyway (linenumbers are often hard to interpret in third party reports).This also fixes what file/line number is reported for waits vias_lock().As PG_FUNCNAME_MACRO is now used outside of elog.h, move it to c.h.Reported-By: Tom LaneDiscussion: 4369.1460435533@sss.pgh.pa.us
1 parent6cead41 commit80abbeb

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,7 +4029,7 @@ rnode_comparator(const void *p1, const void *p2)
40294029
uint32
40304030
LockBufHdr(BufferDesc*desc)
40314031
{
4032-
SpinDelayStatusdelayStatus=init_spin_delay(desc);
4032+
SpinDelayStatusdelayStatus=init_local_spin_delay();
40334033
uint32old_buf_state;
40344034

40354035
while (true)
@@ -4055,7 +4055,7 @@ LockBufHdr(BufferDesc *desc)
40554055
staticuint32
40564056
WaitBufHdrUnlocked(BufferDesc*buf)
40574057
{
4058-
SpinDelayStatusdelayStatus=init_spin_delay(buf);
4058+
SpinDelayStatusdelayStatus=init_local_spin_delay();
40594059
uint32buf_state;
40604060

40614061
buf_state=pg_atomic_read_u32(&buf->state);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ LWLockWaitListLock(LWLock *lock)
870870

871871
/* and then spin without atomic operations until lock is released */
872872
{
873-
SpinDelayStatusdelayStatus=init_spin_delay(&lock->state);
873+
SpinDelayStatusdelayStatus=init_local_spin_delay();
874874

875875
while (old_state&LW_FLAG_LOCKED)
876876
{

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,28 @@ static intspins_per_delay = DEFAULT_SPINS_PER_DELAY;
7070
* s_lock_stuck() - complain about a stuck spinlock
7171
*/
7272
staticvoid
73-
s_lock_stuck(void*p,constchar*file,intline)
73+
s_lock_stuck(constchar*file,intline,constchar*func)
7474
{
75+
if (!func)
76+
func="(unknown)";
7577
#if defined(S_LOCK_TEST)
7678
fprintf(stderr,
77-
"\nStuck spinlock(%p)detected at %s:%d.\n",
78-
p,file,line);
79+
"\nStuck spinlock detected at %s, %s:%d.\n",
80+
func,file,line);
7981
exit(1);
8082
#else
81-
elog(PANIC,"stuck spinlock(%p)detected at %s:%d",
82-
p,file,line);
83+
elog(PANIC,"stuck spinlock detected at %s, %s:%d",
84+
func,file,line);
8385
#endif
8486
}
8587

8688
/*
8789
* s_lock(lock) - platform-independent portion of waiting for a spinlock.
8890
*/
8991
int
90-
s_lock(volatileslock_t*lock,constchar*file,intline)
92+
s_lock(volatileslock_t*lock,constchar*file,intline,constchar*func)
9193
{
92-
SpinDelayStatusdelayStatus=init_spin_delay((void*)lock);
94+
SpinDelayStatusdelayStatus=init_spin_delay(file,line,func);
9395

9496
while (TAS_SPIN(lock))
9597
{
@@ -127,7 +129,7 @@ perform_spin_delay(SpinDelayStatus *status)
127129
if (++(status->spins) >=spins_per_delay)
128130
{
129131
if (++(status->delays)>NUM_DELAYS)
130-
s_lock_stuck(status->ptr,status->file,status->line);
132+
s_lock_stuck(status->file,status->line,status->func);
131133

132134
if (status->cur_delay==0)/* first time to delay? */
133135
status->cur_delay=MIN_DELAY_USEC;

‎src/include/c.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@
169169
#definedummyretchar
170170
#endif
171171

172+
/* Which __func__ symbol do we have, if any? */
173+
#ifdefHAVE_FUNCNAME__FUNC
174+
#definePG_FUNCNAME_MACRO__func__
175+
#else
176+
#ifdefHAVE_FUNCNAME__FUNCTION
177+
#definePG_FUNCNAME_MACRO__FUNCTION__
178+
#else
179+
#definePG_FUNCNAME_MACRONULL
180+
#endif
181+
#endif
182+
172183
/* ----------------------------------------------------------------
173184
*Section 2:bool, true, false, TRUE, FALSE, NULL
174185
* ----------------------------------------------------------------

‎src/include/storage/s_lock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ extern inttas_sema(volatile slock_t *lock);
930930

931931
#if !defined(S_LOCK)
932932
#defineS_LOCK(lock) \
933-
(TAS(lock) ? s_lock((lock), __FILE__, __LINE__) : 0)
933+
(TAS(lock) ? s_lock((lock), __FILE__, __LINE__, PG_FUNCNAME_MACRO) : 0)
934934
#endif/* S_LOCK */
935935

936936
#if !defined(S_LOCK_FREE)
@@ -983,7 +983,7 @@ extern slock_t dummy_spinlock;
983983
/*
984984
* Platform-independent out-of-line support routines
985985
*/
986-
externints_lock(volatileslock_t*lock,constchar*file,intline);
986+
externints_lock(volatileslock_t*lock,constchar*file,intline,constchar*func);
987987

988988
/* Support for dynamic adjustment of spins_per_delay */
989989
#defineDEFAULT_SPINS_PER_DELAY 100
@@ -1000,12 +1000,13 @@ typedef struct
10001000
intspins;
10011001
intdelays;
10021002
intcur_delay;
1003-
void*ptr;
10041003
constchar*file;
10051004
intline;
1005+
constchar*func;
10061006
}SpinDelayStatus;
10071007

1008-
#defineinit_spin_delay(ptr) {0, 0, 0, (ptr), __FILE__, __LINE__}
1008+
#defineinit_spin_delay(file,line,func) {0, 0, 0, file, line, func}
1009+
#defineinit_local_spin_delay() init_spin_delay(__FILE__, __LINE__, PG_FUNCNAME_MACRO)
10091010
voidperform_spin_delay(SpinDelayStatus*status);
10101011
voidfinish_spin_delay(SpinDelayStatus*status);
10111012

‎src/include/utils/elog.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@
7171
#include"utils/errcodes.h"
7272

7373

74-
/* Which __func__ symbol do we have, if any? */
75-
#ifdefHAVE_FUNCNAME__FUNC
76-
#definePG_FUNCNAME_MACRO__func__
77-
#else
78-
#ifdefHAVE_FUNCNAME__FUNCTION
79-
#definePG_FUNCNAME_MACRO__FUNCTION__
80-
#else
81-
#definePG_FUNCNAME_MACRONULL
82-
#endif
83-
#endif
84-
85-
8674
/*----------
8775
* New-style error reporting API: to be used in this way:
8876
*ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp