• Thomas Gleixner's avatar
    sched/wakeup: Prepare for RT sleeping spin/rwlocks · 5f220be2
    Thomas Gleixner authored
    Waiting for spinlocks and rwlocks on non RT enabled kernels is task::state
    preserving. Any wakeup which matches the state is valid.
    
    RT enabled kernels substitutes them with 'sleeping' spinlocks. This creates
    an issue vs. task::__state.
    
    In order to block on the lock, the task has to overwrite task::__state and a
    consecutive wakeup issued by the unlocker sets the state back to
    TASK_RUNNING. As a consequence the task loses the state which was set
    before the lock acquire and also any regular wakeup targeted at the task
    while it is blocked on the lock.
    
    To handle this gracefully, add a 'saved_state' member to task_struct which
    is used in the following way:
    
     1) When a task blocks on a 'sleeping' spinlock, the current state is saved
        in task::saved_state before it is set to TASK_RTLOCK_WAIT.
    
     2) When the task unblocks and after acquiring the lock, it restores the saved
        state.
    
     3) When a regular wakeup happens for a task while it is blocked then the
        state change of that wakeup is redirected to operate on task::saved_state.
    
        This is also required when the task state is running because the task
        might have been woken up from the lock wait and has not yet restored
        the saved state.
    
    To make it complete, provide the necessary helpers to save and restore the
    saved state along with the necessary documentation how the RT lock blocking
    is supposed to work.
    
    For non-RT kernels there is 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.258751046@linutronix.de
    5f220be2
core.c 263 KB