Skip to content

Commit 4586bdd

Browse files
committed
scx_rustland_core: Use RingBuffer:consume_raw_n()
Update libbpf-rs to use the consume_raw_n() API to consume tasks from the BPF ring buffer. Signed-off-by: Andrea Righi <arighi@nvidia.com>
1 parent 03f2c34 commit 4586bdd

File tree

7 files changed

+53
-44
lines changed

7 files changed

+53
-44
lines changed

Cargo.lock

Lines changed: 44 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ if should_build_libbpf
138138
endforeach
139139

140140
message('Fetching libbpf repo')
141-
libbpf_commit = 'c5f22aca0f3aa855daa159b2777472b35e721804'
141+
libbpf_commit = '02bdeb7a2c2e7cb2c9cecb125527a9c5a6bbf139'
142142
run_command(fetch_libbpf, meson.current_build_dir(), libbpf_commit, check: true)
143143

144144
make_jobs = 1

rust/scx_rustland_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "Framework to implement sched_ext schedulers running in user space
1010
[dependencies]
1111
anyhow = "1.0.65"
1212
plain = "0.2.3"
13-
libbpf-rs = "=0.25.0-beta.1"
13+
libbpf-rs = { git = "https://github.com/arighi/libbpf-rs", branch = "consume-raw-n" }
1414
libc = "0.2.137"
1515
seccomp = "0.1"
1616
scx_utils = { path = "../scx_utils", version = "1.0.15" }

rust/scx_rustland_core/assets/bpf.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ struct AlignedBuffer([u8; BUFSIZE]);
169169

170170
static mut BUF: AlignedBuffer = AlignedBuffer([0; BUFSIZE]);
171171

172-
// Special negative error code for libbpf to stop after consuming just one item from a BPF
173-
// ring buffer.
174-
const LIBBPF_STOP: i32 = -255;
175-
176172
static SET_HANDLER: Once = Once::new();
177173

178174
fn set_ctrlc_handler(shutdown: Arc<AtomicBool>) -> Result<(), anyhow::Error> {
@@ -224,18 +220,8 @@ impl<'cb> BpfScheduler<'cb> {
224220
BUF.0.copy_from_slice(data);
225221
}
226222

227-
// Return an unsupported error to stop early and consume only one item.
228-
//
229-
// NOTE: this is quite a hack. I wish libbpf would honor stopping after the first item
230-
// is consumed, upon returning a non-zero positive value here, but it doesn't seem to
231-
// be the case:
232-
//
233-
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/ringbuf.c?h=v6.8-rc5#n260
234-
//
235-
// Maybe we should fix this to stop processing items from the ring buffer also when a
236-
// value > 0 is returned.
237-
//
238-
LIBBPF_STOP
223+
// Return 0 to indicate successful completion of the copy.
224+
0
239225
}
240226

241227
// Check host topology to determine if we need to enable SMT capabilities.
@@ -511,12 +497,12 @@ impl<'cb> BpfScheduler<'cb> {
511497
// Receive a task to be scheduled from the BPF dispatcher.
512498
#[allow(static_mut_refs)]
513499
pub fn dequeue_task(&mut self) -> Result<Option<QueuedTask>, i32> {
514-
match self.queued.consume_raw() {
500+
match self.queued.consume_raw_n(1) {
515501
0 => {
516502
self.skel.maps.bss_data.nr_queued = 0;
517503
Ok(None)
518504
}
519-
LIBBPF_STOP => {
505+
1 => {
520506
// A valid task is received, convert data to a proper task struct.
521507
let task = unsafe { EnqueuedMessage::from_bytes(&BUF.0).to_queued_task() };
522508
self.skel.maps.bss_data.nr_queued =

rust/scx_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bindgen = ">=0.69"
1414
glob = "0.3.2"
1515
hex = "0.4.3"
1616
lazy_static = "1.5.0"
17-
libbpf-sys = "=1.4.6"
17+
libbpf-sys = "1.5.1"
1818
libbpf-cargo = "=0.25.0-beta.1"
1919
libbpf-rs = "=0.25.0-beta.1"
2020
log = "0.4.17"

scheds/rust/scx_rlfifo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "GPL-2.0-only"
1010
anyhow = "1.0.65"
1111
plain = "0.2.3"
1212
ctrlc = { version = "3.1", features = ["termination"] }
13-
libbpf-rs = "=0.25.0-beta.1"
13+
libbpf-rs = { git = "https://github.com/arighi/libbpf-rs", branch = "consume-raw-n" }
1414
libc = "0.2.137"
1515
scx_utils = { path = "../../../rust/scx_utils", version = "1.0.15" }
1616
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.3.1" }

scheds/rust/scx_rustland/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plain = "0.2.3"
1212
clap = { version = "4.5.28", features = ["derive", "env", "unicode", "wrap_help"] }
1313
ctrlc = { version = "3.1", features = ["termination"] }
1414
fb_procfs = "0.7"
15-
libbpf-rs = "=0.25.0-beta.1"
15+
libbpf-rs = { git = "https://github.com/arighi/libbpf-rs", branch = "consume-raw-n" }
1616
libc = "0.2.137"
1717
log = "0.4.17"
1818
ordered-float = "3.4.0"

0 commit comments

Comments
 (0)