lkml.org 
[lkml]   [2005]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs
Hi!

> > > +static inline u64 jiffies_to_nsecs(const unsigned long j)
> > > +{
> > > +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> > > + return (NSEC_PER_SEC / HZ) * (u64)j;
> > > +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> > > + return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > > +#else
> > > + return ((u64)j * NSEC_PER_SEC) / HZ;
> > > +#endif
> > > +}
> >
> > That might look a little better something like:
> >
> > static inline u64 jiffies_to_nsecs(const unsigned long __j)
> > {
> > u64 j = __j;
> >
> > if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
> > return (NSEC_PER_SEC / HZ) * j;
> > else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
> > return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > else
> > return (j * NSEC_PER_SEC) / HZ;
> > }
> >
> > Compilers are smart :)
>
> Well, I was trying to keep it similar to the other conversion functions.
> I guess the compiler can evaluate the conditional full of constants at
> compile-time regardless of whether it is #if or if ().
>
> I can make these changes if others would like them as well.

Yes, please. And feel free to convert nearby functions, too ;-).
Pavel
--
teflon -- maybe it is a trademark, but it should not be.
-
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/

\
 
 \ /
  Last update: 2005-07-16 15:59    [W:0.233 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site