pub struct PerCpuArray<T, V: Pod> { /* private fields */ }Expand description
A per-CPU fixed-size array.
The size of the array is defined on the eBPF side using the bpf_map_def::max_entries field.
All the entries are zero-initialized when the map is created.
§Minimum kernel version
The minimum kernel version required to use this feature is 4.6.
§Examples
use aya::maps::{PerCpuArray, PerCpuValues};
use aya::util::nr_cpus;
let mut array = PerCpuArray::try_from(bpf.map_mut("ARRAY").unwrap())?;
// set array[1] = 42 for all cpus
let nr_cpus = nr_cpus().map_err(|(_, error)| error)?;
array.set(1, PerCpuValues::try_from(vec![42u32; nr_cpus])?, 0)?;
// retrieve the values at index 1 for all cpus
let values = array.get(&1, 0)?;
assert_eq!(values.len(), nr_cpus);
for cpu_val in values.iter() {
assert_eq!(*cpu_val, 42u32);
}Implementations§
Source§impl<T: Borrow<MapData>, V: Pod> PerCpuArray<T, V>
impl<T: Borrow<MapData>, V: Pod> PerCpuArray<T, V>
Sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Returns the number of elements in the array.
This corresponds to the value of bpf_map_def::max_entries on the eBPF side.
Sourcepub fn get(&self, index: &u32, flags: u64) -> Result<PerCpuValues<V>, MapError>
pub fn get(&self, index: &u32, flags: u64) -> Result<PerCpuValues<V>, MapError>
Returns a slice of values - one for each CPU - stored at the given index.
§Errors
Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError
if bpf_map_lookup_elem fails.
Source§impl<T: BorrowMut<MapData>, V: Pod> PerCpuArray<T, V>
impl<T: BorrowMut<MapData>, V: Pod> PerCpuArray<T, V>
Sourcepub fn set(
&mut self,
index: u32,
values: PerCpuValues<V>,
flags: u64,
) -> Result<(), MapError>
pub fn set( &mut self, index: u32, values: PerCpuValues<V>, flags: u64, ) -> Result<(), MapError>
Sets the values - one for each CPU - at the given index.
§Errors
Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError
if bpf_map_update_elem fails.
Trait Implementations§
Source§impl<T: Borrow<MapData>, V: Pod> IterableMap<u32, PerCpuValues<V>> for PerCpuArray<T, V>
impl<T: Borrow<MapData>, V: Pod> IterableMap<u32, PerCpuValues<V>> for PerCpuArray<T, V>
Auto Trait Implementations§
impl<T, V> Freeze for PerCpuArray<T, V>where
T: Freeze,
impl<T, V> RefUnwindSafe for PerCpuArray<T, V>where
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<T, V> Send for PerCpuArray<T, V>
impl<T, V> Sync for PerCpuArray<T, V>
impl<T, V> Unpin for PerCpuArray<T, V>
impl<T, V> UnsafeUnpin for PerCpuArray<T, V>where
T: UnsafeUnpin,
impl<T, V> UnwindSafe for PerCpuArray<T, V>where
T: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more