[PATCH] Fix compat V1 for nodemask_ interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

found an issue with the compat interface for the nodemask_ interfaces.
The nodemask_ interfaces are even not compatible when compiling with -DNUMA_VERSION1_COMPATIBILITY. Found this when compiling latest LTP
against numactl/libnuma version 2.0.2.

Moved nodemask_ interfaces back to numa.h for compat V1 interface.
Are nodemask_zero() and nodemask_equal() interfaces with struct bitmask parameters 
intended?

best regards,
Daniel

---
 libnuma.c     |   26 ++++----------------------
 numa.h        |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 numacompat1.h |    5 +++++
 3 files changed, 56 insertions(+), 23 deletions(-)

Index: numactl-2.0.2/numa.h
===================================================================
--- numactl-2.0.2.orig/numa.h
+++ numactl-2.0.2/numa.h
@@ -60,7 +60,8 @@ void copy_nodemask_to_bitmask(nodemask_t
 void copy_bitmask_to_nodemask(struct bitmask *, nodemask_t *);
 void copy_bitmask_to_bitmask(struct bitmask *, struct bitmask *);
 
-/* compatibility for codes that used them: */
+
+/* V2 touched interfaces */
 static inline void nodemask_zero(struct bitmask *mask)
 { 
 	numa_bitmask_clearall(mask);
@@ -71,6 +72,51 @@ static inline int nodemask_equal(struct
 	return numa_bitmask_equal(a, b);
 } 
 
+/* compatibility for codes that used them: */
+static inline void nodemask_zero_compat(nodemask_t *mask)
+{ 
+	struct bitmask tmp;
+
+	tmp.maskp = (unsigned long *)mask;
+	tmp.size = sizeof(nodemask_t) * 8;
+	numa_bitmask_clearall(&tmp);
+} 
+
+static inline void nodemask_set_compat(nodemask_t *mask, int node)
+{
+	mask->n[node / (8*sizeof(unsigned long))] |=
+		(1UL<<(node%(8*sizeof(unsigned long))));
+}
+
+static inline void nodemask_clr_compat(nodemask_t *mask, int node)
+{
+	mask->n[node / (8*sizeof(unsigned long))] &=
+		~(1UL<<(node%(8*sizeof(unsigned long))));
+}
+
+static inline int nodemask_isset_compat(const nodemask_t *mask, int node)
+{
+	if ((unsigned)node >= NUMA_NUM_NODES)
+		return 0;
+	if (mask->n[node / (8*sizeof(unsigned long))] &
+		(1UL<<(node%(8*sizeof(unsigned long)))))
+		return 1;
+	return 0;
+}
+
+static inline int nodemask_equal_compat(const nodemask_t *a, const nodemask_t *b) 
+{ 
+	struct bitmask tmp_a, tmp_b;
+
+	tmp_a.maskp = (unsigned long *)a;
+	tmp_a.size = sizeof(nodemask_t) * 8;
+
+	tmp_b.maskp = (unsigned long *)b;
+	tmp_b.size = sizeof(nodemask_t) * 8;
+
+	return numa_bitmask_equal(&tmp_a, &tmp_b);
+} 
+
 /* NUMA support available. If this returns a negative value all other function
    in this library are undefined. */
 int numa_available(void);
Index: numactl-2.0.2/libnuma.c
===================================================================
--- numactl-2.0.2.orig/libnuma.c
+++ numactl-2.0.2/libnuma.c
@@ -74,24 +74,6 @@ int numa_exit_on_error = 0;
 int numa_exit_on_warn = 0;
 static void set_sizes(void);
 
-static inline void
-nodemask_set_v1(nodemask_t *mask, int node)
-{
-	mask->n[node / (8*sizeof(unsigned long))] |=
-		(1UL<<(node%(8*sizeof(unsigned long))));
-}
-
-static inline int
-nodemask_isset_v1(const nodemask_t *mask, int node)
-{
-	if ((unsigned)node >= NUMA_NUM_NODES)
-		return 0;
-	if (mask->n[node / (8*sizeof(unsigned long))] &
-		(1UL<<(node%(8*sizeof(unsigned long)))))
-		return 1;
-	return 0;
-}
-
 /*
  * There are two special functions, _init(void) and _fini(void), which
  * are called automatically by the dynamic loader whenever a library is loaded.
@@ -107,7 +89,7 @@ numa_init(void)
 	/* numa_all_nodes should represent existing nodes on this system */
         max = numa_num_configured_nodes();
         for (i = 0; i < max; i++)
-                nodemask_set_v1((nodemask_t *)&numa_all_nodes, i);
+                nodemask_set_compat((nodemask_t *)&numa_all_nodes, i);
 	memset(&numa_no_nodes, 0, sizeof(numa_no_nodes));
 }
 
@@ -995,7 +977,7 @@ copy_bitmask_to_nodemask(struct bitmask
 		if (i >= max)
 			break;
 		if (numa_bitmask_isbitset(bmp, i))
-                	nodemask_set_v1((nodemask_t *)nmp, i);
+                	nodemask_set_compat((nodemask_t *)nmp, i);
 	}
 }
 
@@ -1034,7 +1016,7 @@ copy_nodemask_to_bitmask(nodemask_t *nmp
 	if (max > bmp->size)
 		max = bmp->size;
 	for (i=0; i<max; i++) {
-		if (nodemask_isset_v1(nmp, i))
+		if (nodemask_isset_compat(nmp, i))
 			numa_bitmask_setbit(bmp, i);
 	}
 }
@@ -1329,7 +1311,7 @@ numa_run_on_node_mask_v1(const nodemask_
 	for (i = 0; i < NUMA_NUM_NODES; i++) {
 		if (mask->n[i / BITS_PER_LONG] == 0)
 			continue;
-		if (nodemask_isset_v1(mask, i)) {
+		if (nodemask_isset_compat(mask, i)) {
 			if (numa_node_to_cpus_v1_int(i, nodecpus, CPU_BYTES(ncpus)) < 0) {
 				numa_warn(W_noderunmask,
 					  "Cannot read node cpumask from sysfs");
Index: numactl-2.0.2/numacompat1.h
===================================================================
--- numactl-2.0.2.orig/numacompat1.h
+++ numactl-2.0.2/numacompat1.h
@@ -11,3 +11,8 @@
 #define numa_sched_getaffinity(p,l,m)   numa_sched_getaffinity_compat(p,l,m)
 #define numa_sched_setaffinity(p,l,m)   numa_sched_setaffinity_compat(p,l,m)
 #define numa_node_to_cpus(n,b,bl)       numa_node_to_cpus_compat(n,b,bl)
+#define nodemask_zero(m)		nodemask_zero_compat(m)
+#define nodemask_set(m, n)		nodemask_set_compat(m, n)
+#define nodemask_clr(m, n)		nodemask_clr_compat(m, n)
+#define nodemask_isset(m, n)		nodemask_isset_compat(m, n)
+#define nodemask_equal(a, b)		nodemask_equal_compat(a, b)
--
To unsubscribe from this list: send the line "unsubscribe linux-numa" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]     [Devices]

  Powered by Linux