Skip to content

Commit 6e317c3

Browse files
a13xp0p0vKAGA-KOKO
authored andcommitted
timer: Improve the comment describing schedule_timeout()
When working commit 6dcd5d7, 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
1 parent e876f0b commit 6e317c3

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎kernel/time/timer.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,29 +1828,31 @@ static void process_timeout(struct timer_list *t)
18281828
* schedule_timeout - sleep until timeout
18291829
* @timeout: timeout value in jiffies
18301830
*
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):
18341834
*
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.
18361838
*
18371839
* %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
18381840
* 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()).
18401842
*
18411843
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
18421844
* delivered to the current task or the current task is explicitly woken
18431845
* up.
18441846
*
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
18461848
* routine returns.
18471849
*
18481850
* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule
18491851
* the CPU away without a bound on the timeout. In this case the return
18501852
* value will be %MAX_SCHEDULE_TIMEOUT.
18511853
*
18521854
* Returns 0 when the timer has expired otherwise the remaining time in
1853-
* jiffies will be returned. In all cases the return value is guaranteed
1855+
* jiffies will be returned. In all cases the return value is guaranteed
18541856
* to be non-negative.
18551857
*/
18561858
signed long __sched schedule_timeout(signed long timeout)

0 commit comments

Comments
 (0)