* [PATCH] numactl: fix libnuma on big-endian 64-bit systems
@ 2008-12-04 17:34 Arnd Bergmann
2008-12-04 17:46 ` Lee Schermerhorn
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2008-12-04 17:34 UTC (permalink / raw)
To: Cliff Wickman, Mijo Safradin, Christoph Lameter, Lee Schermerhorn,
linuxppc-dev
The read-mask function assumes that it is running in 32-bit mode,
by addressing the bitmask as a series of int values, instead of
longs. This is broken as can easily be reproduced by running numademo
on a bit-endian 64-bit system.
Changing the addressing to use 'long' values fixes the problem.
Reported-by: Mijo Safradin <safradin@de.ibm.com>
---
Note: the set_nodemask_size() function is broken as well, it seems
to always set the nodemask size to "17" with the s2nbits implementation.
The fallback path in there looks correct.
--- a/libnuma.c 2008-12-04 14:25:30.000000000 +0100
+++ b/libnuma.c 2008-11-20 13:40:29.000000000 +0100
@@ -392,9 +372,9 @@ read_mask(char *s, struct bitmask *bmp)
{
char *end = s;
char *prevend;
- unsigned long *start = bmp->maskp;
- unsigned long *p = start;
- unsigned long *q;
+ unsigned int *start = (unsigned int *)bmp->maskp;
+ unsigned int *p = start;
+ unsigned int *q;
unsigned int i;
unsigned int n = 0;
@@ -431,14 +411,14 @@
}
/* Poor mans fls() */
- for(i = sizeof(long) * 8 - 1; i >= 0; i--)
+ for(i = 31; i >= 0; i--)
if (test_bit(i, start + n))
break;
/*
* Return the last bit set
*/
- return ((sizeof(unsigned long)*8) * n) + i;
+ return ((sizeof(unsigned int)*8) * n) + i;
}
/*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] numactl: fix libnuma on big-endian 64-bit systems
2008-12-04 17:34 [PATCH] numactl: fix libnuma on big-endian 64-bit systems Arnd Bergmann
@ 2008-12-04 17:46 ` Lee Schermerhorn
2008-12-04 20:49 ` Arnd Bergmann
0 siblings, 1 reply; 5+ messages in thread
From: Lee Schermerhorn @ 2008-12-04 17:46 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linuxppc-dev, Mijo Safradin, Cliff Wickman, Christoph Lameter
On Thu, 2008-12-04 at 18:34 +0100, Arnd Bergmann wrote:
> The read-mask function assumes that it is running in 32-bit mode,
> by addressing the bitmask as a series of int values, instead of
> longs. This is broken as can easily be reproduced by running numademo
> on a bit-endian 64-bit system.
>
> Changing the addressing to use 'long' values fixes the problem.
Hi, Arnd:
Not sure what you mean here. If the patch below is a proposed fix [I
don't see a 'Signed-off-by:", but maybe not needed for libnuma
patches?], the description above doesn't match the code. Looks like
you're changing the addressing FROM 'long' values to use 'int' values so
that the size is compatible between 32- and 64-bits. Or is that a
reverse patch/diff below?
Lee
> Reported-by: Mijo Safradin <safradin@de.ibm.com>
>
> ---
>
> Note: the set_nodemask_size() function is broken as well, it seems
> to always set the nodemask size to "17" with the s2nbits implementation.
> The fallback path in there looks correct.
>
> --- a/libnuma.c 2008-12-04 14:25:30.000000000 +0100
> +++ b/libnuma.c 2008-11-20 13:40:29.000000000 +0100
> @@ -392,9 +372,9 @@ read_mask(char *s, struct bitmask *bmp)
> {
> char *end = s;
> char *prevend;
> - unsigned long *start = bmp->maskp;
> - unsigned long *p = start;
> - unsigned long *q;
> + unsigned int *start = (unsigned int *)bmp->maskp;
> + unsigned int *p = start;
> + unsigned int *q;
> unsigned int i;
> unsigned int n = 0;
>
> @@ -431,14 +411,14 @@
> }
>
> /* Poor mans fls() */
> - for(i = sizeof(long) * 8 - 1; i >= 0; i--)
> + for(i = 31; i >= 0; i--)
> if (test_bit(i, start + n))
> break;
>
> /*
> * Return the last bit set
> */
> - return ((sizeof(unsigned long)*8) * n) + i;
> + return ((sizeof(unsigned int)*8) * n) + i;
> }
>
> /*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] numactl: fix libnuma on big-endian 64-bit systems
2008-12-04 17:46 ` Lee Schermerhorn
@ 2008-12-04 20:49 ` Arnd Bergmann
2008-12-04 20:51 ` [PATCH, v2] " Arnd Bergmann
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2008-12-04 20:49 UTC (permalink / raw)
To: Lee Schermerhorn
Cc: linuxppc-dev, Mijo Safradin, Cliff Wickman, Christoph Lameter
On Thursday 04 December 2008, Lee Schermerhorn wrote:
> On Thu, 2008-12-04 at 18:34 +0100, Arnd Bergmann wrote:
> > The read-mask function assumes that it is running in 32-bit mode,
> > by addressing the bitmask as a series of int values, instead of
> > longs. This is broken as can easily be reproduced by running numademo
> > on a bit-endian 64-bit system.
> >
> > Changing the addressing to use 'long' values fixes the problem.
>
> Hi, Arnd:
>
> Not sure what you mean here. If the patch below is a proposed fix [I
> don't see a 'Signed-off-by:", but maybe not needed for libnuma
> patches?], the description above doesn't match the code. Looks like
> you're changing the addressing FROM 'long' values to use 'int' values so
> that the size is compatible between 32- and 64-bits. Or is that a
> reverse patch/diff below?
Sorry about that, I was in a hurry when sending this one out and attached
the wrong file, the reverse patch is needed indeed. I'll resend with
a proper Signed-off-by.
Arnd <><
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH, v2] numactl: fix libnuma on big-endian 64-bit systems
2008-12-04 20:49 ` Arnd Bergmann
@ 2008-12-04 20:51 ` Arnd Bergmann
2008-12-05 15:12 ` Arnd Bergmann
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2008-12-04 20:51 UTC (permalink / raw)
To: Lee Schermerhorn
Cc: linuxppc-dev, Mijo Safradin, Cliff Wickman, Christoph Lameter
The read-mask function assumes that it is running in 32-bit mode,
by addressing the bitmask as a series of int values, instead of
longs. This is broken as can easily be reproduced by running numademo
on a bit-endian 64-bit system.
Changing the addressing to use 'long' values fixes the problem.
Reported-by: Mijo Safradin <safradin@de.ibm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
libnuma.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libnuma.c b/libnuma.c
index 4d26093..9a9fbbe 100755
--- a/libnuma.c
+++ b/libnuma.c
@@ -376,9 +376,9 @@ read_mask(char *s, struct bitmask *bmp)
{
char *end = s;
char *prevend;
- unsigned int *start = (unsigned int *)bmp->maskp;
- unsigned int *p = start;
- unsigned int *q;
+ unsigned long *start = bmp->maskp;
+ unsigned long *p = start;
+ unsigned long *q;
unsigned int i;
unsigned int n = 0;
@@ -415,14 +415,14 @@ read_mask(char *s, struct bitmask *bmp)
}
/* Poor mans fls() */
- for(i = 31; i >= 0; i--)
+ for(i = sizeof(long) * 8 - 1; i >= 0; i--)
if (test_bit(i, start + n))
break;
/*
* Return the last bit set
*/
- return ((sizeof(unsigned int)*8) * n) + i;
+ return ((sizeof(unsigned long)*8) * n) + i;
}
/*
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH, v2] numactl: fix libnuma on big-endian 64-bit systems
2008-12-04 20:51 ` [PATCH, v2] " Arnd Bergmann
@ 2008-12-05 15:12 ` Arnd Bergmann
0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2008-12-05 15:12 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Lee Schermerhorn, Mijo Safradin, Cliff Wickman
On Thursday 04 December 2008, Arnd Bergmann wrote:
> The read-mask function assumes that it is running in 32-bit mode,
> by addressing the bitmask as a series of int values, instead of
> longs. This is broken as can easily be reproduced by running numademo
> on a bit-endian 64-bit system.
>
> Changing the addressing to use 'long' values fixes the problem.
Unfortunately, this is still wrong, as it tries recreating a kernel
data structure that is represented as a series of 'int' values, just
in a different order.
What we really need is the reverse of bitmap_scnprintf from
linux/lib/bitmap.c. I don't have access to a little-endian NUMA
machine with more than 64 CPUs, so I really don't want to send
another embarrassingly wrong patch for this.
Can anyone else try to come up with a version that handles endianess
correctly and still works on x86-64?
Arnd <><
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-12-05 15:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-04 17:34 [PATCH] numactl: fix libnuma on big-endian 64-bit systems Arnd Bergmann
2008-12-04 17:46 ` Lee Schermerhorn
2008-12-04 20:49 ` Arnd Bergmann
2008-12-04 20:51 ` [PATCH, v2] " Arnd Bergmann
2008-12-05 15:12 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).