[Cbe-oss-dev] [PATCH 1/5]MARS/base: host side mutex contention

Yuji Mano yuji.mano at am.sony.com
Tue Jun 16 10:03:50 EST 2009


This reduces the chances of mutex lock contention on the host-side which becomes
apparent when a large number of pthreads are created and access the mutex
simultaneously.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/host/lib/mutex_cell.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/base/src/host/lib/mutex_cell.c
+++ b/base/src/host/lib/mutex_cell.c
@@ -108,16 +108,17 @@ int mars_mutex_lock(uint64_t mutex_ea)
 	uint8_t id;
 	int retry;
 
-	if (!mutex_ea) {
+	if (!mutex_ea)
 		return MARS_ERROR_NULL;
-	}
 
 	do {
 		header.bits = __lwarx(&mutex->status);
 
 		/* get my id */
 		id = header.status.next_id++;
-	} while (!__stwcx(&mutex->status, header.bits));
+		if ((retry = !__stwcx(&mutex->status, header.bits)))
+			sched_yield();
+	} while (retry);
 
 	do {
 		header.bits = __lwarx(&mutex->status);
@@ -125,7 +126,7 @@ int mars_mutex_lock(uint64_t mutex_ea)
 		if (header.status.lock == MARS_MUTEX_LOCKED ||
 		    header.status.current_id != id) {
 			/* wait until mutex is released */
-			usleep(1);
+			sched_yield();
 			retry = 1;
 		}
 		else {






More information about the cbe-oss-dev mailing list