* [PATCH] joydev: fix HZ->millisecond transformation
@ 2002-12-16 19:27 Bjorn Helgaas
2002-12-20 10:41 ` george anzinger
0 siblings, 1 reply; 9+ messages in thread
From: Bjorn Helgaas @ 2002-12-16 19:27 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: vojtech, linux-kernel
* fix a problem with HZ->millisecond transformation on
non-x86 archs (from 2.5 change by vojtech@suse.cz)
Applies to 2.4.20.
diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c
--- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002
+++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002
@@ -50,6 +50,8 @@
#define JOYDEV_MINORS 32
#define JOYDEV_BUFFER_SIZE 64
+#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ)
+
struct joydev {
int exist;
int open;
@@ -134,7 +136,7 @@
return;
}
- event.time = jiffies * (1000 / HZ);
+ event.time = MSECS(jiffies);
while (list) {
@@ -279,7 +281,7 @@
struct js_event event;
- event.time = jiffies * (1000/HZ);
+ event.time = MSECS(jiffies);
if (list->startup < joydev->nkey) {
event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-16 19:27 [PATCH] joydev: fix HZ->millisecond transformation Bjorn Helgaas @ 2002-12-20 10:41 ` george anzinger 2002-12-20 13:24 ` Vojtech Pavlik 0 siblings, 1 reply; 9+ messages in thread From: george anzinger @ 2002-12-20 10:41 UTC (permalink / raw) To: Bjorn Helgaas; +Cc: Marcelo Tosatti, vojtech, linux-kernel Bjorn Helgaas wrote: > > * fix a problem with HZ->millisecond transformation on > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > Applies to 2.4.20. > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > @@ -50,6 +50,8 @@ > #define JOYDEV_MINORS 32 > #define JOYDEV_BUFFER_SIZE 64 > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) Uh... ^^^^^^^^^^^^^^^^ by definition this is zero, is it not? > + > struct joydev { > int exist; > int open; > @@ -134,7 +136,7 @@ > return; > } > > - event.time = jiffies * (1000 / HZ); > + event.time = MSECS(jiffies); > > while (list) { > > @@ -279,7 +281,7 @@ > > struct js_event event; > > - event.time = jiffies * (1000/HZ); > + event.time = MSECS(jiffies); > > if (list->startup < joydev->nkey) { > event.type = JS_EVENT_BUTTON | JS_EVENT_INIT; > > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- George Anzinger george@mvista.com High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 10:41 ` george anzinger @ 2002-12-20 13:24 ` Vojtech Pavlik 2002-12-20 14:52 ` Joe Korty 2002-12-20 17:24 ` george anzinger 0 siblings, 2 replies; 9+ messages in thread From: Vojtech Pavlik @ 2002-12-20 13:24 UTC (permalink / raw) To: george anzinger; +Cc: Bjorn Helgaas, Marcelo Tosatti, linux-kernel On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > Bjorn Helgaas wrote: > > > > * fix a problem with HZ->millisecond transformation on > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > Applies to 2.4.20. > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > @@ -50,6 +50,8 @@ > > #define JOYDEV_MINORS 32 > > #define JOYDEV_BUFFER_SIZE 64 > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > Uh... > ^^^^^^^^^^^^^^^^ > by definition this is zero, is it not? No, both parts of the equaition can be nonzero. Though it might be easier to say (1000 * t) / HZ, now that I think about it. -- Vojtech Pavlik SuSE Labs ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 13:24 ` Vojtech Pavlik @ 2002-12-20 14:52 ` Joe Korty 2002-12-20 17:24 ` george anzinger 1 sibling, 0 replies; 9+ messages in thread From: Joe Korty @ 2002-12-20 14:52 UTC (permalink / raw) To: Vojtech Pavlik Cc: george anzinger, Bjorn Helgaas, Marcelo Tosatti, linux-kernel [ repost -- I am going to have to get outgoing mail fixed on my lkml-reading machine ] > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: >> Bjorn Helgaas wrote: >>> >>> * fix a problem with HZ->millisecond transformation on >>> non-x86 archs (from 2.5 change by vojtech@suse.cz) >>> [...] >>> +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) >>> [...] > Though it might be easier to say (1000 * t) / HZ, now that I think about > it. The more complex version avoids integer overflow for more values of 't' in the (1000 * t) subexpression. Joe ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 13:24 ` Vojtech Pavlik 2002-12-20 14:52 ` Joe Korty @ 2002-12-20 17:24 ` george anzinger 2002-12-20 17:35 ` Vojtech Pavlik 1 sibling, 1 reply; 9+ messages in thread From: george anzinger @ 2002-12-20 17:24 UTC (permalink / raw) To: Vojtech Pavlik; +Cc: Bjorn Helgaas, Marcelo Tosatti, linux-kernel Vojtech Pavlik wrote: > > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > > Bjorn Helgaas wrote: > > > > > > * fix a problem with HZ->millisecond transformation on > > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > > > Applies to 2.4.20. > > > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > @@ -50,6 +50,8 @@ > > > #define JOYDEV_MINORS 32 > > > #define JOYDEV_BUFFER_SIZE 64 > > > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > > Uh... > > ^^^^^^^^^^^^^^^^ > > by definition this is zero, is it not? > > No, both parts of the equaition can be nonzero. I don't think so. s%HZ has to be less than HZ. Then dividing that by HZ should result in zero. Where is my thinking flawed? > > Though it might be easier to say (1000 * t) / HZ, now that I think about > it. That overflows... As does the other if HZ is less than 1000.... > > -- > Vojtech Pavlik > SuSE Labs > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- George Anzinger george@mvista.com High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 17:24 ` george anzinger @ 2002-12-20 17:35 ` Vojtech Pavlik 2002-12-20 18:16 ` george anzinger 0 siblings, 1 reply; 9+ messages in thread From: Vojtech Pavlik @ 2002-12-20 17:35 UTC (permalink / raw) To: george anzinger Cc: Vojtech Pavlik, Bjorn Helgaas, Marcelo Tosatti, linux-kernel On Fri, Dec 20, 2002 at 09:24:58AM -0800, george anzinger wrote: > Vojtech Pavlik wrote: > > > > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > > > Bjorn Helgaas wrote: > > > > > > > > * fix a problem with HZ->millisecond transformation on > > > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > > > > > Applies to 2.4.20. > > > > > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > @@ -50,6 +50,8 @@ > > > > #define JOYDEV_MINORS 32 > > > > #define JOYDEV_BUFFER_SIZE 64 > > > > > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > > > Uh... > > > ^^^^^^^^^^^^^^^^ > > > by definition this is zero, is it not? > > > > No, both parts of the equaition can be nonzero. > > I don't think so. s%HZ has to be less than HZ. Then > dividing that by HZ should result in zero. Where is my > thinking flawed? You first multiply it by 1000. > > Though it might be easier to say (1000 * t) / HZ, now that I think about > > it. > > That overflows... As does the other if HZ is less than 1000.... You're right, t can be all 32 bits. -- Vojtech Pavlik SuSE Labs ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 17:35 ` Vojtech Pavlik @ 2002-12-20 18:16 ` george anzinger 2002-12-21 9:18 ` Vojtech Pavlik 0 siblings, 1 reply; 9+ messages in thread From: george anzinger @ 2002-12-20 18:16 UTC (permalink / raw) To: Vojtech Pavlik; +Cc: Bjorn Helgaas, Marcelo Tosatti, linux-kernel Vojtech Pavlik wrote: > > On Fri, Dec 20, 2002 at 09:24:58AM -0800, george anzinger wrote: > > Vojtech Pavlik wrote: > > > > > > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > > > > Bjorn Helgaas wrote: > > > > > > > > > > * fix a problem with HZ->millisecond transformation on > > > > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > > > > > > > Applies to 2.4.20. > > > > > > > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > > > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > @@ -50,6 +50,8 @@ > > > > > #define JOYDEV_MINORS 32 > > > > > #define JOYDEV_BUFFER_SIZE 64 > > > > > > > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > > > > Uh... > > > > ^^^^^^^^^^^^^^^^ > > > > by definition this is zero, is it not? > > > > > > No, both parts of the equaition can be nonzero. > > > > I don't think so. s%HZ has to be less than HZ. Then > > dividing that by HZ should result in zero. Where is my > > thinking flawed? > > You first multiply it by 1000. But then it should read: (1000 * (t)) % HZ) / HZ But this is still zero. There is no way that ((X % HZ) / HZ) is other than zero, me thinks. > > > > Though it might be easier to say (1000 * t) / HZ, now that I think about > > > it. > > > > That overflows... As does the other if HZ is less than 1000.... > > You're right, t can be all 32 bits. What, exactly, is this code trying to do? It looks like the number is being passed to user space... > > -- > Vojtech Pavlik > SuSE Labs > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- George Anzinger george@mvista.com High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-20 18:16 ` george anzinger @ 2002-12-21 9:18 ` Vojtech Pavlik 2002-12-21 16:46 ` george anzinger 0 siblings, 1 reply; 9+ messages in thread From: Vojtech Pavlik @ 2002-12-21 9:18 UTC (permalink / raw) To: george anzinger Cc: Vojtech Pavlik, Bjorn Helgaas, Marcelo Tosatti, linux-kernel On Fri, Dec 20, 2002 at 10:16:27AM -0800, george anzinger wrote: > Vojtech Pavlik wrote: > > > > On Fri, Dec 20, 2002 at 09:24:58AM -0800, george anzinger wrote: > > > Vojtech Pavlik wrote: > > > > > > > > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > > > > > Bjorn Helgaas wrote: > > > > > > > > > > > > * fix a problem with HZ->millisecond transformation on > > > > > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > > > > > > > > > Applies to 2.4.20. > > > > > > > > > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > > > > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > > @@ -50,6 +50,8 @@ > > > > > > #define JOYDEV_MINORS 32 > > > > > > #define JOYDEV_BUFFER_SIZE 64 > > > > > > > > > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > > > > > Uh... > > > > > ^^^^^^^^^^^^^^^^ > > > > > by definition this is zero, is it not? > > > > > > > > No, both parts of the equaition can be nonzero. > > > > > > I don't think so. s%HZ has to be less than HZ. Then > > > dividing that by HZ should result in zero. Where is my > > > thinking flawed? > > > > You first multiply it by 1000. > > But then it should read: (1000 * (t)) % HZ) / HZ The expression is evaluated from left to right. No need for parentheses here. > But this is still zero. There is no way that ((X % HZ) / > HZ) is other than zero, me thinks. Example: HZ = 100 t = 70 1000 * (t % HZ) / HZ = 1000 * 70 / 100 = 700 != 0 Anyway (x % HZ) / HZ must be zero, but that's something different. > > > > Though it might be easier to say (1000 * t) / HZ, now that I think about > > > > it. > > > > > > That overflows... As does the other if HZ is less than 1000.... > > > > You're right, t can be all 32 bits. > > What, exactly, is this code trying to do? It looks like the > number is being passed to user space... It's trying to convert jiffies to microseconds from computer start (or any other arbitrary point in time), thus making the value independent of HZ. > -- > George Anzinger george@mvista.com > High-res-timers: > http://sourceforge.net/projects/high-res-timers/ > Preemption patch: > http://www.kernel.org/pub/linux/kernel/people/rml -- Vojtech Pavlik SuSE Labs ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] joydev: fix HZ->millisecond transformation 2002-12-21 9:18 ` Vojtech Pavlik @ 2002-12-21 16:46 ` george anzinger 0 siblings, 0 replies; 9+ messages in thread From: george anzinger @ 2002-12-21 16:46 UTC (permalink / raw) To: Vojtech Pavlik; +Cc: Bjorn Helgaas, Marcelo Tosatti, linux-kernel Vojtech Pavlik wrote: > > On Fri, Dec 20, 2002 at 10:16:27AM -0800, george anzinger wrote: > > Vojtech Pavlik wrote: > > > > > > On Fri, Dec 20, 2002 at 09:24:58AM -0800, george anzinger wrote: > > > > Vojtech Pavlik wrote: > > > > > > > > > > On Fri, Dec 20, 2002 at 02:41:50AM -0800, george anzinger wrote: > > > > > > Bjorn Helgaas wrote: > > > > > > > > > > > > > > * fix a problem with HZ->millisecond transformation on > > > > > > > non-x86 archs (from 2.5 change by vojtech@suse.cz) > > > > > > > > > > > > > > Applies to 2.4.20. > > > > > > > > > > > > > > diff -Nru a/drivers/input/joydev.c b/drivers/input/joydev.c > > > > > > > --- a/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > > > +++ b/drivers/input/joydev.c Mon Dec 16 12:16:32 2002 > > > > > > > @@ -50,6 +50,8 @@ > > > > > > > #define JOYDEV_MINORS 32 > > > > > > > #define JOYDEV_BUFFER_SIZE 64 > > > > > > > > > > > > > > +#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ) > > > > > > Uh... > > > > > > ^^^^^^^^^^^^^^^^ > > > > > > by definition this is zero, is it not? > > > > > > > > > > No, both parts of the equaition can be nonzero. > > > > > > > > I don't think so. s%HZ has to be less than HZ. Then > > > > dividing that by HZ should result in zero. Where is my > > > > thinking flawed? > > > > > > You first multiply it by 1000. > > > > But then it should read: (1000 * (t)) % HZ) / HZ > > The expression is evaluated from left to right. No need for parentheses > here. > > > But this is still zero. There is no way that ((X % HZ) / > > HZ) is other than zero, me thinks. > > Example: > > HZ = 100 > t = 70 > > 1000 * (t % HZ) / HZ = 1000 * 70 / 100 = 700 != 0 > > Anyway (x % HZ) / HZ must be zero, but that's something different. OK, I miss read the "("s. :( > > > > > > Though it might be easier to say (1000 * t) / HZ, now that I think about > > > > > it. > > > > > > > > That overflows... As does the other if HZ is less than 1000.... > > > > > > You're right, t can be all 32 bits. > > > > What, exactly, is this code trying to do? It looks like the > > number is being passed to user space... > > It's trying to convert jiffies to microseconds from computer start (or > any other arbitrary point in time), thus making the value independent of > HZ. > This is possible, but in general it can not be kept in one 32-bit word. I don't know what it is used for or if the format can be changed, but the struct timeval comes to mind. -- George Anzinger george@mvista.com High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2002-12-21 16:38 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2002-12-16 19:27 [PATCH] joydev: fix HZ->millisecond transformation Bjorn Helgaas 2002-12-20 10:41 ` george anzinger 2002-12-20 13:24 ` Vojtech Pavlik 2002-12-20 14:52 ` Joe Korty 2002-12-20 17:24 ` george anzinger 2002-12-20 17:35 ` Vojtech Pavlik 2002-12-20 18:16 ` george anzinger 2002-12-21 9:18 ` Vojtech Pavlik 2002-12-21 16:46 ` george anzinger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox