Skip to content

Commit

Permalink
Merge pull request #38 from arighi/scx-rustlite
Browse files Browse the repository at this point in the history
scx_rustlite: simple vtime-based scheduler written in Rust
  • Loading branch information
Byte-Lab authored Dec 21, 2023
2 parents cfb41a7 + 086c6df commit 4cadb92
Show file tree
Hide file tree
Showing 12 changed files with 1,107 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"
55 changes: 55 additions & 0 deletions scheds/rust/scx_rustlite/src/bpf/intf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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))

#define NSEC_PER_SEC 1000000000L
#define CLOCK_BOOTTIME 7

#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

/*
* Task sent to the user-space scheduler by the BPF dispatcher.
*
* All attributes are collected from the kernel by the the BPF component.
*/
struct queued_task_ctx {
s32 pid;
u64 sum_exec_runtime; /* Total cpu time */
u64 weight; /* Task static priority */
};

/*
* Task sent to the BPF dispatcher by the user-space scheduler.
*
* This structure has a payload that can be used by the user-space scheduler to
* send debugging information to the BPF dispatcher (i.e., vruntime, etc.),
* depending on the particular scheduler implementation.
*
* This struct can be easily extended to send more information to the
* dispatcher (i.e., a target CPU, a variable time slice, etc.).
*/
struct dispatched_task_ctx {
s32 pid;
u64 payload; /* Task payload */
};

#endif /* __INTF_H */
Loading

0 comments on commit 4cadb92

Please sign in to comment.