[Cbe-oss-dev] [PATCH 08/11]MARS: Workload queue api add set flag

Yuji Mano yuji.mano at am.sony.com
Fri Sep 12 05:34:59 EST 2008


This adds a new internal API workload_queue_exit that sets the exit flag inside
the workload queue header.

Previously this was done inside the workload_queue_finalize function, but since
the MARS context must first join all mpu context threads before finalizing the
workload queue, a separate function to set the exit flag for those threads is
required.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 include/common/mars/mars_kernel_types.h   |    3 ---
 include/common/mars/mars_workload_types.h |    6 +++++-
 include/host/mars/mars_workload_queue.h   |    1 +
 src/host/lib/mars_context.c               |   28 ++++++++++++++++------------
 src/host/lib/mars_workload_queue.c        |   11 +++++++++--
 src/mpu/kernel/mars_kernel_scheduler.c    |    2 +-
 6 files changed, 32 insertions(+), 19 deletions(-)

--- a/include/common/mars/mars_kernel_types.h
+++ b/include/common/mars/mars_kernel_types.h
@@ -44,9 +44,6 @@ extern "C" {
 
 #include <stdint.h>
 
-#define MARS_FLAG_NONE			0x0
-#define MARS_FLAG_EXIT			0x1
-
 #define MARS_KERNEL_PARAMS_ALIGN	128
 
 /* mars kernel parameters */
--- a/include/common/mars/mars_workload_types.h
+++ b/include/common/mars/mars_workload_types.h
@@ -64,8 +64,8 @@ extern "C" {
 #define MARS_WORKLOAD_COUNTER_MIN		0x0000	/* minimum counter */
 #define MARS_WORKLOAD_COUNTER_MAX		0xffff	/* maximum counter */
 
-#define MARS_WORKLOAD_SIGNAL_ON			0x1	/* signal set on */
 #define MARS_WORKLOAD_SIGNAL_OFF		0x0	/* signal set off */
+#define MARS_WORKLOAD_SIGNAL_ON			0x1	/* signal set on */
 
 #define MARS_WORKLOAD_PER_BLOCK			15	/* wl/block */
 #define MARS_WORKLOAD_NUM_BLOCKS		100	/* total blocks */
@@ -73,10 +73,14 @@ extern "C" {
 
 #define MARS_WORKLOAD_CONTEXT_SIZE		128	/* size of 128 bytes */
 #define MARS_WORKLOAD_CONTEXT_ALIGN		128	/* align to 128 bytes */
+
 #define MARS_WORKLOAD_QUEUE_ALIGN		128	/* align to 128 bytes */
 #define MARS_WORKLOAD_QUEUE_HEADER_ALIGN	128	/* align to 128 bytes */
 #define MARS_WORKLOAD_QUEUE_BLOCK_ALIGN		128	/* align to 128 bytes */
 
+#define MARS_WORKLOAD_QUEUE_FLAG_NONE		0x0	/* no flag set */
+#define MARS_WORKLOAD_QUEUE_FLAG_EXIT		0x1	/* exit flag */
+
 /*
  * MARS workload queue block bits
  * ----------------------------------------------------------------------------
--- a/include/host/mars/mars_workload_queue.h
+++ b/include/host/mars/mars_workload_queue.h
@@ -46,6 +46,7 @@ extern "C" {
 
 int workload_queue_initialize(struct mars_workload_queue *queue);
 int workload_queue_finalize(struct mars_workload_queue *queue);
+int workload_queue_exit(struct mars_workload_queue *queue);
 
 int workload_queue_add_begin(struct mars_workload_queue *queue, uint16_t *id,
 				uint8_t type,
--- a/src/host/lib/mars_context.c
+++ b/src/host/lib/mars_context.c
@@ -116,6 +116,10 @@ static int destroy_mpu_contexts(struct m
 	void *p_ret;
 	unsigned int i;
 
+	/* shutdown the workload queue so mpu context threads exit */
+	ret = workload_queue_exit(mars->workload_queue);
+	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+
 	/* join all mpu context threads */
 	for (i = 0; i < mars->mpu_context_count; i++) {
 		ret = pthread_join(mars->mpu_context_threads[i], &p_ret);
@@ -155,16 +159,16 @@ int mars_initialize(struct mars_context 
 	MARS_CHECK_CLEANUP_RET(mars->workload_queue, mars_finalize(mars),
 				MARS_ERROR_MEMORY);
 
-	/* initialize workload queue */
-	ret = workload_queue_initialize(mars->workload_queue);
-	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);
-
 	/* allocate mpu context thread array */
 	mars->mpu_context_threads = (pthread_t *)
 		malloc(sizeof(pthread_t) * num_mpus);
 	MARS_CHECK_CLEANUP_RET(mars->mpu_context_threads, mars_finalize(mars),
 				MARS_ERROR_MEMORY);
 
+	/* initialize workload queue */
+	ret = workload_queue_initialize(mars->workload_queue);
+	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);
+
 	/* create contexts */
 	ret = create_mpu_contexts(mars, num_mpus);
 	MARS_CHECK_CLEANUP_RET(ret == MARS_SUCCESS, mars_finalize(mars), ret);
@@ -178,22 +182,22 @@ int mars_finalize(struct mars_context *m
 
 	int ret;
 
-	/* finalize workload queue */
-	if (mars->workload_queue) {
-		ret = workload_queue_finalize(mars->workload_queue);
-		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
-	}
-
 	/* destroy contexts */
 	if (mars->mpu_context_count) {
 		ret = destroy_mpu_contexts(mars);
 		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
 	}
 
+	/* finalize workload queue */
+	if (mars->workload_queue) {
+		ret = workload_queue_finalize(mars->workload_queue);
+		MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
+	}
+
 	/* free allocated memory */
-	free(mars->kernel_params);
-	free(mars->workload_queue);
 	free(mars->mpu_context_threads);
+	free(mars->workload_queue);
+	free(mars->kernel_params);
 
 	/* zero context */
 	memset(mars, 0, sizeof(struct mars_context));
--- a/src/host/lib/mars_workload_queue.c
+++ b/src/host/lib/mars_workload_queue.c
@@ -51,9 +51,9 @@ int workload_queue_initialize(struct mar
 	int block;
 	int index;
 
+	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE;
 	queue->header.queue_ea = (uint64_t)(uintptr_t)queue;
 	queue->header.context_ea = (uint64_t)(uintptr_t)&queue->context;
-	queue->header.flag = MARS_FLAG_NONE;
 
 	/* initialize workload queue blocks */
 	for (block = 0; block < MARS_WORKLOAD_NUM_BLOCKS; block++) {
@@ -109,7 +109,14 @@ int workload_queue_finalize(struct mars_
 	/* found some task left in workload queue */
 	MARS_CHECK_RET(id < MARS_WORKLOAD_MAX, MARS_ERROR_STATE);
 
-	queue->header.flag = MARS_FLAG_EXIT;
+	return MARS_SUCCESS;
+}
+
+int workload_queue_exit(struct mars_workload_queue *queue)
+{
+	MARS_CHECK_RET(queue, MARS_ERROR_NULL);
+
+	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_EXIT;
 
 	return MARS_SUCCESS;
 }
--- a/src/mpu/kernel/mars_kernel_scheduler.c
+++ b/src/mpu/kernel/mars_kernel_scheduler.c
@@ -244,7 +244,7 @@ int scheduler(void)
 			MARS_DMA_TAG);
 
 	/* return exit status if exit flag is set from host */
-	if (queue_header.flag == MARS_FLAG_EXIT)
+	if (queue_header.flag == MARS_WORKLOAD_QUEUE_FLAG_EXIT)
 		return MARS_KERNEL_STATUS_EXIT;
 
 	/* reserve next workload to run or return idle status if none found */






More information about the cbe-oss-dev mailing list