• Thomas Gleixner's avatar
    sched/core: Rework the __schedule() preempt argument · b4bfa3fc
    Thomas Gleixner authored
    PREEMPT_RT needs to hand a special state into __schedule() when a task
    blocks on a 'sleeping' spin/rwlock. This is required to handle
    rcu_note_context_switch() correctly without having special casing in the
    RCU code. From an RCU point of view the blocking on the sleeping spinlock
    is equivalent to preemption, because the task might be in a read side
    critical section.
    
    schedule_debug() also has a check which would trigger with the !preempt
    case, but that could be handled differently.
    
    To avoid adding another argument and extra checks which cannot be optimized
    out by the compiler, the following solution has been chosen:
    
     - Replace the boolean 'preempt' argument with an unsigned integer
       'sched_mode' argument and define constants to hand in:
       (0 == no preemption, 1 = preemption).
    
     - Add two masks to apply on that mode: one for the debug/rcu invocations,
       and one for the actual scheduling decision.
    
       For a non RT kernel these masks are UINT_MAX, i.e. all bits are set,
       which allows the compiler to optimize the AND operation out, because it is
       not masking out anything. IOW, it's not different from the boolean.
    
       RT enabled kernels will define these masks separately.
    
    No functional change.
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20210815211302.315473019@linutronix.de
    b4bfa3fc
core.c 264 KB