Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something went wrong with the 'timeout_ms' field in the 'struct sched_ext_ops' structure #151

Closed
Faione opened this issue Feb 22, 2024 · 8 comments

Comments

@Faione
Copy link

Faione commented Feb 22, 2024

I'am interest in sched_ext and try it on debian on qemu, with sched_ext kernel(sched_ext/d93dc).Some schedulers works fine but BPF code that utilizes the timeout_ms field generates 'Failed to attach struct_ops' errors. This occurs both on scx_qmap and scx_rustland scheduler, built from scx version 0.1.7,.

$ ./scx_qmap
scx_qmap.c:88 [scx panic]: Argument list too long
Failed to attach struct_op

------

$ ./scx_rustland
Error: Failed to attach struct ops

Caused by:
    bpf call "libbpf_rs::map::Map::attach_struct_ops::{{closure}}" returned NULL

schedulers work fine after removing timeout_ms field

$ ./test/scx_qmap 
enq=0, dsp=0, delta=0, reenq=0, deq=0, core=0
enq=80, dsp=80, delta=0, reenq=0, deq=0, core=0
enq=156, dsp=156, delta=0, reenq=0, deq=0, core=0
^CEXIT: BPF scheduler unregistered

--- 

$ ./test/scx_rustland 
06:24:54 [INFO] RustLand scheduler attached
06:24:55 [INFO] vruntime=105489434
06:24:55 [INFO]   tasks=7
06:24:55 [INFO]   nr_user_dispatches=18 nr_kernel_dispatches=144
06:24:55 [INFO]   nr_cancel_dispatches=0 nr_bounce_dispatches=0
06:24:55 [INFO]   nr_waiting=1 [nr_queued=1 + nr_scheduled=0]
06:24:55 [INFO]   nr_failed_dispatches=0 nr_sched_congested=0 nr_page_faults=0 [OK]
06:24:55 [INFO] time slice = 20000 us
06:24:55 [INFO] slice boost = 200

Same results on newest sched_ext kernel

Is there any way to solve this problem?

@htejun
Copy link
Contributor

htejun commented Feb 22, 2024

Can you try one of the packaged kernels (for arch or ubuntu)? This might be hitting a known limitation in BPF struct_ops which is being addressed.

@Faione
Copy link
Author

Faione commented Feb 22, 2024

I tired v6.7.5-scx1 and v6.8.0-rc4-scx2, which are mentioned in the PKGBUILD of scx-packaging-arch, but still encountered a similar situation as above.

I also tired sched_ext-release-v6.6 . It seems things have changed, but I believe it should be an issue with version mismatch.

$ ./test/scx_rustland 
libbpf: extern (func ksym) 'scx_bpf_dispatch_cancel': not found in kernel or module BTFs
libbpf: failed to load object 'bpf_bpf'
libbpf: failed to load BPF skeleton 'bpf_bpf': -22
Error: Failed to load BPF program

Caused by:
    Invalid argument (os error 22)

@htejun
Copy link
Contributor

htejun commented Feb 22, 2024

Can you please try a packaged kernel and schedulers? Just so that we have a better idea on where the problem is - ie. does a packaged kernel + self-built schedulers work? How about self-built kernel + packaged scheduler?

@Faione
Copy link
Author

Faione commented Feb 23, 2024

Thanks a lot. I am currently testing on my Arch Linux and waiting for the results.

@htejun
Copy link
Contributor

htejun commented Feb 23, 2024

That's curious tho. It'd be interesting to find out what went wrong. If you still have a copy of the scheduler binaries from the previous unsuccessful installations, can you copy them over to the arch and see whether it works there?

@Faione
Copy link
Author

Faione commented Feb 24, 2024

Yes, although everything workes fine in my Arch Linux with packaged kernel, if I change to my own compiled kernel, the previous error occurs again, so it can be determined that the problem is with my kernel configuration.

I was using a kernel configuration optimized for virtualization scenarios, with sched_ext related options enabled. I checked all the configurations and finally found that it was caused by CONFIG_HZ. Mine is 100 instead of 300, and then in the following code where sched_ext attaches the eBPF scheduler, it will cause an error.

SCX_WATCHDOG_MAX_TIMEOUT	= 30 * HZ,

...

case offsetof(struct sched_ext_ops, timeout_ms):
	if (*(u32 *)(udata + moff) > SCX_WATCHDOG_MAX_TIMEOUT)
		return -E2BIG;
	ops->timeout_ms = *(u32 *)(udata + moff);
	return 1;

In scx_qmap and scx_rustland, the timeout_ms feild is hard-coded as 5000, which is greater than 3000 (30 * 100). Changing timeout_ms to 3000U(for CONFIG_HZ_100) solved the problem. I was now able to experience sched_ext. Thanks for your assistance.

@htejun
Copy link
Contributor

htejun commented Feb 24, 2024

Thanks for tracking that down. That's definitely a bug in sched_ext. Will fix.

htejun added a commit to sched-ext/sched_ext that referenced this issue Feb 26, 2024
…version

ops->timeout_ms wasn't being converted to jiffies before testing against
SCX_WATHCDOG_MATX_TIMEOUT which led to spurious verification failures when
with lower HZ kernels. Fix it.

Link: sched-ext/scx#151
@htejun
Copy link
Contributor

htejun commented Feb 26, 2024

sched-ext/sched_ext#147 should fix it. Thanks for reporting and debugging the issue. Closing.

@htejun htejun closed this as completed Feb 26, 2024
Byte-Lab pushed a commit to sched-ext/scx-kernel-releases that referenced this issue Feb 26, 2024
…version

ops->timeout_ms wasn't being converted to jiffies before testing against
SCX_WATHCDOG_MATX_TIMEOUT which led to spurious verification failures when
with lower HZ kernels. Fix it.

Link: sched-ext/scx#151
(cherry picked from commit 90b8f6e)
Byte-Lab pushed a commit to sched-ext/scx-kernel-releases that referenced this issue Feb 26, 2024
…version

ops->timeout_ms wasn't being converted to jiffies before testing against
SCX_WATHCDOG_MATX_TIMEOUT which led to spurious verification failures when
with lower HZ kernels. Fix it.

Link: sched-ext/scx#151
(cherry picked from commit 90b8f6e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants