From nobody Sat Feb 7 11:39:12 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E73F358ACC for ; Mon, 1 Apr 2024 23:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712015100; cv=none; b=LdSf47+yGGZY37mwhRnWgiHuzqq2zr+9uRZsFOzNNa4DTy8/ZUOzkCZwxeykgB105eHn8EtL0rDdfnOA6stpCfZzwhP26mKRx/f0qc1Hst1aAEK6c4+SIX08+Qxna1bjJIqnxgAZ8H74RhzMn/gN3wBomeI0Ir4D3eGiIGULVoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712015100; c=relaxed/simple; bh=xOMUb+GmiXukMH9HQceN3GVQdj0ZjM9Tp+Q+1CsUWig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b5hVLrEOkgZ18u6HNTQwHJGRrgvaKllJhW6lLduJufWxvuX5y+GVFMKGNYGnnm53dTGmOiAClH46U4pyxX0yFBtMwdx17jDP4vDNE8alO1Ka4R23Rcqsx3+FxfgMIi0fq6uH4V4D4NxAjszS7Lzvm77pv5P/T4yOM6ZxQp3HDFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fhtwqDpo; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fhtwqDpo" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcd94cc48a1so7104800276.3 for ; Mon, 01 Apr 2024 16:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712015098; x=1712619898; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QgqtM/d+7PpQv4HE31iqvyKrSmgqLa7oQqkgUO0r7vE=; b=fhtwqDpoEWrXo0lB5QIDUAOhYIl61Qn9zQXIuF4HEr/OSFJ7YykZG9dmmiYDRvZbCH W4MJjv6oYU5204fN1F29HeVnXV02CIYyV+y97ydv0GIKjag3PSvTEq31RI94pC1G2J+g UOvaepNyyK89AiEdhIAFZcE6O1a9yncTEwl/5tE84jMenm/v4fCVgY7RF0A+FLv21G59 7uUgl+/ch/mhaTk7rKmQFkkY9YYR8AsR5odVt+nuEYk560LUpr4D6Z7rua+PfjlYAQdX o9XAsEp1O+qxGdZqTlxkoxYpw+5KoIwQ0fZqwhzjR1K3pASNBw+Lbk+h660DhyowS08q BJEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712015098; x=1712619898; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QgqtM/d+7PpQv4HE31iqvyKrSmgqLa7oQqkgUO0r7vE=; b=FWr7Q+6gw4AJj1yrpwlfeT5+9Rqno8D5pZmxlQXpaZ8oAZR7EDQsUu7u6nHYzDsLAs aWGwixNEZv3Q8EuNFAOnv6gKCsWsvxfTFLDwNBNM1wJ+BfD8tPINdbecIhwmkvw9v3H8 p+ms2bGZGPMfTN/xHsH0OKs1A1CL4GZaaVK1u7RoHx+rLCwVqBYu/HhpNd7CZJLZZbgm TqIMhLysYDTymmLiA6dboDHdGb2juH3qrNi6KXxVQ/GY5mULBk1RcWTArE8pyM4hUk77 VohALRGQMqxqZahMArJFjIGZn5idN1u+iIuJ5Q3RWSAU7tQNGV6R9f31DC1tS9cTAaLS nRig== X-Gm-Message-State: AOJu0YzKgq5aKq3J9YKg/EPMHkAd5/jnEBtH0qwL6t+mMkJt+OwU3CRS nrr7TzIMCRWVdyFNn7a4Nu06MROqp47dah4hqvx/BN0+EYlMbYTCphkpUTaLdJ7Pk3Th7dxM3n1 O2LGNpUCaxfeXfS5IDvN7VVEo6FzA6VVsxz64XCs9+qgh6voIbICsOda7GxRvyTCF/zOlRL/PIB Q1uy38aPkKxkvU4ZNP785x2eAqT/Otc65Xut+jvrPiBAKF X-Google-Smtp-Source: AGHT+IG81utI2kl1Gn1sM2N8PqFdBdAaI2i00f63wU9a+w5ADuC0vVidLWOXzMl+jp7aeSU/i4t9+9F8b9w5 X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:1006:b0:dd9:4ad1:a1f7 with SMTP id w6-20020a056902100600b00dd94ad1a1f7mr3543161ybt.9.1712015097848; Mon, 01 Apr 2024 16:44:57 -0700 (PDT) Date: Mon, 1 Apr 2024 16:44:28 -0700 In-Reply-To: <20240401234439.834544-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240401234439.834544-1-jstultz@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240401234439.834544-7-jstultz@google.com> Subject: [RESEND][PATCH v9 6/7] sched: Split out __schedule() deactivate task logic into a helper From: John Stultz To: LKML Cc: John Stultz , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Youssef Esmat , Mel Gorman , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As we're going to re-use the deactivation logic, split it into a helper. Cc: Joel Fernandes Cc: Qais Yousef Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Valentin Schneider Cc: Steven Rostedt Cc: Ben Segall Cc: Zimuzo Ezeozue Cc: Youssef Esmat Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Cc: Metin Kaya Cc: Xuewen Yan Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: kernel-team@android.com Tested-by: K Prateek Nayak Signed-off-by: John Stultz --- v6: * Define function as static to avoid "no previous prototype" warnings as Reported-by: kernel test robot v7: * Rename state task_state to be more clear, as suggested by Metin Kaya --- kernel/sched/core.c | 72 +++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 586a3f8186bd..0eaa0855ef86 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6572,6 +6572,48 @@ pick_next_task(struct rq *rq, struct task_struct *pr= ev, struct rq_flags *rf) # define SM_MASK_PREEMPT SM_PREEMPT #endif =20 +/* + * Helper function for __schedule() + * + * If a task does not have signals pending, deactivate it and return true + * Otherwise marks the task's __state as RUNNING and returns false + */ +static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p, + unsigned long task_state) +{ + if (signal_pending_state(task_state, p)) { + WRITE_ONCE(p->__state, TASK_RUNNING); + } else { + p->sched_contributes_to_load =3D + (task_state & TASK_UNINTERRUPTIBLE) && + !(task_state & TASK_NOLOAD) && + !(task_state & TASK_FROZEN); + + if (p->sched_contributes_to_load) + rq->nr_uninterruptible++; + + /* + * __schedule() ttwu() + * prev_state =3D prev->state; if (p->on_rq && ...) + * if (prev_state) goto out; + * p->on_rq =3D 0; smp_acquire__after_ctrl_dep(); + * p->state =3D TASK_WAKING + * + * Where __schedule() and ttwu() have matching control dependencies. + * + * After this, schedule() must not care about p->state any more. + */ + deactivate_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); + + if (p->in_iowait) { + atomic_inc(&rq->nr_iowait); + delayacct_blkio_start(); + } + return true; + } + return false; +} + /* * __schedule() is the main scheduler function. * @@ -6665,35 +6707,7 @@ static void __sched notrace __schedule(unsigned int = sched_mode) */ prev_state =3D READ_ONCE(prev->__state); if (!(sched_mode & SM_MASK_PREEMPT) && prev_state) { - if (signal_pending_state(prev_state, prev)) { - WRITE_ONCE(prev->__state, TASK_RUNNING); - } else { - prev->sched_contributes_to_load =3D - (prev_state & TASK_UNINTERRUPTIBLE) && - !(prev_state & TASK_NOLOAD) && - !(prev_state & TASK_FROZEN); - - if (prev->sched_contributes_to_load) - rq->nr_uninterruptible++; - - /* - * __schedule() ttwu() - * prev_state =3D prev->state; if (p->on_rq && ...) - * if (prev_state) goto out; - * p->on_rq =3D 0; smp_acquire__after_ctrl_dep(); - * p->state =3D TASK_WAKING - * - * Where __schedule() and ttwu() have matching control dependencies. - * - * After this, schedule() must not care about p->state any more. - */ - deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); - - if (prev->in_iowait) { - atomic_inc(&rq->nr_iowait); - delayacct_blkio_start(); - } - } + try_to_deactivate_task(rq, prev, prev_state); switch_count =3D &prev->nvcsw; } =20 --=20 2.44.0.478.gd926399ef9-goog