Skip to content

Commit 631beea

Browse files
committed
Use LWSYNC in place of SYNC/ISYNC in PPC spinlocks, where possible.
This is allegedly a win, at least on some PPC implementations, according to the PPC ISA documents. However, as with LWARX hints, some PPC platforms give an illegal-instruction failure. Use the same trick as before of assuming that PPC64 platforms will accept it; we might need to refine that based on experience, but there are other projects doing likewise according to google. I did not add an assembler compatibility test because LWSYNC has been around much longer than hint bits, and it seems unlikely that any toolchains currently in use don't recognize it.
1 parent 8496c6c commit 631beea

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/include/pg_config_manual.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@
188188
#endif
189189
#endif
190190

191+
/*
192+
* On PPC machines, decide whether to use LWSYNC instructions in place of
193+
* ISYNC and SYNC. This provides slightly better performance, but will
194+
* result in illegal-instruction failures on some pre-POWER4 machines.
195+
* By default we use LWSYNC when building for 64-bit PPC, which should be
196+
* safe in nearly all cases.
197+
*/
198+
#if defined(__ppc64__) || defined(__powerpc64__)
199+
#define USE_PPC_LWSYNC
200+
#endif
201+
191202
/*
192203
*------------------------------------------------------------------------
193204
* The following symbols are for enabling debugging code, not for

src/include/storage/s_lock.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ typedef unsigned int slock_t;
361361
/*
362362
* NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
363363
* an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
364+
* On newer machines, we can use lwsync instead for better performance.
364365
*/
365366
static __inline__ int
366367
tas(volatile slock_t *lock)
@@ -382,7 +383,11 @@ tas(volatile slock_t *lock)
382383
"1: li %1,1 \n"
383384
" b 3f \n"
384385
"2: \n"
386+
#ifdef USE_PPC_LWSYNC
387+
" lwsync \n"
388+
#else
385389
" isync \n"
390+
#endif
386391
" li %1,0 \n"
387392
"3: \n"
388393

@@ -392,13 +397,25 @@ tas(volatile slock_t *lock)
392397
return _res;
393398
}
394399

395-
/* PowerPC S_UNLOCK is almost standard but requires a "sync" instruction */
400+
/*
401+
* PowerPC S_UNLOCK is almost standard but requires a "sync" instruction.
402+
* On newer machines, we can use lwsync instead for better performance.
403+
*/
404+
#ifdef USE_PPC_LWSYNC
405+
#define S_UNLOCK(lock) \
406+
do \
407+
{ \
408+
__asm__ __volatile__ (" lwsync \n"); \
409+
*((volatile slock_t *) (lock)) = 0; \
410+
} while (0)
411+
#else
396412
#define S_UNLOCK(lock) \
397413
do \
398414
{ \
399415
__asm__ __volatile__ (" sync \n"); \
400416
*((volatile slock_t *) (lock)) = 0; \
401417
} while (0)
418+
#endif /* USE_PPC_LWSYNC */
402419

403420
#endif /* powerpc */
404421

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy