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=1796119743; b=ZCI1uI/mn149eWjR6Tsu+kK80y/5fdkWrzuMtU46W0mMRsK5jaOpF2aV8hVZkPA917Sq jCbkb0IBNmDFPkStE15JciV9wZLIJYqXsCh5mV9uBnYCH0+WvSX3queErUZjBmpVHLkad /8vwOMjNlDy88h5ufU19ZhKa0q2GI9GMC+xXG/MokIZxzs9Xa98J7PU+1MaYAn802EEvy kxYY0K3pHPvq37VQf/AEspWKIDH1L0L4w3lHhi4qn5CIts8gxBACoDByNjeMS7KPpOkqf 4ZE6tNX18dmqMtvF9NrcLAz4UfLXaVmLveE4fcO7Kx9AvL3Ig+sMXuXW1xMc+m2xRAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796119743; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=W0jZAukKbEqd6CI4tD+HJuU8aFk+2Cj9grPRuQ00+dk=; b=ASkypcePLE/I2TnHkElJjz7MYEa4QQpnUy9XuNf1bIxvXmzfal60ovaU+p22PzF6DLi5 tyajn3XTjPGOnIjqyzwd4OO7tmc9DEwbRWymyYNWSxB3vEje0KmIcljY8GL9Ta1moUUFb Ss0wUNFBRN0kThqkeIssDgF98c1jxA1JcsUS5fXuv1Ixjw02v+zST4AxE20ckqUj+wIva 7xsHVDqiBUFK+vyQNlHpBi6uNgFh1gc50kEpmLrMenEHXIqJ1K6qDekhJQWRfbyntNJrI yikTlWEfMPtCe3JQXFeWrtsyFMM+To5rmtp8poF1Uw7C601uo/7O4OQGKNUu3w6h57A== 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=RW9fKKrG; 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 C042D606A32C for ; Tue, 1 Dec 2026 10:09:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C042D606A32C 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) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=RW9fKKrG Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a20e41008cso66079785e9.1 for ; Tue, 01 Dec 2026 02:09:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796119741; x=1796724541; 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=W0jZAukKbEqd6CI4tD+HJuU8aFk+2Cj9grPRuQ00+dk=; b=RW9fKKrGtRaIQgqcvQJzrvNzhXfOB1jRXA3ZTQM+o0Xl0kH8Xj02ztlBf/RuFYYXSQ pfVUm+NxpIlOj5OEQ1myKMhueus84A4NOdWMiGSd9pTALuPSo8KtWPtIrXX/seBG6lNV cVpjZmH4UDuJwLFTzWFkrm7BRZ8nfuReATmsWwbnickXAZwI1XIOEm1HR+ShC/oI5Ibx PQCIu0axi9Knu3FDshMNzg9sgITZF9nc7xR00TDBWiuaHkHFsOM1cVGy6i+AwdEJxMYR ZbgGrKQDWvuram8m8bHWYp0DSWTL4SJrzxrozJeHVeZnJY8azRyvOsFL/CHeTLpsYa1C HsKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796119741; x=1796724541; 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=W0jZAukKbEqd6CI4tD+HJuU8aFk+2Cj9grPRuQ00+dk=; b=XwsxAeYgp4XU2bZcVsmy7Sdnal9bzU3sh2I8bHtAAiRhNbih82lIcrh9QQEmAonkQp zwcsBE6laFSoL2GP64W6gnWhxlMMhzhEEFwu7hmwEXue3nN98Br06TtGnDkGv/bAUzgU Lkx0m54G27V2ZOnl200hsD9y22dheRUHb5ZJIHzcgRxblYGkjIPeIKecAQXyi9GKyDU8 KFX+NrpGZgWKQbGEJjDQX+GtxbWQxp/v2kYdDTr3hz+JTAwzlxipLtllY3EgB8+TK9dH s2Cg0m3R4P0zcid3H0KbcelGihBXbpvz11tlNDXL9wFKrIrlIieo6Cfz4ukkGgwSrUif 1B7A== X-Gm-Message-State: APuU4Z8odVCDOAL2M96AJ/XnXWXywMDX48aK18GEEZTB7g22rEyqH4ow T5cfxU8+vLco5MkkVeaGFPOmvniWPEnjIl2CCKCKSigs+ucL2oKUCvflyN44uNVQ7iDcimXxwPi HZz32macHweddaU6daRD3rl3O46YttDAXmByRbliv0znrwxC52QfjsVqGFe30a+TzLOJtAvtkLK p0OsLxXpIJOL36V7RT4OG3AbWljZc8D67CcKy0V8SXGVOM/Zg= X-Received: from wrvh7.prod.google.com ([2002:a5d:5487:0:b0:48d:f7b7:436f]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1548:b0:4a3:59c9:a756 with SMTP id 5b1f17b1804b1-4bb88800013mr769481375e9.6.1796119740958; Tue, 01 Dec 2026 02:09:00 -0800 (PST) Date: Tue, 1 Dec 2026 10:09:00 +0000 X-Mailing-List: stable@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: <20261201100829.1669582-1-jpiecuch@google.com> Subject: [PATCH 6.12.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.12.119 (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: 21/21 pass 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 7a4b23e48cc6..d429209103ef 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -2980,24 +2980,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); } } @@ -3987,12 +4001,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