1616use anyhow:: Context ;
1717use aya:: {
1818 Ebpf ,
19- maps:: perf:: AsyncPerfEventArray ,
19+ maps:: perf:: PerfEventArray ,
2020 util:: { nr_cpus, online_cpus} ,
2121} ;
2222use bytes:: BytesMut ;
2323use procfs:: page_size;
2424use std:: mem:: size_of;
25- use tokio:: sync:: broadcast;
25+ use tokio:: {
26+ io:: { Interest , unix:: AsyncFd } ,
27+ sync:: broadcast,
28+ } ;
2629use tracing:: { error, trace} ;
2730
2831use 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