diff options
author | Yuji Mano <yuji.mano@am.sony.com> | 2009-01-20 16:27:53 -0800 |
---|---|---|
committer | Yuji Mano <yuji.mano@am.sony.com> | 2009-01-23 10:59:04 -0800 |
commit | c427278ba15443f4c699b082792900cc46ddbc05 (patch) | |
tree | ca660178b4f658473090138e82ab2643a2c0d392 | |
parent | df7def06141351af7ce310a8ae46df3d449d1ec4 (diff) | |
download | mars-src-c427278ba15443f4c699b082792900cc46ddbc05.tar.gz |
base: Mutex cleanup
This fixes cleansup the mutex implementation to reduce code size.
It removes the mars_mutex_lock/unlock api that used a static mutex instance.
Caller must always supply the pointer to an allocated mutex structure.
Remove dependency on base library dma routines from the mutex implementations.
Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
Acked-by: Kazunori Asayama <asayama@sm.sony.co.jp>
-rw-r--r-- | base/include/host/mars/mutex.h | 53 | ||||
-rw-r--r-- | base/include/mpu/mars/mutex.h | 53 | ||||
-rw-r--r-- | base/src/mpu/lib/mutex.c | 21 | ||||
-rw-r--r-- | doxygen/src/doxygen | 4 | ||||
-rw-r--r-- | samples/mutex/mpu_task.c | 5 |
5 files changed, 55 insertions, 81 deletions
diff --git a/base/include/host/mars/mutex.h b/base/include/host/mars/mutex.h index 8bc4df0..a6a0268 100644 --- a/base/include/host/mars/mutex.h +++ b/base/include/host/mars/mutex.h @@ -57,7 +57,7 @@ extern "C" { * This function creates a mutex instance that can be locked or unlocked * from both host and MPU to restrict concurrent accesses. * - * \param[in] mutex_ea - address of 64-bit address of mutex instance + * \param[in] mutex_ea - ea of mutex instance * \return * MARS_SUCCESS - successfully created mutex * \n MARS_ERROR_NULL - null pointer is specified @@ -71,7 +71,7 @@ int mars_mutex_create(uint64_t *mutex_ea); * * This function destroys a mutex instance. * - * \param[in] mutex_ea - 64-bit address of mutex instance + * \param[in] mutex_ea - ea of mutex instance * \return * MARS_SUCCESS - successfully destroyed mutex * \n MARS_ERROR_NULL - null pointer is specified @@ -86,7 +86,7 @@ int mars_mutex_destroy(uint64_t mutex_ea); * This function resets a mutex instance and forces it into an unlocked state * regardless of whether it is locked or unlocked. * - * \param[in] mutex_ea - 64-bit address of mutex instance + * \param[in] mutex_ea - ea of mutex instance * \return * MARS_SUCCESS - successfully reset mutex * \n MARS_ERROR_NULL - null pointer is specified @@ -100,7 +100,7 @@ int mars_mutex_reset(uint64_t mutex_ea); * * This function locks a mutex and blocks other requests to lock it. * - * \param[in] mutex_ea - 64-bit address of mutex instance + * \param[in] mutex_ea - ea of mutex instance * \return * MARS_SUCCESS - successfully locked mutex * \n MARS_ERROR_NULL - null pointer is specified @@ -114,7 +114,7 @@ int mars_mutex_lock(uint64_t mutex_ea); * * This function unlocks a previously locked mutex to allow other lock requests. * - * \param[in] mutex_ea - 64-bit address of mutex instance + * \param[in] mutex_ea - ea of mutex instance * \return * MARS_SUCCESS - successfully unlocked mutex * \n MARS_ERROR_NULL - null pointer is specified @@ -123,11 +123,48 @@ int mars_mutex_lock(uint64_t mutex_ea); */ int mars_mutex_unlock(uint64_t mutex_ea); - -/* lock the mutex, then copy the mutex from EA to host */ +/** + * \ingroup group_mars_mutex + * \brief <b>[host/MPU]</b> Locks a mutex. + * + * This function locks a mutex and blocks other requests to lock it. + * It also loads the mutex instance from the effective address specified + * into the local mutex instance. + * + * \note The <b>[host]</b> call should only be used when + * MARS_ENABLE_DISCRETE_SHARED_MEMORY is enabled. Otherwise, the mutex + * parameter is ignored and the function behaves the same as + * \ref mars_mutex_lock. + * + * \param[in] mutex_ea - ea of mutex instance to lock + * \param[in] mutex - pointer to local mutex instance + * \return + * MARS_SUCCESS - successfully locked mutex + * \n MARS_ERROR_NULL - ea is 0 or mutex is NULL + * \n MARS_ERROR_ALIGN - ea or mutex not aligned properly + */ int mars_mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex); -/* copy the mutex from host to EA, then unlock lock the mutex */ +/** + * \ingroup group_mars_mutex + * \brief <b>[host/MPU]</b> Unlocks a mutex. + * + * This function unlocks a previously locked mutex to allow other lock requests. + * It also stores the local mutex instance into the effective address specified. + * + * \note The <b>[host]</b> call should only be used when + * MARS_ENABLE_DISCRETE_SHARED_MEMORY is enabled. Otherwise, the mutex + * parameter is ignored and the function behaves the same as + * \ref mars_mutex_unlock. + * + * \param[in] mutex_ea - ea of mutex instance to unlock + * \param[in] mutex - pointer to local mutex instance + * \return + * MARS_SUCCESS - successfully unlocked mutex + * \n MARS_ERROR_NULL - ea is 0 or mutex is NULL + * \n MARS_ERROR_ALIGN - ea or mutex not aligned properly + * \n MARS_ERROR_STATE - instance not in locked state + */ int mars_mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex); #if defined(__cplusplus) diff --git a/base/include/mpu/mars/mutex.h b/base/include/mpu/mars/mutex.h index 1173ded..8ea31c9 100644 --- a/base/include/mpu/mars/mutex.h +++ b/base/include/mpu/mars/mutex.h @@ -53,64 +53,11 @@ extern "C" { /** * \ingroup group_mars_mutex - * \brief <b>[MPU]</b> Locks a mutex. - * - * This function locks a mutex and blocks other requests to lock it. - * - * \param[in] mutex_ea - ea of mutex instance to lock - * \return - * MARS_SUCCESS - successfully locked mutex - * \n MARS_ERROR_NULL - ea is 0 - * \n MARS_ERROR_ALIGN - ea not aligned properly - */ -int mars_mutex_lock(uint64_t mutex_ea); - -/** - * \ingroup group_mars_mutex - * \brief <b>[MPU]</b> Unlocks a mutex. - * - * This function unlocks a previously locked mutex to allow other lock requests. - * - * \param[in] mutex_ea - ea of mutex instance to unlock - * \return - * MARS_SUCCESS - successfully unlocked mutex - * \n MARS_ERROR_NULL - ea is 0 - * \n MARS_ERROR_ALIGN - ea not aligned properly - * \n MARS_ERROR_STATE - instance not in locked state - */ -int mars_mutex_unlock(uint64_t mutex_ea); - -/** - * \ingroup group_mars_mutex - * \brief <b>[MPU]</b> Locks a mutex. - * - * This function locks a mutex and blocks other requests to lock it. - * It also loads the mutex instance from the effective address specified - * into the local mutex instance. - * - * \param[in] mutex_ea - ea of mutex instance to lock - * \param[in] mutex - pointer to local mutex instance - * \return - * MARS_SUCCESS - successfully locked mutex - * \n MARS_ERROR_NULL - ea is 0 or mutex is NULL - * \n MARS_ERROR_ALIGN - ea or mutex not aligned properly */ int mars_mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex); /** * \ingroup group_mars_mutex - * \brief <b>[MPU]</b> Unlocks a mutex. - * - * This function unlocks a previously locked mutex to allow other lock requests. - * It also stores the local mutex instance into the effective address specified. - * - * \param[in] mutex_ea - ea of mutex instance to unlock - * \param[in] mutex - pointer to local mutex instance - * \return - * MARS_SUCCESS - successfully unlocked mutex - * \n MARS_ERROR_NULL - ea is 0 or mutex is NULL - * \n MARS_ERROR_ALIGN - ea or mutex not aligned properly - * \n MARS_ERROR_STATE - instance not in locked state */ int mars_mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex); diff --git a/base/src/mpu/lib/mutex.c b/base/src/mpu/lib/mutex.c index cdaa0b5..fd02ab3 100644 --- a/base/src/mpu/lib/mutex.c +++ b/base/src/mpu/lib/mutex.c @@ -39,22 +39,9 @@ #include "config.h" -#include "mars/dma.h" #include "mars/error.h" #include "mars/mutex.h" -static struct mars_mutex mutex; - -int mars_mutex_lock(uint64_t mutex_ea) -{ - return mars_mutex_lock_get(mutex_ea, &mutex); -} - -int mars_mutex_unlock(uint64_t mutex_ea) -{ - return mars_mutex_unlock_put(mutex_ea, &mutex); -} - int mars_mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex) { int status, mask; @@ -116,9 +103,11 @@ int mars_mutex_unlock_put(uint64_t mutex_ea, struct mars_mutex *mutex) mutex->lock = MARS_MUTEX_UNLOCKED; - mars_dma_sync(MARS_DMA_TAG); - mars_dma_put_and_wait(mutex, mutex_ea, sizeof(struct mars_mutex), - MARS_DMA_TAG); + mfc_sync(0); + mfc_put(mutex, mutex_ea, sizeof(struct mars_mutex), 0, 0, 0); + mfc_write_tag_mask(1 << 0); + mfc_write_tag_update_all(); + mfc_read_tag_status(); return MARS_SUCCESS; } diff --git a/doxygen/src/doxygen b/doxygen/src/doxygen index 8267bc9..259901a 100644 --- a/doxygen/src/doxygen +++ b/doxygen/src/doxygen @@ -4329,7 +4329,9 @@ This section will describe the MARS API. - \ref mars_mutex_destroy - \ref mars_mutex_reset - \ref mars_mutex_lock + - \ref mars_mutex_lock_get - \ref mars_mutex_unlock + - \ref mars_mutex_unlock_put - Workload Model Management - \ref mars_workload_queue_add_begin - \ref mars_workload_queue_add_end @@ -4387,9 +4389,7 @@ This section will describe the MARS API. - \ref mars_dma_wait - \ref mars_dma_sync - Mutex Management - - \ref mars_mutex_lock - \ref mars_mutex_lock_get - - \ref mars_mutex_unlock - \ref mars_mutex_unlock_put - Workload Model Management - \ref mars_module_main diff --git a/samples/mutex/mpu_task.c b/samples/mutex/mpu_task.c index a5b2873..a4ed3ad 100644 --- a/samples/mutex/mpu_task.c +++ b/samples/mutex/mpu_task.c @@ -28,6 +28,7 @@ int mars_task_main(const struct mars_task_args *task_args) { int ret; + static struct mars_mutex mutex; uint64_t mutex_ea = task_args->type.u64[0]; uint64_t shared_resource_ea = task_args->type.u64[1]; uint32_t shared_resource __attribute__((aligned(16))); @@ -35,7 +36,7 @@ int mars_task_main(const struct mars_task_args *task_args) printf("MPU(%d): %s - Started\n", mars_task_get_kernel_id(), mars_task_get_name()); - ret = mars_mutex_lock(mutex_ea); + ret = mars_mutex_lock_get(mutex_ea, &mutex); if (ret) { printf("MARS mutex lock failed! (%d)\n", ret); return 1; @@ -61,7 +62,7 @@ int mars_task_main(const struct mars_task_args *task_args) printf("MPU(%d): %s - Unlocking Mutex\n", mars_task_get_kernel_id(), mars_task_get_name()); - ret = mars_mutex_unlock(mutex_ea); + ret = mars_mutex_unlock_put(mutex_ea, &mutex); if (ret) { printf("MARS mutex unlock failed! (%d)\n", ret); return 1; |