Re: [PATCH 1/9] time: Condense timekeeper.xtime into xtime_sec

From: Richard Cochran
Date: Sat Mar 03 2012 - 00:54:55 EST


On Fri, Mar 02, 2012 at 03:13:25PM -0600, Christoph Lameter wrote:
> On Thu, 1 Mar 2012, John Stultz wrote:
>
> > +static inline void tk_normalize_xtime(struct timekeeper *tk)
> > +{
> > + while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) {
> > + tk->xtime_nsec -= (u64)NSEC_PER_SEC << tk->shift;
> > + tk->xtime_sec++;
> > + }
> > +}
>
> Could we avoid the loop?
>
> y = ((u64)NSEC_PER_SEC << tk->shift));
> tk->xtime_sec += tk->xtime_nsec / y;
> tk->xtime_nsec %= y;

But the two divisions are more costly than addition, substraction, and
shift.

(Normally the code loops just once.)

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