Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1235036
| From | Frederic Weisbecker <fweisbec@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant |
| Date | 2015-09-29 15:00 +0200 |
| Message-ID | <qe2FJ-6Wy-19@gated-at.bofh.it> (permalink) |
| References | <qdZHQ-2IS-3@gated-at.bofh.it> <qdZHS-2IS-41@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, Sep 29, 2015 at 11:28:27AM +0200, Peter Zijlstra wrote:
> Ensure that upon scheduling preempt_count == 2; although currently an
> additional PREEMPT_ACTIVE is still possible.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> arch/x86/include/asm/preempt.h | 3 ++-
> include/asm-generic/preempt.h | 2 +-
> kernel/sched/core.c | 14 ++++++++++----
> 3 files changed, 13 insertions(+), 6 deletions(-)
>
> --- a/arch/x86/include/asm/preempt.h
> +++ b/arch/x86/include/asm/preempt.h
> @@ -31,7 +31,8 @@ static __always_inline void preempt_coun
> * must be macros to avoid header recursion hell
> */
> #define init_task_preempt_count(p) do { \
> - task_thread_info(p)->saved_preempt_count = PREEMPT_DISABLED; \
> + task_thread_info(p)->saved_preempt_count = \
> + 2*PREEMPT_DISABLE_OFFSET + PREEMPT_NEED_RESCHED; \
> } while (0)
>
> #define init_idle_preempt_count(p, cpu) do { \
> --- a/include/asm-generic/preempt.h
> +++ b/include/asm-generic/preempt.h
> @@ -24,7 +24,7 @@ static __always_inline void preempt_coun
> * must be macros to avoid header recursion hell
> */
> #define init_task_preempt_count(p) do { \
> - task_thread_info(p)->preempt_count = PREEMPT_DISABLED; \
> + task_thread_info(p)->preempt_count = 2*PREEMPT_DISABLED; \
Since it's not quite obvious why we use this magic value without looking
at schedule_tail() details, maybe add a little comment? (Just "/* see schedule_tail() */").
> } while (0)
>
> #define init_idle_preempt_count(p, cpu) do { \
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2588,11 +2588,17 @@ asmlinkage __visible void schedule_tail(
> {
> struct rq *rq;
>
> - /* finish_task_switch() drops rq->lock and enables preemtion */
> - preempt_disable();
> - rq = finish_task_switch(prev);
> + /*
> + * Still have preempt_count() == 2, from:
> + *
> + * schedule()
> + * preempt_disable(); // 1
> + * __schedule()
> + * raw_spin_lock_irq(&rq->lock) // 2
> + */
I found that a bit confusing first, because that's a preempt_count()
we actually emulate for a new task. Maybe something like:
+ /*
+ * New task is init with preempt_count() == 2 because prev task left
+ * us after:
+ *
+ * schedule()
+ * preempt_disable(); // 1
+ * __schedule()
+ * raw_spin_lock_irq(&rq->lock) // 2
+ */
> + rq = finish_task_switch(prev); /* drops rq->lock, preempt_count() == 1 */
> balance_callback(rq);
> - preempt_enable();
> + preempt_enable(); /* preempt_count() == 0 */
Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC][PATCH 02/11] sched: Create preempt_count invariant Peter Zijlstra <peterz@infradead.org> - 2015-09-29 11:50 +0200
[tip:sched/core] sched/core: Create preempt_count invariant tip-bot for Peter Zijlstra <tipbot@zytor.com> - 2015-09-29 12:40 +0200
Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Frederic Weisbecker <fweisbec@gmail.com> - 2015-09-29 15:00 +0200
Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Peter Zijlstra <peterz@infradead.org> - 2015-09-29 15:10 +0200
Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Steven Rostedt <rostedt@goodmis.org> - 2015-09-29 16:50 +0200
Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Thomas Gleixner <tglx@linutronix.de> - 2015-09-29 15:20 +0200
Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Peter Zijlstra <peterz@infradead.org> - 2015-09-29 16:20 +0200
csiph-web