From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384167; b=bFwf4dhRtq/QE6MDYzl1MJ4gTxHwXQ/1tq8ZuutYcoY0wjQTtKQWbkAYh9oZxU8Fh5JD 8yED2g6gSQBv+qtM+OQpsv5aNJzsW8hD/0iFWp2V+7Gwd0f/WkD6jtcf6xI/tGxrcWwmF J8e++yiktlyDSTP8oCIrX2cJPz62hQjOD+VdCdBj0xa/hi4E+RRkxFenx7vnq6PdRUzh4 5VRL11i32cF+XY1DnEhaszPI5xLEuUgkk0RNDljl64sEI3Nf+KpQ7iq7GxPF+q08NJtpx cp0eYPirV217IGV/IWRq3hQVDe4kSMc5TSAeHL/olrpAWi1QogkVQmrQF8y+jfB0i0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384167; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=9u7n3oCGjMG3Q+j71MuMrV+BplXJbZDbslLy9MgQZzk=; b=4uwjnbXcsFEwAoHe7KJb/jRGU63aOGxmHTjCJu99rTbXQlUXv4mk4uM+ysC5hpHPhQxL ywShhj4Ifru96aufv0xuKuIkZdJpVdhmp9+ZUhBkSdFtDUgr80pldI7w42thGackU9zo3 AZtA1EiXbnHXlAqAXe5rluc5QCdiDJBkr7GKiGHo4oKmCWTMoVnR92RC3NIOwAbNLT6nU MAJNXtt8qcOM/dus7nhE+HeEufT3ZM0HOySJoKSxJBDAgURdGBCmrPewyXjUpw1KfIv+J vAz+3So61kNerboTzAUKV9cZm3fQbP85AIm4XbMDHjSduHOxuCc034MRzU1iEoMTJKA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=iUbuQ8LI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCB32606A322; Fri, 4 Dec 2026 11:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=iUbuQ8LI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53FCE1F000CE; Fri, 4 Dec 2026 11:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384167; bh=9u7n3oCGjMG3Q+j71MuMrV+BplXJbZDbslLy9MgQZzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iUbuQ8LIs3cOumob+i+aJWwB7To3VHVVZC1X8nVEgNCbtC7E4UVDFFxPetwT9tlXa oYsmPxa8UKg75KrWhLjUi3oZlsDp+m6ZR6pDoCy2gu5rbGYsl7wdSQFrF6C0rn685v /eID++fdMLYNEnhFA9NjyOhVIjQ2TR124ra1O/Z4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrea Righi , Tejun Heo , Kuba Piecuch , Sasha Levin Subject: [PATCH 6.12 525/555] sched_ext: Enable tick for finite slices on nohz_full Date: Fri, 4 Dec 2026 19:09:28 +0900 Message-ID: <20261204100628.750410609@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Sasha Levin --- 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 63e83e55d170f..5f5a41f6fed28 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); } } @@ -3992,12 +4006,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.53.0