Re: MSEC_TO_JIFFIES is messed up...
From: Sridhar Samudrala
Date: Wed May 12 2004 - 16:22:17 EST
I have submitted a patch just to do this some time back on netdev mailing
list. You can find it at
http://marc.theaimsgroup.com/?l=linux-netdev&m=108024598716537&w=2
static inline unsigned long msecs_to_jiffies(unsigned long msecs)
{
#if 1000 % HZ == 0
return msecs / (1000 / HZ);
#elif HZ % 1000 == 0
return msecs * (HZ / 1000);
#else
return (msecs / 1000) * HZ + (msecs % 1000) * HZ / 1000;
#endif
}
static inline unsigned long jiffies_to_msecs(unsigned long jiffs)
{
#if 1000 % HZ == 0
return jiffs * (1000 / HZ);
#elif HZ % 1000 == 0
return jiffs / (HZ / 1000);
#else
return (jiffs / HZ) * 1000 + (jiffs % HZ) * 1000 / HZ;
#endif
}
I was told that some users of these routines need an explicit roundup of
delays.
For ex: when HZ=100 and msecs is less than 10, the above msecs_to_jiffies()
returns 0 jiffies, whereas some users expect 1 jiffy.
So i modified msecs_to_jiffies() as follows which should do proper rounding
when HZ=100. But didn't get back any response.
static inline unsigned long msecs_to_jiffies(unsigned long msecs)
{
#if 1000 % HZ == 0
return (msecs + ((1000 / HZ) - 1)) / (1000 / HZ);
#elif HZ % 1000 == 0
return msecs * (HZ / 1000);
#else
return (msecs / 1000) * HZ + (msecs % 1000) * HZ / 1000;
#endif
}
Thanks
Sridhar
On Wed, 12 May 2004, Andrew Morton wrote:
> Jeff Garzik <jgarzik@xxxxxxxxx> wrote:
> >
> > > How about we do:
> > >
> > > #if HZ=1000
> > > #define MSEC_TO_JIFFIES(msec) (msec)
> > > #define JIFFIES_TO_MESC(jiffies) (jiffies)
> > > #elif HZ=100
> > > #define MSEC_TO_JIFFIES(msec) (msec * 10)
> > > #define JIFFIES_TO_MESC(jiffies) (jiffies / 10)
> > > #else
> > > #define MSEC_TO_JIFFIES(msec) ((HZ * (msec) + 999) / 1000)
> > > #define JIFFIES_TO_MSEC(jiffies) ...
> > > #endif
> > >
> > > in some kernel-wide header then kill off all the private implementations?
> >
> >
> > include/linux/time.h. One of the SCTP people already did this, but I
> > suppose it's straightforward to reproduce.
>
> OK, I'll do it.
>
>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/