[Cbe-oss-dev] [PATCH 02/22]MARS/base: context cleanup

Yuji Mano yuji.mano at am.sony.com
Fri Mar 20 07:53:48 EST 2009


This cleans up some of the context initialization code in preparation for next
patch.

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

--- a/base/src/host/lib/context.c
+++ b/base/src/host/lib/context.c
@@ -75,20 +75,21 @@ static void kernel_ticks_sync(uint64_t k
 	mars_ea_put_uint32(flag_ea, MARS_KERNEL_TICKS_FLAG_SYNC_END);
 }
 
-static int mpu_single_context_create(struct mars_context *mars, int index)
+static int kernel_params_init(struct mars_context *mars, uint64_t params_ea,
+			      uint16_t kernel_id)
 {
-	int ret;
-	uint64_t params_ea = mars->kernel_params_ea +
-		sizeof(struct mars_kernel_params) * index;
 	struct mars_kernel_params *params =
 		mars_ea_work_area_get(params_ea,
 				      MARS_KERNEL_PARAMS_ALIGN,
 				      sizeof(struct mars_kernel_params));
 
+	if (!params)
+		return MARS_ERROR_MEMORY;
+
 	/* zero kernel params */
 	memset(params, 0, sizeof(struct mars_kernel_params));
 
-	params->kernel_id = index;
+	params->kernel_id = kernel_id;
 	params->mars_context_ea = mars_ptr_to_ea(mars);
 	params->workload_queue_ea = mars->workload_queue_ea;
 
@@ -96,26 +97,34 @@ static int mpu_single_context_create(str
 	mars_ea_put(params_ea, params, sizeof(struct mars_kernel_params));
 	mars_ea_sync();
 
-	ret = mars_mpu_run(&mars->mpu_contexts[index], params_ea);
-	if (ret != MARS_SUCCESS)
-		return ret;
-
-	kernel_ticks_sync(params_ea +
-			  offsetof(struct mars_kernel_params, kernel_ticks));
-
 	return MARS_SUCCESS;
 }
 
 static int mpu_contexts_create(struct mars_context *mars, uint32_t num_mpus)
 {
 	int ret;
-	unsigned int i;
+	uint16_t i;
 
 	/* create threads for each mpu context */
 	for (i = mars->mpu_context_count; i < num_mpus; i++) {
-		ret = mpu_single_context_create(mars, i);
+		uint64_t params_ea = mars->kernel_params_ea +
+				     sizeof(struct mars_kernel_params) * i;
+
+		/* initialize kernel params for current mpu context */
+		ret = kernel_params_init(mars, params_ea, i);
 		if (ret != MARS_SUCCESS)
 			return ret;
+
+		/* run current mpu context */
+		ret = mars_mpu_run(&mars->mpu_contexts[i], params_ea);
+		if (ret != MARS_SUCCESS)
+			return ret;
+
+		/* sync kernel ticks for current mpu context */
+		kernel_ticks_sync(params_ea +
+			offsetof(struct mars_kernel_params, kernel_ticks));
+
+		/* increment mars context mpu context count */
 		mars->mpu_context_count++;
 	}
 
@@ -125,15 +134,11 @@ static int mpu_contexts_create(struct ma
 static int mpu_contexts_destroy(struct mars_context *mars)
 {
 	int ret;
-	unsigned int i;
-
-	/* shutdown the workload queue so mpu context threads exit */
-	ret = mars_workload_queue_exit(mars);
-	if (ret != MARS_SUCCESS)
-		return ret;
+	uint16_t i;
 
-	/* join all mpu context threads */
+	/* destroy all mpu contexts */
 	for (i = 0; i < mars->mpu_context_count; i++) {
+		/* wait for mpu context threads */
 		ret = mars_mpu_wait(&mars->mpu_contexts[i]);
 		if (ret != MARS_SUCCESS)
 			return ret;
@@ -277,6 +282,11 @@ int mars_context_destroy(struct mars_con
 	if (mars->reference_count)
 		goto done;
 
+	/* shutdown the workload queue so mpu context threads exit */
+	ret = mars_workload_queue_exit(mars);
+	if (ret != MARS_SUCCESS)
+		return ret;
+
 	/* destroy mpu contexts */
 	if (mars->mpu_context_count) {
 		ret = mpu_contexts_destroy(mars);






More information about the cbe-oss-dev mailing list