1. 14 11月, 2009 2 次提交
    • J
      nohz: Prevent clocksource wrapping during idle · 98962465
      Jon Hunter 提交于
      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: NJon Hunter <jon-hunter@ti.com>
      Cc: John Stultz <johnstul@us.ibm.com>
      LKML-Reference: <1250617512-23567-2-git-send-email-jon-hunter@ti.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      98962465
    • T
      clocksource: Provide a generic mult/shift factor calculation · 7d2f944a
      Thomas Gleixner 提交于
      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: NThomas Gleixner <tglx@linutronix.de>
      Tested-by: NMikael Pettersson <mikpe@it.uu.se>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Acked-by: NLinus Walleij <linus.walleij@stericsson.com>
      Cc: John Stultz <johnstul@us.ibm.com>
      LKML-Reference: <20091111134229.766673305@linutronix.de>
      7d2f944a
  2. 25 9月, 2009 1 次提交
    • M
      clocksource: Resume clocksource without taking the clocksource mutex · 89133f93
      Martin Schwidefsky 提交于
      git commit 75c5158f converted the clocksource spinlock to a
      mutex. This causes the following BUG:
      
      BUG: sleeping function called from invalid context at
      kernel/mutex.c:280 in_atomic(): 0, irqs_disabled(): 1, pid: 2473,
      name: pm-suspend 2 locks held by pm-suspend/2473:
       #0:  (&buffer->mutex){......}, at: [<ffffffff8115ab13>]
      sysfs_write_file+0x3c/0x137
       #1:  (pm_mutex){......}, at: [<ffffffff810865b5>]
      enter_state+0x39/0x130 Pid: 2473, comm: pm-suspend Not tainted 2.6.31
      #1 Call Trace:
       [<ffffffff810792f0>] ? __debug_show_held_locks+0x22/0x24
       [<ffffffff8104a2ef>] __might_sleep+0x107/0x10b
       [<ffffffff8141fca9>] mutex_lock_nested+0x25/0x43
       [<ffffffff81073537>] clocksource_resume+0x1c/0x60
       [<ffffffff81072902>] timekeeping_resume+0x1e/0x1c8
       [<ffffffff812aee62>] __sysdev_resume+0x25/0xcf
       [<ffffffff812aef79>] sysdev_resume+0x6d/0xae
       [<ffffffff810864f8>] suspend_devices_and_enter+0x12b/0x1af
       [<ffffffff8108665b>] enter_state+0xdf/0x130
       [<ffffffff81085dc3>] state_store+0xb6/0xd3
       [<ffffffff81204c73>] kobj_attr_store+0x17/0x19
       [<ffffffff8115abd2>] sysfs_write_file+0xfb/0x137
       [<ffffffff811057d2>] vfs_write+0xae/0x10b
       [<ffffffff81208392>] ? __up_read+0x1a/0x7f
       [<ffffffff811058ef>] sys_write+0x4a/0x6e
       [<ffffffff81011b82>] system_call_fastpath+0x16/0x1b
      
      clocksource_resume is called early in the resume process, there is
      only one cpu, no processes are running and the interrupts are
      disabled. It is therefore possible to resume the clocksources
      without taking the clocksource mutex.
      Reported-by: NXiaotian Feng <xtfeng@gmail.com>
      Signed-off-by: NMartin Schwidefsky <schwidefsky@de.ibm.com>
      Tested-by: NMichal Schmidt <mschmidt@redhat.com>
      Cc: Xiaotian Feng <xtfeng@gmail.com>
      Cc: John Stultz <johnstul@us.ibm.com>
      LKML-Reference: <20090924172952.49697825@mschwide.boeblingen.de.ibm.com>
      Signed-off-by: NIngo Molnar <mingo@elte.hu>
      89133f93
  3. 15 9月, 2009 2 次提交
  4. 12 9月, 2009 1 次提交
    • M
      clocksource: Resolve cpu hotplug dead lock with TSC unstable, fix crash · f79e0258
      Martin Schwidefsky 提交于
      The watchdog timer is started after the watchdog clocksource
      and at least one watched clocksource have been registered. The
      clocksource work element watchdog_work is initialized just
      before the clocksource timer is started. This is too late for
      the clocksource_mark_unstable call from native_cpu_up. To fix
      this use a static initializer for watchdog_work.
      
      This resolves a boot crash reported by multiple people.
      Signed-off-by: NMartin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Cc: John Stultz <johnstul@us.ibm.com>
      LKML-Reference: <20090911153305.3fe9a361@skybase>
      Signed-off-by: NIngo Molnar <mingo@elte.hu>
      f79e0258
  5. 29 8月, 2009 1 次提交
    • T
      clocksource: Resolve cpu hotplug dead lock with TSC unstable · 7285dd7f
      Thomas Gleixner 提交于
      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: NThomas Gleixner <tglx@linutronix.de>
      LKML-Reference: <new-submission>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: John Stultz <johnstul@us.ibm.com>
      7285dd7f
  6. 19 8月, 2009 2 次提交
    • M
      clocksource: Avoid clocksource watchdog circular locking dependency · 01548f4d
      Martin Schwidefsky 提交于
      stop_machine from a multithreaded workqueue is not allowed because
      of a circular locking dependency between cpu_down and the workqueue
      execution. Use a kernel thread to do the clocksource downgrade.
      Signed-off-by: NMartin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: john stultz <johnstul@us.ibm.com>
      LKML-Reference: <20090818170942.3ab80c91@skybase>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      01548f4d
    • T
      clocksource: Protect the watchdog rating changes with clocksource_mutex · d0981a1b
      Thomas Gleixner 提交于
      Martin pointed out that commit 6ea41d2529 (clocksource: Call
      clocksource_change_rating() outside of watchdog_lock) has a
      theoretical reference count problem. The calls to
      clocksource_change_rating() are now done outside of the clocksource
      mutex and outside of the watchdog lock. A concurrent
      clocksource_unregister() could remove the clock.
      
      Split out the code which changes the rating from
      clocksource_change_rating() into __clocksource_change_rating().
      
      Protect the clocksource_watchdog_work() code sequence with the
      clocksource_mutex() and call __clocksource_change_rating().
      
      LKML-Reference: <alpine.LFD.2.00.0908171038420.2782@localhost.localdomain>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      d0981a1b
  7. 15 8月, 2009 8 次提交
  8. 19 7月, 2009 1 次提交
  9. 13 6月, 2009 1 次提交
  10. 11 6月, 2009 1 次提交
  11. 02 5月, 2009 1 次提交
    • M
      clocksource: setup mult_orig in clocksource_enable() · a25cbd04
      Magnus Damm 提交于
      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: NMagnus Damm <damm@igel.co.jp>
      LKML-Reference: <20090501054546.8193.10688.sendpatchset@rx1.opensource.se>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      a25cbd04
  12. 22 4月, 2009 1 次提交
  13. 16 2月, 2009 1 次提交
    • P
      clocksource: allow usage independent of timekeeping.c · a038a353
      Patrick Ohly 提交于
      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: NJohn Stultz <johnstul@us.ibm.com>
      Signed-off-by: NPatrick Ohly <patrick.ohly@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a038a353
  14. 01 1月, 2009 2 次提交
  15. 21 8月, 2008 1 次提交
    • J
      clocksource: keep track of original clocksource frequency · 1aa5dfb7
      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: NJohn Stultz <johnstul@us.ibm.com>
      Signed-off-by: NRoman Zippel <zippel@linux-m68k.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NIngo Molnar <mingo@elte.hu>
      1aa5dfb7
  16. 22 7月, 2008 1 次提交
    • A
      sysdev: Pass the attribute to the low level sysdev show/store function · 4a0b2b4d
      Andi Kleen 提交于
      This allow to dynamically generate attributes and share show/store
      functions between attributes. Right now most attributes are generated
      by special macros and lots of duplicated code. With the attribute
      passed it's instead possible to attach some data to the attribute
      and then use that in shared low level functions to do different things.
      
      I need this for the dynamically generated bank attributes in the x86
      machine check code, but it'll allow some further cleanups.
      
      I converted all users in tree to the new show/store prototype. It's a single
      huge patch to avoid unbisectable sections.
      
      Runtime tested: x86-32, x86-64
      Compiled only: ia64, powerpc
      Not compile tested/only grep converted: sh, arm, avr32
      Signed-off-by: NAndi Kleen <ak@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      4a0b2b4d
  17. 24 5月, 2008 1 次提交
  18. 04 5月, 2008 2 次提交
  19. 18 4月, 2008 1 次提交
  20. 17 4月, 2008 1 次提交
  21. 26 3月, 2008 1 次提交
  22. 20 3月, 2008 1 次提交
  23. 09 2月, 2008 1 次提交
  24. 07 2月, 2008 1 次提交
    • M
      time: fix sysfs_show_{available,current}_clocksources() buffer overflow problem · 5e2cb101
      Miao Xie 提交于
      I found that there is a buffer overflow problem in the following code.
      
      Version:	2.6.24-rc2,
      File:		kernel/time/clocksource.c:417-432
      --------------------------------------------------------------------
      static ssize_t
      sysfs_show_available_clocksources(struct sys_device *dev, char *buf)
      {
      	struct clocksource *src;
      	char *curr = buf;
      
      	spin_lock_irq(&clocksource_lock);
      	list_for_each_entry(src, &clocksource_list, list) {
      		curr += sprintf(curr, "%s ", src->name);
      	}
      	spin_unlock_irq(&clocksource_lock);
      
      	curr += sprintf(curr, "\n");
      
      	return curr - buf;
      }
      -----------------------------------------------------------------------
      
      sysfs_show_current_clocksources() also has the same problem though in practice
      the size of current clocksource's name won't exceed PAGE_SIZE.
      
      I fix the bug by using snprintf according to the specification of the kernel
      (Version:2.6.24-rc2,File:Documentation/filesystems/sysfs.txt)
      
      Fix sysfs_show_available_clocksources() and sysfs_show_current_clocksources()
      buffer overflow problem with snprintf().
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Cc: WANG Cong <xiyou.wangcong@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: john stultz <johnstul@us.ibm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5e2cb101
  25. 30 1月, 2008 3 次提交
  26. 25 1月, 2008 1 次提交