Blame SOURCES/numactl-2.0.9-mpol-bind-preferred.patch

dcabb6
Date: Tue, 15 Jul 2014 13:53:14 -0400
dcabb6
From: Bill Gray <bgray@redhat.com>
dcabb6
To: linux-numa@vger.kernel.org
dcabb6
Cc: Cliff Wickman <cpw@sgi.com>
dcabb6
Subject: [PATCH] Fix numactl --show preferred node for case MPOL_BIND
dcabb6
dcabb6
This patch is mostly to fix an issue in "numactl --show" which did not 
dcabb6
print the correct preferred node:
dcabb6
dcabb6
# for i in 0 1 2 3 4 5 6 7 ; do numactl -N$i -m$i numactl -s; done | 
dcabb6
grep preferred
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
preferred node: 4
dcabb6
dcabb6
# for i in 0 1 2 3 4 5 6 7 ; do ./numactl -N$i -m$i ./numactl -s; done | 
dcabb6
grep preferred
dcabb6
preferred node: 0
dcabb6
preferred node: 1
dcabb6
preferred node: 2
dcabb6
preferred node: 3
dcabb6
preferred node: 4
dcabb6
preferred node: 5
dcabb6
preferred node: 6
dcabb6
preferred node: 7
dcabb6
dcabb6
Patch Changes:
dcabb6
- eliminated bitops.[cho]
dcabb6
- eliminated redundant printcpumask() (which duplicated printmask())
dcabb6
- added find_first() to util.[ch]
dcabb6
- fixed some compiler warnings
dcabb6
dcabb6
These files can be deleted:
dcabb6
- Only in numactl-2.0.9-orig/: bitops.c
dcabb6
- Only in numactl-2.0.9-orig/: bitops.h
dcabb6
- Only in numactl-2.0.9-orig/: numastat
dcabb6
- Only in numactl-2.0.9-orig/test: move_pages
dcabb6
dcabb6
diffstats:
dcabb6
  Makefile        |   12 ++++++------
dcabb6
  bitops.c        |   13 -------------
dcabb6
  bitops.h        |   13 -------------
dcabb6
  migspeed.c      |    4 +---
dcabb6
  numactl.c       |    5 ++---
dcabb6
  numaint.h       |    2 +-
dcabb6
  test/move_pages |binary
dcabb6
 Makefile       |   12 ++++++------
dcabb6
 bitops.c       |   13 -------------
dcabb6
 bitops.h       |   13 -------------
dcabb6
 migspeed.c     |    4 +---
dcabb6
 numactl.c      |    5 ++---
dcabb6
 numaint.h      |    2 +-
dcabb6
 test/nodemap.c |    1 -
dcabb6
 test/tbitmap.c |   10 +++++++++-
dcabb6
 util.c         |   14 +++++---------
dcabb6
 util.h         |    2 +-
dcabb6
 10 files changed, 25 insertions(+), 51 deletions(-)
dcabb6
dcabb6
Signed-off-by: Bill Gray <bgray@redhat.com>
dcabb6
dcabb6
Index: numactl-dev/bitops.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/bitops.c
dcabb6
+++ /dev/null
dcabb6
@@ -1,13 +0,0 @@
dcabb6
-#include "bitops.h"
dcabb6
-
dcabb6
-/* extremly dumb */
dcabb6
-int find_first_bit(void *m, int max)
dcabb6
-{
dcabb6
-	unsigned long *mask = m;
dcabb6
-	int i;
dcabb6
-	for (i = 0; i < max; i++) {
dcabb6
-		if (test_bit(i, mask))
dcabb6
-			break;			
dcabb6
-	}
dcabb6
-	return i;
dcabb6
-}
dcabb6
Index: numactl-dev/bitops.h
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/bitops.h
dcabb6
+++ /dev/null
dcabb6
@@ -1,13 +0,0 @@
dcabb6
-#ifndef BITOPS_H
dcabb6
-#define BITOPS_H 1
dcabb6
-
dcabb6
-#define BITS_PER_LONG (sizeof(unsigned long) * 8)
dcabb6
-#define BYTES_PER_LONG (sizeof(long))
dcabb6
-
dcabb6
-#define test_bit(i,p)  ((p)[(i) / BITS_PER_LONG] &   (1UL << ((i)%BITS_PER_LONG)))
dcabb6
-#define set_bit(i,p)   ((p)[(i) / BITS_PER_LONG] |=  (1UL << ((i)%BITS_PER_LONG)))
dcabb6
-#define clear_bit(i,p) ((p)[(i) / BITS_PER_LONG] &= ~(1UL << ((i)%BITS_PER_LONG)))
dcabb6
-
dcabb6
-extern int find_first_bit(void *mask, int max);
dcabb6
-
dcabb6
-#endif
dcabb6
Index: numactl-dev/Makefile
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/Makefile
dcabb6
+++ numactl-dev/Makefile
dcabb6
@@ -23,7 +23,7 @@ ifeq ($(THREAD_SUPPORT),yes)
dcabb6
 endif
dcabb6
 
dcabb6
 CLEANFILES := numactl.o libnuma.o numactl numademo numademo.o distance.o \
dcabb6
-	      memhog libnuma.so libnuma.so.1 numamon numamon.o syscall.o bitops.o \
dcabb6
+	      memhog libnuma.so libnuma.so.1 numamon numamon.o syscall.o \
dcabb6
 	      memhog.o util.o stream_main.o stream_lib.o shm.o stream clearcache.o \
dcabb6
 	      test/pagesize test/tshared test/mynode.o test/tshared.o mt.o empty.o empty.c \
dcabb6
 	      test/mynode test/ftok test/prefered test/randmap \
dcabb6
@@ -32,8 +32,8 @@ CLEANFILES := numactl.o libnuma.o numact
dcabb6
 	      test/mbind_mig_pages test/migrate_pages \
dcabb6
 	      migratepages migspeed migspeed.o libnuma.a \
dcabb6
 	      test/move_pages test/realloc_test sysfs.o affinity.o \
dcabb6
-	      test/node-parse rtnetlink.o test/A numastat
dcabb6
-SOURCES := bitops.c libnuma.c distance.c memhog.c numactl.c numademo.c \
dcabb6
+	      test/node-parse rtnetlink.o test/A numastat numastat.o
dcabb6
+SOURCES := libnuma.c distance.c memhog.c numactl.c numademo.c \
dcabb6
 	numamon.c shm.c stream_lib.c stream_main.c syscall.c util.c mt.c \
dcabb6
 	clearcache.c test/*.c affinity.c sysfs.c rtnetlink.c numastat.c
dcabb6
 
dcabb6
@@ -51,11 +51,11 @@ all: numactl migratepages migspeed libnu
dcabb6
      test/mbind_mig_pages test/migrate_pages test/realloc_test libnuma.a \
dcabb6
      test/node-parse numastat
dcabb6
 
dcabb6
-numactl: numactl.o util.o shm.o bitops.o libnuma.so
dcabb6
+numactl: numactl.o util.o shm.o libnuma.so
dcabb6
 
dcabb6
 numastat: CFLAGS += -std=gnu99
dcabb6
 
dcabb6
-migratepages: migratepages.c util.o bitops.o libnuma.so
dcabb6
+migratepages: migratepages.c util.o libnuma.so
dcabb6
 
dcabb6
 migspeed: LDLIBS += -lrt
dcabb6
 migspeed: migspeed.o util.o libnuma.so
dcabb6
@@ -129,7 +129,7 @@ test/nodemap: test/nodemap.c libnuma.so
dcabb6
 
dcabb6
 test/distance: test/distance.c libnuma.so
dcabb6
 
dcabb6
-test/tbitmap: test/tbitmap.c libnuma.so
dcabb6
+test/tbitmap: test/tbitmap.c libnuma.so util.o
dcabb6
 
dcabb6
 test/move_pages: test/move_pages.c libnuma.so
dcabb6
 
dcabb6
Index: numactl-dev/migspeed.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/migspeed.c
dcabb6
+++ numactl-dev/migspeed.c
dcabb6
@@ -65,7 +65,6 @@ int main(int argc, char *argv[])
dcabb6
 {
dcabb6
 	char *p;
dcabb6
 	int option;
dcabb6
-	int error = 0;
dcabb6
 	struct timespec result;
dcabb6
 	unsigned long bytes;
dcabb6
 	double duration, mbytes;
dcabb6
@@ -82,8 +81,7 @@ int main(int argc, char *argv[])
dcabb6
 	switch (option) {
dcabb6
 	case 'h' :
dcabb6
 	case '?' :
dcabb6
-		error = 1;
dcabb6
-		break;
dcabb6
+		usage();
dcabb6
 	case 'v' :
dcabb6
 		verbose++;
dcabb6
 		break;
dcabb6
Index: numactl-dev/numactl.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/numactl.c
dcabb6
+++ numactl-dev/numactl.c
dcabb6
@@ -119,7 +119,7 @@ void show_physcpubind(void)
dcabb6
 			}
dcabb6
 			err("sched_get_affinity");
dcabb6
 		}
dcabb6
-		printcpumask("physcpubind", cpubuf);
dcabb6
+		printmask("physcpubind", cpubuf);
dcabb6
 		break;
dcabb6
 	}
dcabb6
 }
dcabb6
@@ -130,7 +130,6 @@ void show(void)
dcabb6
 	struct bitmask *membind, *interleave, *cpubind;
dcabb6
 	unsigned long cur;
dcabb6
 	int policy;
dcabb6
-	int numa_num_nodes = numa_num_possible_nodes();
dcabb6
 	
dcabb6
 	if (numa_available() < 0) {
dcabb6
 		show_physcpubind();
dcabb6
@@ -166,7 +165,7 @@ void show(void)
dcabb6
 		printf("%ld (interleave next)\n",cur);
dcabb6
 		break;
dcabb6
 	case MPOL_BIND:
dcabb6
-		printf("%d\n", find_first_bit(&membind, numa_num_nodes));
dcabb6
+		printf("%d\n", find_first(membind));
dcabb6
 		break;
dcabb6
 	}
dcabb6
 	if (policy == MPOL_INTERLEAVE) {
dcabb6
Index: numactl-dev/numaint.h
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/numaint.h
dcabb6
+++ numactl-dev/numaint.h
dcabb6
@@ -1,5 +1,4 @@
dcabb6
 /* Internal interfaces of libnuma */
dcabb6
-#include "bitops.h"
dcabb6
 
dcabb6
 extern int numa_sched_setaffinity_v1(pid_t pid, unsigned len, const unsigned long *mask);
dcabb6
 extern int numa_sched_getaffinity_v1(pid_t pid, unsigned len, const unsigned long *mask);
dcabb6
@@ -12,6 +11,7 @@ extern int numa_sched_getaffinity_v2_int
dcabb6
 
dcabb6
 #define SHM_HUGETLB     04000   /* segment will use huge TLB pages */
dcabb6
 
dcabb6
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
dcabb6
 #define CPU_BYTES(x) (round_up(x, BITS_PER_LONG)/8)
dcabb6
 #define CPU_LONGS(x) (CPU_BYTES(x) / sizeof(long))
dcabb6
 
dcabb6
Index: numactl-dev/test/nodemap.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/test/nodemap.c
dcabb6
+++ numactl-dev/test/nodemap.c
dcabb6
@@ -1,5 +1,4 @@
dcabb6
 #include "numa.h"
dcabb6
-#include "bitops.h"
dcabb6
 #include <stdio.h>
dcabb6
 #include <stdlib.h>
dcabb6
 
dcabb6
Index: numactl-dev/test/tbitmap.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/test/tbitmap.c
dcabb6
+++ numactl-dev/test/tbitmap.c
dcabb6
@@ -7,6 +7,13 @@
dcabb6
 #include <stdlib.h>
dcabb6
 #include <ctype.h>
dcabb6
 #include "numa.h"
dcabb6
+#include "util.h"
dcabb6
+
dcabb6
+/* For util.c. Fixme. */
dcabb6
+void usage(void)
dcabb6
+{
dcabb6
+	exit(1);
dcabb6
+}
dcabb6
 
dcabb6
 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
dcabb6
 
dcabb6
@@ -81,11 +88,12 @@ int main(void)
dcabb6
 		numa_bitmask_clearall(mask);
dcabb6
 		numa_bitmask_clearall(mask2);
dcabb6
 		numa_bitmask_setbit(mask, i);
dcabb6
+		assert(find_first(mask) == i);
dcabb6
 		bitmap_scnprintf(buf, sizeof(buf), mask);
dcabb6
 		strcat(buf,"\n");
dcabb6
 		if (numa_parse_bitmap(buf, mask2) < 0)
dcabb6
 			assert(0);
dcabb6
-		if (memcmp(mask, mask2, sizeof(mask))) { 
dcabb6
+		if (memcmp(mask->maskp, mask2->maskp, numa_bitmask_nbytes(mask))) {
dcabb6
 			bitmap_scnprintf(buf, sizeof(buf), mask2);
dcabb6
 			printf("mask2 differs: %s\n", buf);
dcabb6
 			assert(0);
dcabb6
Index: numactl-dev/util.c
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/util.c
dcabb6
+++ numactl-dev/util.c
dcabb6
@@ -16,7 +16,6 @@
dcabb6
 #include "numa.h"
dcabb6
 #include "numaif.h"
dcabb6
 #include "util.h"
dcabb6
-#include "bitops.h"
dcabb6
 #include <stdio.h>
dcabb6
 #include <string.h>
dcabb6
 #include <stdlib.h>
dcabb6
@@ -28,23 +27,20 @@
dcabb6
 void printmask(char *name, struct bitmask *mask)
dcabb6
 {
dcabb6
 	int i;
dcabb6
-
dcabb6
 	printf("%s: ", name);
dcabb6
-	for (i = 0; i <= mask->size; i++)
dcabb6
+	for (i = 0; i < mask->size; i++)
dcabb6
 		if (numa_bitmask_isbitset(mask, i))
dcabb6
 			printf("%d ", i);
dcabb6
 	putchar('\n');
dcabb6
 }
dcabb6
 
dcabb6
-void printcpumask(char *name, struct bitmask *mask)
dcabb6
+int find_first(struct bitmask *mask)
dcabb6
 {
dcabb6
 	int i;
dcabb6
-	printf("%s: ", name);
dcabb6
-	for (i = 0; i < mask->size; i++) {
dcabb6
+	for (i = 0; i < mask->size; i++)
dcabb6
 		if (numa_bitmask_isbitset(mask, i))
dcabb6
-			printf("%d ", i);
dcabb6
-	}
dcabb6
-	putchar('\n');
dcabb6
+			return i;
dcabb6
+	return -1;
dcabb6
 }
dcabb6
 
dcabb6
 void complain(char *fmt, ...)
dcabb6
Index: numactl-dev/util.h
dcabb6
===================================================================
dcabb6
--- numactl-dev.orig/util.h
dcabb6
+++ numactl-dev/util.h
dcabb6
@@ -1,5 +1,5 @@
dcabb6
 extern void printmask(char *name, struct bitmask *mask);
dcabb6
-extern void printcpumask(char *name, struct bitmask *mask);
dcabb6
+extern int find_first(struct bitmask *mask);
dcabb6
 extern struct bitmask *nodemask(char *s);
dcabb6
 extern struct bitmask *cpumask(char *s, int *ncpus);
dcabb6
 extern int read_sysctl(char *name);