From nobody Fri Dec 19 20:59:51 2025 Received: from out187-16.us.a.mail.aliyun.com (out187-16.us.a.mail.aliyun.com [47.90.187.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C57301A76DA for ; Wed, 8 Jan 2025 08:52:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.187.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736326371; cv=none; b=WnRWRQgneRJGpspQOMXYhGEbHP9YT0ZliCMR1uvHFYazwIPjYsdFiEGrcUTIxp729IHdzFXcRLzDBro06HTHNaz1kBQj4hFmRTPofklbLDKNmAp+prsYUCukSORFKWqWKYKBciV9Q5d/RwZ2rXACVmk2QbJ7n+F6A5ZZsdEgQ4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736326371; c=relaxed/simple; bh=kOmAyV1HcgoxM4LQQGOUlm66qkNHyClgZKmQPUNWSY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sk0aeTEr4ecMOqVB1ZDuT51eUauPGQgBxrgIh8LnvlK7/LITLXrCdS/FgIdUsTL73sJBpsPADVIf3jfJ9AkyJ2SjhHYX4tAS4MNi8UkcWHWPhlj//Utj1J4YtcZSei3iWEBMSk28r3Xwv/PxUWRqi9jyg1csrAfQQ4LrGpD3iEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=cqhLdQTm; arc=none smtp.client-ip=47.90.187.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="cqhLdQTm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1736326351; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=SI9cS5Z0YPf0KYEE5W1PTzjOqs/lg0DDyK14BriaRPI=; b=cqhLdQTm08QLSsBPqyCcLoG1/JG+Aks9CVypAjCmmxC+tENNNpC0Sqg9rfD7qP+hLoUwRUwsYxZDZgcwx/ZMi+SmQ3xJj25QVhSvOmHi/BIE1vTHQaoVVNjvYWBw8XSUZV6W9HZwKyAg0g/7ejMEG3xgH0m9EtrwFkeMwa01qNo= Received: from localhost(mailfrom:henry.hj@antgroup.com fp:SMTPD_---.ayxpIhS_1736326034 cluster:ay29) by smtp.aliyun-inc.com; Wed, 08 Jan 2025 16:47:15 +0800 From: "Henry Huang" To: tj@kernel.org, void@manifault.com Cc: "=?UTF-8?B?6LCI6Ym06ZSL?=" , "=?UTF-8?B?WWFuIFlhbihjYWlsaW5nKQ==?=" , , "Henry Huang" Subject: [PATCH v2] sched_ext: keep running prev when prev->scx.slice != 0 Date: Wed, 08 Jan 2025 16:47:10 +0800 Message-ID: <20250108084710.42747-2-henry.hj@antgroup.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250108084710.42747-1-henry.hj@antgroup.com> References: <20250108084710.42747-1-henry.hj@antgroup.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When %SCX_OPS_ENQ_LAST is set and prev->scx.slice !=3D 0, @prev will be dispacthed into the local DSQ in put_prev_task_scx(). However, pick_task_scx() is executed before put_prev_task_scx(), so it will not pick @prev. Set %SCX_RQ_BAL_KEEP in balance_one() to ensure that pick_task_scx() can pick @prev. Signed-off-by: Henry Huang --- kernel/sched/ext.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 81da76a..ba74e07 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -2747,6 +2747,7 @@ static int balance_one(struct rq *rq, struct task_str= uct *prev) { struct scx_dsp_ctx *dspc =3D this_cpu_ptr(scx_dsp_ctx); bool prev_on_scx =3D prev->sched_class =3D=3D &ext_sched_class; + bool prev_on_rq =3D (prev->scx.flags & SCX_TASK_QUEUED) !=3D 0; int nr_loops =3D SCX_DSP_MAX_LOOPS; =20 lockdep_assert_rq_held(rq); @@ -2779,8 +2780,7 @@ static int balance_one(struct rq *rq, struct task_str= uct *prev) * See scx_ops_disable_workfn() for the explanation on the * bypassing test. */ - if ((prev->scx.flags & SCX_TASK_QUEUED) && - prev->scx.slice && !scx_rq_bypassing(rq)) { + if (prev_on_rq && prev->scx.slice && !scx_rq_bypassing(rq)) { rq->scx.flags |=3D SCX_RQ_BAL_KEEP; goto has_tasks; } @@ -2813,6 +2813,10 @@ static int balance_one(struct rq *rq, struct task_st= ruct *prev) =20 flush_dispatch_buf(rq); =20 + if (prev_on_rq && prev->scx.slice) { + rq->scx.flags |=3D SCX_RQ_BAL_KEEP; + goto has_tasks; + } if (rq->scx.local_dsq.nr) goto has_tasks; if (consume_global_dsq(rq)) @@ -2838,8 +2842,7 @@ static int balance_one(struct rq *rq, struct task_str= uct *prev) * Didn't find another task to run. Keep running @prev unless * %SCX_OPS_ENQ_LAST is in effect. */ - if ((prev->scx.flags & SCX_TASK_QUEUED) && - (!static_branch_unlikely(&scx_ops_enq_last) || + if (prev_on_rq && (!static_branch_unlikely(&scx_ops_enq_last) || scx_rq_bypassing(rq))) { rq->scx.flags |=3D SCX_RQ_BAL_KEEP; goto has_tasks; --=20 Henry