10 May, 2010

1 commit

  • How to pick good mult/shift pairs has always been difficult to
    describe to folks writing clocksource drivers, since it requires
    careful tradeoffs in adjustment accuracy vs overflow limits.

    Now, with the clocks_calc_mult_shift function, its much
    easier. However, not many clocksources have converted to using that
    function, and there is still the issue of the max interval length
    assumption being made by each clocksource driver independently.

    So this patch simplifies the registration process by having
    clocksources be registered with a hz/khz value and the registration
    function taking care of setting mult/shift.

    This should take most of the confusion out of writing a clocksource
    driver.

    Additionally it also keeps the shift size tradeoff (more accuracy vs
    longer possible nohz times) centralized so the timekeeping core can
    keep track of the assumptions being made.

    [ tglx: Coding style and comments fixed ]

    Signed-off-by: John Stultz
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    John Stultz
     

05 Feb, 2010

2 commits

  • Add a clocksource suspend callback. This callback can be used by the
    clocksource driver to shutdown and perform any kind of late suspend
    activities even though the clocksource driver itself is a non-sysdev
    driver.

    One example where this is useful is to fix the sh_cmt.c platform driver
    that today suspends using the platform bus and shuts down the clocksource
    too early.

    With this callback in place the sh_cmt driver will suspend using the
    clocksource and clockevent hooks and leave the platform device pm
    callbacks unused.

    Signed-off-by: Magnus Damm
    Cc: Paul Mundt
    Cc: john stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Thomas Gleixner

    Magnus Damm
     
  • Pass the clocksource as an argument to the clocksource resume callback.
    Needed so we can point out which CMT channel the sh_cmt.c driver shall
    resume.

    Signed-off-by: Magnus Damm
    Cc: john stultz
    Cc: Paul Mundt
    Signed-off-by: Andrew Morton
    Signed-off-by: Thomas Gleixner

    Magnus Damm
     

09 Dec, 2009

1 commit


17 Nov, 2009

1 commit

  • Since commit 0a544198 "timekeeping: Move NTP adjusted clock multiplier
    to struct timekeeper" the clock multiplier of vsyscall is updated with
    the unmodified clock multiplier of the clock source and not with the
    NTP adjusted multiplier of the timekeeper.

    This causes user space observerable time warps:
    new CLOCK-warp maximum: 120 nsecs, 00000025c337c537 -> 00000025c337c4bf

    Add a new argument "mult" to update_vsyscall() and hand in the
    timekeeping internal NTP adjusted multiplier.

    Signed-off-by: Lin Ming
    Cc: "Zhang Yanmin"
    Cc: Martin Schwidefsky
    Cc: Benjamin Herrenschmidt
    Cc: Tony Luck
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Lin Ming
     

14 Nov, 2009

2 commits

  • The dynamic tick allows the kernel to sleep for periods longer than a
    single tick, but it does not limit the sleep time currently. In the
    worst case the kernel could sleep longer than the wrap around time of
    the time keeping clock source which would result in losing track of
    time.

    Prevent this by limiting it to the safe maximum sleep time of the
    current time keeping clock source. The value is calculated when the
    clock source is registered.

    [ tglx: simplified the code a bit and massaged the commit msg ]

    Signed-off-by: Jon Hunter
    Cc: John Stultz
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Jon Hunter
     
  • MIPS has two functions to calculcate the mult/shift factors for clock
    sources and clock events at run time. ARM needs such functions as
    well.

    Implement a function which calculates the mult/shift factors based on
    the frequencies to which and from which is converted. The function
    also has a parameter to specify the minimum conversion range in
    seconds. This range is guaranteed not to produce a 64bit overflow when
    a value is multiplied with the calculated mult factor. The larger the
    conversion range the less becomes the conversion accuracy.

    Provide two inline wrappers which handle clock events and clock
    sources. For clock events the "from" frequency is nano seconds per
    second which corresponds to 1GHz and "to" is the device frequency. For
    clock sources "from" is the device frequency and "to" is nano seconds
    per second.

    Signed-off-by: Thomas Gleixner
    Tested-by: Mikael Pettersson
    Acked-by: Ralf Baechle
    Acked-by: Linus Walleij
    Cc: John Stultz
    LKML-Reference:

    Thomas Gleixner
     

29 Aug, 2009

1 commit

  • Martin Schwidefsky analyzed it:
    To register a clocksource the clocksource_mutex is acquired and if
    necessary timekeeping_notify is called to install the clocksource as
    the timekeeper clock. timekeeping_notify uses stop_machine which needs
    to take cpu_add_remove_lock mutex.
    Starting a new cpu is done with the cpu_add_remove_lock mutex held.
    native_cpu_up checks the tsc of the new cpu and if the tsc is no good
    clocksource_change_rating is called. Which needs the clocksource_mutex
    and the deadlock is complete.

    The solution is to replace the TSC via the clocksource watchdog
    mechanism. Mark the TSC as unstable and schedule the watchdog work so
    it gets removed in the watchdog thread context.

    Signed-off-by: Thomas Gleixner
    LKML-Reference:
    Cc: Martin Schwidefsky
    Cc: John Stultz

    Thomas Gleixner
     

15 Aug, 2009

6 commits

  • update_wall_time calls change_clocksource HZ times per second to check
    if a new clock source is available. In close to 100% of all calls
    there is no new clock. Replace the tick based check by an update done
    with stop_machine.

    Signed-off-by: Martin Schwidefsky
    Cc: Ingo Molnar
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     
  • The clocksource structure has two multipliers, the unmodified multiplier
    clock->mult_orig and the NTP corrected multiplier clock->mult. The NTP
    multiplier is misplaced in the struct clocksource, this is private
    information of the timekeeping code. Add the mult field to the struct
    timekeeper to contain the NTP corrected value, keep the unmodifed
    multiplier in clock->mult and remove clock->mult_orig.

    Signed-off-by: Martin Schwidefsky
    Cc: Ingo Molnar
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     
  • Add struct timekeeper to keep the internal values timekeeping.c needs
    in regard to the currently selected clock source. This moves the
    timekeeping intervals, xtime_nsec and the ntp error value from struct
    clocksource to struct timekeeper. The raw_time is removed from the
    clocksource as well. It gets treated like xtime as a global variable.
    Eventually xtime raw_time should be moved to struct timekeeper.

    [ tglx: minor cleanup ]

    Signed-off-by: Martin Schwidefsky
    Cc: Ingo Molnar
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     
  • Move the downgrade of an unstable clocksource from the timer interrupt
    context into the process context of a work queue thread. This is
    needed to be able to do the clocksource switch with stop_machine.

    Signed-off-by: Martin Schwidefsky
    Cc: Ingo Molnar
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     
  • If a non high-resolution clocksource is first set as override clock
    and then registered it becomes active even if the system is in one-shot
    mode. Move the override check from sysfs_override_clocksource to the
    clocksource selection. That fixes the bug and simplifies the code. The
    check in clocksource_register for double registration of the same
    clocksource is removed without replacement.

    To find the initial clocksource a new weak function in jiffies.c is
    defined that returns the jiffies clocksource. The architecture code
    can then override the weak function with a more suitable clocksource,
    e.g. the TOD clock on s390.

    [ tglx: Folded in a fix from John Stultz ]

    Signed-off-by: Martin Schwidefsky
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     
  • The three inline functions clocksource_read, clocksource_enable and
    clocksource_disable are simple wrappers of an indirect call plus the
    copy from and to the mult_orig value. The functions are exclusively
    used by the timekeeping code which has intimate knowledge of the
    clocksource anyway. Therefore remove the inline functions. No
    functional change.

    Signed-off-by: Martin Schwidefsky
    Acked-by: John Stultz
    Cc: Daniel Walker
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Martin Schwidefsky
     

31 Jul, 2009

1 commit

  • To fix the common case where ->enable() does not set up
    mult, make sure mult_orig is saved in mult on disable.

    Also add comments to explain why we do this.

    Signed-off-by: Magnus Damm
    Cc: johnstul@us.ibm.com
    Cc: lethal@linux-sh.org
    Cc: akpm@linux-foundation.org
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Magnus Damm
     

02 May, 2009

1 commit

  • Setup clocksource mult_orig in clocksource_enable().

    Clocksource drivers can save power by using keeping the
    device clock disabled while the clocksource is unused.

    In practice this means that the enable() and disable()
    callbacks perform clk_enable() and clk_disable().

    The enable() callback may also use clk_get_rate() to get
    the clock rate from the clock framework. This information
    can then be used to calculate the shift and mult variables.

    Currently the mult_orig variable is setup from mult at
    registration time only. This is conflicting with the above
    case since the clock is disabled and the mult variable is
    not yet calculated at the time of registration.

    Moving the mult_orig setup code to clocksource_enable()
    allows us to both handle the common case with no enable()
    callback and the mult-changed-after-enable() case.

    [ Impact: allow dynamic clock source usage ]

    Signed-off-by: Magnus Damm
    LKML-Reference:
    Signed-off-by: Thomas Gleixner

    Magnus Damm
     

22 Apr, 2009

2 commits

  • Add enable() and disable() callbacks for clocksources.

    This allows us to put unused clocksources in power save mode. The
    functions clocksource_enable() and clocksource_disable() wrap the
    callbacks and are inserted in the timekeeping code to enable before use
    and disable after switching to a new clocksource.

    Signed-off-by: Magnus Damm
    Acked-by: John Stultz
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Magnus Damm
     
  • Pass clocksource pointer to the read() callback for clocksources. This
    allows us to share the callback between multiple instances.

    [hugh@veritas.com: fix powerpc build of clocksource pass clocksource mods]
    [akpm@linux-foundation.org: cleanup]
    Signed-off-by: Magnus Damm
    Acked-by: John Stultz
    Cc: Thomas Gleixner
    Signed-off-by: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Magnus Damm
     

16 Feb, 2009

1 commit

  • So far struct clocksource acted as the interface between time/timekeeping.c
    and hardware. This patch generalizes the concept so that a similar
    interface can also be used in other contexts. For that it introduces
    new structures and related functions *without* touching the existing
    struct clocksource.

    The reasons for adding these new structures to clocksource.[ch] are
    * the APIs are clearly related
    * struct clocksource could be cleaned up to use the new structs
    * avoids proliferation of files with similar names (timesource.h?
    timecounter.h?)

    As outlined in the discussion with John Stultz, this patch adds
    * struct cyclecounter: stateless API to hardware which counts clock cycles
    * struct timecounter: stateful utility code built on a cyclecounter which
    provides a nanosecond counter
    * only the function to read the nanosecond counter; deltas are used internally
    and not exposed to users of timecounter

    The code does no locking of the shared state. It must be called at least
    as often as the cycle counter wraps around to detect these wrap arounds.
    Both is the responsibility of the timecounter user.

    Acked-by: John Stultz
    Signed-off-by: Patrick Ohly
    Signed-off-by: David S. Miller

    Patrick Ohly
     

21 Aug, 2008

2 commits

  • In talking with Josip Loncaric, and his work on clock synchronization (see
    btime.sf.net), he mentioned that for really close synchronization, it is
    useful to have access to "hardware time", that is a notion of time that is
    not in any way adjusted by the clock slewing done to keep close time sync.

    Part of the issue is if we are using the kernel's ntp adjusted
    representation of time in order to measure how we should correct time, we
    can run into what Paul McKenney aptly described as "Painting a road using
    the lines we're painting as the guide".

    I had been thinking of a similar problem, and was trying to come up with a
    way to give users access to a purely hardware based time representation
    that avoided users having to know the underlying frequency and mask values
    needed to deal with the wide variety of possible underlying hardware
    counters.

    My solution is to introduce CLOCK_MONOTONIC_RAW. This exposes a
    nanosecond based time value, that increments starting at bootup and has no
    frequency adjustments made to it what so ever.

    The time is accessed from userspace via the posix_clock_gettime() syscall,
    passing CLOCK_MONOTONIC_RAW as the clock_id.

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

    John Stultz
     
  • The clocksource frequency is represented by
    clocksource->mult/2^(clocksource->shift). Currently, when NTP makes
    adjustments to the clock frequency, they are made directly to the mult
    value.

    This has the drawback that once changed, we cannot know what the orignal
    mult value was, or how much adjustment has been applied.

    This property causes problems in calculating proper ntp intervals when
    switching back and forth between clocksources.

    This patch separates the current mult value into a mult and mult_orig
    pair. The mult_orig value stays constant, while the ntp clocksource
    adjustments are done only to the mult value.

    This allows for correct ntp interval calculation and additionally lays the
    groundwork for a new notion of time, what I'm calling the monotonic-raw
    time, which is introduced in a following patch.

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

    John Stultz
     

01 May, 2008

1 commit

  • 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
     

18 Apr, 2008

1 commit


30 Jan, 2008

2 commits


19 Oct, 2007

1 commit

  • On platforms that copy sys_tz into the vdso (currently only x86_64, soon to
    include powerpc), it is possible for the vdso to get out of sync if a user
    calls (admittedly unusual) settimeofday(NULL, ptr).

    This patch adds a hook for architectures that set
    CONFIG_GENERIC_TIME_VSYSCALL to ensure when sys_tz is updated they can also
    updatee their copy in the vdso.

    Signed-off-by: Tony Breeds
    Cc: Andi Kleen
    Cc: Tony Luck
    Acked-by: John Stultz
    Cc: Paul Mackerras
    Cc: Benjamin Herrenschmidt
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tony Breeds
     

21 Jul, 2007

1 commit


10 May, 2007

1 commit

  • We need to make sure that the clocksources are resumed, when timekeeping is
    resumed. The current resume logic does not guarantee this.

    Add a resume function pointer to the clocksource struct, so clocksource
    drivers which need to reinitialize the clocksource can provide a resume
    function.

    Add a resume function, which calls the maybe available clocksource resume
    functions and resets the watchdog function, so a stable TSC can be used
    accross suspend/resume.

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

    Thomas Gleixner
     

09 May, 2007

1 commit

  • struct clocksource is a critical data structure.

    Most of its fields are read only, some of them are heavily modified at each
    timer interrupt.

    It makes sense to separate those fields and make sure they all share one
    cache line, or at least the minimum for machines with small cache lines.

    [akpm@linux-foundation.org: build fix]
    Signed-off-by: Eric Dumazet
    Acked-by: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Dumazet
     

17 Feb, 2007

5 commits

  • Provides generic infrastructure for vsyscall-gtod.

    [akpm@osdl.org: cleanup]
    Signed-off-by: John Stultz
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: Andi Kleen
    Cc: Roman Zippel

    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    john stultz
     
  • The TSC needs to be verified against another clocksource. Instead of using
    hardwired assumptions of available hardware, provide a generic verification
    mechanism. The verification uses the best available clocksource and handles
    the usability for high resolution timers / dynticks of the clocksource which
    needs to be verified.

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

    Thomas Gleixner
     
  • The clocksource code allows direct updates of the rating of a given
    clocksource now. Change TSC unstable tracking to use this interface and
    remove the update callback.

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

    Thomas Gleixner
     
  • Using a flag filed allows to encode more than one information into a variable.
    Preparatory patch for the generic clocksource verification.

    [mingo@elte.hu: convert vmitime.c to the new clocksource flag]
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Ingo Molnar
    Cc: john stultz
    Cc: Roman Zippel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     
  • Enqueue clocksources in rating order to make selection of the clocksource
    easier. Also check the match with an user override at enqueue time.

    Preparatory patch for the generic clocksource verification.

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

    Thomas Gleixner
     

11 Dec, 2006

1 commit

  • Mostly changing alignment. Just some general cleanup.

    [akpm@osdl.org: build fix]
    Signed-off-by: Daniel Walker
    Acked-by: John Stultz
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Walker
     

27 Jun, 2006

5 commits

  • This fixes the clock source updates in update_wall_time() to correctly
    track the time coming in via current_tick_length(). Optimize the fast
    paths to be as short as possible to keep the overhead low.

    Signed-off-by: Roman Zippel
    Acked-by: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Zippel
     
  • Add a CLOCKSOURCE_MASK macro to simplify initializing the mask for a struct
    clocksource, and use it to replace literal mask constants in the various
    clocksource drivers.

    Signed-off-by: Jim Cromie
    Acked-by: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jim Cromie
     
  • As suggested by Roman Zippel, change clocksource functions to use
    clocksource_xyz rather then xyz_clocksource to avoid polluting the
    namespace.

    Signed-off-by: John Stultz
    Cc: Roman Zippel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    john stultz
     
  • Instead of incrementing xtime by tick_nsec + ntp adjustments, use the
    clocksource abstraction to increment and scale time. Using the clocksource
    abstraction allows other clocksources to be used consistently in the face of
    late or lost ticks, while preserving the existing behavior via the jiffies
    clocksource.

    This removes the need to keep time_phase adjustments as we just use the
    current_tick_length() function as the NTP interface and accumulate time using
    shifted nanoseconds.

    The basics of this design was by Roman Zippel, however it is my own
    interpretation and implementation, so the credit should go to him and the
    blame to me.

    Signed-off-by: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    john stultz
     
  • This introduces the clocksource management infrastructure. A clocksource is a
    driver-like architecture generic abstraction of a free-running counter. This
    code defines the clocksource structure, and provides management code for
    registering, selecting, accessing and scaling clocksources.

    Additionally, this includes the trivial jiffies clocksource, a lowest common
    denominator clocksource, provided mainly for use as an example.

    [hirofumi@mail.parknet.co.jp: Don't enable IRQ too early]
    Signed-off-by: John Stultz
    Signed-off-by: Ingo Molnar
    Signed-off-by: Paul Mundt
    Signed-off-by: John Stultz
    Signed-off-by: OGAWA Hirofumi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    john stultz