Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2357396rdf; Mon, 6 Nov 2023 11:37:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpFdJHUTvUDwmIXmsC2NROh329LzQ9d8a/CaSEk4eBI0S/Xi/2QbRo7kGWlpDou3W854fA X-Received: by 2002:a05:6a00:2443:b0:68f:b5cb:ced0 with SMTP id d3-20020a056a00244300b0068fb5cbced0mr34468754pfj.34.1699299444881; Mon, 06 Nov 2023 11:37:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699299444; cv=none; d=google.com; s=arc-20160816; b=Yy2g+XEG209PHR7OILR48i2dLwVMTJQcufL8mMT8TSbRaHCr8Te5HHzYe7BsyUaxjE c7fKgr9n123faXPtuB3CtIFROXi5MONKdPN7b/IDrfBEfIxhR84QqHl8vGp9Ur0hOTMz tBBaLfRyOLB8dUWRAup6VKr13EcEOhMFQiz41vx2ZunQZB/hnKiVZnoK1sgUEcLZsolY Qy3N+HLSG7+lDguoAJZh7SdE3dFyzx4YBnhB8Gbxxoi3R2VwNi3l18oQLP60xJTh58Vu aWsd/ox52h9zdGjREhaiM1/UfzL/g6BOTTiDTWcjgjBDgRNRtUAkzPuXxl4Q+iOcdSjZ ssKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Q8WchLjhxzR8hLwmAM2b8K3LlHrmaAbxbI1VulbCNAg=; fh=7UDRnXAyFwoHSGMn0t+ldgDKuKM1JE0l1TSpusfeMFI=; b=AdrPf5EwiQGLnc7PTikl1/+8X3tpat4UBs/ULzNxCXnP0QZDIQ3Jcf3c8W404V9vFh Mf5LXcwESE1hYOrf9LJyHAZEeGGHXGhrui9z1+d541/KwtOV3/ICcN+UOsXfUsVhZ+K8 wnxMHQniTdW1GBW9020hf0KsHjXUgvYJgboVBulseS2qeg7xlai9TzwnDDVP77RV0Q7x K9jeSBJbpSom8DIXcQY0xzaWWLZ2qE5wd7sObb2pCNSp72V8pn8erIhWMdsxQHnhrZqD IXtUCmqueqyH7+eEKUexV4tey5tlIt9qBNx3GTSXJw4paMj0XA8kwb6JSnTW156Rnssu Bf9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ng3201E8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y185-20020a6364c2000000b005bd0f2c2671si294875pgb.626.2023.11.06.11.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:37:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ng3201E8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3133F801D4AD; Mon, 6 Nov 2023 11:37:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232948AbjKFTgx (ORCPT + 99 others); Mon, 6 Nov 2023 14:36:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbjKFTgJ (ORCPT ); Mon, 6 Nov 2023 14:36:09 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7188173F for ; Mon, 6 Nov 2023 11:36:02 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d86dac81f8fso5882315276.1 for ; Mon, 06 Nov 2023 11:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699299361; x=1699904161; 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=Q8WchLjhxzR8hLwmAM2b8K3LlHrmaAbxbI1VulbCNAg=; b=ng3201E88f0muoa/itwNYD0l/qp/0PZVu723T1YVJth0r44XVnz6xyJNcpzjn2Ounw 7SlVT0xm2+5eh+2RXgTGEj/GhLGe5x45UPPm+JT1n6LmItMQUNHtfyq+9d3pltLZRjvF /uN/O3S7LMUfIJ3LMb/bpVcDVwLnXk6MoTLHWRoIgis56FXzjg3HLT0ph+nFM8zzP7ft SZYg+J6J/HODFwShn98jWrV3dsoRnH4FffgaLqveuC2qH1pRDRI49AWIQUbt/yviW12o mJaXJd5pofJC17aPaWKp17Y31c/IYysIYPF55aO3gu5hWCX8nXw/zcFhDjxDiabQHgjM Wd8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699299361; x=1699904161; 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=Q8WchLjhxzR8hLwmAM2b8K3LlHrmaAbxbI1VulbCNAg=; b=EQHWJdTEJ2+nJCra4aZMl4t4fP8RqJtKbzISaGO/Hmt0luGjuEXqcTRhh61gZmv5Yn ZLMhf8PPTAQA88TEVDljwKnx3nDRC8HFsoFlpkC+9TnsgywP2wppF6IlFUgagN1PKrKM DTUzHDw53J8ER+aXr7REj5h2/sHhqy2ykNu3OOvizuxgAfeQRMhMMP1Q4PdzEYqOuy5e oeJAshFdCtmNV+Yr2rQ3MaehGRy/hPWWTiHw5ypvHKq8LVynAt0ECBcnvjS3JVMq5iRW mzesQUdNyKNXTyWRNWZV80IFz8Z2ncVr+FzUtZrxBS+qIGDbKUhlSJJXNaR7he1yN5Gw jsmw== X-Gm-Message-State: AOJu0Ywsg6amn+jwMqk170gaCZkDZIBkC4fljXWY8zMP3+SrN4UqkXzj UrEtQkZHpAOikQ6FqLgCfgXRX2djXqACnUtq8HjPRnVL1USPpouJDx0ayHR+L+5TPqtz7iberji NTo6dYks3bXA0mFtlzFUaisrpSV+7ieh1wQFtYnxmYQ4M6u/dI6IYysuTZHPLWzoj6ScfwN8= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a25:aae7:0:b0:da0:5a30:6887 with SMTP id t94-20020a25aae7000000b00da05a306887mr537996ybi.4.1699299361477; Mon, 06 Nov 2023 11:36:01 -0800 (PST) Date: Mon, 6 Nov 2023 19:34:56 +0000 In-Reply-To: <20231106193524.866104-1-jstultz@google.com> Mime-Version: 1.0 References: <20231106193524.866104-1-jstultz@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231106193524.866104-14-jstultz@google.com> Subject: [PATCH v6 13/20] sched: Split out __sched() 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" , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 11:37:18 -0800 (PST) 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: 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 --- kernel/sched/core.c | 65 +++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9931940ba474..1b38b34d3f64 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6575,6 +6575,41 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) # define SM_MASK_PREEMPT SM_PREEMPT #endif +static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p, unsigned long state) +{ + if (signal_pending_state(state, p)) { + WRITE_ONCE(p->__state, TASK_RUNNING); + } else { + p->sched_contributes_to_load = + (state & TASK_UNINTERRUPTIBLE) && + !(state & TASK_NOLOAD) && + !(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. * @@ -6665,35 +6700,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.42.0.869.gea05f2083d-goog