aya: perf_map: fix bug when max_entries=0

When a perf map has max_entries=0, max_entries is dynamically set at
load time to the number of possible cpus as reported by
/sys/devices/system/cpu/possible.

This change fixes a bug where instead of setting max_entries to the
number of possible cpus, we were setting it to the cpu index of the last
possible cpu.
pull/1/head
Alessandro Decina 4 years ago
parent 3b7ffd0048
commit 4222b140ec

@ -117,13 +117,12 @@ impl Bpf {
for (_, mut obj) in obj.maps.drain() { for (_, mut obj) in obj.maps.drain() {
if obj.def.map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY as u32 && obj.def.max_entries == 0 if obj.def.map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY as u32 && obj.def.max_entries == 0
{ {
obj.def.max_entries = *possible_cpus() obj.def.max_entries = possible_cpus()
.map_err(|error| BpfError::FileError { .map_err(|error| BpfError::FileError {
path: PathBuf::from(POSSIBLE_CPUS), path: PathBuf::from(POSSIBLE_CPUS),
error, error,
})? })?
.last() .len() as u32;
.unwrap_or(&0);
} }
let mut map = Map { obj, fd: None }; let mut map = Map { obj, fd: None };
let fd = map.create()?; let fd = map.create()?;

Loading…
Cancel
Save