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

Commitd0b7ffc

Browse files
committed
Fix spinlock implementation for some !solaris sparc platforms.
Some Sparc CPUs can be run in various coherence models, ranging fromRMO (relaxed) over PSO (partial) to TSO (total). Solaris has alwaysrun CPUs in TSO mode while in userland, but linux didn't use to andthe various *BSDs still don't. Unfortunately the sparc TAS/S_UNLOCKwere only correct under TSO. Fix that by adding the necessary memorybarrier instructions. On sparcv8+, which should be all relevant CPUs,these are treated as NOPs if the current consistency model doesn'trequire the barriers.Discussion: 20140630222854.GW26930@awork2.anarazel.deWill be backpatched to all released branches once a few buildfarmcycles haven't shown up problems. As I've no access to sparc, this isblindly written.
1 parent886b58b commitd0b7ffc

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

‎src/backend/port/tas/sunstudio_sparc.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pg_atomic_cas:
3737
!
3838
!http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/sparc/threads/sparc.il
3939
!
40+
!NB: We're assuming we're running on a TSO system here - solaris
41+
! userland luckily always has done so.
4042

4143
#if defined(__sparcv9) || defined(__sparcv8plus)
4244
cas [%o0],%o2,%o1

‎src/include/storage/s_lock.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ tas(volatile slock_t *lock)
383383

384384

385385
#if defined(__sparc__)/* Sparc */
386+
/*
387+
* Solaris has always run sparc processors in TSO (total store) mode, but
388+
* linux didn't use to and the *BSDs still don't. So, be careful about
389+
* acquire/release semantics. The CPU will treat superflous membars as NOPs,
390+
* so it's just code space.
391+
*/
386392
#defineHAS_TEST_AND_SET
387393

388394
typedefunsignedcharslock_t;
@@ -404,9 +410,50 @@ tas(volatile slock_t *lock)
404410
:"=r"(_res),"+m"(*lock)
405411
:"r"(lock)
406412
:"memory");
413+
#if defined(__sparcv7)
414+
/*
415+
* No stbar or membar available, luckily no actually produced hardware
416+
* requires a barrier.
417+
*/
418+
#elif defined(__sparcv8)
419+
/* stbar is available (and required for both PSO, RMO), membar isn't */
420+
__asm__ __volatile__ ("stbar \n":::"memory");
421+
#else
422+
/*
423+
* #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire
424+
* barrier for sparcv8+ upwards.
425+
*/
426+
__asm__ __volatile__ ("membar #LoadStore | #LoadLoad \n":::"memory");
427+
#endif
407428
return (int)_res;
408429
}
409430

431+
#if defined(__sparcv7)
432+
/*
433+
* No stbar or membar available, luckily no actually produced hardware
434+
* requires a barrier.
435+
*/
436+
#defineS_UNLOCK(lock)(*((volatile slock_t *) (lock)) = 0)
437+
#elif__sparcv8
438+
/* stbar is available (and required for both PSO, RMO), membar isn't */
439+
#defineS_UNLOCK(lock)\
440+
do \
441+
{ \
442+
__asm__ __volatile__ ("stbar \n":::"memory"); \
443+
*((volatile slock_t *) (lock)) = 0; \
444+
} while (0)
445+
#else
446+
/*
447+
* #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate
448+
* release barrier for sparcv8+ upwards.
449+
*/
450+
do \
451+
{ \
452+
__asm__ __volatile__ ("membar #LoadStore | #StoreStore \n":::"memory"); \
453+
*((volatileslock_t*) (lock))=0; \
454+
}while (0)
455+
#endif
456+
410457
#endif/* __sparc__ */
411458

412459

@@ -907,7 +954,7 @@ typedef int slock_t;
907954
#endif/* _AIX */
908955

909956

910-
/* These are ins_lock.c */
957+
/* These are insunstudio_(sparc|x86).s */
911958

912959

913960
#if defined(sun3)/* Sun3 */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp