[Cbe-oss-dev] [PATCH 01/13]MARS/core: Refactor shared context management

Yuji Mano yuji.mano at am.sony.com
Fri Dec 12 15:33:00 EST 2008


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

Refactor shared context management routine

This patch separates shared context management routine from the core
MARS context operation part.

This change is a preparation for NUMA support.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
 core/src/host/lib/Makefile.am              |    1 
 core/src/host/lib/context.c                |   22 ++++----
 core/src/host/lib/context_internal_types.h |    3 +
 core/src/host/lib/shared_context.c         |   74 +++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+), 11 deletions(-)

Index: mars-src/core/src/host/lib/Makefile.am
===================================================================
--- mars-src.orig/core/src/host/lib/Makefile.am
+++ mars-src/core/src/host/lib/Makefile.am
@@ -103,6 +103,7 @@ libmars_core_la_SOURCES = \
 	alloc.c \
 	context.c \
 	context_internal_types.h \
+	shared_context.c \
 	workload_queue.c
 
 nodist_libmars_core_la_SOURCES = \
Index: mars-src/core/src/host/lib/shared_context.c
===================================================================
--- /dev/null
+++ mars-src/core/src/host/lib/shared_context.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2008 Sony Corporation of America
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this Library and associated documentation files (the
+ * "Library"), to deal in the Library without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Library, and to
+ * permit persons to whom the Library is furnished to do so, subject to
+ * the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be
+ *  included in all copies or substantial portions of the Library.
+ *
+ *  If you modify the Library, you may copy and distribute your modified
+ *  version of the Library in object code or as an executable provided
+ *  that you also do one of the following:
+ *
+ *   Accompany the modified version of the Library with the complete
+ *   corresponding machine-readable source code for the modified version
+ *   of the Library; or,
+ *
+ *   Accompany the modified version of the Library with a written offer
+ *   for a complete machine-readable copy of the corresponding source
+ *   code of the modified version of the Library.
+ *
+ *
+ * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
+ */
+
+
+#include "config.h"
+
+#include "mars/context.h"
+#include "mars/error.h"
+
+#include "context_internal_types.h"
+
+/* Note that it is assumed that global data access in this file is
+ * protected by caller's lock.
+ */
+static struct mars_context *shared_context;
+
+int mars_shared_context_get(struct mars_context **mars)
+{
+	*mars = shared_context;
+
+	if (!*mars)
+		return MARS_ERROR_INTERNAL;
+
+	return MARS_SUCCESS;
+}
+
+int mars_shared_context_register(struct mars_context *mars)
+{
+	shared_context = mars;
+
+	return MARS_SUCCESS;
+}
+
+int mars_shared_context_unregister(struct mars_context *mars)
+{
+	if (mars == shared_context)
+		shared_context = NULL;
+
+	return MARS_SUCCESS;
+}
Index: mars-src/core/src/host/lib/context.c
===================================================================
--- mars-src.orig/core/src/host/lib/context.c
+++ mars-src/core/src/host/lib/context.c
@@ -48,8 +48,6 @@
 #include "context_internal_types.h"
 #include "kernel_internal_types.h"
 
-static struct mars_context *mars_shared_context;
-
 uint32_t mars_get_ticks(void)
 {
 	return __mftb() & 0xffffffff;
@@ -170,17 +168,17 @@ int mars_context_create(struct mars_cont
 		return ret;
 
 	/* shared context requested */
-	if (shared && mars_shared_context) {
+	if (shared && mars_shared_context_get(&mars) == MARS_SUCCESS) {
 		/* create any extra mpu contexts necessary */
-		ret = mpu_contexts_create(mars_shared_context, num_mpus);
+		ret = mpu_contexts_create(mars, num_mpus);
 		if (ret != MARS_SUCCESS)
 			goto error;
 
 		/* increment shared context reference count */
-		mars_shared_context->reference_count++;
+		mars->reference_count++;
 
 		/* return the shared context */
-		*mars_ret = mars_shared_context;
+		*mars_ret = mars;
 
 		goto done;
 	}
@@ -226,8 +224,11 @@ int mars_context_create(struct mars_cont
 		goto error_mpu_contexts_create;
 
 	/* set the shared context pointer */
-	if (shared)
-		mars_shared_context = mars;
+	if (shared) {
+		ret = mars_shared_context_register(mars);
+		if (ret != MARS_SUCCESS)
+			goto error_shared_context_unlock;
+	}
 
 	/* return mars context pointer */
 	*mars_ret = mars;
@@ -295,9 +296,8 @@ int mars_context_destroy(struct mars_con
 	mars_ea_free(mars->kernel_params_ea);
 	mars_free(mars);
 
-	/* check if it is the shared context pointer and set to NULL */
-	if (mars == mars_shared_context)
-		mars_shared_context = NULL;
+	/* unregister shared context */
+	mars_shared_context_unregister(mars);
 
 done:
 	/* unlock mutex */
Index: mars-src/core/src/host/lib/context_internal_types.h
===================================================================
--- mars-src.orig/core/src/host/lib/context_internal_types.h
+++ mars-src/core/src/host/lib/context_internal_types.h
@@ -69,6 +69,9 @@ int mars_mpu_max(int *num);
 int mars_mpu_run(mars_mpu_context_t *mpu, uint64_t params_ea);
 int mars_mpu_wait(mars_mpu_context_t *mpu);
 
+int mars_shared_context_get(struct mars_context **mars);
+int mars_shared_context_register(struct mars_context *mars);
+int mars_shared_context_unregister(struct mars_context *mars);
 
 extern mars_host_mutex_t mars_shared_context_lock;
 






More information about the cbe-oss-dev mailing list