Commit Graph

326 Commits

Author SHA1 Message Date
Ming Yang
a23f3566e3 Use per-arch vmlinux.h
vmlinux.h is not compatible across archs.

Handle this compatibility issue by
* Add arch info into vmlinux.h real file name
* Link vmlinux.h to the target-arch real file at build time
* Use target-arch real file for scx_utils bindgen.

Also refactored clang related logic into a new clang_info mod, which is
shared by bpf_builder.rs and builder.rs.

Signed-off-by: Ming Yang <minos.future@gmail.com>
2024-10-13 07:57:12 -07:00
Andrea Righi
b3c5a23693 scx_rustland_core: use handle_mm_fault kprobe
The symbol __handle_mm_fault isn't available anymore in 6.12, let's rely
on handle_mm_fault that is available both on 6.12 and older kernels.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-10-11 15:39:34 +02:00
Ryan Wilson
fbdb6664ec [rusty] Fix load stats when host is under-utilized 2024-10-08 21:08:07 -07:00
Tejun Heo
4979cb8762
Merge pull request #739 from CachyOS/feature/scx-loader-switch-sched
scx_loader: Add SwitchScheduler methods to DBUS interface
2024-10-07 16:40:12 +00:00
Daniel Hodges
d86638ef0b
scx_layered: Add big cpumask
Add big cpumask to scx_layered and prefer selecting big idle cores when
using the BigLittle growth algo.

Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
2024-10-06 14:05:12 -04:00
Vladislav Nepogodin
7bd61f4334
scx_loader: Add SwitchScheduler methods to DBUS interface
These methods allow switching between different schedulers without requiring manual stopping and starting.
2024-10-05 02:57:17 +04:00
Tejun Heo
7402895f4a version: v1.0.5 2024-10-02 08:34:57 -10:00
Tejun Heo
0dda8de2b0
Merge pull request #707 from CachyOS/scx-loader-dbus-introspection
scx_loader: Add D-Bus Introspection XML
2024-09-30 19:27:15 +00:00
Tejun Heo
04648bc511
Merge pull request #703 from minosfuture/main
scx_stats: Implement macro #stat_doc to autogen doc from stat desc
2024-09-30 17:58:56 +00:00
Vladislav Nepogodin
6df06c5569
scx_loader: Add D-Bus Introspection XML
XML can be used for code generation like `gdbus-codegen`,`zbus-xmlgen`

refs:
- https://dbus2.github.io/zbus/client.html
- https://docs.gtk.org/gio/migrating-gdbus.html#generating-code-and-docs
- https://dbus.freedesktop.org/doc/dbus-api-design.html
- https://dbus.freedesktop.org/doc/dbus-specification.html
2024-09-30 03:28:30 +04:00
Andrea Righi
302dadd1ae Revert "scx_rustland_core: prevent deadlock with per-CPU DSQs and CPU affinity"
It seems that with the latest kernel the per-CPU DSQ stall while
executing sched_setaffinity() doesn't happen anymore.

Therefore, get rid of the temporary workaround introduced by commit
86db45f ("scx_rustland_core: prevent deadlock with per-CPU DSQs and CPU
affinity") and restore the old behavior, which offers more fair
scheduling policy.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-29 14:42:41 +02:00
Ming Yang
28bfd2986a scx_stats: Implement #stat_doc to autogen doc from stat desc
The doc of scx_layered `Opt` is out of sync.

Implement attribute macro #stat_doc to generate doc from the `desc`
property.

Apply #stat_doc to `LayerStats` and `SysStats in scx_layered.

Signed-off-by : Ming Yang <minos.future@gmail.com>
2024-09-28 09:32:48 -07:00
Vladislav Nepogodin
9b5e8da8e3
scx_loader: Add systemd service and on-DBUS launch
- add ability to start loader at system start as a service

- add ability to automatically launch on DBUS call whenever third-party
calls the interface

ref: "Example 7. DBus services" https://www.freedesktop.org/software/systemd/man/256/systemd.service.html
2024-09-27 23:51:28 +04:00
likewhatevs
bd2e90b0b6
run cargo +nightly-2024-09-10 fmt to fix lint err (#691)
run cargo +nightly-2024-09-10 fmt to fix lint err
2024-09-25 17:34:53 -04:00
Daniel Hodges
73d33e86e8
Merge pull request #686 from frelon/scx_utils-gpu-topo
scx_utils: Add gpu-topology crate feature
2024-09-25 15:09:27 -04:00
Tejun Heo
64b815b6a6
Merge pull request #676 from MitchellAugustin/scx_loader_automatic
scx_loader: Add initial automatic scheduler switching via --monitor-no-dbus
2024-09-25 08:03:51 -10:00
Fredrik Lönnegren
bbce932393 scx_utils: Add gpu-topology crate feature
The gpu-topology feature can be enabled to include GPUs when generating
a topology-map. Disabling the feature will remove the nvml-wrapper
dependency as well as GPU-specific code in topology.rs.

Most of the code was moved to a new module in rust/scx_utils/src/gpu.rs
but some of it was kept in topology.rs and hidden behind #[cfg(feature =
"gpu-topology")].

Signed-off-by: Fredrik Lönnegren <fredrik@frelon.se>
2024-09-25 14:54:52 +02:00
Andrea Righi
aea431c0c6
Merge pull request #678 from sched-ext/rustland-core-fix-mm-stall
scx_rustland_core: fix mm stall
2024-09-24 23:26:24 +02:00
likewhatevs
99d1179866
enable ide's etc. to work on bpf.c files (#668)
* enable ide's etc. to work on the bpf.c files
this makes it so that clangd and ide tools which use clangd
can work on the bpf.c code.

nothing should actually be changed outside of that ide/editor
environment, all the changes are ifdef'ed on LSP which is set
in the added .clangd file.

* move intf include out of both sides of ifdef toggle
2024-09-24 16:55:02 -04:00
Mitchell Augustin
e4eaed07a8 Change monitor_no_dbus to auto, use enum-string conv, use log::info, use Tokio spawning 2024-09-24 09:36:27 -05:00
Mitchell Augustin
b7e82bdeba
Merge branch 'sched-ext:main' into scx_loader_automatic 2024-09-24 08:16:37 -05:00
I Hsin Cheng
61cb3f7fc5 scx_common_bpf: Append cast_mask()
Remove cast_mask() function distributed throughout different schedulers
and add it in common.bpf.h so every scheduler can reference it once they
need to.

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
2024-09-24 16:01:19 +08:00
Andrea Righi
0a57b93846 scx_rustland_core: prevent mm stall
Bypass user-space scheduling for tasks currently handling a page fault,
preventing potential deadlock conditions involving VMA lock / mmap_lock
during user-space scheduling.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-24 08:46:14 +02:00
Andrea Righi
34bc6a2b64 Revert "scx_rustland_core: dispatch all kthreads directly from BPF"
This reverts commit 809d39aa7f.

Dispatching all kthreads directly doesn't really help much at preventing
stalls with the stress-ng fork stressor, so revert this commit. A better
workaround will be provided in the next commit.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-24 08:24:01 +02:00
Mitchell Augustin
d434ab4266 scx_loader: Add initial automatic scheduler switching via --monitor-no-dbus
Exposes an option --monitor-no-dbus in scx_loader that will monitor CPU
utilization and start scx_lavd when any CPU exceeds 90% for more than 5
seconds. scx_lavd will be terminated if all CPUs are below 90% for
more than 30 seconds. When this flag is specified, scx_loader's
dbus functionality is not utilized.
2024-09-23 17:07:43 -05:00
Daniel Hodges
a9f3190b5f
scx_utils: Add extra ordering macros for topology
Add extra ordering macros for Core/CPU structs for ease of use with
Rust standard library features. This issue was hit when trying to sort
cores based on the CoreType. See this similar issue for details:
https://github.com/rust-lang/rust/issues/113550

Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
2024-09-20 11:41:23 -04:00
I Hsin Cheng
9f64db7cbc scx_rustland_core: Access the returned value of saturating_sub()
Use an "_" variable to access the returned valued of "saturating_sub()"
to mute the compilation warnings.

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
2024-09-19 23:01:17 +08:00
Andrea Righi
809d39aa7f scx_rustland_core: dispatch all kthreads directly from BPF
Dispatching kthreads via user-space can still lead to deadlocks in
certain cases (for example we can still trigger stalls by running the
fork stressor via stress-ng).

To prevent such stalls simply dispatch kthreads directly from BPF for
now to prevent failures.

In the future we may consider to provide an API to restrict the
selection of tasks directly dispatched (for example passing a mask PF_*
flags to "whitelist" the tasks that are allowed to bypass the user-space
scheduler).

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-19 09:12:13 +02:00
Andrea Righi
e78ee41a2e scx_rustand_core: prevent nr_queued underflow
Updating nr_queued in a non-atomic when a queued task is consumed can
lead to underflows. We don't really care about being 100% accurate here,
since nr_queued should be considered more of a statistic than an
accurate value.

Therefore, just accept the fact that nr_queued can be inaccurate and
handle potential underflows.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-19 09:09:24 +02:00
Andrea Righi
3f8db5783b
Merge pull request #658 from sched-ext/rustland-core-improve-cpu-selection
scx_rustland_core: improve idle CPU selection API and logic
2024-09-17 22:38:15 +02:00
Andrea Righi
86db45f855 scx_rustland_core: prevent deadlock with per-CPU DSQs and CPU affinity
If a task that is executing sched_setaffinity() is dispatched on a
per-CPU DSQ it may stall the DSQ completely, since the task won't be
able to be consumed from the corresponding CPU.

This can be easily triggered running the following stress test:

  $ stress-ng --aggressive -c (nproc) -f (nproc)

From the stall trace we can see something like the following:

  R stress-ng[2648662] -6880ms
      scx_state/flags=3/0x9 dsq_flags=0x1 ops_state/qseq=0/0
      sticky/holding_cpu=-1/-1 dsq_id=0x5 dsq_vtime=0
      cpus=ff

    __set_cpus_allowed_ptr+0x1c8/0x260
    __sched_setaffinity+0x105/0x1c0
    sched_setaffinity+0x1ed/0x2d0
    __x64_sys_sched_setaffinity+0xa5/0x100
    do_syscall_64+0x82/0x190
    entry_SYSCALL_64_after_hwframe+0x76/0x7e

This should probably be addressed in the core sched_ext, but for now
prevent this deadlock by tracking when a task is executing
sched_setaffinity() and automatically bounce those tasks to the shared
DSQ (that can be consumed from any CPU).

This should solve all the recent CI failures with the scx_rustland_core
schedulers.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-17 07:42:37 +02:00
Andrea Righi
e6b624a97c scx_rustland_core: improve idle CPU selection API and logic
Pass enqueue flags to user-space: flags will be passed via
QueuedTask.flags and can be forwarded back to BPF via
DispatchedTask.flags.

These flags can be also passed to BpfScheduler.select_cpu() to apply a
more refined CPU selection policy.

Moreover, avoid to prioritize the user-space scheduler too much and
dispatch it only if there are no other tasks that needs to be dispatched
in ops.dispatch().

This improves CPU utilization and enhances the fairness, robustness, and
resilience of schedulers based on scx_rustland_core, particularly under
stress test conditions.

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-16 22:12:38 +02:00
Jake Hillion
23acd6ebe9 scxstats_to_openmetrics: fix format string
On Python versions that perform validation of this line it fails because
of a square bracket mismatch. This is due to the single quotes being
parsed first. Fix by changing the outer string to double quotes.
2024-09-16 18:16:28 +01:00
Daniel Hodges
dde6e0c7f9 scx_utils: Add node/llc id to core topology
Add ids for node/llc in the Core topology struct.
2024-09-12 10:05:02 -07:00
Jake Hillion
8ca45cfa37
lint: enable cargo fmt (#643)
Use `cargo fmt` with a specific nightly branch in the CI to enforce formatting. Globally format these files while the diff is still small so we can stay on top of it.

Test plan:
- CI lint check passes.
2024-09-11 10:03:20 +01:00
Fredrik Lönnegren
f155966b77 scx_rusty: init domains when calculating averages
The domains are added to the aggregator when load is added (and
duty_cycle is not 0.0f64).

This commit makes sure that all domains are added to the aggregator even
when the calculated duty_cycle is 0.

Signed-off-by: Fredrik Lönnegren <fredrik@frelon.se>
2024-09-10 21:51:41 +02:00
patso
c1df85914b
remove dependency on rlimit.rs
the rlimit crate is the only dependency crate
with a build.rs. build.rs files complicate portability.
this removes the need for rlimit.rs
2024-09-10 01:16:53 -04:00
patso
2e46f71780
generate docs for scx and kernel
generate docs for scx and kernel and push to gh page

this "adds" kernel scheduler and bpf docs to
the generated scx rust docs.
2024-09-09 15:37:59 -04:00
Tejun Heo
b2a71b166e build: Remove unused rust/meson.build
The previous commit makes this file unused but forgot to remove it. Remove
it.
2024-09-08 20:00:35 -10:00
Tejun Heo
56bb963136 build: Use a single top-level rust workspace
Rust build was using two separate workspaces - rust/ and scheds/rust.
There's no reason to separate them and it makes doc generation tricky. Use
single top level workspace so that we can drive all rust building from
cargo.
2024-09-08 14:23:48 -10:00
Andrea Righi
92b887c8e4
Merge pull request #629 from sched-ext/scx-rustland-core-fix-crate
scx_rustland_core: move includes back to the lib section
2024-09-07 20:15:10 +02:00
Tejun Heo
10c16cc443
Merge pull request #628 from sched-ext/htejun/release
release: Add cargo-publish.py
2024-09-07 07:50:34 -10:00
Andrea Righi
1e26cb91f1 scx_rustland_core: move includes back to the lib section
Move included artifacts in the lib section (without this change we can't
publish the crate on crates.io).

Fixes: 082bccb ("fix/enable rust tests, make build faster")
Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-07 19:32:08 +02:00
Tejun Heo
fcea4d3729 scx_loader: Fix broken LICENSE symlink 2024-09-07 07:16:22 -10:00
Andrea Righi
9301d7d78a
Merge pull request #622 from sched-ext/rustland-core-topology-awareness
scx_rustland_core: introduce topology awareness
2024-09-06 23:11:49 +02:00
patso
eaa636dfcc
set vng cpus to 8 for rust tests
set vng cpus to 8 for rust tests (for stability in testing),
update relevant doc test.
2024-09-06 10:07:37 -04:00
patso
082bccb557
fix/enable rust tests, make build faster
This commit fixes rust tests and configures ci to
run them on commit. It also sets up CI to run those
in a timely manner by caching dependencies and splitting jobs.
2024-09-06 06:18:11 -04:00
Andrea Righi
168fb78387 scx_rustland_core: introduce cache awareness
Introduce some concepts of cache awareness (taken from scx_bpfland).

This change is transparently affecting the BpfScheduler::select_cpu()
API, even if the particular cache topology is not (yet) exposed to the
user-space.

When calling select_cpu() the backend will prioritize idle CPUs that
share the same L2 cache, then the same L3 cache, considering the target
CPU specified in select_cpu() (usually the task's previously used CPU).

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-06 11:25:24 +02:00
Andrea Righi
ed879bae28 scx_rustland_core: expose enq_flags to user-space
Pass the enqueue flags to the user-space scheduler through the
QueuedTask struct.

These flags allow the user-space scheduler to make more informed
scheduling decisions.

Also bump up scx_rustland_core minor version to reflect the new API (we
are not breaking the old API, so we don't need to bump the major version
in this case).

Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
2024-09-06 11:25:24 +02:00
Tejun Heo
46fc2e1a49 version: v1.0.4 2024-09-05 18:12:45 -10:00