Re: [PATCH v2] Provide an interface for getting the current tick length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



john stultz writes:

> > +	if (time_adjust_step)
> >  		/* Reduce by this step the amount of time left  */
> >  		time_adjust -= time_adjust_step;
> 
> Does the if statement really buy you anything here? 

Well, just avoiding dirtying a cache line in the common case where
time_adjust and time_adjust_step are zero, that's all.  It's a very
minor thing.  In fact if time_adjust is zero we could avoid the
procedure call, the subtraction and the multiplication by 1000, like
this:

	delta_nsec = tick_nsec;
	if (time_adjust) {
		time_adjust_step = adjtime_adjustment();
		/* Reduce by this step the amount of time left  */
		time_adjust -= time_adjust_step;
		delta_nsec += time_adjust_step * 1000;
	}

> > +u64 current_tick_length(void)
> > +{
> > +	long delta_nsec;
> > +
> > +	delta_nsec = tick_nsec + adjtime_adjustment() * 1000;
> > +	return ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj;
> > +}
> 
> You've got time_adj here, but you're not using what's been accumulated
> in time_phase, is that really ok?

Yes.

What's been accumulated in time_phase is always less than a
nanosecond's worth.  I took the approach of delivering the full
precision of time_adj to the arch code (i.e. including the 12 bits to
the right of the binary point), rather than truncating it to whole
nanoseconds and then having to vary it by +/- 1 nanosecond each tick.

Basically time_phase is just accumulating the fraction of a nanosecond
that we haven't been able to add onto xtime yet.  The effect of that
is that some ticks are 1 nanosecond longer or shorter than others,
depending on the fractional part of time_adj.  I set the factor and
offset that I use in the lockless gettimeofday to take into account
the whole time_adj value, including the fractional part.  That way I
don't have to change the factor and offset every tick, but only when
time_adj changes (or when the adjtime adjustment changes, of course).
The possible +/- 1 nanosecond difference is smaller than the
resolution of the timebase register, and way smaller than the time it
takes to do a gettimeofday and compare it with xtime, so it can be
ignored.

Paul.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux