Re: [PATCH] tools/sched_ext: scx_central: start timer from central dispatch

From: Tejun Heo

Date: Thu Mar 26 2026 - 20:58:53 EST


Hello, Zhao.

On Thu, Mar 26, 2026 at 05:15:23PM +0800, Zhao Mengmeng wrote:
> From: Zhao Mengmeng <zhaomengmeng@xxxxxxxxxx>
>
> scx_central currently assumes that ops.init() runs on the selected
> central CPU and aborts otherwise. This is no longer true, as ops.init()
> is invoked from the scx_enable_helper thread, which can run on any
> CPU. As a result, sched_setaffinity() from userspace doesn't work, loading
> scx_central can fail with:
>
> [ 1985.319942] sched_ext: central: scx_central.bpf.c:314: init from non-central CPU
> [ 1985.320317] scx_exit+0xa3/0xd0
> [ 1985.320535] scx_bpf_error_bstr+0xbd/0x220
> [ 1985.320840] bpf_prog_3a445a8163fa8149_central_init+0x103/0x1ba
> [ 1985.321073] bpf__sched_ext_ops_init+0x40/0xa8
> [ 1985.321286] scx_root_enable_workfn+0x507/0x1650
> [ 1985.321461] kthread_worker_fn+0x260/0x940
> [ 1985.321745] kthread+0x303/0x3e0
> [ 1985.321901] ret_from_fork+0x589/0x7d0
> [ 1985.322065] ret_from_fork_asm+0x1a/0x30
>
> DEBUG DUMP
> ===================================================================
>
> central: root
> scx_enable_help[134] triggered exit kind 1025:
> scx_bpf_error (scx_central.bpf.c:314: init from non-central CPU)
>
> To fix it, initialize the BPF timer from ops.init(), but defer
> bpf_timer_start() to the first dispatch on the central CPU. This preserves
> the requirement that the timer be started from the central CPU when
> BPF_F_TIMER_CPU_PIN is used, without depending on the CPU affinity of
> the enable path.

Can you do the followings please?

- Remove now unnecessary sched_setaffinity() call.

- Do scx_bpf_kick_cpu(central_cpu, 0) so that we're guaranteed to enter the
dispatch path on the central CPU immediately.

Thanks.

--
tejun