[Cbe-oss-dev] [PATCH 9/10 v2] MARS: remove separate atomic implementation

Kazunori Asayama asayama at sm.sony.co.jp
Fri Aug 29 14:57:54 EST 2008


Yuji Mano wrote:
> This removes the atomic.h headers for both host and mpu. Since the atomics are
> now used only in the mutex implementation, we get rid of the extra abstraction
> and use the atomic intrinsics directly in the mutex implementations.
> 
> Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

Acked-by: Kazunori Asayama <asayama at sm.sony.co.jp>

> 
> ---
> v2:
>  - remove unnecessary clearing of phantom events
>  - save previous event mask and restore later
>  - unconditionally ack any remnant MFC_LLR_LOST_EVENT after restoring mask
> 
>  include/Makefile.am             |    2 
>  include/host/mars/mars_atomic.h |   74 -----------------------------
>  include/mpu/mars/mars_atomic.h  |   99 ----------------------------------------
>  src/host/lib/mars_mutex.c       |   11 ++--
>  src/mpu/lib/mars_mutex.c        |   28 ++++++++---
>  5 files changed, 27 insertions(+), 187 deletions(-)
> 
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -79,11 +79,9 @@ EXTRA_DIST = \
>  	common/mars/mars_debug.h \
>  	common/mars/mars_kernel_types.h \
>  	common/mars/mars_workload_types.h \
> -	host/mars/mars_atomic.h \
>  	host/mars/mars_elf.h \
>  	host/mars/mars_timer.h \
>  	host/mars/mars_workload_queue.h \
> -	mpu/mars/mars_atomic.h \
>  	mpu/mars/mars_dma.h \
>  	mpu/mars/mars_kernel.h \
>  	mpu/mars/mars_timer.h \
> --- a/include/host/mars/mars_atomic.h
> +++ /dev/null
> @@ -1,74 +0,0 @@
> -/*
> - * Copyright 2008 Sony Corporation of America
> - *
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining
> - * a copy of this Library and associated documentation files (the
> - * "Library"), to deal in the Library without restriction, including
> - * without limitation the rights to use, copy, modify, merge, publish,
> - * distribute, sublicense, and/or sell copies of the Library, and to
> - * permit persons to whom the Library is furnished to do so, subject to
> - * the following conditions:
> - *
> - *  The above copyright notice and this permission notice shall be
> - *  included in all copies or substantial portions of the Library.
> - *
> - *  If you modify the Library, you may copy and distribute your modified
> - *  version of the Library in object code or as an executable provided
> - *  that you also do one of the following:
> - *
> - *   Accompany the modified version of the Library with the complete
> - *   corresponding machine-readable source code for the modified version
> - *   of the Library; or,
> - *
> - *   Accompany the modified version of the Library with a written offer
> - *   for a complete machine-readable copy of the corresponding source
> - *   code of the modified version of the Library.
> - *
> - *
> - * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> - * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
> - */
> -
> -#ifndef MARS_ATOMIC_H
> -#define MARS_ATOMIC_H
> -
> -#if defined(__cplusplus)
> -extern "C" {
> -#endif
> -
> -#include <ppu_intrinsics.h>
> -#include "mars/mars_debug.h"
> -
> -#define MARS_ATOMIC_ALIGNMENT_MASK	0x7f
> -
> -static inline int atomic_get(void *addr)
> -{
> -	MARS_ASSERT(((uintptr_t)addr & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -
> -	return __lwarx(addr);
> -}
> -
> -static inline int atomic_put(void *addr, uint32_t val)
> -{
> -	MARS_ASSERT(((uintptr_t)addr & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -
> -	__lwsync();
> -	return __stwcx(addr, val);
> -}
> -
> -static inline void atomic_sync(void)
> -{
> -	__isync();
> -}
> -
> -#if defined(__cplusplus)
> -}
> -#endif
> -
> -#endif
> --- a/include/mpu/mars/mars_atomic.h
> +++ /dev/null
> @@ -1,99 +0,0 @@
> -/*
> - * Copyright 2008 Sony Corporation of America
> - *
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining
> - * a copy of this Library and associated documentation files (the
> - * "Library"), to deal in the Library without restriction, including
> - * without limitation the rights to use, copy, modify, merge, publish,
> - * distribute, sublicense, and/or sell copies of the Library, and to
> - * permit persons to whom the Library is furnished to do so, subject to
> - * the following conditions:
> - *
> - *  The above copyright notice and this permission notice shall be
> - *  included in all copies or substantial portions of the Library.
> - *
> - *  If you modify the Library, you may copy and distribute your modified
> - *  version of the Library in object code or as an executable provided
> - *  that you also do one of the following:
> - *
> - *   Accompany the modified version of the Library with the complete
> - *   corresponding machine-readable source code for the modified version
> - *   of the Library; or,
> - *
> - *   Accompany the modified version of the Library with a written offer
> - *   for a complete machine-readable copy of the corresponding source
> - *   code of the modified version of the Library.
> - *
> - *
> - * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> - * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
> - */
> -
> -#ifndef MARS_ATOMIC_H
> -#define MARS_ATOMIC_H
> -
> -#if defined(__cplusplus)
> -extern "C" {
> -#endif
> -
> -#include <spu_mfcio.h>
> -#include "mars/mars_debug.h"
> -
> -#define MARS_ATOMIC_ALIGNMENT_MASK	0x7f
> -
> -static inline void atomic_event_setup(void)
> -{
> -	/* clear phantom events and set event mask */
> -	if (spu_stat_event_status())
> -		spu_write_event_ack(spu_read_event_status());
> -	spu_write_event_mask(MFC_LLR_LOST_EVENT);
> -}
> -
> -static inline void atomic_event_restore(void)
> -{
> -	/* clean up any remnant events, as needed */
> -	spu_write_event_mask(0);
> -
> -	if (spu_stat_event_status()) {
> -		spu_read_event_status();
> -		spu_write_event_ack(MFC_LLR_LOST_EVENT);
> -	}
> -}
> -
> -static inline void atomic_event_wait(void)
> -{
> -	/* wait until reservation is lost */
> -	spu_read_event_status();
> -	spu_write_event_ack(MFC_LLR_LOST_EVENT);
> -}
> -
> -static inline void atomic_get(void *ls, uint64_t ea)
> -{
> -	MARS_ASSERT(((uintptr_t)ls & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -	MARS_ASSERT((ea & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -
> -	mfc_getllar(ls, ea, 0, 0);
> -	mfc_read_atomic_status();
> -}
> -
> -static inline int atomic_put(void *ls, uint64_t ea)
> -{
> -	MARS_ASSERT(((uintptr_t)ls & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -	MARS_ASSERT((ea & MARS_ATOMIC_ALIGNMENT_MASK) == 0);
> -
> -	spu_dsync();
> -	mfc_putllc(ls, ea, 0, 0);
> -	return mfc_read_atomic_status() & MFC_PUTLLC_STATUS;
> -}
> -
> -#if defined(__cplusplus)
> -}
> -#endif
> -
> -#endif
> --- a/src/host/lib/mars_mutex.c
> +++ b/src/host/lib/mars_mutex.c
> @@ -35,8 +35,9 @@
>   * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
>   */
>  
> +#include <ppu_intrinsics.h>
> +
>  #include "mars/mars_mutex.h"
> -#include "mars/mars_atomic.h"
>  #include "mars/mars_error.h"
>  #include "mars/mars_debug.h"
>  
> @@ -47,6 +48,7 @@ int mars_mutex_initialize(struct mars_mu
>  			MARS_ERROR_ALIGN);
>  
>  	mutex->lock = MARS_MUTEX_UNLOCKED;
> +	__lwsync();
>  
>  	return MARS_SUCCESS;
>  }
> @@ -59,10 +61,10 @@ int mars_mutex_lock(struct mars_mutex *m
>  
>  	do {
>  		do {
> -		} while (atomic_get(&mutex->lock) == MARS_MUTEX_LOCKED);
> -	} while (!atomic_put(&mutex->lock, MARS_MUTEX_LOCKED));
> +		} while (__lwarx(&mutex->lock) == MARS_MUTEX_LOCKED);
> +	} while (!__stwcx(&mutex->lock, MARS_MUTEX_LOCKED));
>  
> -	atomic_sync();
> +	__isync();
>  
>  	return MARS_SUCCESS;
>  }
> @@ -74,6 +76,7 @@ int mars_mutex_unlock(struct mars_mutex 
>  			MARS_ERROR_ALIGN);
>  	MARS_CHECK_RET(mutex->lock == MARS_MUTEX_LOCKED, MARS_ERROR_STATE);
>  
> +	__lwsync();
>  	mutex->lock = MARS_MUTEX_UNLOCKED;
>  
>  	return MARS_SUCCESS;
> --- a/src/mpu/lib/mars_mutex.c
> +++ b/src/mpu/lib/mars_mutex.c
> @@ -35,8 +35,9 @@
>   * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
>   */
>  
> +#include <spu_mfcio.h>
> +
>  #include "mars/mars_mutex.h"
> -#include "mars/mars_atomic.h"
>  #include "mars/mars_dma.h"
>  #include "mars/mars_error.h"
>  #include "mars/mars_debug.h"
> @@ -76,23 +77,34 @@ int mars_mutex_lock_get(uint64_t mutex_e
>  	MARS_CHECK_RET(((uintptr_t)mutex & MARS_MUTEX_ALIGN_MASK) == 0,
>  			MARS_ERROR_ALIGN);
>  
> -	int status;
> +	int status, mask;
> +
> +	/* save event mask */
> +	mask = spu_read_event_mask();
>  
> -	atomic_event_setup();
> +	/* set event mask for the lost event */
> +	spu_write_event_mask(MFC_LLR_LOST_EVENT);
>  
>  	do {
> -		atomic_get(mutex, mutex_ea);
> +		mfc_getllar(mutex, mutex_ea, 0, 0);
> +		mfc_read_atomic_status();
>  
>  		if (mutex->lock == MARS_MUTEX_LOCKED) {
> -			atomic_event_wait();
> -			status = 1;
> +			spu_read_event_status();
> +			spu_write_event_ack(MFC_LLR_LOST_EVENT);
> +			status = MFC_PUTLLC_STATUS;
>  		} else {
>  			mutex->lock = MARS_MUTEX_LOCKED;
> -			status = atomic_put(mutex, mutex_ea);
> +			mfc_putllc(mutex, mutex_ea, 0, 0);
> +			status = mfc_read_atomic_status() & MFC_PUTLLC_STATUS;
>  		}
>  	} while (status);
>  
> -	atomic_event_restore();
> +	/* restore event mask */
> +	spu_write_event_mask(mask);
> +
> +	/* clear any remnant lost event */
> +	spu_write_event_ack(MFC_LLR_LOST_EVENT);
>  
>  	return MARS_SUCCESS;
>  }
> 
> 

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list