[Cbe-oss-dev] [PATCH 04/13]MARS/core: Numa shared context
Yuji Mano
yuji.mano at am.sony.com
Fri Dec 12 15:33:20 EST 2008
From: Kazunori Asayama <asayama at sm.sony.co.jp>
Create shared context for each node mask
This patch modifies shared context management routine to create
separate shared MARS contexts for each node mask.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
core/src/host/lib/context_internal_types.h | 2
core/src/host/lib/shared_context.c | 121 +++++++++++++++++++++++++++--
2 files changed, 115 insertions(+), 8 deletions(-)
Index: mars-src/core/src/host/lib/shared_context.c
===================================================================
--- mars-src.orig/core/src/host/lib/shared_context.c
+++ mars-src/core/src/host/lib/shared_context.c
@@ -35,13 +35,108 @@
* 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"
+#include "numa_internal.h"
+
+#ifdef MARS_ENABLE_NUMA
+
+struct mars_numa_shared_context
+{
+ struct mars_context *mars;
+ nodemask_t mask;
+};
+
+static int num_numa_shared_contexts;
+static struct mars_numa_shared_context
+ numa_shared_context_map[MARS_SHARED_CONTEXT_MAX];
+
+static struct mars_context *numa_shared_context_get(void)
+{
+ int i;
+ nodemask_t mask;
+
+ if (num_numa_shared_contexts == 0)
+ return NULL;
+
+ mask = numa_get_run_node_mask();
+ for (i = 0; i < MARS_SHARED_CONTEXT_MAX; i++) {
+ struct mars_numa_shared_context *entry =
+ &numa_shared_context_map[i];
+ if (entry->mars && nodemask_equal(&mask, &entry->mask)) {
+ return entry->mars;
+ }
+ }
+
+ return NULL;
+}
+
+static int numa_shared_context_register(struct mars_context *mars)
+{
+ int i;
+
+ for (i = 0; i < MARS_SHARED_CONTEXT_MAX; i++) {
+ struct mars_numa_shared_context *entry =
+ &numa_shared_context_map[i];
+ if (!entry->mars) {
+ entry->mask = numa_get_run_node_mask();
+ entry->mars = mars;
+ num_numa_shared_contexts++;
+ return MARS_SUCCESS;
+ }
+ }
+
+ return MARS_ERROR_LIMIT;
+}
+
+static int numa_shared_context_unregister(struct mars_context *mars)
+{
+ int i;
+
+ if (num_numa_shared_contexts == 0)
+ return MARS_SUCCESS;
+
+ for (i = 0; i < MARS_SHARED_CONTEXT_MAX; i++) {
+ struct mars_numa_shared_context *entry =
+ &numa_shared_context_map[i];
+ if (entry->mars == mars) {
+ entry->mars = NULL;
+ num_numa_shared_contexts--;
+ return MARS_SUCCESS;
+ }
+ }
+
+ return MARS_ERROR_INTERNAL;
+}
+
+#else /* ! MARS_ENABLE_NUMA */
+
+/* These functions must not be called */
+static struct mars_context *numa_shared_context_get(void)
+{
+ return NULL;
+}
+
+static int numa_shared_context_register(struct mars_context *mars)
+{
+ (void)mars;
+
+ return MARS_ERROR_INTERNAL;
+}
+
+static int numa_shared_context_unregister(struct mars_context *mars)
+{
+ (void)mars;
+
+ return MARS_ERROR_INTERNAL;
+}
+
+#endif /* ! MARS_ENABLE_NUMA */
+
/* Note that it is assumed that global data access in this file is
* protected by caller's lock.
@@ -50,7 +145,10 @@ static struct mars_context *shared_conte
int mars_shared_context_get(struct mars_context **mars)
{
- *mars = shared_context;
+ if (mars_numa_enabled())
+ *mars = numa_shared_context_get();
+ else
+ *mars = shared_context;
if (!*mars)
return MARS_ERROR_INTERNAL;
@@ -60,15 +158,21 @@ int mars_shared_context_get(struct mars_
int mars_shared_context_register(struct mars_context *mars)
{
- shared_context = mars;
-
- return MARS_SUCCESS;
+ if (mars_numa_enabled())
+ return numa_shared_context_register(mars);
+ else {
+ 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;
+ if (mars_numa_enabled())
+ return numa_shared_context_unregister(mars);
+ else {
+ if (mars == shared_context)
+ shared_context = NULL;
+ return MARS_SUCCESS;
+ }
}
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
@@ -44,6 +44,8 @@
#include <pthread.h>
#endif
+#define MARS_SHARED_CONTEXT_MAX 16
+
#ifdef HAVE_LIBSPE2
typedef pthread_t mars_mpu_context_t;
#endif
More information about the cbe-oss-dev
mailing list