]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
timer: Added usleep[_range] timer
authorPatrick Pannuto <ppannuto@codeaurora.org>
Mon, 19 Jul 2010 22:09:26 +0000 (15:09 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 23 Jul 2010 13:08:12 +0000 (15:08 +0200)
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>
include/linux/delay.h
kernel/timer.c

index fd832c6d419efc377a698eecd146032d5f68a8d1..0e303d1aacd8b3fcb40407ca8765c6d2cde3aa0d 100644 (file)
@@ -45,6 +45,12 @@ extern unsigned long lpj_fine;
 void calibrate_delay(void);
 void msleep(unsigned int msecs);
 unsigned long msleep_interruptible(unsigned int msecs);
+void usleep_range(unsigned long min, unsigned long max);
+
+static inline void usleep(unsigned long usecs)
+{
+       usleep_range(usecs, usecs);
+}
 
 static inline void ssleep(unsigned int seconds)
 {
index ce98685cd1cb449adc31b12c694ac7bd755e1abc..f110f241ab66ffcaec4d50f7fc28c27720d67789 100644 (file)
@@ -1755,3 +1755,25 @@ unsigned long msleep_interruptible(unsigned int msecs)
 }
 
 EXPORT_SYMBOL(msleep_interruptible);
+
+static int __sched do_usleep_range(unsigned long min, unsigned long max)
+{
+       ktime_t kmin;
+       unsigned long delta;
+
+       kmin = ktime_set(0, min * NSEC_PER_USEC);
+       delta = max - min;
+       return schedule_hrtimeout_range(&kmin, delta, HRTIMER_MODE_REL);
+}
+
+/**
+ * usleep_range - Drop in replacement for udelay where wakeup is flexible
+ * @min: Minimum time in usecs to sleep
+ * @max: Maximum time in usecs to sleep
+ */
+void usleep_range(unsigned long min, unsigned long max)
+{
+       __set_current_state(TASK_UNINTERRUPTIBLE);
+       do_usleep_range(min, max);
+}
+EXPORT_SYMBOL(usleep_range);