Struct aya::maps::PerCpuArray[][src]

pub struct PerCpuArray<T: Deref<Target = Map>, V: Pod> { /* fields omitted */ }
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.

Examples

use aya::maps::{PerCpuArray, PerCpuValues};
use aya::util::nr_cpus;
use std::convert::TryFrom;

let mut array = PerCpuArray::try_from(bpf.map_mut("ARRAY")?)?;

// set array[1] = 42 for all cpus
let nr_cpus = nr_cpus()?;
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

Returns the number of elements in the array.

This corresponds to the value of bpf_map_def::max_entries on the eBPF side.

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.

An iterator over the elements of the array. The iterator item type is Result<PerCpuValues<V>, 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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.