All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix test/prefered
@ 2009-01-10  5:54 Andi Kleen
  2009-01-10  6:18 ` [PATCH] Fix test/prefered v2 Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2009-01-10  5:54 UTC (permalink / raw)
  To: cpw, linux-numa

Fix test/prefered

Couple of bugs here:

- First the kernel errors out of the nodemask is < MAXNUMNODES,
so have to discover that at runtime. There's no function
in libnuma for this (perhaps there should be one?), so i
wrote one here.
- The loop set the node in the wrong mask, breaking the test

Signed-off-by: Andi Kleen <ak@linux.intel.com>
 
diff -urp numactl-2.0.2/test/prefered.c numactl-2.0.2-hack//test/prefered.c
--- numactl-2.0.2/test/prefered.c	2008-08-05 16:36:58.000000000 +0200
+++ numactl-2.0.2-hack//test/prefered.c	2009-01-10 06:30:11.000000000 +0100
@@ -6,20 +6,38 @@
 #include <assert.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #define err(x) perror(x),exit(1)
 
+/* Discover MAX_NUMNODE of the kernel */
+int max_numnode(void)
+{	
+	int v;
+	unsigned size = 128;
+	struct bitmask *mask = numa_bitmask_alloc(size);
+	while (get_mempolicy(NULL, mask->maskp, mask->size, &v, MPOL_F_ADDR) < 0 &&
+			errno == EINVAL) {
+		numa_bitmask_free(mask);
+		size <<= 1;
+	}
+	numa_bitmask_free(mask);
+	printf("size %d\n", size);
+	return size;
+}
+
 int main(void)
 {
 	int max = numa_max_node();
+	int maxmask = max_numnode();
 	struct bitmask *nodes, *mask;
 	int pagesize = getpagesize();
 	int i;
 	int pol;
 	int node;
 	int err = 0;
-	nodes = numa_bitmask_alloc(max+1);
-	mask = numa_bitmask_alloc(max+1);
+	nodes = numa_bitmask_alloc(maxmask);
+	mask = numa_bitmask_alloc(maxmask);
 
 	for (i = max; i >= 0; --i) { 
 		char *mem = mmap(NULL, pagesize*(max+1), PROT_READ|PROT_WRITE, 
@@ -33,9 +51,9 @@ int main(void)
 
 		numa_bitmask_clearall(nodes);
 		numa_bitmask_clearall(mask);
-		numa_bitmask_setbit(mask, i);
+		numa_bitmask_setbit(nodes, i);
 
 		if (mbind(adr,  pagesize, MPOL_PREFERRED, nodes->maskp,
 							nodes->size, 0) < 0)
 			err("mbind");
 	
-- 
ak@linux.intel.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] Fix test/prefered v2
  2009-01-10  5:54 [PATCH] Fix test/prefered Andi Kleen
@ 2009-01-10  6:18 ` Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2009-01-10  6:18 UTC (permalink / raw)
  To: Andi Kleen; +Cc: cpw, linux-numa

> Fix test/prefered
> 
> Couple of bugs here:
> 
> - First the kernel errors out of the nodemask is < MAXNUMNODES,
> so have to discover that at runtime. There's no function
> in libnuma for this (perhaps there should be one?), so i
> wrote one here.
> - The loop set the node in the wrong mask, breaking the test

Sorry that was the broken version, here's a v2 with a actually
working max_numnode. The older version happened to work
on my test system, but was obviously not correct.

---

Fix test/prefered v2
 
Couple of bugs here:
 
- First the kernel errors out of the nodemask is < MAXNUMNODES,
so have to discover that at runtime. There's no function
in libnuma for this (perhaps there should be one?), so i
wrote one here.
- The loop set the node in the wrong mask, breaking the test

v2: Correct max_numnode detection

Signed-off-by: Andi Kleen <ak@linux.intel.com>


--- numactl-2.0.2/test/prefered.c	2008-08-05 16:36:58.000000000 +0200
+++ numactl-2.0.2-hack/test/prefered.c	2009-01-10 07:00:16.000000000 +0100
@@ -6,20 +6,38 @@
 #include <assert.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #define err(x) perror(x),exit(1)
 
+/* Discover MAXNUMNODE of the kernel */
+int max_numnode(void)
+{	
+	int v;
+	unsigned size = 64;
+	struct bitmask *mask = numa_bitmask_alloc(size);
+	while (get_mempolicy(NULL, mask->maskp, mask->size, &v, MPOL_F_ADDR) < 0 &&
+			errno == EINVAL) {
+		numa_bitmask_free(mask);
+		size <<= 1;
+		mask = numa_bitmask_alloc(size);
+	}
+	numa_bitmask_free(mask);
+	return size;
+}
+
 int main(void)
 {
 	int max = numa_max_node();
+	int maxmask = max_numnode();
 	struct bitmask *nodes, *mask;
 	int pagesize = getpagesize();
 	int i;
 	int pol;
 	int node;
 	int err = 0;
-	nodes = numa_bitmask_alloc(max+1);
-	mask = numa_bitmask_alloc(max+1);
+	nodes = numa_bitmask_alloc(maxmask);
+	mask = numa_bitmask_alloc(maxmask);
 
 	for (i = max; i >= 0; --i) { 
 		char *mem = mmap(NULL, pagesize*(max+1), PROT_READ|PROT_WRITE, 
@@ -33,8 +51,8 @@
 
 		numa_bitmask_clearall(nodes);
 		numa_bitmask_clearall(mask);
-		numa_bitmask_setbit(mask, i);
+		numa_bitmask_setbit(nodes, i);
 
 		if (mbind(adr,  pagesize, MPOL_PREFERRED, nodes->maskp,
 							nodes->size, 0) < 0)
 			err("mbind");



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-10  6:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-10  5:54 [PATCH] Fix test/prefered Andi Kleen
2009-01-10  6:18 ` [PATCH] Fix test/prefered v2 Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.