scx/rust/scx_rustland_core
Tejun Heo ca13e13ad6
Merge pull request #559 from sched-ext/htejun/cargo-workspace
build: Use workspace to group rust sub-projects
2024-08-25 06:26:18 -10:00
..
assets scx_rustland_core: hide shutdown boilerplate in BpfScheduler 2024-08-25 12:17:04 +02:00
src scx_rustland_core: update copyright info 2024-08-07 08:10:53 +02:00
bindings.h rust: introduce scx_rustland_core crate 2024-02-28 17:49:44 +01:00
bpf_h rust: introduce scx_rustland_core crate 2024-02-28 17:49:44 +01:00
build.rs scx_utils: introduce Builder() 2024-02-28 17:49:44 +01:00
Cargo.toml Version: v1.0.3 2024-08-21 06:42:11 -10:00
LICENSE rust: introduce scx_rustland_core crate 2024-02-28 17:49:44 +01:00
README.md scx_rustland_core: update README.md 2024-08-25 12:39:08 +02:00

Framework to implement sched_ext schedulers running in user-space

scx_rustland_core is a Rust framework designed to facilitate the implementation of user-space schedulers based on the Linux kernel sched_ext feature.

sched_ext allows to dynamic load and execute custom schedulers in the kernel, leveraging BPF to manage scheduling policies.

This crate provides an abstraction layer for sched_ext, enabling developers to write schedulers in Rust without dealing with low-level kernel or BPF details.

Features

  • Generic BPF Abstraction: Interact with BPF components using a high-level Rust API.
  • Task Scheduling: Enqueue and dispatch tasks using provided methods.
  • CPU Selection: Select idle CPUs for task execution with a preference for reusing previous CPUs.
  • Time slice: Assign a specific time slice on a per-task basis.
  • Performance Reporting: Access internal scheduling statistics.

API

BpfScheduler

The BpfScheduler struct is the core interface for interacting with the BPF component.

  • Initialization:

    • BpfScheduler::init registers and initializes the BPF component.
  • Task Management:

    • dequeue_task(): Retrieve tasks that need to be scheduled.
    • dispatch_task(task: &DispatchedTask): Dispatch tasks to specific CPUs.
    • select_cpu(pid: i32, prev_cpu: i32, flags: u64): Select an idle CPU for a task.
  • Completion Notification:

    • notify_complete(nr_pending: u64) reports the number of pending tasks to the BPF component.

Getting Started

  • Installation:
    • Add scx_rustland_core to your Cargo.toml dependencies.
[dependencies]
scx_rustland_core = "0.1"
  • Implementation:

    • Create your scheduler by implementing the provided API.
  • Execution:

    • Compile and run your scheduler. Ensure that your kernel supports sched_ext and is configured to load your BPF programs.

Example

You can find a simple example of a fully working FIFO scheduler implemented using the scx_rustland_core framework here: scx_rlfifo.

License

This software is licensed under the GNU General Public License version 2. See the LICENSE file for details.

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.