Revert "scx_rustland_core: use new consume_raw() libbpf-rs API"

In order to use the new consume_raw() API we need to depend on a version
of libbpf-rs that is not released yet.

Apparently adding such dependency may introduce a potential dependency
conflict with libbpf-sys.

Therefore, revert this change and go back to the previous consume() API.
One a new version of libbpf-rs will be out we can update all our
dependencies to use the new libbpf-rs and re-apply this patch to
scx_rustland_core.

Fixes: 7c8c5fd ("scx_rustland_core: use new consume_raw() libbpf-rs API")
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Andrea Righi 2024-03-11 21:54:21 +01:00
parent b7c06b9ed9
commit bd2c18afd5
4 changed files with 9 additions and 14 deletions

View File

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

View File

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

View File

@ -9,7 +9,7 @@ license = "GPL-2.0-only"
[dependencies] [dependencies]
anyhow = "1.0.65" anyhow = "1.0.65"
ctrlc = { version = "3.1", features = ["termination"] } ctrlc = { version = "3.1", features = ["termination"] }
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git#af3296c00d74fd50b311adc7f931563be137cd8b" } libbpf-rs = "0.22.0"
libc = "0.2.137" libc = "0.2.137"
scx_utils = { path = "../../../rust/scx_utils", version = "0.6" } scx_utils = { path = "../../../rust/scx_utils", version = "0.6" }
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "0.1" } 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"] } clap = { version = "4.1", features = ["derive", "env", "unicode", "wrap_help"] }
ctrlc = { version = "3.1", features = ["termination"] } ctrlc = { version = "3.1", features = ["termination"] }
fb_procfs = "0.7.0" fb_procfs = "0.7.0"
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git#af3296c00d74fd50b311adc7f931563be137cd8b" } libbpf-rs = "0.22.0"
libc = "0.2.137" libc = "0.2.137"
log = "0.4.17" log = "0.4.17"
ordered-float = "3.4.0" ordered-float = "3.4.0"