[Cbe-oss-dev] [PATCH 05/23]MARS/base: mpu mutex reduce code size

Yuji Mano yuji.mano at am.sony.com
Sat Mar 14 12:18:18 EST 2009


From: Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>

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 at sm.sony.co.jp>
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/mpu/kernel/mutex.c |   49 +++++++++++++++++---------------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

--- 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, st
 	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++;
 		}
 	}
 






More information about the cbe-oss-dev mailing list