From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796119690; b=WPuFReIt5kH7oGmGAFQCfxk6ZMBlhlimefleK7oEzCMw4/U660UlwGD0r1I5wkaBT3Vc lKHycRi7SZk7tFzm4RB5mkgvtsdo4mpapw8F15vWhZ10Q+ZW2cv+XXAg81Nw2ejwkrYn3 G4Xp3frWlPyB7b6rijtEu8om8yi2CtUPm5w3FJ5mh7TO529/hrqd60XcvMdbo5h8SqUuo T0MtQIMAGWCXmqtEFmK4mYLgK/J+yHy/8s91pe1VGTIH1bkPKG489mVAk3aMySWl6LmGu reM882J2p//air7v6M7jVcyhP5Gml9CYSBB5YY8DiArROfWNHbhEGCPQkdtvOtK2UyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796119690; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=skIw02cxn1ZGBMbM2CQEN1KwPpUezLjlaB70ATYsn9U=; b=oGpMJtHm4Od77UZ5jl9Hi2LVcb0CJ6OOLtatJtS+bTq04ur7Ew/+iP7I2StcXy/9Qoxg ZKoMRnNUhscGj94W4Thbv3QaRI7FrC91LXgJzd/zhr3RFRZH1eBnlNOv62KJyyh6Z/WVq CwOik9gmeT6HdD+dbkDwOudpPRw+peoKkR6A0rGoEP0mARwVZ/gqqvjE72IWh2bfkoK5m kA0PTCrMg1JtiCvG7SQWmZLZzYBNMnB8HYovS/MIhvh42ocs3HjAAj+T8MckH2FOgFdTB UE6zUeHyI+R2XA+HJc/tKOSZ0SdfErVPeUkCgjdMhVjCjFsKSNpzE6tVNJ3X0ah0/vw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="a/B9YU52"; arc=none smtp.remote-ip=209.85.128.70 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEB63606A32C for ; Tue, 1 Dec 2026 10:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EEB63606A32C 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--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=a/B9YU52 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4bb6bbc025aso89409645e9.3 for ; Tue, 01 Dec 2026 02:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796119688; x=1796724488; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=skIw02cxn1ZGBMbM2CQEN1KwPpUezLjlaB70ATYsn9U=; b=a/B9YU52NuugxHXcz9s+Yd0ZghHe/FiSPrQTXXRh63Nf/e1jaM+gEjcoiwCWJD8cHu 6/m8KMkd+wkITeKIK2YbxWTDY1VbVzCwUhIzCYnDXK96b53sDXwYJws8W0FtYKoQr+bV aNE3jE46ucpdJemfCGWtW+97ESrAjla9eQxgF/Xp9z4nrVkQfSt/5xu36PII9oQuktb0 16/QR0U70Xd7DP/Hns4/SKmpmsEFVOBWzI9Z7OxE8Al1zPhSWWkZT4uRjYr5oolSzitv aG8np35Fcd6b1/LDgZfT9NJmUU9i131BRq522zXAXSzaatobbfNDr00sYCTJ8PcRBoYg pREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796119688; x=1796724488; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=skIw02cxn1ZGBMbM2CQEN1KwPpUezLjlaB70ATYsn9U=; b=eMxW8oFvBiWKySbghpRAIHGi+xqEuDzGh6zAY11bcZgE/wJeNhyps3XU27RH30Nitd /I056ePMpiIEHmvyiskEm6ivZy9VsICjpPAGZCh2gvx4gqMVQlB+erWoZdM1blCjvh4p YNBKuKIULF0/c+ZXH2GoWwt+APa2VdqCTP5HUNmlTCJm8YT0ES4eDkH4lWwgXU1TwOUS wkipCFpM5RoVV465QKneUNtKh2I1DGTvLBXuzDUo4FFQ/s4w2h+vROmOQ1Kki5k+rZqh Zc+/gFVleXqcRyYMIDG6qvvJQRcEI0t23y6ZQ64rhnXNbyuBAWvvFriEgsDoVx26ZDhu OTDA== X-Forwarded-Encrypted: i=1; AL+hErH68P/ab5dMVBST39DfNE0Kh+f9Jt6BXlzqZKqV9BNIpVPH4kmZONPP+BQbJrvfLHVrwk5ZDrWp7v3sG04=@vger.kernel.org X-Gm-Message-State: APuU4Z+8ndOzgeU0BPtjLp9slQD6UncWRPDXp+4jk7NvkJsg05XSkETm 9m3kvutng3Nw9vT27v0zwBAFkldZiVe0hByR08aD6o1SfSKeHx7DLBwC9XtqXltfEC0QAT2jkpZ V2wKuX39XahGAWQ== X-Received: from wmlc12.prod.google.com ([2002:a7b:c84c:0:b0:4bb:b1a5:d091]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e0e:b0:4a1:da58:1ee with SMTP id 5b1f17b1804b1-4bb88938dc9mr762975405e9.31.1796119688208; Tue, 01 Dec 2026 02:08:08 -0800 (PST) Date: Tue, 1 Dec 2026 10:08:07 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201100626.3602852-1-jpiecuch@google.com> Subject: [PATCH 6.18.y] sched_ext: Enable tick for finite slices on nohz_full From: Kuba Piecuch To: stable@vger.kernel.org Cc: Andrea Righi , Tejun Heo , Greg Kroah-Hartman , Sasha Levin , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Kuba Piecuch Content-Type: text/plain; charset="UTF-8" From: Andrea Righi [ Upstream commit 4ec10f38ff901dc10503d57cbdcf941248419ac1 ] set_next_task_scx() updates the tick dependency before __schedule() updates rq->curr. When switching from a non-EXT task, such as idle, to an EXT task with a finite slice, sched_update_tick_dependency() checks the outgoing task and can allow the tick to remain stopped. The dependency can also be lost without a slice-type transition. After a finite-slice task leaves the CPU idle, the enqueue path can clear the dependency against the idle rq->curr. SCX_RQ_CAN_STOP_TICK still records a finite slice, so another finite task skips the transition block and can run without the ticks needed to expire its slice. The reverse mismatch can also happen when the last finite-slice EXT task is dequeued: sub_nr_running() updates the dependency before rq->curr changes, so the outgoing task state can keep the dependency set after the CPU goes idle. Fix this by unconditionally enabling the scheduler tick whenever a finite-slice EXT task is selected on a nohz_full CPU. Moreover, when the last runnable EXT task leaves, ignore the outgoing EXT slice state so the generic scheduler can correctly re-evaluate and clear the tick dependency. Fixes: 22a920209ab6 ("sched_ext: Implement tickless support") Signed-off-by: Andrea Righi Signed-off-by: Tejun Heo [ jpiecuch: Adapted path to kernel/sched/ext.c and moved scx_rq_bypassing() below the !rq->scx.nr_running check in scx_can_stop_tick(). ] Signed-off-by: Kuba Piecuch --- Tested on v6.18.65 (CONFIG_NO_HZ_FULL=y, CONFIG_SCHED_CORE=y, CONFIG_PROVE_LOCKING=y, booted with nohz_full=1-3): - Custom BPF reproducer exercising SCX_SLICE_INF -> idle -> finite and finite -> idle -> finite slice transitions on a nohz_full CPU: fails 5/5 without the backport, passes 10/10 with it. - tools/testing/selftests/sched_ext/runner: 23/23 pass (after locally working around the unrelated select_cpu_vtime.bpf.c build break on v6.18.65), with no kernel warnings or lockdep splats. This backport was prepared with the help of an AI coding assistant. I have reviewed the patch and verified the tests run by the tool. kernel/sched/ext.c | 53 +++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index af5828f09304..9fb229882f8d 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -2308,24 +2308,38 @@ static void set_next_task_scx(struct rq *rq, struct task_struct *p, bool first) /* * @p is getting newly scheduled or got kicked after someone updated its - * slice. Refresh whether tick can be stopped. See scx_can_stop_tick(). + * slice. Update SCX_RQ_CAN_STOP_TICK to reflect whether the tick can be + * stopped. See scx_can_stop_tick(). + * + * Moreover, refresh the load_avgs just when transitioning in and out of + * nohz. In the future, we might want to add a mechanism to update + * load_avgs periodically on tick-stopped CPUs. */ - if ((p->scx.slice == SCX_SLICE_INF) != - (bool)(rq->scx.flags & SCX_RQ_CAN_STOP_TICK)) { - if (p->scx.slice == SCX_SLICE_INF) + if (p->scx.slice == SCX_SLICE_INF) { + if (!(rq->scx.flags & SCX_RQ_CAN_STOP_TICK)) { + /* + * Bypass mode always assigns finite slices, so @p + * can't have an infinite slice while bypassing. + * Therefore, sched_update_tick_dependency() can safely + * evaluate the outgoing task. + */ rq->scx.flags |= SCX_RQ_CAN_STOP_TICK; - else - rq->scx.flags &= ~SCX_RQ_CAN_STOP_TICK; + sched_update_tick_dependency(rq); - sched_update_tick_dependency(rq); + update_other_load_avgs(rq); + } + } else { + if (rq->scx.flags & SCX_RQ_CAN_STOP_TICK) { + rq->scx.flags &= ~SCX_RQ_CAN_STOP_TICK; + update_other_load_avgs(rq); + } /* - * For now, let's refresh the load_avgs just when transitioning - * in and out of nohz. In the future, we might want to add a - * mechanism which calls the following periodically on - * tick-stopped CPUs. + * @rq still references the outgoing scheduling context. A finite + * slice is sufficient by itself to require the tick. */ - update_other_load_avgs(rq); + if (tick_nohz_full_cpu(cpu_of(rq))) + tick_nohz_dep_set_cpu(cpu_of(rq), TICK_DEP_BIT_SCHED); } } @@ -3170,12 +3184,21 @@ bool scx_can_stop_tick(struct rq *rq) { struct task_struct *p = rq->curr; - if (scx_rq_bypassing(rq)) - return false; - if (p->sched_class != &ext_sched_class) return true; + /* + * @rq->curr may still reference an outgoing EXT task after it has been + * dequeued. If no EXT tasks are accounted on @rq, ignore its stale + * slice state. If another task is dispatched from a DSQ, + * set_next_task_scx() will update the dependency for the incoming task. + */ + if (!rq->scx.nr_running) + return true; + + if (scx_rq_bypassing(rq)) + return false; + /* * @rq can dispatch from different DSQs, so we can't tell whether it * needs the tick or not by looking at nr_running. Allow stopping ticks -- 2.56.1.839.g22a8290db9-goog