Index: alpha/mutex.c =================================================================== RCS file: /cvs/src/sys/arch/alpha/alpha/mutex.c,v retrieving revision 1.13 diff -u -p -r1.13 mutex.c --- alpha/mutex.c 11 Feb 2015 01:15:06 -0000 1.13 +++ alpha/mutex.c 16 Apr 2015 10:28:26 -0000 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -38,40 +39,19 @@ static inline int try_lock(struct mutex *mtx) { #ifdef MULTIPROCESSOR - unsigned long t0, v0; - - __asm volatile( - "1: ldl_l %0, %3 \n" /* t0 = mtx->mtx_lock */ - " bne %0, 2f \n" - " bis $31, 1, %0 \n" /* t0 = 1 */ - " stl_c %0, %2 \n" /* mtx->mtx_lock = 1 */ - " beq %0, 3f \n" - " mb \n" - " bis $31, 1, %1 \n" /* v0 = 1 */ - " br 4f \n" - "3: br 1b \n" /* update failed */ - "2: bis $31, $31, %1 \n" /* v0 = 0 */ - "4: \n" - : "=&r" (t0), "=r" (v0), "=m" (mtx->mtx_lock) - : "m" (mtx->mtx_lock) - : "memory"); - - return (v0 != 0); + return (atomic_cas_ptr(&mtx->mtx_owner, NULL, curcpu()) == NULL); #else - mtx->mtx_lock = 1; - return 1; + mtx->mtx_owner = curcpu(); + return (1); #endif } void __mtx_init(struct mutex *mtx, int wantipl) { + mtx->mtx_owner = NULL; mtx->mtx_oldipl = IPL_NONE; mtx->mtx_wantipl = wantipl; - mtx->mtx_lock = 0; -#ifdef MULTIPROCESSOR - mtx->mtx_owner = NULL; -#endif } void @@ -85,10 +65,12 @@ mtx_enter(struct mutex *mtx) if (try_lock(mtx)) { if (mtx->mtx_wantipl != IPL_NONE) mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif +#ifdef MULTIPROCESSOR + membar_enter(); +#endif return; } if (mtx->mtx_wantipl != IPL_NONE) @@ -110,7 +92,6 @@ mtx_enter_try(struct mutex *mtx) if (try_lock(mtx)) { if (mtx->mtx_wantipl != IPL_NONE) mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif @@ -132,9 +113,8 @@ mtx_leave(struct mutex *mtx) #endif s = mtx->mtx_oldipl; mtx->mtx_owner = NULL; - mtx->mtx_lock = 0; #ifdef MULTIPROCESSOR - alpha_wmb(); + membar_exit(); #endif if (mtx->mtx_wantipl != IPL_NONE) splx(s); Index: include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/alpha/include/mutex.h,v retrieving revision 1.6 diff -u -p -r1.6 mutex.h --- include/mutex.h 18 Mar 2014 21:09:28 -0000 1.6 +++ include/mutex.h 16 Apr 2015 10:28:26 -0000 @@ -29,10 +29,9 @@ #define _MACHINE_MUTEX_H_ struct mutex { - int mtx_lock; + void *mtx_owner; int mtx_wantipl; int mtx_oldipl; - void *mtx_owner; }; /* @@ -49,7 +48,7 @@ struct mutex { #define __MUTEX_IPL(ipl) (ipl) #endif -#define MUTEX_INITIALIZER(ipl) { 0, __MUTEX_IPL((ipl)), IPL_NONE, NULL } +#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE } void __mtx_init(struct mutex *, int); #define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) @@ -57,7 +56,7 @@ void __mtx_init(struct mutex *, int); #ifdef DIAGNOSTIC #ifdef MULTIPROCESSOR #define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ + if ((mtx)->mtx_owner == NULL) \ panic("mutex %p not held in %s", (mtx), __func__); \ if ((mtx)->mtx_owner != curcpu()) \ panic("mutex %p held by cpu %p in %s", \ @@ -65,13 +64,13 @@ void __mtx_init(struct mutex *, int); } while (0) #else #define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ + if ((mtx)->mtx_owner == NULL) \ panic("mutex %p not held in %s", (mtx), __func__); \ } while (0) #endif #define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_lock != 0) \ + if ((mtx)->mtx_owner == curcpu()) \ panic("mutex %p held in %s", (mtx), __func__); \ } while (0) #else