Merge pull request #180 from sched-ext/rustland-core-new-libbpf-rs-api

scx_rustland_core: use new consume_raw() libbpf-rs API
This commit is contained in:
Andrea Righi 2024-03-10 19:30:40 +01:00 committed by GitHub
commit 743e3528dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 9 deletions

View File

@ -15,7 +15,7 @@ include = [
[dependencies]
anyhow = "1.0"
libbpf-rs = "0.22.0"
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git#af3296c00d74fd50b311adc7f931563be137cd8b" }
libc = "0.2.137"
buddy-alloc = "0.5.1"
scx_utils = { path = "../scx_utils", version = "0.6" }

View File

@ -172,6 +172,10 @@ struct AlignedBuffer([u8; BUFSIZE]);
static mut BUF: AlignedBuffer = AlignedBuffer([0; BUFSIZE]);
// Special negative error code for libbpf to stop after consuming just one item from a BPF
// ring buffer.
const LIBBPF_STOP: i32 = -255;
impl<'cb> BpfScheduler<'cb> {
pub fn init(
slice_us: u64,
@ -221,7 +225,7 @@ impl<'cb> BpfScheduler<'cb> {
// Maybe we should fix this to stop processing items from the ring buffer also when a
// value > 0 is returned.
//
-255
LIBBPF_STOP
}
// Initialize online CPUs counter.
@ -372,15 +376,16 @@ impl<'cb> BpfScheduler<'cb> {
// Receive a task to be scheduled from the BPF dispatcher.
//
// NOTE: if task.cpu is negative the task is exiting and it does not require to be scheduled.
pub fn dequeue_task(&mut self) -> Result<Option<QueuedTask>, libbpf_rs::Error> {
match self.queued.consume() {
Ok(()) => Ok(None),
Err(error) if error.kind() == libbpf_rs::ErrorKind::Other => {
pub fn dequeue_task(&mut self) -> Result<Option<QueuedTask>, i32> {
match self.queued.consume_raw() {
0 => Ok(None),
LIBBPF_STOP => {
// A valid task is received, convert data to a proper task struct.
let task = unsafe { EnqueuedMessage::from_bytes(&BUF.0).to_queued_task() };
Ok(Some(task))
}
Err(error) => Err(error),
res if res < 0 => Err(res),
res => panic!("Unexpected return value from libbpf-rs::consume_raw(): {}", res),
}
}

View File

@ -9,7 +9,7 @@ license = "GPL-2.0-only"
[dependencies]
anyhow = "1.0.65"
ctrlc = { version = "3.1", features = ["termination"] }
libbpf-rs = "0.22.0"
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git#af3296c00d74fd50b311adc7f931563be137cd8b" }
libc = "0.2.137"
scx_utils = { path = "../../../rust/scx_utils", version = "0.6" }
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "0.1" }

View File

@ -11,7 +11,7 @@ anyhow = "1.0.65"
clap = { version = "4.1", features = ["derive", "env", "unicode", "wrap_help"] }
ctrlc = { version = "3.1", features = ["termination"] }
fb_procfs = "0.7.0"
libbpf-rs = "0.22.0"
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git#af3296c00d74fd50b311adc7f931563be137cd8b" }
libc = "0.2.137"
log = "0.4.17"
ordered-float = "3.4.0"