[Cbe-oss-dev] [PATCH 19/22]MARS/task: No busy wait

Yuji Mano yuji.mano at am.sony.com
Wed Jan 21 11:30:15 EST 2009


From: Kazunori Asayama <asayama at sm.sony.co.jp>

Remove busy loops from host side code (task module)

This patch removes busy loops from host side code by using futex.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/lib/task_event_flag.c |    8 ++++++++
 task/src/mpu/lib/task_queue.c      |   34 ++++++++++++++++++++++++++++------
 task/src/mpu/module/task_module.c  |    6 ++++++
 task/src/mpu/module/task_module.h  |    1 +
 4 files changed, 43 insertions(+), 6 deletions(-)

--- a/task/src/mpu/lib/task_event_flag.c
+++ b/task/src/mpu/lib/task_event_flag.c
@@ -35,6 +35,7 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <stddef.h>
 #include <string.h>
 
 #include "config.h"
@@ -95,6 +96,13 @@ int mars_task_event_flag_set(uint64_t ev
 	/* save current set bits */
 	bits = event_flag.bits;
 
+	/* signal the waiting host */
+	if (event_flag.direction != MARS_TASK_EVENT_FLAG_HOST_TO_MPU &&
+	    event_flag.direction != MARS_TASK_EVENT_FLAG_MPU_TO_MPU)
+		(*mars_task_module_syscalls->signal_host)(
+			event_flag_ea +
+			offsetof(struct mars_task_event_flag, bits));
+
 	/* search through wait list for tasks to be signalled */
 	for (i = 0; i < event_flag.wait_count; i++) {
 		/* check condition based on wait mode */
--- a/task/src/mpu/lib/task_queue.c
+++ b/task/src/mpu/lib/task_queue.c
@@ -35,6 +35,7 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <stddef.h>
 #include <string.h>
 
 #include "config.h"
@@ -84,6 +85,13 @@ int mars_task_queue_clear(uint64_t queue
 
 	mars_mutex_lock_get(queue_ea, (struct mars_mutex *)&queue);
 
+	/* signal the waiting host */
+	if (queue.count == queue.depth &&
+	    queue.direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
+	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
+		(*mars_task_module_syscalls->signal_host)(
+			queue_ea + offsetof(struct mars_task_queue, count));
+
 	/* signal all waiting tasks that queue is ready for push */
 	for (i = 0; i < queue.push_wait_count; i++)
 		(*mars_task_module_syscalls->signal_send)
@@ -102,8 +110,15 @@ int mars_task_queue_clear(uint64_t queue
 	return MARS_SUCCESS;
 }
 
-static void push_update(void)
+static void push_update(uint64_t queue_ea)
 {
+	/* signal the waiting host */
+	if (queue.count == 0 &&
+	    queue.direction != MARS_TASK_QUEUE_HOST_TO_MPU &&
+	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
+		(*mars_task_module_syscalls->signal_host)(
+			queue_ea + offsetof(struct mars_task_queue, count));
+
 	/* signal waiting task that queue is ready for pop */
 	if (queue.pop_wait_count) {
 		/* signal waiting task */
@@ -198,7 +213,7 @@ static int push(uint64_t queue_ea, const
 	mars_dma_wait(tag);
 
 	/* update queue data */
-	push_update();
+	push_update(queue_ea);
 
 	mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
@@ -230,7 +245,7 @@ int mars_task_queue_push_end(uint64_t qu
 	mars_dma_wait(tag);
 
 	/* update queue data */
-	push_update();
+	push_update(queue_ea);
 
 	mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
@@ -248,8 +263,15 @@ int mars_task_queue_try_push_begin(uint6
 	return push(queue_ea, data, 1, 1, tag);
 }
 
-static void pop_update(void)
+static void pop_update(uint64_t queue_ea)
 {
+	/* signal the waiting host */
+	if (queue.count == queue.depth &&
+	    queue.direction != MARS_TASK_QUEUE_MPU_TO_HOST &&
+	    queue.direction != MARS_TASK_QUEUE_MPU_TO_MPU)
+		(*mars_task_module_syscalls->signal_host)(
+			queue_ea + offsetof(struct mars_task_queue, count));
+
 	/* signal waiting task that queue is ready for push */
 	if (queue.push_wait_count) {
 		/* signal waiting task */
@@ -344,7 +366,7 @@ static int pop(uint64_t queue_ea, void *
 
 	/* update queue data only if this is not a peek operation */
 	if (!peek)
-		pop_update();
+		pop_update(queue_ea);
 
 	mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
@@ -375,7 +397,7 @@ int mars_task_queue_pop_end(uint64_t que
 	mars_dma_wait(tag);
 
 	/* update queue data */
-	pop_update();
+	pop_update(queue_ea);
 
 	mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue);
 
--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -400,6 +400,11 @@ static int task_try_wait(uint16_t worklo
 	return mars_module_workload_wait_reset();
 }
 
+static int task_signal_host(uint64_t watch_point_ea)
+{
+	return mars_module_host_signal_send(watch_point_ea);
+}
+
 static int task_signal_send(uint16_t workload_id)
 {
 	return mars_module_workload_signal_set(workload_id);
@@ -434,6 +439,7 @@ static struct mars_task_module_syscalls 
 	task_schedule,
 	task_wait,
 	task_try_wait,
+	task_signal_host,
 	task_signal_send,
 	task_signal_wait,
 	task_signal_try_wait
--- a/task/src/mpu/module/task_module.h
+++ b/task/src/mpu/module/task_module.h
@@ -58,6 +58,7 @@ struct mars_task_module_syscalls {
 			    uint8_t priority);
 	int	(*wait)(uint16_t workload_id);
 	int	(*try_wait)(uint16_t workload_id);
+	int	(*signal_host)(uint64_t watch_point_ea);
 	int	(*signal_send)(uint16_t workload_id);
 	int	(*signal_wait)(void);
 	int	(*signal_try_wait)(void);






More information about the cbe-oss-dev mailing list