* 2.5.75 as-iosched.c & asm-generic/div64.h breakage
@ 2003-07-11 20:48 Mikael Pettersson
2003-07-11 21:01 ` Andrew Morton
0 siblings, 1 reply; 6+ messages in thread
From: Mikael Pettersson @ 2003-07-11 20:48 UTC (permalink / raw)
To: axboe, bernie; +Cc: linux-kernel
Compiling 2.5.75 for PPC32 results in:
gcc -Wp,-MD,drivers/block/.as-iosched.o.d -D__KERNEL__ -Iinclude -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -Iarch/ppc -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring -fomit-frame-pointer -nostdinc -iwithprefix include -DKBUILD_BASENAME=as_iosched -DKBUILD_MODNAME=as_iosched -c -o drivers/block/as-iosched.o drivers/block/as-iosched.c
drivers/block/as-iosched.c: In function `as_update_iohist':
drivers/block/as-iosched.c:840: warning: right shift count >= width of type
drivers/block/as-iosched.c:840: warning: passing arg 1 of `__div64_32' from incompatible pointer type
The statement is "do_div(aic->seek_mean, aic->seek_samples);".
There are two problems here:
- aic->seek_mean is a sector_t, but this type is usually only u32 on 32-bitters,
unless CONFIG_LBD is set. Thus, as-iosched.c often passes a u32 lvalue to
do_div() where a u64 lvalue is expected.
- include/asm-generic/div64.h, which is what several 32-bit archs use now, is
unsafe when its first parameter "n" is a u32 lvalue:
* The "((n) >> 32) == 0" in the initial test invokes undefined behaviour.
We want it to be false, but this isn't guaranteed.
* The call "__div64_32(&(n), __base)" passes a u32* to a function
expecting a u64*. Major breakage.
x86 survives this because it's custom do_div() implicitly casts "n" to u64
before pulling it apart, and updates "n" with an assignment from a u64, so
the compiler can compensate when "n" is a u32. asm-generic/div64.h should
do something similar, IMO.
/Mikael
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 2.5.75 as-iosched.c & asm-generic/div64.h breakage
2003-07-11 20:48 2.5.75 as-iosched.c & asm-generic/div64.h breakage Mikael Pettersson
@ 2003-07-11 21:01 ` Andrew Morton
2003-07-12 0:49 ` Paul Mackerras
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2003-07-11 21:01 UTC (permalink / raw)
To: Mikael Pettersson; +Cc: axboe, bernie, linux-kernel
Mikael Pettersson <mikpe@csd.uu.se> wrote:
>
> drivers/block/as-iosched.c: In function `as_update_iohist':
> drivers/block/as-iosched.c:840: warning: right shift count >= width of type
> drivers/block/as-iosched.c:840: warning: passing arg 1 of `__div64_32' from incompatible pointer type
You mean that code was in -mm for all those months and no ppc32 person
bothered testing it? Bah.
Something like this? (Could be sped up for 32-bit sector_t)
diff -puN drivers/block/as-iosched.c~as-do_div-fix drivers/block/as-iosched.c
--- 25/drivers/block/as-iosched.c~as-do_div-fix Fri Jul 11 14:00:55 2003
+++ 25-akpm/drivers/block/as-iosched.c Fri Jul 11 14:00:58 2003
@@ -836,8 +836,10 @@ static void as_update_iohist(struct as_i
aic->seek_samples += 256;
aic->seek_total += 256*seek_dist;
if (aic->seek_samples) {
- aic->seek_mean = aic->seek_total + 128;
- do_div(aic->seek_mean, aic->seek_samples);
+ u64 seek_mean = aic->seek_total + 128;
+
+ do_div(seek_mean, aic->seek_samples);
+ aic->seek_mean = seek_mean;
}
aic->seek_samples = (aic->seek_samples>>1)
+ (aic->seek_samples>>2);
_
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 2.5.75 as-iosched.c & asm-generic/div64.h breakage
2003-07-11 21:01 ` Andrew Morton
@ 2003-07-12 0:49 ` Paul Mackerras
2003-07-12 1:03 ` Nick Piggin
0 siblings, 1 reply; 6+ messages in thread
From: Paul Mackerras @ 2003-07-12 0:49 UTC (permalink / raw)
To: Andrew Morton; +Cc: Mikael Pettersson, axboe, bernie, linux-kernel
Andrew Morton writes:
> Mikael Pettersson <mikpe@csd.uu.se> wrote:
> >
> > drivers/block/as-iosched.c: In function `as_update_iohist':
> > drivers/block/as-iosched.c:840: warning: right shift count >= width of type
> > drivers/block/as-iosched.c:840: warning: passing arg 1 of `__div64_32' from incompatible pointer type
>
> You mean that code was in -mm for all those months and no ppc32 person
> bothered testing it? Bah.
We've only been getting those warnings since the changeover to the new
asm-generic/div64.h. Settle down. :)
> Something like this? (Could be sped up for 32-bit sector_t)
>
> diff -puN drivers/block/as-iosched.c~as-do_div-fix drivers/block/as-iosched.c
> --- 25/drivers/block/as-iosched.c~as-do_div-fix Fri Jul 11 14:00:55 2003
> +++ 25-akpm/drivers/block/as-iosched.c Fri Jul 11 14:00:58 2003
> @@ -836,8 +836,10 @@ static void as_update_iohist(struct as_i
> aic->seek_samples += 256;
> aic->seek_total += 256*seek_dist;
> if (aic->seek_samples) {
> - aic->seek_mean = aic->seek_total + 128;
> - do_div(aic->seek_mean, aic->seek_samples);
> + u64 seek_mean = aic->seek_total + 128;
> +
> + do_div(seek_mean, aic->seek_samples);
> + aic->seek_mean = seek_mean;
> }
There are several interesting aspects to this:
1. For some reason the LBD config option in drivers/block/Kconfig
depends on X86. (CONFIG_LBD is what makes sector_t an unsigned
long long instead of an unsigned long). I think the LBD option
should be available on all 32-bit platforms. Working out a neat
way to tell the config system that is left as an exercise for the
reader. :)
2. It seems to me that seek_total is bounded above by 1024 * the
maximum seek distance. I'm a bit concerned about that overflowing
32 bits - AFAICS I would only need a > 2GB disk (or do I mean
partition?) for that to happen. Could we make seek_total be a u64
unconditionally please?
3. I guess that adding 128 on to the seek_total is to get a
round-to-nearest effect in the division. In fact you need to add
on (seek_samples >> 1) to get that effect.
Regards,
Paul.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 2.5.75 as-iosched.c & asm-generic/div64.h breakage
2003-07-12 0:49 ` Paul Mackerras
@ 2003-07-12 1:03 ` Nick Piggin
2003-07-14 4:10 ` Peter Chubb
0 siblings, 1 reply; 6+ messages in thread
From: Nick Piggin @ 2003-07-12 1:03 UTC (permalink / raw)
To: Paul Mackerras
Cc: Andrew Morton, Mikael Pettersson, axboe, bernie, linux-kernel
Hi!
Paul Mackerras wrote:
>Andrew Morton writes:
>
>
>>Mikael Pettersson <mikpe@csd.uu.se> wrote:
>>
>>>drivers/block/as-iosched.c: In function `as_update_iohist':
>>>drivers/block/as-iosched.c:840: warning: right shift count >= width of type
>>>drivers/block/as-iosched.c:840: warning: passing arg 1 of `__div64_32' from incompatible pointer type
>>>
>>You mean that code was in -mm for all those months and no ppc32 person
>>bothered testing it? Bah.
>>
>
>We've only been getting those warnings since the changeover to the new
>asm-generic/div64.h. Settle down. :)
>
>
>>Something like this? (Could be sped up for 32-bit sector_t)
>>
>>diff -puN drivers/block/as-iosched.c~as-do_div-fix drivers/block/as-iosched.c
>>--- 25/drivers/block/as-iosched.c~as-do_div-fix Fri Jul 11 14:00:55 2003
>>+++ 25-akpm/drivers/block/as-iosched.c Fri Jul 11 14:00:58 2003
>>@@ -836,8 +836,10 @@ static void as_update_iohist(struct as_i
>> aic->seek_samples += 256;
>> aic->seek_total += 256*seek_dist;
>> if (aic->seek_samples) {
>>- aic->seek_mean = aic->seek_total + 128;
>>- do_div(aic->seek_mean, aic->seek_samples);
>>+ u64 seek_mean = aic->seek_total + 128;
>>+
>>+ do_div(seek_mean, aic->seek_samples);
>>+ aic->seek_mean = seek_mean;
>> }
>>
>
>There are several interesting aspects to this:
>
>1. For some reason the LBD config option in drivers/block/Kconfig
> depends on X86. (CONFIG_LBD is what makes sector_t an unsigned
> long long instead of an unsigned long). I think the LBD option
> should be available on all 32-bit platforms. Working out a neat
> way to tell the config system that is left as an exercise for the
> reader. :)
>
Not me :P
>
>2. It seems to me that seek_total is bounded above by 1024 * the
> maximum seek distance. I'm a bit concerned about that overflowing
> 32 bits - AFAICS I would only need a > 2GB disk (or do I mean
> partition?) for that to happen. Could we make seek_total be a u64
> unconditionally please?
>
Probably a good idea. It is only the seek distance for one
process though. But it wouldn't hurt.
>
>3. I guess that adding 128 on to the seek_total is to get a
> round-to-nearest effect in the division. In fact you need to add
> on (seek_samples >> 1) to get that effect.
>
You're right. Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 2.5.75 as-iosched.c & asm-generic/div64.h breakage
2003-07-12 1:03 ` Nick Piggin
@ 2003-07-14 4:10 ` Peter Chubb
0 siblings, 0 replies; 6+ messages in thread
From: Peter Chubb @ 2003-07-14 4:10 UTC (permalink / raw)
To: Nick Piggin
Cc: Paul Mackerras, Andrew Morton, Mikael Pettersson, axboe, bernie,
linux-kernel
>>
>> 1. For some reason the LBD config option in drivers/block/Kconfig
>> depends on X86. (CONFIG_LBD is what makes sector_t an unsigned
>> long long instead of an unsigned long). I think the LBD option
>> should be available on all 32-bit platforms. Working out a neat
>> way to tell the config system that is left as an exercise for the
>> reader. :)
>>
Nick> Not me :P
No 'twas me --- because I couldn't work oput any cvlean way to do it,
and, of the 32-bit plaftforms, I could test only x86.
--
Dr Peter Chubb http://www.gelato.unsw.edu.au peterc AT gelato.unsw.edu.au
You are lost in a maze of BitKeeper repositories, all slightly different.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 2.5.75 as-iosched.c & asm-generic/div64.h breakage
@ 2003-07-11 21:36 Mikael Pettersson
0 siblings, 0 replies; 6+ messages in thread
From: Mikael Pettersson @ 2003-07-11 21:36 UTC (permalink / raw)
To: akpm, mikpe; +Cc: axboe, bernie, linux-kernel
On Fri, 11 Jul 2003 14:01:58 -0700, Andrew Morton wrote:
> Mikael Pettersson <mikpe@csd.uu.se> wrote:
> >
> > drivers/block/as-iosched.c: In function `as_update_iohist':
> > drivers/block/as-iosched.c:840: warning: right shift count >= width of type
> > drivers/block/as-iosched.c:840: warning: passing arg 1 of `__div64_32' from incompatible pointer type
>
> You mean that code was in -mm for all those months and no ppc32 person
> bothered testing it? Bah.
Apparently. I don't have time for anything but standard kernels.
> Something like this? (Could be sped up for 32-bit sector_t)
>
> diff -puN drivers/block/as-iosched.c~as-do_div-fix drivers/block/as-iosched.c
> --- 25/drivers/block/as-iosched.c~as-do_div-fix Fri Jul 11 14:00:55 2003
> +++ 25-akpm/drivers/block/as-iosched.c Fri Jul 11 14:00:58 2003
> @@ -836,8 +836,10 @@ static void as_update_iohist(struct as_i
> aic->seek_samples += 256;
> aic->seek_total += 256*seek_dist;
> if (aic->seek_samples) {
> - aic->seek_mean = aic->seek_total + 128;
> - do_div(aic->seek_mean, aic->seek_samples);
> + u64 seek_mean = aic->seek_total + 128;
> +
> + do_div(seek_mean, aic->seek_samples);
> + aic->seek_mean = seek_mean;
> }
> aic->seek_samples = (aic->seek_samples>>1)
> + (aic->seek_samples>>2);
Perhaps, but it's my opinion that do_div() needs to be made more robust,
since arch-specific data abstraction means that callers in generic code
don't always know if some value is u32 or u64.
So your change should be in do_div() itself, not in its callers.
/Mikael
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-07-14 3:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-11 20:48 2.5.75 as-iosched.c & asm-generic/div64.h breakage Mikael Pettersson
2003-07-11 21:01 ` Andrew Morton
2003-07-12 0:49 ` Paul Mackerras
2003-07-12 1:03 ` Nick Piggin
2003-07-14 4:10 ` Peter Chubb
2003-07-11 21:36 Mikael Pettersson
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).