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

Commit5af508f

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 parent440fcc5 commit5af508f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ tas(volatile slock_t *lock)
321321

322322

323323
#if defined(__sparc__)/* Sparc */
324+
/*
325+
* Solaris has always run sparc processors in TSO (total store) mode, but
326+
* linux didn't use to and the *BSDs still don't. So, be careful about
327+
* acquire/release semantics. The CPU will treat superflous membars as NOPs,
328+
* so it's just code space.
329+
*/
324330
#defineHAS_TEST_AND_SET
325331

326332
typedefunsignedcharslock_t;
@@ -342,9 +348,50 @@ tas(volatile slock_t *lock)
342348
:"=r"(_res),"+m"(*lock)
343349
:"r"(lock)
344350
:"memory");
351+
#if defined(__sparcv7)
352+
/*
353+
* No stbar or membar available, luckily no actually produced hardware
354+
* requires a barrier.
355+
*/
356+
#elif defined(__sparcv8)
357+
/* stbar is available (and required for both PSO, RMO), membar isn't */
358+
__asm__ __volatile__ ("stbar \n":::"memory");
359+
#else
360+
/*
361+
* #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire
362+
* barrier for sparcv8+ upwards.
363+
*/
364+
__asm__ __volatile__ ("membar #LoadStore | #LoadLoad \n":::"memory");
365+
#endif
345366
return (int)_res;
346367
}
347368

369+
#if defined(__sparcv7)
370+
/*
371+
* No stbar or membar available, luckily no actually produced hardware
372+
* requires a barrier.
373+
*/
374+
#defineS_UNLOCK(lock)(*((volatile slock_t *) (lock)) = 0)
375+
#elif__sparcv8
376+
/* stbar is available (and required for both PSO, RMO), membar isn't */
377+
#defineS_UNLOCK(lock)\
378+
do \
379+
{ \
380+
__asm__ __volatile__ ("stbar \n":::"memory"); \
381+
*((volatile slock_t *) (lock)) = 0; \
382+
} while (0)
383+
#else
384+
/*
385+
* #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate
386+
* release barrier for sparcv8+ upwards.
387+
*/
388+
do \
389+
{ \
390+
__asm__ __volatile__ ("membar #LoadStore | #StoreStore \n":::"memory"); \
391+
*((volatileslock_t*) (lock))=0; \
392+
}while (0)
393+
#endif
394+
348395
#endif/* __sparc__ */
349396

350397

@@ -823,15 +870,14 @@ typedef struct mutex slock_t;
823870
#endif/* nextstep */
824871

825872

826-
/* These are in s_lock.c */
827-
828873

829874
#if defined(sun3)/* Sun3 */
830875
#defineHAS_TEST_AND_SET
831876

832877
typedefunsignedcharslock_t;
833878
#endif
834879

880+
/* These are in sunstudio_(sparc|x86).s */
835881

836882
#if defined(__SUNPRO_C)&& (defined(__i386)|| defined(__x86_64__)|| defined(__sparc__)|| defined(__sparc))
837883
#defineHAS_TEST_AND_SET

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp