aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazunori Asayama <asayama@sm.sony.co.jp>2009-03-13 18:18:18 -0700
committerYuji Mano <yuji.mano@am.sony.com>2009-03-17 11:07:44 -0700
commit24a37c16d752aeae65abddae7e0e841c3d224336 (patch)
treec41ccbe3f1e56580bb5eca234f436762fe086aff
parentc99278833e2521a20b968e3a0b89b501996d59e1 (diff)
downloadmars-src-24a37c16d752aeae65abddae7e0e841c3d224336.tar.gz
base: MPU mutex reduce code size
Reduce code size of MPU mutex This patch reduces code size of mutex on MPU side by simplifying algorithm and sharing code. Signed-off-by: Kazunori Asayama <asayama@sm.sony.co.jp> Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
-rw-r--r--base/src/mpu/kernel/mutex.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/base/src/mpu/kernel/mutex.c b/base/src/mpu/kernel/mutex.c
index 8dc6009..3608a06 100644
--- a/base/src/mpu/kernel/mutex.c
+++ b/base/src/mpu/kernel/mutex.c
@@ -43,11 +43,15 @@
#include "kernel_internal_types.h"
+#define MARS_MUTEX_STATE_NONE 0
+#define MARS_MUTEX_STATE_DONE 2
+
static struct mars_mutex mutex_buffer;
int mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex)
{
- int status, mask, done = 0;
+ int mask;
+ int state = MARS_MUTEX_STATE_NONE;
uint8_t id = 0;
/* check function params */
@@ -67,45 +71,32 @@ int mutex_lock_get(uint64_t mutex_ea, struct mars_mutex *mutex)
spu_write_event_mask(MFC_LLR_LOST_EVENT);
/* update waiting state */
- do {
- mfc_getllar(mutex, mutex_ea, 0, 0);
- mfc_read_atomic_status();
-
- if (mutex->status.lock == MARS_MUTEX_UNLOCKED &&
- mutex->status.current_id == mutex->status.next_id) {
- /* no other thread waiting for mutex so get lock now */
- mutex->status.lock = MARS_MUTEX_LOCKED;
- done = 1;
- }
- else {
- /* otherwise update waiting state */
- id = mutex->status.next_id++;
- done = 0;
- }
-
- spu_dsync();
- mfc_putllc(mutex, mutex_ea, 0, 0);
- status = mfc_read_atomic_status() & MFC_PUTLLC_STATUS;
- } while (status);
-
- while (!done) {
+ while (state != MARS_MUTEX_STATE_DONE) {
mfc_getllar(mutex, mutex_ea, 0, 0);
mfc_read_atomic_status();
- if (mutex->status.lock == MARS_MUTEX_LOCKED ||
- mutex->status.current_id != id) {
+ if (state &&
+ (mutex->status.lock == MARS_MUTEX_LOCKED ||
+ mutex->status.current_id != id)) {
/* wait until mutex is released */
spu_read_event_status();
spu_write_event_ack(MFC_LLR_LOST_EVENT);
}
else {
- /* get lock */
- mutex->status.lock = MARS_MUTEX_LOCKED;
- mutex->status.current_id++;
+ if (state) {
+ /* get lock */
+ mutex->status.lock = MARS_MUTEX_LOCKED;
+ mutex->status.current_id++;
+ }
+ else {
+ /* get my id */
+ id = mutex->status.next_id++;
+ }
spu_dsync();
mfc_putllc(mutex, mutex_ea, 0, 0);
- done = !(mfc_read_atomic_status() & MFC_PUTLLC_STATUS);
+ if (!(mfc_read_atomic_status() & MFC_PUTLLC_STATUS))
+ state++;
}
}