From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CDECC4338F for ; Wed, 11 Aug 2021 12:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1EF160C41 for ; Wed, 11 Aug 2021 12:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237997AbhHKMX0 (ORCPT ); Wed, 11 Aug 2021 08:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237837AbhHKMW5 (ORCPT ); Wed, 11 Aug 2021 08:22:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28C5BC06179C for ; Wed, 11 Aug 2021 05:22:34 -0700 (PDT) Message-ID: <20210811121414.179583019@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628684551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=Ddzbu9shj00bPE22RZT2bhOuL8oRLRncH8m4i2+p1ZA=; b=LqfJnmxQHcOozPS2v8Wz/QawhwG1TSKWrsAYCWu832dzYLZap0vmirVRooZCzX2mCeq+BY dmbg5EC4ZE92/AQ0HfuTK+tvrpAItqT/X4g4TpnnGHtJ2e/Qxmnj1+VsE+WrNPkT1MaTy4 Ta+ta9S8eC/6KkveG5Qv31KD/koh610QLkYYbuM5HAJfJDN8ePuzRO0ITJU2cPH8DfwmM7 CrZzxaDEfshlyVHNt3SEOJQMOZTX6OT+gLBHGGHyUdLSqXnZw5S+seLqGHa+GyrP/oL/Nz S1EnLSWQlYq8a0FgHLEsUuL82Ux2bjjxwQwkqmll7FGjexsy8vJ8sDWuKLMT+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628684551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=Ddzbu9shj00bPE22RZT2bhOuL8oRLRncH8m4i2+p1ZA=; b=1UdAGp4vivarCwm/Rg9ouJqN8KWr/DtMG9cmyfAfYvcaDDxNO9fd15azdc0CpK19VBG3Uo M4uNzhacMWUcuaCQ== From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Steven Rostedt , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , Sebastian Andrzej Siewior , Davidlohr Bueso , Mike Galbraith Subject: [patch V4 01/68] sched: Split out the wakeup state check References: <20210811120348.855823694@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Date: Wed, 11 Aug 2021 14:22:31 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner RT kernels have a slightly more complicated handling of wakeups due to 'sleeping' spin/rwlocks. If a task is blocked on such a lock then the original state of the task is preserved over the blocking and any regular (non lock related) wakeup has to be targeted at the saved state to ensure that these wakeups are not lost. Once the task acquired the lock it restores the task state from the saved state. To avoid cluttering try_to_wake_up() with that logic, split the wake up state check out into an inline helper and use it at both places where task::state is checked against the state argument of try_to_wake_up(). No functional change. Signed-off-by: Thomas Gleixner --- kernel/sched/core.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) --- --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3562,6 +3562,22 @@ static void ttwu_queue(struct task_struc } /* + * Invoked from try_to_wake_up() to check whether the task can be woken up. + * + * The caller holds p::pi_lock if p != current or has preemption + * disabled when p == current. + */ +static __always_inline +bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success) +{ + if (READ_ONCE(p->__state) & state) { + *success = 1; + return true; + } + return false; +} + +/* * Notes on Program-Order guarantees on SMP systems. * * MIGRATION @@ -3700,10 +3716,9 @@ try_to_wake_up(struct task_struct *p, un * - we're serialized against set_special_state() by virtue of * it disabling IRQs (this allows not taking ->pi_lock). */ - if (!(READ_ONCE(p->__state) & state)) + if (!ttwu_state_match(p, state, &success)) goto out; - success = 1; trace_sched_waking(p); WRITE_ONCE(p->__state, TASK_RUNNING); trace_sched_wakeup(p); @@ -3718,14 +3733,11 @@ try_to_wake_up(struct task_struct *p, un */ raw_spin_lock_irqsave(&p->pi_lock, flags); smp_mb__after_spinlock(); - if (!(READ_ONCE(p->__state) & state)) + if (!ttwu_state_match(p, state, &success)) goto unlock; trace_sched_waking(p); - /* We're going to change ->state: */ - success = 1; - /* * Ensure we load p->on_rq _after_ p->state, otherwise it would * be possible to, falsely, observe p->on_rq == 0 and get stuck