Re: MSEC_TO_JIFFIES is messed up...

From: Davide Libenzi
Date: Wed May 12 2004 - 16:40:20 EST


On Wed, 12 May 2004 Valdis.Kletnieks@xxxxxx wrote:

> On Wed, 12 May 2004 22:50:28 +0200, Ingo Molnar said:
>
> > Content-Disposition: attachment; filename="hz-cleanup-2.6.6-A2"
> >
> > --- linux/include/linux/time.h.orig
> > +++ linux/include/linux/time.h
> > @@ -177,6 +177,24 @@ struct timezone {
> > (SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC,
> 1) - 1)
> >
> > #endif
> > +
> > +/*
> > + * Convert jiffies to milliseconds and back.
> > + *
> > + * Avoid unnecessary multiplications/divisions in the
> > + * two most common HZ cases:
> > + */
> > +#if HZ == 1000
> > +# define JIFFIES_TO_MSECS(x) (x)
> > +# define MSECS_TO_JIFFIES(x) (x)
> > +#elif HZ == 100
> > +# define JIFFIES_TO_MSECS(x) ((x) * 10)
> > +# define MSECS_TO_JIFFIES(x) ((x) / 10)
> > +#else
> > +# define JIFFIES_TO_MSECS(x) ((x) * 1000 / HZ)
> > +# define MSECS_TO_JIFFIES(x) ((x) * HZ / 1000)
> > +#endif
> > +
>
> Looks good to me.. :)

Guys, why don't you leave the compiler to do its job?



- Davide

-
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/