bpf: PerfEventArray: tweak output API

pull/66/head
Alessandro Decina 3 years ago
parent ea91fe08d3
commit 23a70382b2

@ -49,18 +49,11 @@ impl<T> PerfEventArray<T> {
} }
pub fn output<C: BpfContext>(&mut self, ctx: &C, data: &T, flags: u32) { pub fn output<C: BpfContext>(&mut self, ctx: &C, data: &T, flags: u32) {
self.output_at_index(ctx, None, data, flags) self.output_at_index(ctx, BPF_F_CURRENT_CPU as u32, data, flags)
} }
pub fn output_at_index<C: BpfContext>( pub fn output_at_index<C: BpfContext>(&mut self, ctx: &C, index: u32, data: &T, flags: u32) {
&mut self, let flags = (flags as u64) << 32 | index as u64;
ctx: &C,
index: Option<u32>,
data: &T,
flags: u32,
) {
let index = index.unwrap_or(BPF_F_CURRENT_CPU as u32) as u64;
let flags = (flags as u64) << 32 | index;
unsafe { unsafe {
bpf_perf_event_output( bpf_perf_event_output(
ctx.as_ptr(), ctx.as_ptr(),

Loading…
Cancel
Save