04 Apr, 2011

1 commit

  • The ADJ_SETOFFSET bit added in commit 094aa188 ("ntp: Add ADJ_SETOFFSET
    mode bit") also introduced a way for any user to change the system time.
    Sneaky or buggy calls to adjtimex() could set

    ADJ_OFFSET_SS_READ | ADJ_SETOFFSET

    which would result in a successful call to timekeeping_inject_offset().
    This patch fixes the issue by adding the capability check.

    Signed-off-by: Richard Cochran
    Signed-off-by: Linus Torvalds

    Richard Cochran
     

19 Feb, 2011

1 commit

  • The ADJ_SETOFFSET code redundantly checks the range of the nanoseconds
    field of the time value. This field is checked again in the subsequent
    call to timekeeping_inject_offset(). Also, as is, the check will not
    detect whether the number of microseconds is out of range.

    Let timekeeping_inject_offset() do the error checking.

    Signed-off-by: Richard Cochran
    Cc: johnstul@us.ibm.com
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Richard Cochran
     

02 Feb, 2011

1 commit

  • This patch adds a new mode bit into the timex structure. When set, the bit
    instructs the kernel to add the given time value to the current time.

    Signed-off-by: Richard Cochran
    Acked-by: John Stultz
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Richard Cochran
     

01 Feb, 2011

1 commit

  • All callers of do_timer() are converted to xtime_update(). The only
    users of xtime_lock are in kernel/time/. Make both local to
    kernel/time/ and remove them from the global header files.

    [ tglx: Reuse tick-internal.h instead of creating another local header
    file. Massaged changelog ]

    Signed-off-by: Torben Hohn
    Cc: Peter Zijlstra
    Cc: johnstul@us.ibm.com
    Cc: yong.zhang0@gmail.com
    Cc: hch@infradead.org
    Signed-off-by: Thomas Gleixner

    Torben Hohn
     

14 Jan, 2011

1 commit

  • This commit adds hardpps() implementation based upon the original one from
    the NTPv4 reference kernel code from David Mills. However, it is highly
    optimized towards very fast syncronization and maximum stickness to PPS
    signal. The typical error is less then a microsecond.

    To make it sync faster I had to throw away exponential phase filter so
    that the full phase offset is corrected immediately. Then I also had to
    throw away median phase filter because it gives a bigger error itself if
    used without exponential filter.

    Maybe we will find an appropriate filtering scheme in the future but it's
    not necessary if the signal quality is ok.

    Signed-off-by: Alexander Gordeev
    Acked-by: John Stultz
    Cc: Rodolfo Giometti
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexander Gordeev
     

10 Sep, 2010

1 commit

  • Clamp update interval to reduce PLL gain with low sampling rate (e.g.
    intermittent network connection) to avoid instability.

    The clamp roughly corresponds to the loop time constant, it's 8 * poll
    interval for SHIFT_PLL 2 and 32 * poll interval for SHIFT_PLL 4. This
    gives good results without affecting the gain in normal conditions where
    ntpd skips only up to seven consecutive samples.

    Signed-off-by: Miroslav Lichvar
    Acked-by: john stultz
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Miroslav Lichvar
     

24 Mar, 2010

1 commit


29 Jan, 2010

2 commits


15 Aug, 2009

1 commit


27 Feb, 2009

1 commit


26 Feb, 2009

14 commits

  • Impact: cleanup, no functionality changed

    The 'time_adj' local variable is named in a very confusing
    way because it almost shadows the 'time_adjust' global
    variable - which is used in this same function.

    Rename it to 'delta' - to make them stand apart more clearly.

    kernel/time/ntp.o:

    text data bss dec hex filename
    2545 114 144 2803 af3 ntp.o.before
    2545 114 144 2803 af3 ntp.o.after

    md5:
    1bf0b3be564512279ba7cee299d1d2be ntp.o.before.asm
    1bf0b3be564512279ba7cee299d1d2be ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: micro-optimization

    Convert the (internal) ntp_tick_adj value we store from unscaled
    units to scaled units. This is a constant that we never modify,
    so scaling it up once during bootup is enough - we dont have to
    do it for every adjustment step.

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    - make PPM_SCALE an explicit s64 constant, to
    remove (s64) casts from usage sites.

    kernel/time/ntp.o:

    text data bss dec hex filename
    2536 114 136 2786 ae2 ntp.o.before
    2536 114 136 2786 ae2 ntp.o.after

    md5:
    40a7728d1188aa18e83e21a81fa7b150 ntp.o.before.asm
    40a7728d1188aa18e83e21a81fa7b150 ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Further simplify do_adjtimex():

    - introduce the ntp_start_leap_timer() helper function
    - eliminate the goto adj_done complication

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    do_adjtimex() is currently a monster function with a maze of
    branches. Refactor the txc->modes setting aspects of it into
    two new helper functions:

    process_adj_status()
    process_adjtimex_modes()

    kernel/time/ntp.o:

    text data bss dec hex filename
    2512 114 136 2762 aca ntp.o.before
    2512 114 136 2762 aca ntp.o.after

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: change (fix) the way the NTP PLL seconds offset is initialized/tracked

    Fix a bug and do a micro-optimization:

    When PLL is enabled we do not reset time_reftime. If the PLL
    was off for a long time (for example after bootup), this is
    arguably the wrong thing to do.

    We already had a hack for the common boot-time case in
    ntp_update_offset(), in form of:

    if (unlikely(time_status & STA_FREQHOLD || time_reftime == 0))
    secs = 0;

    But the update delta should be reset later on too - not just when
    the PLL is enabled for the first time after bootup.

    So do it on !STA_PLL -> STA_PLL transitions.

    This changes behavior, as previously if ntpd was disabled for
    a long time and we restarted it, we'd run from that last update,
    with a very large delta.

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    The time_reftime update in ntp_update_offset() to xtime.tv_sec
    is a convoluted way of saying that we want to freeze the frequency
    and want the 'secs' delta to be 0. Also make this branch unlikely.

    This shaves off 8 bytes from the code size:

    text data bss dec hex filename
    2504 114 136 2754 ac2 ntp.o.before
    2496 114 136 2746 aba ntp.o.after

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Change ntp_update_offset_fll() to delta logic instead of
    absolute value logic. This eliminates 'freq_adj' from the
    function.

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    - introduce the ntp_update_offset_fll() helper
    - clean up the flow and variable naming

    kernel/time/ntp.o:

    text data bss dec hex filename
    2504 114 136 2754 ac2 ntp.o.before
    2504 114 136 2754 ac2 ntp.o.after

    md5:
    01f7b8e1a5472a3056f9e4ae84d46315 ntp.o.before.asm
    01f7b8e1a5472a3056f9e4ae84d46315 ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Change ntp_update_frequency() from a hard to follow code
    flow that uses global variables as temporaries, to a clean
    input+output flow.

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Prepare a refactoring of ntp_update_frequency().

    kernel/time/ntp.o:

    text data bss dec hex filename
    2504 114 136 2754 ac2 ntp.o.before
    2504 114 136 2754 ac2 ntp.o.after

    md5:
    41f3009debc9b397d7394dd77d912f0a ntp.o.before.asm
    41f3009debc9b397d7394dd77d912f0a ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    There's an ugly u64 typecase in the MAX_TICKADJ_SCALED definition,
    this can be eliminated by making the MAX_TICKADJ constant's type
    64-bit (signed).

    kernel/time/ntp.o:

    text data bss dec hex filename
    2504 114 136 2754 ac2 ntp.o.before
    2504 114 136 2754 ac2 ntp.o.after

    md5:
    41f3009debc9b397d7394dd77d912f0a ntp.o.before.asm
    41f3009debc9b397d7394dd77d912f0a ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Instead of a hierarchy of conditions, transform them to clean
    gradual conditions and return's.

    This makes the flow easier to read and makes the purpose of
    the function easier to understand.

    kernel/time/ntp.o:

    text data bss dec hex filename
    2552 170 168 2890 b4a ntp.o.before
    2552 170 168 2890 b4a ntp.o.after

    md5:
    eae1275df0b7d6290c13f6f6f8f05c8c ntp.o.before.asm
    eae1275df0b7d6290c13f6f6f8f05c8c ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     
  • Impact: cleanup, no functionality changed

    Make this file a bit more readable by applying a consistent coding style.

    No code changed:

    kernel/time/ntp.o:

    text data bss dec hex filename
    2552 170 168 2890 b4a ntp.o.before
    2552 170 168 2890 b4a ntp.o.after

    md5:
    eae1275df0b7d6290c13f6f6f8f05c8c ntp.o.before.asm
    eae1275df0b7d6290c13f6f6f8f05c8c ntp.o.after.asm

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

19 Feb, 2009

1 commit

  • Since the GENERIC_TIME changes landed, the adjtimex behavior changed
    for struct timex.tick and .freq changed. When the tick or freq value
    is set, we adjust the tick_length_base in ntp_update_frequency().
    However, this new value doesn't get applied to tick_length until the
    next second (via second_overflow).

    This means some applications that do quick time tweaking do not see the
    requested change made as quickly as expected.

    I've run a few tests with this change, and ntpd still functions fine.

    Signed-off-by: John Stultz
    Signed-off-by: Ingo Molnar

    john stultz
     

25 Nov, 2008

1 commit

  • Impact: cleanup, move all hrtimer processing into hardirq context

    This is an attempt at removing some of the hrtimer complexity by
    reducing the number of callback modes to 1.

    This means that all hrtimer callback functions will be ran from HARD-irq
    context.

    I went through all the 30 odd hrtimer callback functions in the kernel
    and saw only one that I'm not quite sure of, which is the one in
    net/can/bcm.c - hence I'm CC-ing the folks responsible for that code.

    Furthermore, the hrtimer core now calls callbacks directly with IRQs
    disabled in case you try to enqueue an expired timer. If this timer is a
    periodic timer (which should use hrtimer_forward() to advance its time)
    then it might be possible to end up in an inf. recursive loop due to the
    fact that hrtimer_forward() doesn't round up to the next timer
    granularity, and therefore keeps on calling the callback - obviously
    this needs a fix.

    Aside from that, this seems to compile and actually boot on my dual core
    test box - although I'm sure there are some bugs in, me not hitting any
    makes me certain :-)

    Signed-off-by: Peter Zijlstra
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

22 Oct, 2008

1 commit


20 Oct, 2008

1 commit


18 Oct, 2008

1 commit


24 Sep, 2008

2 commits

  • Change PPM_SCALE_INV_SHIFT so that it doesn't throw away any input bits
    (19 is the amount of the factor 2 in PPM_SCALE), the output frequency
    can then be calculated back to its input value, as the inverse divide
    produce a slightly larger value, which is then correctly rounded by the
    final shift.

    Reported-by: Martin Ziegler
    Signed-off-by: Roman Zippel
    Cc: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Thomas Gleixner

    Roman Zippel
     
  • This is a change that makes the 11-minute RTC update be run in the process
    context. This is so that update_persistent_clock() can sleep, which may
    be required for certain types of RTC hardware -- most notably I2C devices.

    Signed-off-by: Maciej W. Rozycki
    Cc: Roman Zippel
    Cc: Rik van Riel
    Cc: David Brownell
    Acked-by: Alessandro Zummo
    Signed-off-by: Andrew Morton
    Signed-off-by: Thomas Gleixner

    Maciej W. Rozycki
     

06 Sep, 2008

2 commits

  • We have a bug in the calculation of the next jiffie to trigger the RTC
    synchronisation. The aim here is to run sync_cmos_clock() as close as
    possible to the middle of a second. Which means we want this function to
    be called less than or equal to half a jiffie away from when now.tv_nsec
    equals 5e8 (500000000).

    If this is not the case for a given call to the function, for this purpose
    instead of updating the RTC we calculate the offset in nanoseconds to the
    next point in time where now.tv_nsec will be equal 5e8. The calculated
    offset is then converted to jiffies as these are the unit used by the
    timer.

    Hovewer timespec_to_jiffies() used here uses a ceil()-type rounding mode,
    where the resulting value is rounded up. As a result the range of
    now.tv_nsec when the timer will trigger is from 5e8 to 5e8 + TICK_NSEC
    rather than the desired 5e8 - TICK_NSEC / 2 to 5e8 + TICK_NSEC / 2.

    As a result if for example sync_cmos_clock() happens to be called at the
    time when now.tv_nsec is between 5e8 + TICK_NSEC / 2 and 5e8 to 5e8 +
    TICK_NSEC, it will simply be rescheduled HZ jiffies later, falling in the
    same range of now.tv_nsec again. Similarly for cases offsetted by an
    integer multiple of TICK_NSEC.

    This change addresses the problem by subtracting TICK_NSEC / 2 from the
    nanosecond offset to the next point in time where now.tv_nsec will be
    equal 5e8, effectively shifting the following rounding in
    timespec_to_jiffies() so that it produces a rounded-to-nearest result.

    Signed-off-by: Maciej W. Rozycki
    Signed-off-by: Andrew Morton
    Signed-off-by: Ingo Molnar

    Maciej W. Rozycki
     
  • In order to be able to do range hrtimers we need to use accessor functions
    to the "expire" member of the hrtimer struct.
    This patch converts kernel/* to these accessors.

    Signed-off-by: Arjan van de Ven

    Arjan van de Ven
     

22 Aug, 2008

1 commit

  • Thanks to the review by Michael Kerrisk a bug in the recent
    ADJ_OFFSET_SS_READ option was discovered, where the ntp time_offset was
    inadvertently set by it. This fixes this by making the adjtime code
    more separate from the ntp_adjtime code (both of which really want to
    be separate syscalls).

    Signed-off-by: Roman Zippel
    Signed-off-by: Andrew Morton
    Acked-by: John Stultz
    Signed-off-by: Ingo Molnar

    Roman Zippel
     

01 May, 2008

5 commits

  • Remove the leap second handling from second_overflow(), which doesn't have to
    check for it every second anymore. With CONFIG_NO_HZ this also makes sure the
    leap second is handled close to the full second. Additionally this makes it
    possible to abort a leap second properly by resetting the STA_INS/STA_DEL
    status bits.

    Signed-off-by: Roman Zippel
    Cc: john stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel
     
  • current_tick_length used to do a little more, but now it just returns
    tick_length, which we can also access directly at the few places, where it's
    needed.

    Signed-off-by: Roman Zippel
    Cc: john stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel
     
  • As TICK_LENGTH_SHIFT is used for more than just the tick length, the name
    isn't quite approriate anymore, so this renames it to NTP_SCALE_SHIFT.

    Signed-off-by: Roman Zippel
    Cc: john stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel
     
  • This adds support for setting the TAI value (International Atomic Time). The
    value is reported back to userspace via timex (as we don't have a
    ntp_gettime() syscall).

    Signed-off-by: Roman Zippel
    Cc: john stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel
     
  • time_offset is already a 64bit value but its resolution barely used, so this
    makes better use of it by replacing SHIFT_UPDATE with TICK_LENGTH_SHIFT.

    Side note: the SHIFT_HZ in SHIFT_UPDATE was incorrect for CONFIG_NO_HZ and the
    primary reason for changing time_offset to 64bit to avoid the overflow.

    Signed-off-by: Roman Zippel
    Cc: john stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel