Index: ./src/backend/storage/lmgr/s_lock.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/lmgr/s_lock.c,v retrieving revision 1.22 diff -u -r1.22 s_lock.c --- ./src/backend/storage/lmgr/s_lock.c 23 Dec 2003 22:15:07 -0000 1.22 +++ ./src/backend/storage/lmgr/s_lock.c 27 Dec 2003 10:28:54 -0000 @@ -76,7 +76,7 @@ * The select() delays are measured in centiseconds (0.01 sec) because 10 * msec is a common resolution limit at the OS level. */ -#define SPINS_PER_DELAY 100 +#define SPINS_PER_DELAY 1000 #define NUM_DELAYS 1000 #define MIN_DELAY_CSEC 1 #define MAX_DELAY_CSEC 100 @@ -86,7 +86,7 @@ int cur_delay = MIN_DELAY_CSEC; struct timeval delay; - while (TAS(lock)) + while (!S_LOCK_FREE(lock) || TAS(lock)) { if (++spins > SPINS_PER_DELAY) { @@ -111,6 +111,7 @@ spins = 0; } + CPU_DELAY(); } } Index: ./src/include/storage/s_lock.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/storage/s_lock.h,v retrieving revision 1.123 diff -u -r1.123 s_lock.h --- ./src/include/storage/s_lock.h 23 Dec 2003 22:15:07 -0000 1.123 +++ ./src/include/storage/s_lock.h 27 Dec 2003 10:28:55 -0000 @@ -52,6 +52,15 @@ * in assembly language to execute a hardware atomic-test-and-set * instruction. Equivalent OS-supplied mutex routines could be used too. * + * Additionally, a platform specific delay function can be defined: + * + * void CPU_DELAY(void) + * Notification that the cpu is executing a busy loop. + * + * Some platforms need such an indication. One example are platforms + * that implement SMT, i.e. multiple logical threads that share + * execution resources in one physical cpu. + * * If no system-specific TAS() is available (ie, HAVE_SPINLOCKS is not * defined), then we fall back on an emulation that uses SysV semaphores * (see spin.c). This emulation will be MUCH MUCH slower than a proper TAS() @@ -115,6 +124,17 @@ return (int) _res; } +#define HAS_CPU_DELAY + +#define CPU_DELAY() cpu_delay() + +static __inline__ void +cpu_delay(void) +{ + __asm__ __volatile__( + " rep; nop \n" + : : : "memory"); +} #endif /* __i386__ || __x86_64__ */ @@ -715,6 +735,9 @@ #define TAS(lock) tas(lock) #endif /* TAS */ +#ifndef HAS_CPU_DELAY +#define CPU_DELAY() do { } while(0) +#endif /* * Platform-independent out-of-line support routines