Commit 351b3f7a21e413a9b14d0393171497d2373bd702
Committed by
Thomas Gleixner
1 parent
3bbb9ec946
Exists in
master
and in
7 other branches
hrtimers: Provide schedule_hrtimeout for CLOCK_REALTIME
The current version of schedule_hrtimeout() always uses the monotonic clock. Some system calls such as mq_timedsend() and mq_timedreceive(), however, require the use of the wall clock due to the definition of the system call. This patch provides the infrastructure to use schedule_hrtimeout() with a CLOCK_REALTIME timer. Signed-off-by: Carsten Emde <C.Emde@osadl.org> Tested-by: Pradyumna Sampath <pradysam@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Arjan van de Veen <arjan@infradead.org> LKML-Reference: <20100402204331.167439615@osadl.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Showing 2 changed files with 43 additions and 26 deletions Side-by-side Diff
include/linux/hrtimer.h
... | ... | @@ -422,6 +422,8 @@ |
422 | 422 | |
423 | 423 | extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta, |
424 | 424 | const enum hrtimer_mode mode); |
425 | +extern int schedule_hrtimeout_range_clock(ktime_t *expires, | |
426 | + unsigned long delta, const enum hrtimer_mode mode, int clock); | |
425 | 427 | extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode); |
426 | 428 | |
427 | 429 | /* Soft interrupt function to run the hrtimer queues: */ |
kernel/hrtimer.c
... | ... | @@ -1749,35 +1749,15 @@ |
1749 | 1749 | } |
1750 | 1750 | |
1751 | 1751 | /** |
1752 | - * schedule_hrtimeout_range - sleep until timeout | |
1752 | + * schedule_hrtimeout_range_clock - sleep until timeout | |
1753 | 1753 | * @expires: timeout value (ktime_t) |
1754 | 1754 | * @delta: slack in expires timeout (ktime_t) |
1755 | 1755 | * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL |
1756 | - * | |
1757 | - * Make the current task sleep until the given expiry time has | |
1758 | - * elapsed. The routine will return immediately unless | |
1759 | - * the current task state has been set (see set_current_state()). | |
1760 | - * | |
1761 | - * The @delta argument gives the kernel the freedom to schedule the | |
1762 | - * actual wakeup to a time that is both power and performance friendly. | |
1763 | - * The kernel give the normal best effort behavior for "@expires+@delta", | |
1764 | - * but may decide to fire the timer earlier, but no earlier than @expires. | |
1765 | - * | |
1766 | - * You can set the task state as follows - | |
1767 | - * | |
1768 | - * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to | |
1769 | - * pass before the routine returns. | |
1770 | - * | |
1771 | - * %TASK_INTERRUPTIBLE - the routine may return early if a signal is | |
1772 | - * delivered to the current task. | |
1773 | - * | |
1774 | - * The current task state is guaranteed to be TASK_RUNNING when this | |
1775 | - * routine returns. | |
1776 | - * | |
1777 | - * Returns 0 when the timer has expired otherwise -EINTR | |
1756 | + * @clock: timer clock, CLOCK_MONOTONIC or CLOCK_REALTIME | |
1778 | 1757 | */ |
1779 | -int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta, | |
1780 | - const enum hrtimer_mode mode) | |
1758 | +int __sched | |
1759 | +schedule_hrtimeout_range_clock(ktime_t *expires, unsigned long delta, | |
1760 | + const enum hrtimer_mode mode, int clock) | |
1781 | 1761 | { |
1782 | 1762 | struct hrtimer_sleeper t; |
1783 | 1763 | |
... | ... | @@ -1799,7 +1779,7 @@ |
1799 | 1779 | return -EINTR; |
1800 | 1780 | } |
1801 | 1781 | |
1802 | - hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode); | |
1782 | + hrtimer_init_on_stack(&t.timer, clock, mode); | |
1803 | 1783 | hrtimer_set_expires_range_ns(&t.timer, *expires, delta); |
1804 | 1784 | |
1805 | 1785 | hrtimer_init_sleeper(&t, current); |
... | ... | @@ -1817,6 +1797,41 @@ |
1817 | 1797 | __set_current_state(TASK_RUNNING); |
1818 | 1798 | |
1819 | 1799 | return !t.task ? 0 : -EINTR; |
1800 | +} | |
1801 | + | |
1802 | +/** | |
1803 | + * schedule_hrtimeout_range - sleep until timeout | |
1804 | + * @expires: timeout value (ktime_t) | |
1805 | + * @delta: slack in expires timeout (ktime_t) | |
1806 | + * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL | |
1807 | + * | |
1808 | + * Make the current task sleep until the given expiry time has | |
1809 | + * elapsed. The routine will return immediately unless | |
1810 | + * the current task state has been set (see set_current_state()). | |
1811 | + * | |
1812 | + * The @delta argument gives the kernel the freedom to schedule the | |
1813 | + * actual wakeup to a time that is both power and performance friendly. | |
1814 | + * The kernel give the normal best effort behavior for "@expires+@delta", | |
1815 | + * but may decide to fire the timer earlier, but no earlier than @expires. | |
1816 | + * | |
1817 | + * You can set the task state as follows - | |
1818 | + * | |
1819 | + * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to | |
1820 | + * pass before the routine returns. | |
1821 | + * | |
1822 | + * %TASK_INTERRUPTIBLE - the routine may return early if a signal is | |
1823 | + * delivered to the current task. | |
1824 | + * | |
1825 | + * The current task state is guaranteed to be TASK_RUNNING when this | |
1826 | + * routine returns. | |
1827 | + * | |
1828 | + * Returns 0 when the timer has expired otherwise -EINTR | |
1829 | + */ | |
1830 | +int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta, | |
1831 | + const enum hrtimer_mode mode) | |
1832 | +{ | |
1833 | + return schedule_hrtimeout_range_clock(expires, delta, mode, | |
1834 | + CLOCK_MONOTONIC); | |
1820 | 1835 | } |
1821 | 1836 | EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); |
1822 | 1837 |