To: linux-numa@vger.kernel.org
Subject: [PATCH] libnuma: numa_get_run_node_mask
From: Cliff Wickman <cpw@sgi.com>

The numa_get_run_node_mask() function does not do what it is documented
as doing:
  "returns the mask of nodes that the current task is allowed to run on."
It returns a bit mask of cpu's.  And that mask is erroneous.
I've been testing it in conjunction with the qthreads package, which
needs this function to be cpuset-aware.

Does anyone use this function?

The below simply makes a copy of the numa_all_nodes_ptr mask, which really
is a mask of available nodes, and is cpuset-aware.  That is, it is
constrained to the nodes that the caller can use.

Signed-off-by: Cliff Wickman <cpw@sgi.com>

------------- this patch subsequently replaced on 110112 ---------------

---
 libnuma.c |   29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

Index: numactl-dev/libnuma.c
===================================================================
--- numactl-dev.orig/libnuma.c
+++ numactl-dev/libnuma.c
@@ -1538,33 +1538,8 @@ __asm__(".symver numa_get_run_node_mask_
 struct bitmask *
 numa_get_run_node_mask_v2(void)
 { 
-	int i, k;
-	int ncpus = numa_num_configured_cpus();
-	int max = numa_max_node_int();
-	struct bitmask *bmp, *cpus, *nodecpus;
-
-
-	bmp = numa_allocate_cpumask();
-	cpus = numa_allocate_cpumask();
-	if (numa_sched_getaffinity_v2_int(0, cpus) < 0){
-		copy_bitmask_to_bitmask(numa_no_nodes_ptr, bmp);
-		goto free_cpus;
-	}
-
-	nodecpus = numa_allocate_cpumask();
-	for (i = 0; i <= max; i++) {
-		if (numa_node_to_cpus_v2_int(i, nodecpus) < 0) {
-			/* It's possible for the node to not exist */
-			continue;
-		}
-		for (k = 0; k < CPU_LONGS(ncpus); k++) {
-			if (nodecpus->maskp[k] & cpus->maskp[k])
-				numa_bitmask_setbit(bmp, i);
-		}
-	}		
-	numa_bitmask_free(nodecpus);
-free_cpus:
-	numa_bitmask_free(cpus);
+	struct bitmask *bmp = numa_allocate_nodemask();
+        copy_bitmask_to_bitmask(numa_all_nodes_ptr, bmp);
 	return bmp;
 } 
 __asm__(".symver numa_get_run_node_mask_v2,numa_get_run_node_mask@@libnuma_1.2");
