Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

timer: Improve the comment describing schedule_timeout()

When working commit 6dcd5d7a7a29c1e, a mistake was noticed by Linus:
schedule_timeout() was called without setting the task state to anything
particular.

It calls the scheduler, but doesn't delay anything, because the task stays
runnable. That happens because sched_submit_work() does nothing for tasks
in TASK_RUNNING state.

That turned out to be the intended behavior. Adding a WARN() is not useful
as the task could be woken up right after setting the state and before
reaching schedule_timeout().

Improve the comment about schedule_timeout() and describe that more
explicitly.

Signed-off-by: Alexander Popov <alex.popov@linux.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200117225900.16340-1-alex.popov@linux.com


authored by

Alexander Popov and committed by
Thomas Gleixner
6e317c32 e876f0b6

+9 -7
+9 -7
kernel/time/timer.c
··· 1828 1828 * schedule_timeout - sleep until timeout 1829 1829 * @timeout: timeout value in jiffies 1830 1830 * 1831 - * Make the current task sleep until @timeout jiffies have 1832 - * elapsed. The routine will return immediately unless 1833 - * the current task state has been set (see set_current_state()). 1831 + * Make the current task sleep until @timeout jiffies have elapsed. 1832 + * The function behavior depends on the current task state 1833 + * (see also set_current_state() description): 1834 1834 * 1835 - * You can set the task state as follows - 1835 + * %TASK_RUNNING - the scheduler is called, but the task does not sleep 1836 + * at all. That happens because sched_submit_work() does nothing for 1837 + * tasks in %TASK_RUNNING state. 1836 1838 * 1837 1839 * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to 1838 1840 * pass before the routine returns unless the current task is explicitly 1839 - * woken up, (e.g. by wake_up_process())". 1841 + * woken up, (e.g. by wake_up_process()). 1840 1842 * 1841 1843 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is 1842 1844 * delivered to the current task or the current task is explicitly woken 1843 1845 * up. 1844 1846 * 1845 - * The current task state is guaranteed to be TASK_RUNNING when this 1847 + * The current task state is guaranteed to be %TASK_RUNNING when this 1846 1848 * routine returns. 1847 1849 * 1848 1850 * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule ··· 1852 1850 * value will be %MAX_SCHEDULE_TIMEOUT. 1853 1851 * 1854 1852 * Returns 0 when the timer has expired otherwise the remaining time in 1855 - * jiffies will be returned. In all cases the return value is guaranteed 1853 + * jiffies will be returned. In all cases the return value is guaranteed 1856 1854 * to be non-negative. 1857 1855 */ 1858 1856 signed long __sched schedule_timeout(signed long timeout)