Skip to content

Commit a19f388

Browse files
authored
refactor(ebpf): use AsyncFd in PerfEventReader for tokio integration as AsyncPerfEventArray is removed (#601)
1 parent 07743c0 commit a19f388

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auraed/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ path = "src/bin/main.rs"
2828
anyhow = { workspace = true }
2929
client = { workspace = true }
3030
aurae-ebpf-shared = { path = "../ebpf-shared" }
31-
aya = { version = "0.13.1", features = ["async_tokio"] }
31+
aya = { version = "0.13.1" }
3232
backoff = { version = "0.4.0", features = ["tokio"] }
3333
bytes = "1.2.1"
3434
clap = { workspace = true }

auraed/src/ebpf/perf_buffer_reader.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
use anyhow::Context;
1717
use aya::{
1818
Ebpf,
19-
maps::perf::AsyncPerfEventArray,
19+
maps::perf::PerfEventArray,
2020
util::{nr_cpus, online_cpus},
2121
};
2222
use bytes::BytesMut;
2323
use procfs::page_size;
2424
use std::mem::size_of;
25-
use tokio::sync::broadcast;
25+
use tokio::{
26+
io::{Interest, unix::AsyncFd},
27+
sync::broadcast,
28+
};
2629
use tracing::{error, trace};
2730

2831
use super::perf_event_broadcast::PerfEventBroadcast;
@@ -66,7 +69,7 @@ pub trait PerfBufferReader<T: Clone + Send + 'static> {
6669
// kernel to userspace. This array contains the per-CPU buffers and is
6770
// indexed by CPU id.
6871
// https://libbpf.readthedocs.io/en/latest/api.html
69-
let mut perf_array = AsyncPerfEventArray::try_from(
72+
let mut perf_array = PerfEventArray::try_from(
7073
bpf.take_map(perf_buffer)
7174
.context("Failed to find '{perf_buffer}' perf event array")?,
7275
)?;
@@ -81,8 +84,10 @@ pub trait PerfBufferReader<T: Clone + Send + 'static> {
8184
for cpu_id in online_cpus {
8285
trace!("spawning task for cpu {cpu_id}");
8386
// Open the per-CPU buffer for the current CPU id
84-
let mut per_cpu_buffer =
87+
let per_cpu_buffer =
8588
perf_array.open(cpu_id, Some(PER_CPU_BUFFER_SIZE_IN_PAGES))?;
89+
let mut fd =
90+
AsyncFd::with_interest(per_cpu_buffer, Interest::READABLE)?;
8691

8792
// Clone the sender of the event broadcast channel
8893
let per_cpu_tx = tx.clone();
@@ -99,9 +104,13 @@ pub trait PerfBufferReader<T: Clone + Send + 'static> {
99104

100105
// Start polling the per-CPU buffer for events
101106
loop {
102-
let events = match per_cpu_buffer
103-
.read_events(&mut buffers)
107+
let mut guard = fd
108+
.readable_mut()
104109
.await
110+
.expect("Failed to read from per-CPU event buffer");
111+
let events = match guard
112+
.get_inner_mut()
113+
.read_events(&mut buffers)
105114
{
106115
Ok(events) => events,
107116
Err(error) => {

0 commit comments

Comments
 (0)