History

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

Patrick Pannuto committed 16 years ago

Commit 22b8f151 parent 866e2612 files · +28 −0Browse files

Showing the changes to kernel/timer.c (1 of 2 files). Show all

Unified · Split

kernel/timer.c+22−0
@@ -1755,3 +1755,25 @@ unsigned long msleep_interruptible(unsigned int msecs) · 1754 unmodified lines
17551755 }
17561756
17571757 EXPORT_SYMBOL(msleep_interruptible);
1758+
1759+static 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+ */
1774+void usleep_range(unsigned long min, unsigned long max)
1775+{
1776+ __set_current_state(TASK_UNINTERRUPTIBLE);
1777+ do_usleep_range(min, max);
1778+}
1779+EXPORT_SYMBOL(usleep_range);