Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp549886lqb; Thu, 14 Mar 2024 21:41:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgAice4VGJyPJdN8f9UUeSY+sc8KXGEUyJDvnoyXEf4hSEYELLFlMrakHjiH74xV05DDkisd5O2ssbLq430m0JP4PG8GNbU1G0hfsOgg== X-Google-Smtp-Source: AGHT+IFZC2laIyCyemOTakIgZTKVcfhTsxFz+L8ddohI4MPqHfstcTveY/JwMK7wd2L4+LRfFbjL X-Received: by 2002:a19:5e12:0:b0:513:5c10:309c with SMTP id s18-20020a195e12000000b005135c10309cmr2493879lfb.3.1710477703431; Thu, 14 Mar 2024 21:41:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710477703; cv=pass; d=google.com; s=arc-20160816; b=t+yEdXIJKvrXCR87caxymW2eI0t5O/qkzC5PzjTIT+mDnNxTlEXudqdQCERiHcX2lF AoH5bIC0woxPSe0zDTzEa9+xyiylZP68/lp+eJIj1FUGCu00Y+0Pw+T+LWvOEPvo1Fpc rDkgI1XSFhI98rJvpeS9vin3WIuyxDJ8/L0P/S4Iuv5806gF/bEBYyqI6QPYgFrvOpvp QZFVfzHFCi+eNn7B0ZPItgx3cqs4rA3BFfrLI46G8nl8DACcapfdMurec1Rsx8bVtnir rNsOrfno9EWD7SU5KURys38pl4AGZJlvPadjo9AAXlOJsovY046axOKoXaTQhReD8Alz Wrkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=sBZo6XA+wJmJL8a6sUAHL6sA97t7m/9VOLS633itAWU=; fh=lq1k4m46TqOToIb7rHC/F2KmHTJTjmaV9sS3Am9W7nA=; b=YwByn1U+JJp9aPw0zdDoIaP1YtbduvofGzU/tfY2zaslDITjqDTNo/QYFiEDColofM yM5J5uA0aWB7gvuiFKHkBT6DgzzKCqq1G0YWe6JwGfgxmOqKRJsQcurSTaPwa6g79zO8 vKkjwqUlDRXHFnyvvCmBJg6B8QKsyI7Dl41WzwgfFSt22/ydpUKzIT2ms+dnbljYCeNP 1Ns1jLNXb0OQzjr/qIquiCPL0HfVpNwHWBULeuRcKLRBCtZ9iAhy908KUjRQb6+aujQH iBA/KF4YVFNDNUOpCkK0ZIrc3B4fWrBwnJXeYGZDwavJ1KLLmYE7xaSv4tCCwUUeakXx FpGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gNOt+Gzz; arc=pass (i=1 spf=pass spfdomain=flex--jstultz.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-104053-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104053-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e13-20020a1709062c0d00b00a465ff29305si1377242ejh.557.2024.03.14.21.41.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 21:41:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104053-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gNOt+Gzz; arc=pass (i=1 spf=pass spfdomain=flex--jstultz.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-104053-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104053-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 019FA1F22655 for ; Fri, 15 Mar 2024 04:41:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D106F15AE0; Fri, 15 Mar 2024 04:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gNOt+Gzz" Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 46481DDA9 for ; Fri, 15 Mar 2024 04:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710477633; cv=none; b=lxO/RUyfPre42dJ4/nUzKGgrQLGazTAIoJVdJ5rdJL8iglWeBV8r+4mUfA/sD8d34L2/C4CIoQwbtC/cuvyHmcyO5ZDxn+CZj3Qx/zfcerC3hBRcOeLhTtcvcYTkgbEXdvZ1AWif5cRXdIsZ7nOvpRUhXjCU8xpYWcZPyWmyrMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710477633; c=relaxed/simple; bh=oAooOCHqvipNleN1AM7UMHZk9HQovQoUz6g88NsOR8I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NdyqwWY9xZYCwHY1rtQR1HVThpzoPV/IU69dI00wQskujOKEVa43gEolajcFvMOx2vQim0tSteuOMOEvrO35KPYFmk43eM/UKf5eRmJ+iIeK9fQ8Pa3avDqCLmL7f+GvY45ffLHX2O0sZAmmP5VUzAb3SBaDYXnl1mfDmeCaF/g= 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=gNOt+Gzz; arc=none smtp.client-ip=209.85.214.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 Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1dd6198c570so21402835ad.1 for ; Thu, 14 Mar 2024 21:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710477631; x=1711082431; 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=sBZo6XA+wJmJL8a6sUAHL6sA97t7m/9VOLS633itAWU=; b=gNOt+GzzeVV6a5XssOtgwBLliZ28swzqCZKZra8D44e8MEv+HQhOs9Oq0OTt3N8VRA S4A34B9SUrETeWUSvEMU3TGuhszfpvz6NtTB52yPjauQ6LStvQdyl2UG1qDeEn1qF64G Vr7MUlRDbvn4cL/+yvJ+8aaaCyrPTkLNQgEQTzjuZxqajQjnL7xoW5NUwl7EyabTThj9 v8FF+7kMjr1c4KrdVLP5qkGweKixoyRDQiJ1QvADVnIWP6l8uxkhZrX7/tTiOb+8ACXE mcgQ2uke1059D/ps9ssNjY4U+RFRdqlavUOl/m/tJ4R7fl8zC0iwYy/jf0nDF13bdDSl hLWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710477631; x=1711082431; 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=sBZo6XA+wJmJL8a6sUAHL6sA97t7m/9VOLS633itAWU=; b=nkvfckrizy74aRFDJJeT8od6FYrRYIQhse18h7xw5t84IjE8Qq2GiNxh5WeL8IVZGj 1XI7kXLQ+I5RC9qrjUDJ+NGd2mOMT7/bsW4n2ZJGwcZuWagLpNFQbYDJWSO+ndhIFDvo 2NWJrhtbKckaFWHEcSBr222W96arep60IKjt09T/eGR2pEQ4pkLp/hjvMUxcA7xhAubb jjpxC1KOFB4kiqC/+lGMUKz3byyMqvxKfL1kNpnvn03U47SENdh4gsEaGF7jcSfM1huE ivvAZjodi+hzMHwumEYKC3lztdAfoW55zolS3IltbIS4NzTns/kTWFZUv1eINGJb+jfg oQOA== X-Gm-Message-State: AOJu0YzAPuK6pPFNT+VJFd2SukAL+scdYlJ4x4ryljvCWSsdHOPt3nZV /vJ6dHpZwRUBGOexIDi8JALA/kbhSqRjvnULYVDJuPWdAnUTOwwMCUlZ77uUIY0zsD+4qF6SHtm LbFoXPpBsZ5bG8kn4qSbDgkTeAC1Q5d8wP0yP83MedfRmAily7MiEfw8b5c7yv36oDU3JfGb00p 7wQP/oRyKLrv9YuaOB8GtXSKERQ6b2tR8MjSDjE9IZxOW7 X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:902:e80c:b0:1db:a861:f0ff with SMTP id u12-20020a170902e80c00b001dba861f0ffmr23433plg.3.1710477630362; Thu, 14 Mar 2024 21:40:30 -0700 (PDT) Date: Thu, 14 Mar 2024 21:39:51 -0700 In-Reply-To: <20240315044007.2778856-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: <20240315044007.2778856-1-jstultz@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240315044007.2778856-7-jstultz@google.com> Subject: [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-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 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 ad4748327651..b537e5f501ea 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6563,6 +6563,48 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) # define SM_MASK_PREEMPT SM_PREEMPT #endif +/* + * 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 = + (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 = prev->state; if (p->on_rq && ...) + * if (prev_state) goto out; + * p->on_rq = 0; smp_acquire__after_ctrl_dep(); + * p->state = 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. * @@ -6654,35 +6696,7 @@ static void __sched notrace __schedule(unsigned int sched_mode) */ prev_state = 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 = - (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 = prev->state; if (p->on_rq && ...) - * if (prev_state) goto out; - * p->on_rq = 0; smp_acquire__after_ctrl_dep(); - * p->state = 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 = &prev->nvcsw; } -- 2.44.0.291.gc1ea87d7ee-goog