timer: Improve the comment describing schedule_timeout()

When working commit 6dcd5d7a7a, 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
This commit is contained in:
Alexander Popov 2020-01-18 01:59:00 +03:00 committed by Thomas Gleixner
parent e876f0b69d
commit 6e317c32fd

View File

@ -1828,21 +1828,23 @@ static void process_timeout(struct timer_list *t)
* schedule_timeout - sleep until timeout * schedule_timeout - sleep until timeout
* @timeout: timeout value in jiffies * @timeout: timeout value in jiffies
* *
* Make the current task sleep until @timeout jiffies have * Make the current task sleep until @timeout jiffies have elapsed.
* elapsed. The routine will return immediately unless * The function behavior depends on the current task state
* the current task state has been set (see set_current_state()). * (see also set_current_state() description):
* *
* You can set the task state as follows - * %TASK_RUNNING - the scheduler is called, but the task does not sleep
* at all. That happens because sched_submit_work() does nothing for
* tasks in %TASK_RUNNING state.
* *
* %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
* pass before the routine returns unless the current task is explicitly * pass before the routine returns unless the current task is explicitly
* woken up, (e.g. by wake_up_process())". * woken up, (e.g. by wake_up_process()).
* *
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
* delivered to the current task or the current task is explicitly woken * delivered to the current task or the current task is explicitly woken
* up. * up.
* *
* The current task state is guaranteed to be TASK_RUNNING when this * The current task state is guaranteed to be %TASK_RUNNING when this
* routine returns. * routine returns.
* *
* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule