Skip to content

Commit

Permalink
scx_rustlite: simple vtime-based scheduler written in Rust
Browse files Browse the repository at this point in the history
Provide a simple scheduler with a BPF part and a user-space counterpart,
written in Rust, that can be used as a template to implement more
complex scheduling policies.

The main goal of this scheduler is to be easy to read and well
documented, so that newcomers (i.e., students, researchers, junior devs,
etc.) can use it to quickly experiment their scheduling theories.

For this reason the design of this scheduler is mostly focused on
simplicity and code readability.

Signed-off-by: Andrea Righi <[email protected]>
  • Loading branch information
Andrea Righi committed Dec 18, 2023
1 parent 239d5d1 commit da8a99a
Show file tree
Hide file tree
Showing 12 changed files with 788 additions and 0 deletions.
1 change: 1 addition & 0 deletions scheds/rust/meson.build
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
subdir('scx_layered')
subdir('scx_rusty')
subdir('scx_rustlite')
3 changes: 3 additions & 0 deletions scheds/rust/scx_rustlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/bpf/.output
Cargo.lock
target
27 changes: 27 additions & 0 deletions scheds/rust/scx_rustlite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "scx_rustlite"
version = "0.0.1"
authors = ["Andrea Righi <[email protected]>", "Canonical"]
edition = "2021"
description = "Userspace scheduling with BPF"
license = "GPL-2.0-only"

[dependencies]
anyhow = "1.0.65"
bitvec = { version = "1.0", features = ["serde"] }
clap = { version = "4.1", features = ["derive", "env", "unicode", "wrap_help"] }
ctrlc = { version = "3.1", features = ["termination"] }
fb_procfs = "0.7.0"
hex = "0.4.3"
libbpf-rs = "0.22.0"
libc = "0.2.137"
log = "0.4.17"
ordered-float = "3.4.0"
scx_utils = { path = "../../../rust/scx_utils", version = "0.4" }
simplelog = "0.12.0"

[build-dependencies]
scx_utils = { path = "../../../rust/scx_utils", version = "0.4" }

[features]
enable_backtrace = []
1 change: 1 addition & 0 deletions scheds/rust/scx_rustlite/LICENSE
11 changes: 11 additions & 0 deletions scheds/rust/scx_rustlite/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.

fn main() {
scx_utils::BpfBuilder::new()
.unwrap()
.enable_intf("src/bpf/intf.h", "bpf_intf.rs")
.enable_skel("src/bpf/main.bpf.c", "bpf")
.build()
.unwrap();
}
7 changes: 7 additions & 0 deletions scheds/rust/scx_rustlite/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
custom_target('scx_rustlite',
output: '@PLAINNAME@.__PHONY__',
input: 'Cargo.toml',
command: [cargo, 'build', '--manifest-path=@INPUT@', '--target-dir=@OUTDIR@',
cargo_build_args],
env: cargo_env,
build_by_default: true)
8 changes: 8 additions & 0 deletions scheds/rust/scx_rustlite/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Get help on options with `rustfmt --help=config`
# Please keep these in alphabetical order.
edition = "2021"
group_imports = "StdExternalCrate"
imports_granularity = "Item"
merge_derives = false
use_field_init_shorthand = true
version = "Two"
33 changes: 33 additions & 0 deletions scheds/rust/scx_rustlite/src/bpf/intf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.

#ifndef __INTF_H
#define __INTF_H

#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))

#include <stdbool.h>
#ifndef __kptr
#ifdef __KERNEL__
#error "__kptr_ref not defined in the kernel"
#endif
#define __kptr
#endif

#ifndef __KERNEL__
typedef unsigned char u8;
typedef unsigned int u32;
typedef int s32;
typedef unsigned long long u64;
typedef long long s64;
#endif

#include <scx/ravg.bpf.h>

struct task_ctx {
s32 pid;
u64 vtime;
};

#endif /* __INTF_H */
Loading

0 comments on commit da8a99a

Please sign in to comment.