This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sched_ext: Add a rust userspace hybrid example scheduler
Atropos is a multi-domain BPF / userspace hybrid scheduler where the BPF part does simple round robin in each domain and the userspace part calculates the load factor of each domain and tells the BPF part how to load balance the domains. This scheduler demonstrates dividing scheduling logic between BPF and userspace and using rust to build the userspace part. An earlier variant of this scheduler was used to balance across six domains, each representing a chiplet in a six-chiplet AMD processor, and could match the performance of production setup using CFS. v3: * The userspace code is substantially restructured and rewritten. The binary is renamed to scx_atropos and can now figure out the domain topology automatically based on L3 cache configuration. The LB logic which was rather broken in the previous postings are revamped and should behave better. * Updated to support weighted vtime scheduling (can be turned off with --fifo-sched). Added a couple options (--slice_us, --kthreads-local) to modify scheduling behaviors. * Converted to use BPF inline iterators. v2: * Updated to use generic BPF cpumask helpers. Signed-off-by: Dan Schatzberg <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,867 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/bpf/.output | ||
Cargo.lock | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "scx_atropos" | ||
version = "0.5.0" | ||
authors = ["Dan Schatzberg <[email protected]>", "Meta"] | ||
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 = { git = "https://github.com/facebookincubator/below.git", rev = "f305730"} | ||
hex = "0.4.3" | ||
libbpf-rs = "0.19.1" | ||
libbpf-sys = { version = "1.0.4", features = ["novendor", "static"] } | ||
libc = "0.2.137" | ||
log = "0.4.17" | ||
ordered-float = "3.4.0" | ||
simplelog = "0.12.0" | ||
|
||
[build-dependencies] | ||
bindgen = { version = "0.61.0", features = ["logging", "static"], default-features = false } | ||
libbpf-cargo = "0.13.0" | ||
|
||
[features] | ||
enable_backtrace = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
// This software may be used and distributed according to the terms of the | ||
// GNU General Public License version 2. | ||
extern crate bindgen; | ||
|
||
use std::env; | ||
use std::fs::create_dir_all; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
use libbpf_cargo::SkeletonBuilder; | ||
|
||
const HEADER_PATH: &str = "src/bpf/atropos.h"; | ||
|
||
fn bindgen_atropos() { | ||
// Tell cargo to invalidate the built crate whenever the wrapper changes | ||
println!("cargo:rerun-if-changed={}", HEADER_PATH); | ||
|
||
// The bindgen::Builder is the main entry point | ||
// to bindgen, and lets you build up options for | ||
// the resulting bindings. | ||
let bindings = bindgen::Builder::default() | ||
// The input header we would like to generate | ||
// bindings for. | ||
.header(HEADER_PATH) | ||
// Tell cargo to invalidate the built crate whenever any of the | ||
// included header files changed. | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks)) | ||
// Finish the builder and generate the bindings. | ||
.generate() | ||
// Unwrap the Result and panic on failure. | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the $OUT_DIR/bindings.rs file. | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("atropos-sys.rs")) | ||
.expect("Couldn't write bindings!"); | ||
} | ||
|
||
fn gen_bpf_sched(name: &str) { | ||
let bpf_cflags = env::var("ATROPOS_BPF_CFLAGS").unwrap(); | ||
let clang = env::var("ATROPOS_CLANG").unwrap(); | ||
eprintln!("{}", clang); | ||
let outpath = format!("./src/bpf/.output/{}.skel.rs", name); | ||
let skel = Path::new(&outpath); | ||
let src = format!("./src/bpf/{}.bpf.c", name); | ||
SkeletonBuilder::new() | ||
.source(src.clone()) | ||
.clang(clang) | ||
.clang_args(bpf_cflags) | ||
.build_and_generate(&skel) | ||
.unwrap(); | ||
println!("cargo:rerun-if-changed={}", src); | ||
} | ||
|
||
fn main() { | ||
bindgen_atropos(); | ||
// It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton. | ||
// Reasons are because the generated skeleton contains compiler attributes | ||
// that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]` | ||
// trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside | ||
// the path attribute either (see https://github.com/rust-lang/rust/pull/83366). | ||
// | ||
// However, there is hope! When the above feature stabilizes we can clean this | ||
// all up. | ||
create_dir_all("./src/bpf/.output").unwrap(); | ||
gen_bpf_sched("atropos"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
// This software may be used and distributed according to the terms of the | ||
// GNU General Public License version 2. | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_snake_case)] | ||
#![allow(dead_code)] | ||
|
||
include!(concat!(env!("OUT_DIR"), "/atropos-sys.rs")); |
Oops, something went wrong.