All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sched: Document schedule() entry points
@ 2012-08-04  8:49 Pekka Enberg
  2012-08-04 16:04 ` Randy Dunlap
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pekka Enberg @ 2012-08-04  8:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, a.p.zijlstra, Pekka Enberg, Randy Dunlap

This patch adds a comment on top of the schedule() function to explain
to scheduler newbies how the main scheduler function is entered.

Cc: Randy Dunlap <rdunlap@xenotime.net>
Explained-by: Ingo Molnar <mingo@kernel.org>
Explained-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
V1 -> V2: Fix funky grammar pointed out by Peter and Randy.

 kernel/sched/core.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 468bdd4..7dc75df 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3361,6 +3361,40 @@ pick_next_task(struct rq *rq)
 
 /*
  * __schedule() is the main scheduler function.
+ *
+ * The main means of driving the scheduler and thus entering this function are:
+ *
+ *   1. Explicit blocking: mutex, semaphore, waitqueue, etc.
+ *
+ *   2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return
+ *      paths. For example, see arch/x86/entry_64.S.
+ *
+ *      To drive preemption between tasks, the scheduler sets the flag in timer
+ *      interrupt handler scheduler_tick().
+ *
+ *   3. Wakeups don't really cause entry into schedule(). They add a
+ *      task to the run-queue and that's it.
+ *
+ *      Now, if the new task added to the run-queue preempts the current
+ *      task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets
+ *      called on the nearest possible occasion:
+ *
+ *       - If the kernel is preemptible (CONFIG_PREEMPT=y):
+ *
+ *         - in syscall or exception context, at the next outmost
+ *           preempt_enable(). (this might be as soon as the wake_up()'s
+ *           spin_unlock()!)
+ *
+ *         - in IRQ context, return from interrupt-handler to
+ *           preemptible context
+ *
+ *       - If the kernel is not preemptible (CONFIG_PREEMPT is not set)
+ *         then at the next:
+ *
+ *          - cond_resched() call
+ *          - explicit schedule() call
+ *          - return from syscall or exception to user-space
+ *          - return from interrupt-handler to user-space
  */
 static void __sched __schedule(void)
 {
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Document schedule() entry points
  2012-08-04  8:49 [PATCH v2] sched: Document schedule() entry points Pekka Enberg
@ 2012-08-04 16:04 ` Randy Dunlap
  2012-08-13 16:59 ` [tip:sched/core] " tip-bot for Pekka Enberg
  2012-08-13 17:05 ` tip-bot for Pekka Enberg
  2 siblings, 0 replies; 4+ messages in thread
From: Randy Dunlap @ 2012-08-04 16:04 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-kernel, mingo, a.p.zijlstra

On 08/04/2012 01:49 AM, Pekka Enberg wrote:

> This patch adds a comment on top of the schedule() function to explain
> to scheduler newbies how the main scheduler function is entered.
> 
> Cc: Randy Dunlap <rdunlap@xenotime.net>
> Explained-by: Ingo Molnar <mingo@kernel.org>
> Explained-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>
> ---
> V1 -> V2: Fix funky grammar pointed out by Peter and Randy.

Ack.  Thanks.

>  kernel/sched/core.c |   34 ++++++++++++++++++++++++++++++++++
>  1 files changed, 34 insertions(+), 0 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 468bdd4..7dc75df 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3361,6 +3361,40 @@ pick_next_task(struct rq *rq)
>  
>  /*
>   * __schedule() is the main scheduler function.
> + *
> + * The main means of driving the scheduler and thus entering this function are:
> + *
> + *   1. Explicit blocking: mutex, semaphore, waitqueue, etc.
> + *
> + *   2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return
> + *      paths. For example, see arch/x86/entry_64.S.
> + *
> + *      To drive preemption between tasks, the scheduler sets the flag in timer
> + *      interrupt handler scheduler_tick().
> + *
> + *   3. Wakeups don't really cause entry into schedule(). They add a
> + *      task to the run-queue and that's it.
> + *
> + *      Now, if the new task added to the run-queue preempts the current
> + *      task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets
> + *      called on the nearest possible occasion:
> + *
> + *       - If the kernel is preemptible (CONFIG_PREEMPT=y):
> + *
> + *         - in syscall or exception context, at the next outmost
> + *           preempt_enable(). (this might be as soon as the wake_up()'s
> + *           spin_unlock()!)
> + *
> + *         - in IRQ context, return from interrupt-handler to
> + *           preemptible context
> + *
> + *       - If the kernel is not preemptible (CONFIG_PREEMPT is not set)
> + *         then at the next:
> + *
> + *          - cond_resched() call
> + *          - explicit schedule() call
> + *          - return from syscall or exception to user-space
> + *          - return from interrupt-handler to user-space
>   */
>  static void __sched __schedule(void)
>  {



-- 
~Randy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:sched/core] sched: Document schedule() entry points
  2012-08-04  8:49 [PATCH v2] sched: Document schedule() entry points Pekka Enberg
  2012-08-04 16:04 ` Randy Dunlap
@ 2012-08-13 16:59 ` tip-bot for Pekka Enberg
  2012-08-13 17:05 ` tip-bot for Pekka Enberg
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Pekka Enberg @ 2012-08-13 16:59 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, penberg, rdunlap, tglx

Commit-ID:  7cbcdf58442fe7bf477d549be92329e22e64b146
Gitweb:     http://git.kernel.org/tip/7cbcdf58442fe7bf477d549be92329e22e64b146
Author:     Pekka Enberg <penberg@kernel.org>
AuthorDate: Sat, 4 Aug 2012 11:49:47 +0300
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 13 Aug 2012 18:51:59 +0200

sched: Document schedule() entry points

This patch adds a comment on top of the schedule() function to explain
to scheduler newbies how the main scheduler function is entered.

Acked-by: Randy Dunlap <rdunlap@xenotime.net>
Explained-by: Ingo Molnar <mingo@kernel.org>
Explained-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1344070187-2420-1-git-send-email-penberg@kernel.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/sched/core.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 82ad284..a1f71f9 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3361,6 +3361,40 @@ pick_next_task(struct rq *rq)
 
 /*
  * __schedule() is the main scheduler function.
+ *
+ * The main means of driving the scheduler and thus entering this function are:
+ *
+ *   1. Explicit blocking: mutex, semaphore, waitqueue, etc.
+ *
+ *   2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return
+ *      paths. For example, see arch/x86/entry_64.S.
+ *
+ *      To drive preemption between tasks, the scheduler sets the flag in timer
+ *      interrupt handler scheduler_tick().
+ *
+ *   3. Wakeups don't really cause entry into schedule(). They add a
+ *      task to the run-queue and that's it.
+ *
+ *      Now, if the new task added to the run-queue preempts the current
+ *      task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets
+ *      called on the nearest possible occasion:
+ *
+ *       - If the kernel is preemptible (CONFIG_PREEMPT=y):
+ *
+ *         - in syscall or exception context, at the next outmost
+ *           preempt_enable(). (this might be as soon as the wake_up()'s
+ *           spin_unlock()!)
+ *
+ *         - in IRQ context, return from interrupt-handler to
+ *           preemptible context
+ *
+ *       - If the kernel is not preemptible (CONFIG_PREEMPT is not set)
+ *         then at the next:
+ *
+ *          - cond_resched() call
+ *          - explicit schedule() call
+ *          - return from syscall or exception to user-space
+ *          - return from interrupt-handler to user-space
  */
 static void __sched __schedule(void)
 {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [tip:sched/core] sched: Document schedule() entry points
  2012-08-04  8:49 [PATCH v2] sched: Document schedule() entry points Pekka Enberg
  2012-08-04 16:04 ` Randy Dunlap
  2012-08-13 16:59 ` [tip:sched/core] " tip-bot for Pekka Enberg
@ 2012-08-13 17:05 ` tip-bot for Pekka Enberg
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Pekka Enberg @ 2012-08-13 17:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, penberg, rdunlap, tglx

Commit-ID:  edde96eafc91a510f404e7b82cfc0ecb608505ee
Gitweb:     http://git.kernel.org/tip/edde96eafc91a510f404e7b82cfc0ecb608505ee
Author:     Pekka Enberg <penberg@kernel.org>
AuthorDate: Sat, 4 Aug 2012 11:49:47 +0300
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 13 Aug 2012 18:58:15 +0200

sched: Document schedule() entry points

This patch adds a comment on top of the schedule() function to explain
to scheduler newbies how the main scheduler function is entered.

Acked-by: Randy Dunlap <rdunlap@xenotime.net>
Explained-by: Ingo Molnar <mingo@kernel.org>
Explained-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1344070187-2420-1-git-send-email-penberg@kernel.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/sched/core.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fbf1fd0..c9a3655 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3367,6 +3367,40 @@ pick_next_task(struct rq *rq)
 
 /*
  * __schedule() is the main scheduler function.
+ *
+ * The main means of driving the scheduler and thus entering this function are:
+ *
+ *   1. Explicit blocking: mutex, semaphore, waitqueue, etc.
+ *
+ *   2. TIF_NEED_RESCHED flag is checked on interrupt and userspace return
+ *      paths. For example, see arch/x86/entry_64.S.
+ *
+ *      To drive preemption between tasks, the scheduler sets the flag in timer
+ *      interrupt handler scheduler_tick().
+ *
+ *   3. Wakeups don't really cause entry into schedule(). They add a
+ *      task to the run-queue and that's it.
+ *
+ *      Now, if the new task added to the run-queue preempts the current
+ *      task, then the wakeup sets TIF_NEED_RESCHED and schedule() gets
+ *      called on the nearest possible occasion:
+ *
+ *       - If the kernel is preemptible (CONFIG_PREEMPT=y):
+ *
+ *         - in syscall or exception context, at the next outmost
+ *           preempt_enable(). (this might be as soon as the wake_up()'s
+ *           spin_unlock()!)
+ *
+ *         - in IRQ context, return from interrupt-handler to
+ *           preemptible context
+ *
+ *       - If the kernel is not preemptible (CONFIG_PREEMPT is not set)
+ *         then at the next:
+ *
+ *          - cond_resched() call
+ *          - explicit schedule() call
+ *          - return from syscall or exception to user-space
+ *          - return from interrupt-handler to user-space
  */
 static void __sched __schedule(void)
 {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-13 17:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-04  8:49 [PATCH v2] sched: Document schedule() entry points Pekka Enberg
2012-08-04 16:04 ` Randy Dunlap
2012-08-13 16:59 ` [tip:sched/core] " tip-bot for Pekka Enberg
2012-08-13 17:05 ` tip-bot for Pekka Enberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.