02 Oct, 2015

1 commit

  • There is only one user of the hardpps function in the kernel, so
    it makes sense to atomically change it over to using 64-bit
    timestamps for y2038 safety. In the hardpps implementation,
    we also need to change the pps_normtime structure, which is
    similar to struct timespec and also requires a 64-bit
    seconds portion.

    This introduces two temporary variables in pps_kc_event() to
    do the conversion, they will be removed again in the next step,
    which seemed preferable to having a larger patch changing it
    all at the same time.

    Acked-by: Richard Cochran
    Acked-by: David S. Miller
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Arnd Bergmann
    Signed-off-by: John Stultz

    Arnd Bergmann
     

11 Oct, 2013

2 commits

  • Pull /dev/random changes from Ted Ts'o:
    "These patches are designed to enable improvements to /dev/random for
    non-x86 platforms, in particular MIPS and ARM"

    * tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
    random: allow architectures to optionally define random_get_entropy()
    random: run random_int_secret_init() run after all late_initcalls

    Linus Torvalds
     
  • Allow architectures which have a disabled get_cycles() function to
    provide a random_get_entropy() function which provides a fine-grained,
    rapidly changing counter that can be used by the /dev/random driver.

    For example, an architecture might have a rapidly changing register
    used to control random TLB cache eviction, or DRAM refresh that
    doesn't meet the requirements of get_cycles(), but which is good
    enough for the needs of the random driver.

    Signed-off-by: "Theodore Ts'o"
    Cc: stable@vger.kernel.org

    Theodore Ts'o
     

12 Sep, 2013

1 commit

  • Gerlando Falauto reported that when HRTICK is enabled, it is
    possible to trigger system deadlocks. These were hard to
    reproduce, as HRTICK has been broken in the past, but seemed
    to be connected to the timekeeping_seq lock.

    Since seqlock/seqcount's aren't supported w/ lockdep, I added
    some extra spinlock based locking and triggered the following
    lockdep output:

    [ 15.849182] ntpd/4062 is trying to acquire lock:
    [ 15.849765] (&(&pool->lock)->rlock){..-...}, at: [] __queue_work+0x145/0x480
    [ 15.850051]
    [ 15.850051] but task is already holding lock:
    [ 15.850051] (timekeeper_lock){-.-.-.}, at: [] do_adjtimex+0x7f/0x100

    [ 15.850051] Chain exists of: &(&pool->lock)->rlock --> &p->pi_lock --> timekeeper_lock
    [ 15.850051] Possible unsafe locking scenario:
    [ 15.850051]
    [ 15.850051] CPU0 CPU1
    [ 15.850051] ---- ----
    [ 15.850051] lock(timekeeper_lock);
    [ 15.850051] lock(&p->pi_lock);
    [ 15.850051] lock(timekeeper_lock);
    [ 15.850051] lock(&(&pool->lock)->rlock);
    [ 15.850051]
    [ 15.850051] *** DEADLOCK ***

    The deadlock was introduced by 06c017fdd4dc48451a ("timekeeping:
    Hold timekeepering locks in do_adjtimex and hardpps") in 3.10

    This patch avoids this deadlock, by moving the call to
    schedule_delayed_work() outside of the timekeeper lock
    critical section.

    Reported-by: Gerlando Falauto
    Tested-by: Lin Ming
    Signed-off-by: John Stultz
    Cc: Mathieu Desnoyers
    Cc: stable #3.11, 3.10
    Link: http://lkml.kernel.org/r/1378943457-27314-1-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    John Stultz
     

05 Apr, 2013

1 commit

  • In preparation for changing the ntp locking rules, move
    do_adjtimex and hardpps accessor functions to timekeeping.c,
    but keep the code logic in ntp.c.

    This patch also introduces a ntp_internal.h file so timekeeping
    specific interfaces of ntp.c can be more limitedly shared with
    timekeeping.c.

    Cc: Thomas Gleixner
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Signed-off-by: John Stultz

    John Stultz
     

13 Oct, 2012

1 commit


31 Jul, 2012

1 commit

  • Ingo noted that ACTHZ is a confusing name, and requested it
    be renamed, so this patch renames ACTHZ to SHIFTED_HZ to
    better describe it.

    Signed-off-by: John Stultz
    Cc: Prarit Bhargava
    Link: http://lkml.kernel.org/r/1343414893-45779-3-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    John Stultz
     

23 Mar, 2012

1 commit

  • Since commit 7dffa3c673fbcf835cd7be80bb4aec8ad3f51168 the ntp
    subsystem has used an hrtimer for triggering the leapsecond
    adjustment. However, this can cause a potential livelock.

    Thomas diagnosed this as the following pattern:
    CPU 0 CPU 1
    do_adjtimex()
    spin_lock_irq(&ntp_lock);
    process_adjtimex_modes(); timer_interrupt()
    process_adj_status(); do_timer()
    ntp_start_leap_timer(); write_lock(&xtime_lock);
    hrtimer_start(); update_wall_time();
    hrtimer_reprogram(); ntp_tick_length()
    tick_program_event() spin_lock(&ntp_lock);
    clockevents_program_event()
    ktime_get()
    seq = req_seqbegin(xtime_lock);

    This patch tries to avoid the problem by reverting back to not using
    an hrtimer to inject leapseconds, and instead we handle the leapsecond
    processing in the second_overflow() function.

    The downside to this change is that on systems that support highres
    timers, the leap second processing will occur on a HZ tick boundary,
    (ie: ~1-10ms, depending on HZ) after the leap second instead of
    possibly sooner (~34us in my tests w/ x86_64 lapic).

    This patch applies on top of tip/timers/core.

    CC: Sasha Levin
    CC: Thomas Gleixner
    Reported-by: Sasha Levin
    Diagnoised-by: Thomas Gleixner
    Tested-by: Sasha Levin
    Signed-off-by: John Stultz

    John Stultz
     

27 Jan, 2012

2 commits


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
     

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
     

24 Mar, 2010

2 commits


29 Jan, 2010

1 commit


09 Dec, 2009

1 commit


05 Oct, 2009

1 commit

  • Accumulating one tick at a time works well unless we're using NOHZ.
    Then it can be an issue, since we may have to run through the loop
    a few thousand times, which can increase timer interrupt caused
    latency.

    The current solution was to accumulate in half-second intervals
    with NOHZ. This kept the number of loops down, however it did
    slightly change how we make NTP adjustments. While not an issue
    with NTPd users, as NTPd makes adjustments over a longer period of
    time, other adjtimex() users have noticed the half-second
    granularity with which we can apply frequency changes to the clock.

    For instance, if a application tries to apply a 100ppm frequency
    correction for 20ms to correct a 2us offset, with NOHZ they either
    get no correction, or a 50us correction.

    Now, there will always be some granularity error for applying
    frequency corrections. However with users sensitive to this error
    have seen a 50-500x increase with NOHZ compared to running without
    NOHZ.

    So I figured I'd try another approach then just simply increasing
    the interval. My approach is to consume the time interval
    logarithmically. This reduces the number of times through the loop
    needed keeping latency down, while still preserving the original
    granularity error for adjtimex() changes.

    Further, this change allows us to remove the xtime_cache code
    (patch to follow), as xtime is always within one tick of the
    current time, instead of the half-second updates it saw before.

    An earlier version of this patch has been shipping to x86 users in
    the RedHat MRG releases for awhile without issue, but I've reworked
    this version to be even more careful about avoiding possible
    overflows if the shift value gets too large.

    Signed-off-by: John Stultz
    Acked-by: Thomas Gleixner
    Reviewed-by: John Kacur
    Cc: Clark Williams
    Cc: Martin Schwidefsky
    Cc: Andrew Morton
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    john stultz
     

28 Aug, 2009

1 commit

  • MOD_NANO, ADJ_NANO, MOD_NANO, ADJ_NANO!
    Lets call the whole thing off!
    But oh! If we call the whole thing off,
    Then we must part.
    And oh! If we ever part,
    Then that might break my heart^H^H^H^Hclock!
    So, if you like MOD_NANO and I like ADJ_NANO,
    I'll include MOD_NANO and give up ADJ_NANO (not really!).
    For we know we need each other,
    So we better call the calling off off.
    Let's call the whole thing off!

    The tumultuous NTP and Linux relationship has hit another snag: Ends
    up NTPd still uses the "xntp 3.4 compatability names" and when the
    STA_NANO value was added (along with ADJ_NANO), NTPd expected MOD_NANO
    to be added and has apparently hit some build errors.

    Report to ntp hackers:
    https://lists.ntp.org/pipermail/hackers/2009-August/004455.html

    Related Bugs:
    https://support.ntp.org/bugs/show_bug.cgi?id=1219
    https://bugzilla.redhat.com/show_bug.cgi?id=505566

    So in an effort to make peace, here's a patch to help get things
    building again. I also have updated the comment to make sure folks
    don't think the MOD_* values are just legacy constants.

    Of course, NTPd really uses the glibc-headers, so those will need to
    be similarly updated before things are working again (the RH bug above
    should probably cover that).

    Thanks to Michael Tatarinov and Hal Murray for finding and reporting
    the issue!

    Signed-off-by: John Stultz
    Cc: Miroslav Lichvar
    Cc: hmurray@megapathdsl.net
    Cc: Ulrich Drepper
    Cc: Michael Tatarinov
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    john stultz
     

17 Jun, 2009

1 commit

  • PIT_TICK_RATE is currently defined in four architectures, but in three
    different places. While linux/timex.h is not the perfect place for it, it
    is still a reasonable replacement for those drivers that traditionally use
    asm/timex.h to get CLOCK_TICK_RATE and expect it to be the PIT frequency.

    Note that for Alpha, the actual value changed from 1193182UL to 1193180UL.
    This is unlikely to make a difference, and probably can only improve
    accuracy. There was a discussion on the correct value of CLOCK_TICK_RATE
    a few years ago, after which every existing instance was getting changed
    to 1193182. According to the specification, it should be
    1193181.818181...

    Signed-off-by: Arnd Bergmann
    Cc: Richard Henderson
    Cc: Ivan Kokshaysky
    Cc: Ralf Baechle
    Cc: Benjamin Herrenschmidt
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: Len Brown
    Cc: john stultz
    Cc: Dmitry Torokhov
    Cc: Takashi Iwai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arnd Bergmann
     

12 May, 2009

1 commit

  • Bernhard Schiffner noticed I had a few comment typos in this patch,
    (note: to save embarrassment, when making typos, avoid copying and
    pasting them) so this patch corrects them.

    [ Impact: cleanup ]

    Reported-by: Bernhard Schiffner
    Signed-off-by: John Stultz
    Cc: riel@redhat.com
    Cc: akpm@linux-foundation.org
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    john stultz
     

06 May, 2009

1 commit

  • The conversion to the ntpv4 reference model
    f19923937321244e7dc334767eb4b67e0e3d5c74 ("ntp: convert to the NTP4
    reference model") in 2.6.19 added nanosecond resolution the adjtimex
    interface, but also changed the "stiffness" of the frequency adjustments,
    causing NTP convergence time to greatly increase.

    SHIFT_PLL, which reduces the stiffness of the freq adjustments, was
    designed to be inversely linked to HZ, and the reference value of 4 was
    designed for Unix systems using HZ=100. However Linux's clock steering
    code mostly independent of HZ.

    So this patch reduces the SHIFT_PLL value from 4 to 2, which causes NTPd
    behavior to match kernels prior to 2.6.19, greatly reducing convergence
    times, and improving close synchronization through environmental thermal
    changes.

    The patch also changes some l's to L's in nearby code to avoid misreading
    50l as 501.

    [ Impact: tweak NTP algorithm for faster convergence ]

    Signed-off-by: John Stultz
    Acked-by: Rik van Riel
    Cc: zippel@linux-m68k.org
    Signed-off-by: Andrew Morton
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    john stultz
     

26 Feb, 2009

1 commit

  • 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
     

13 Dec, 2008

1 commit

  • Impact: fix user-space exported use

    Move all the kernel-specific defines and includes into the __KERNEL__
    section so that they don't get leaked into userspace.

    [akpm@linux-foundation.org: coding-style fixes]

    Signed-off-by: Mike Frysinger
    Signed-off-by: Andrew Morton
    Signed-off-by: Thomas Gleixner

    Mike Frysinger
     

24 Sep, 2008

1 commit

  • 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
     

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

7 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
     
  • This changes time_freq to a 64bit value and makes it static (the only outside
    user had no real need to modify it). Intermediate values were already 64bit,
    so the change isn't that big, but it saves a little in shifts by replacing
    SHIFT_NSEC with TICK_LENGTH_SHIFT. PPM_SCALE is then used to convert between
    user space and kernel space representation.

    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 a few more things from the ntp nanokernel related to user space.
    It's now possible to select the resolution used of some values via STA_NANO
    and the kernel reports in which mode it works (pll/fll).

    If some values for adjtimex() are outside the acceptable range, they are now
    simply normalized instead of letting the syscall fail. I removed
    MOD_CLKA/MOD_CLKB as the mapping didn't really makes any sense, the kernel
    doesn't support setting the clock.

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

    Roman Zippel
     

09 Mar, 2008

1 commit

  • The first version of the ntp_interval/tick_length inconsistent usage patch was
    recently merged as bbe4d18ac2e058c56adb0cd71f49d9ed3216a405

    http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=bbe4d18ac2e058c56adb0cd71f49d9ed3216a405

    While the fix did greatly improve the situation, it was correctly pointed out
    by Roman that it does have a small bug: If the users change clocksources after
    the system has been running and NTP has made corrections, the correctoins made
    against the old clocksource will be applied against the new clocksource,
    causing error.

    The second attempt, which corrects the issue in the NTP_INTERVAL_LENGTH
    definition has also made it up-stream as commit
    e13a2e61dd5152f5499d2003470acf9c838eab84

    http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e13a2e61dd5152f5499d2003470acf9c838eab84

    Roman has correctly pointed out that CLOCK_TICK_ADJUST is calculated
    based on the PIT's frequency, and isn't really relevant to non-PIT
    driven clocksources (that is, clocksources other then jiffies and pit).

    This patch reverts both of those changes, and simply removes
    CLOCK_TICK_ADJUST.

    This does remove the granularity error correction for users of PIT and Jiffies
    clocksource users, but the granularity error but for the majority of users, it
    should be within the 500ppm range NTP can accommodate for.

    For systems that have granularity errors greater then 500ppm, the
    "ntp_tick_adj=" boot option can be used to compensate.

    [johnstul@us.ibm.com: provided changelog]
    [mattilinnanvuori@yahoo.com: maek ntp_tick_adj static]
    Signed-off-by: Roman Zippel
    Acked-by: john stultz
    Signed-off-by: Matti Linnanvuori
    Signed-off-by: Andrew Morton
    Cc: mingo@elte.hu
    Signed-off-by: Thomas Gleixner

    Roman Zippel
     

10 Feb, 2008

1 commit

  • clocksource initialization and error accumulation. This corrects a 280ppm
    drift seen on some systems using acpi_pm, and affects other clocksources as
    well (likely to a lesser degree).

    Signed-off-by: John Stultz
    Cc: Roman Zippel
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    john stultz
     

07 Feb, 2008

1 commit

  • - All implementations can be __devinit

    - The function prototypes were in asm/timex.h but they all must be the same,
    so create a single declaration in linux/timex.h.

    - uninline the sparc64 version to match the other architectures

    - Don't bother #defining ARCH_HAS_READ_CURRENT_TIMER to a particular value.

    [ezk@cs.sunysb.edu: fix build]
    Cc: "David S. Miller"
    Cc: Haavard Skinnemoen
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     

27 Nov, 2007

1 commit

  • Michael Kerrisk reported that a long standing bug in the adjtimex()
    system call causes glibc's adjtime(3) function to deliver the wrong
    results if 'delta' is NULL.

    add the ADJ_OFFSET_SS_READ API detail, which will be used by glibc
    to fix this API compatibility bug.

    Also see: http://bugzilla.kernel.org/show_bug.cgi?id=6761

    [ mingo@elte.hu: added patch description and made it backwards compatible ]

    NOTE: the new flag is defined 0xa001 so that it returns -EINVAL on
    older kernels - this way glibc can use it safely. Suggested by Ulrich
    Drepper.

    Acked-by: Ulrich Drepper
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    John Stultz
     

21 Jul, 2007

1 commit

  • Remove time_interpolator code (This is generic code, but
    only user was ia64. It has been superseded by the
    CONFIG_GENERIC_TIME code).

    Signed-off-by: Bob Picco
    Signed-off-by: John Stultz
    Signed-off-by: Peter Keilty
    Signed-off-by: Tony Luck

    Bob Picco
     

17 Feb, 2007

1 commit

  • Distangle the NTP update from HZ. This is necessary for dynamic tick enabled
    kernels.

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

    john stultz
     

12 Feb, 2007

1 commit

  • The 32bit and 64bit PARISC Linux kernels suffers from the problem, that the
    gettimeofday() call sometimes returns non-monotonic times.

    The easiest way to fix this, is to drop the PARISC-specific implementation
    and switch over to the generic TIME_INTERPOLATION framework.

    But in order to make it even compile on 32bit PARISC, the patch below which
    touches the generic Linux code, is mandatory.

    More information and the full patch with the parisc-specific changes is included in this thread: http://lists.parisc-linux.org/pipermail/parisc-linux/2006-December/031003.html

    As far as I could see, this patch does not change anything for the existing
    architectures which use this framework (IA64 and SPARC64), since "cycles_t"
    is defined there as unsigned 64bit-integer anyway (which then makes this
    patch a no-change for them).

    Signed-off-by: Helge Deller
    Cc:
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Helge Deller
     

06 Oct, 2006

1 commit