aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Pannuto <ppannuto@codeaurora.org>2010-07-19 18:09:26 -0400
committerThomas Gleixner <tglx@linutronix.de>2010-07-23 09:08:12 -0400
commit22b8f15c2f7130bb0386f548428df2ffd4e81903 (patch)
tree4ed7ac08115afdce20d21bd923cd1071c2249dda
parent866e26115cba6b59cec669b6307599e3e4440491 (diff)
timer: Added usleep[_range] timer
usleep[_range] are finer precision implementations of msleep and are designed to be drop-in replacements for udelay where a precise sleep / busy-wait is unnecessary. They also allow an easy interface to specify slack when a precise (ish) wakeup is unnecessary to help minimize wakeups Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org> Cc: akinobu.mita@gmail.com Cc: sboyd@codeaurora.org Acked-by: Arjan van de Ven <arjan@linux.intel.com> LKML-Reference: <4C44CDD2.1070708@codeaurora.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--include/linux/delay.h6
-rw-r--r--kernel/timer.c22
2 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/delay.h b/include/linux/delay.h
index fd832c6d419e..0e303d1aacd8 100644
--- a/include/linux/delay.h
+++ b/include/linux/delay.h
@@ -45,6 +45,12 @@ extern unsigned long lpj_fine;
45void calibrate_delay(void); 45void calibrate_delay(void);
46void msleep(unsigned int msecs); 46void msleep(unsigned int msecs);
47unsigned long msleep_interruptible(unsigned int msecs); 47unsigned long msleep_interruptible(unsigned int msecs);
48void usleep_range(unsigned long min, unsigned long max);
49
50static inline void usleep(unsigned long usecs)
51{
52 usleep_range(usecs, usecs);
53}
48 54
49static inline void ssleep(unsigned int seconds) 55static inline void ssleep(unsigned int seconds)
50{ 56{
diff --git a/kernel/timer.c b/kernel/timer.c
index ce98685cd1cb..f110f241ab66 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1755,3 +1755,25 @@ unsigned long msleep_interruptible(unsigned int msecs)
1755} 1755}
1756 1756
1757EXPORT_SYMBOL(msleep_interruptible); 1757EXPORT_SYMBOL(msleep_interruptible);
1758
1759static int __sched do_usleep_range(unsigned long min, unsigned long max)
1760{
1761 ktime_t kmin;
1762 unsigned long delta;
1763
1764 kmin = ktime_set(0, min * NSEC_PER_USEC);
1765 delta = max - min;
1766 return schedule_hrtimeout_range(&kmin, delta, HRTIMER_MODE_REL);
1767}
1768
1769/**
1770 * usleep_range - Drop in replacement for udelay where wakeup is flexible
1771 * @min: Minimum time in usecs to sleep
1772 * @max: Maximum time in usecs to sleep
1773 */
1774void usleep_range(unsigned long min, unsigned long max)
1775{
1776 __set_current_state(TASK_UNINTERRUPTIBLE);
1777 do_usleep_range(min, max);
1778}
1779EXPORT_SYMBOL(usleep_range);