Struct aya::maps::hash_map::PerCpuHashMap[][src]

pub struct PerCpuHashMap<T: Deref<Target = Map>, K: Pod, V: Pod> { /* fields omitted */ }
Expand description

Similar to HashMap but each CPU holds a separate value for a given key. Tipically used to minimize lock contention in eBPF programs.

This type can be used with eBPF maps of type BPF_MAP_TYPE_PERCPU_HASH and BPF_MAP_TYPE_LRU_PERCPU_HASH.

Examples

use aya::maps::PerCpuHashMap;
use std::convert::TryFrom;

const CPU_IDS: u8 = 1;
const WAKEUPS: u8 = 2;

let mut hm = PerCpuHashMap::<_, u8, u32>::try_from(bpf.map("COUNTERS")?)?;
let cpu_ids = unsafe { hm.get(&CPU_IDS, 0)? };
let wakeups = unsafe { hm.get(&WAKEUPS, 0)? };
for (cpu_id, wakeups) in cpu_ids.iter().zip(wakeups.iter()) {
    println!("cpu {} woke up {} times", cpu_id, wakeups);
}

Implementations

Returns a slice of values - one for each CPU - associated with the key.

An iterator visiting all key-value pairs in arbitrary order. The iterator item type is Result<(K, PerCpuValues<V>), MapError>.

An iterator visiting all keys in arbitrary order. The iterator element type is Result<K, MapError>.

Inserts a slice of values - one for each CPU - for the given key.

Examples

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

const RETRIES: u8 = 1;

let mut hm = PerCpuHashMap::<_, u8, u32>::try_from(bpf.map_mut("PER_CPU_STORAGE")?)?;
hm.insert(
    RETRIES,
    PerCpuValues::try_from(vec![3u32; nr_cpus()?])?,
    0,
)?;

Removes a key from the map.

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.

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.