lkml.org 
[lkml]   [2015]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[RFC][PATCH 02/11] sched: Create preempt_count invariant
    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; \
    } 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
    + */
    + rq = finish_task_switch(prev); /* drops rq->lock, preempt_count() == 1 */
    balance_callback(rq);
    - preempt_enable();
    + preempt_enable(); /* preempt_count() == 0 */

    if (current->set_child_tid)
    put_user(task_pid_vnr(current), current->set_child_tid);



    \
     
     \ /
      Last update: 2015-09-29 12:01    [W:2.171 / U:0.236 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site