[Cbe-oss-dev] [PATCH 02/13]MARS/core: Numa base

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


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

Add base part of NUMA support

This patch adds build system support and basic functions for NUMA
support.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
 core/src/host/configure.ac.in     |    5 +++
 core/src/host/lib/Makefile.am     |    1 
 core/src/host/lib/mpu_cell.c      |   43 +++++++++++++++++++++++++++++-
 core/src/host/lib/numa_internal.h |   54 ++++++++++++++++++++++++++++++++++++++
 scripts/acinclude.m4              |   24 ++++++++++++++++
 5 files changed, 126 insertions(+), 1 deletion(-)

Index: mars-src/scripts/acinclude.m4
===================================================================
--- mars-src.orig/scripts/acinclude.m4
+++ mars-src/scripts/acinclude.m4
@@ -102,8 +102,32 @@ AC_CONFIG_MARS_POST
 
 ### Host specific definitions
 
+AC_DEFUN([AC_CONFIG_MARS_NUMA],[
+AC_ARG_ENABLE(
+	[numa],
+	[AS_HELP_STRING([--enable-numa], [enable NUMA support])])
+
+case "$with_mars_platform" in
+	cell)
+		if test "x$enable_numa" = "x"; then
+			AC_CHECK_HEADER([numa.h],[enable_numa=yes])
+		fi
+		;;
+	*)
+		enable_numa=no
+		;;
+esac
+AC_MSG_RESULT([using enable-numa ${enable_numa}])
+if test "x$enable_numa" = "xyes"; then
+	AC_DEFINE([MARS_ENABLE_NUMA],[1],
+		[Define to 1 if NUMA support is enabled.])
+fi
+AM_CONDITIONAL([NUMA], [test "x${enable_numa}" = "xyes"])
+]) # AC_CONFIG_MARS_NUMA
+
 AC_DEFUN([AC_CONFIG_MARS_HOST],[
 AC_CONFIG_MARS
+AC_CONFIG_MARS_NUMA
 ]) # AC_CONFIG_MARS_HOST
 
 
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 \
+	numa_internal.h \
 	shared_context.c \
 	workload_queue.c
 
Index: mars-src/core/src/host/configure.ac.in
===================================================================
--- mars-src.orig/core/src/host/configure.ac.in
+++ mars-src/core/src/host/configure.ac.in
@@ -57,6 +57,11 @@ case "$with_mars_platform" in
 	;;
 esac
 
+if test "x$enable_numa" = "xyes"; then
+	AC_CHECK_HEADERS(numa.h)
+	AC_CHECK_LIB(numa, numa_available)
+fi
+
 AC_CONFIG_AUX_DIR([.])
 
 AC_PROG_LIBTOOL
Index: mars-src/core/src/host/lib/mpu_cell.c
===================================================================
--- mars-src.orig/core/src/host/lib/mpu_cell.c
+++ mars-src/core/src/host/lib/mpu_cell.c
@@ -44,12 +44,53 @@
 #include "mars/error.h"
 
 #include "context_internal_types.h"
+#include "numa_internal.h"
+
+#ifdef MARS_ENABLE_NUMA
+
+static int numa_mpu_max(void)
+{
+	int i;
+	int max_node = numa_max_node();
+	nodemask_t mask = numa_get_run_node_mask();
+	int num = 0;
+
+	for (i = 0; i <= max_node; i++) {
+		int ret;
+		if (nodemask_isset(&mask, i)) {
+			/* this call assumes assignment of
+			 * each node number is identical
+			 * between numa API and libspe.
+			 */
+			ret = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, i);
+			if (ret < 0)
+				return ret;
+			num += ret;
+		}
+	}
+
+	return num;
+}
+
+#else /* ! MARS_ENABLE_NUMA */
+
+/* This function must not be called */
+static int numa_mpu_max(void)
+{
+	return -1;
+}
+
+#endif /* ! MARS_ENABLE_NUMA */
 
 extern const unsigned char mars_kernel_entry[];
 
 int mars_mpu_max(int *num)
 {
-	*num = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
+	if (mars_numa_enabled())
+		*num = numa_mpu_max();
+	else
+		*num = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
+
 	if (*num <= 0)
 		return MARS_ERROR_INTERNAL;
 
Index: mars-src/core/src/host/lib/numa_internal.h
===================================================================
--- /dev/null
+++ mars-src/core/src/host/lib/numa_internal.h
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#ifndef MARS_NUMA_INTERNAL_H
+#define MARS_NUMA_INTERNAL_H
+
+#ifdef MARS_ENABLE_NUMA
+#include <numa.h>
+#endif
+
+static inline int mars_numa_enabled(void)
+{
+#ifdef MARS_ENABLE_NUMA
+	return (numa_available() != -1);
+#else
+	return 0;
+#endif
+}
+
+#endif






More information about the cbe-oss-dev mailing list