[Cbe-oss-dev] [PATCH 02/22]MARS/base: NUMA api version 2
Yuji Mano
yuji.mano at am.sony.com
Wed Jan 21 11:27:35 EST 2009
From: Kazunori Asayama <asayama at sm.sony.co.jp>
Add support for NUMA library API version 2
This patch adds support for the new NUMA library API version 2, so
that MARS NUMA support is available on recent Linux distributions like
Fedora 10.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
base/src/host/lib/mpu_cell.c | 11 +++++++----
base/src/host/lib/numa_internal.h | 29 ++++++++++++++++++++++++++++-
base/src/host/lib/shared_context.c | 14 +++++++++-----
3 files changed, 44 insertions(+), 10 deletions(-)
Index: b/base/src/host/lib/mpu_cell.c
===================================================================
--- a/base/src/host/lib/mpu_cell.c 2009-01-13 20:35:24.000000000 +0900
+++ b/base/src/host/lib/mpu_cell.c 2009-01-13 21:15:40.000000000 +0900
@@ -52,22 +52,25 @@ static int numa_mpu_max(void)
{
int i;
int max_node = numa_max_node();
- nodemask_t mask = numa_get_run_node_mask();
+ numa_bitmask_t mask = numa_get_run_node_mask();
int num = 0;
for (i = 0; i <= max_node; i++) {
int ret;
- if (nodemask_isset(&mask, i)) {
+ if (numa_bitmask_isbitset(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;
+ if (ret < 0) {
+ num = ret;
+ break;
+ }
num += ret;
}
}
+ numa_bitmask_free(mask);
return num;
}
Index: b/base/src/host/lib/numa_internal.h
===================================================================
--- a/base/src/host/lib/numa_internal.h 2009-01-13 20:35:24.000000000 +0900
+++ b/base/src/host/lib/numa_internal.h 2009-01-13 20:39:56.000000000 +0900
@@ -40,7 +40,34 @@
#ifdef MARS_ENABLE_NUMA
#include <numa.h>
-#endif
+
+#if !defined(LIBNUMA_API_VERSION) || (LIBNUMA_API_VERSION <= 1)
+
+typedef nodemask_t numa_bitmask_t;
+
+static inline int numa_bitmask_isbitset(nodemask_t mask, unsigned int n)
+{
+ return nodemask_isset(&mask, n);
+}
+
+static inline int numa_bitmask_equal(nodemask_t a, nodemask_t b)
+{
+ return nodemask_equal(&a, &b);
+}
+
+static inline void numa_bitmask_free(nodemask_t mask)
+{
+ (void)mask;
+ /* do nothing */
+}
+
+#else /* LIBNUMA_API_VERSION >= 2 */
+
+typedef struct bitmask *numa_bitmask_t;
+
+#endif /* LIBNUMA_API_VERSION >= 2 */
+
+#endif /* MARS_ENABLE_NUMA */
static inline int mars_numa_enabled(void)
{
Index: b/base/src/host/lib/shared_context.c
===================================================================
--- a/base/src/host/lib/shared_context.c 2009-01-13 20:35:24.000000000 +0900
+++ b/base/src/host/lib/shared_context.c 2009-01-13 20:35:36.000000000 +0900
@@ -48,7 +48,7 @@
struct mars_numa_shared_context
{
struct mars_context *mars;
- nodemask_t mask;
+ numa_bitmask_t mask;
};
static int num_numa_shared_contexts;
@@ -58,7 +58,8 @@ static struct mars_numa_shared_context
static struct mars_context *numa_shared_context_get(void)
{
int i;
- nodemask_t mask;
+ numa_bitmask_t mask;
+ struct mars_context *mars = NULL;
if (num_numa_shared_contexts == 0)
return NULL;
@@ -67,12 +68,14 @@ static struct mars_context *numa_shared_
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;
+ if (entry->mars && numa_bitmask_equal(mask, entry->mask)) {
+ mars = entry->mars;
+ break;
}
}
+ numa_bitmask_free(mask);
- return NULL;
+ return mars;
}
static int numa_shared_context_register(struct mars_context *mars)
@@ -104,6 +107,7 @@ static int numa_shared_context_unregiste
struct mars_numa_shared_context *entry =
&numa_shared_context_map[i];
if (entry->mars == mars) {
+ numa_bitmask_free(entry->mask);
entry->mars = NULL;
num_numa_shared_contexts--;
return MARS_SUCCESS;
More information about the cbe-oss-dev
mailing list