Skip to content

Commit

Permalink
fix(bpf): get_on_cpu_cycles not returning delta
Browse files Browse the repository at this point in the history
Current code assigns val to c.counter, which is always
0 since it's not used by bpf_perf_event_read_value -
we're using bpf_perf_event_read in this function since the
former produces a strange verifier error.

In addition, add some logging around eBPF array resizing.

Fixes: #1402

Signed-off-by: Dave Tucker <[email protected]>
  • Loading branch information
dave-tucker committed May 8, 2024
1 parent 18f8d2b commit ecb4e9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 9 additions & 10 deletions bpfassets/libbpf/src/kepler.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,18 @@ static inline u64 calc_delta(u64 *prev_val, u64 *val)

static inline u64 get_on_cpu_cycles(u32 *cpu_id)
{
u64 delta, val, *prev_val;
struct bpf_perf_event_value c;
int error;
u64 delta, *prev_val, count;
s64 error;

// TODO: Fix Verifier errors upon changing this to bpf_perf_event_read_value
error = bpf_perf_event_read(&cpu_cycles_event_reader, *cpu_id);
if (error < 0) {
return delta;
}
val = c.counter;
count = bpf_perf_event_read(&cpu_cycles_event_reader, *cpu_id);
error = (s64)count;
if (error <= -2 && error >= -22)
return 0;

prev_val = bpf_map_lookup_elem(&cpu_cycles, cpu_id);
delta = calc_delta(prev_val, &val);
bpf_map_update_elem(&cpu_cycles, cpu_id, &val, BPF_ANY);
delta = calc_delta(prev_val, &count);
bpf_map_update_elem(&cpu_cycles, cpu_id, &count, BPF_ANY);

return delta;
}
Expand Down
1 change: 1 addition & 0 deletions pkg/bpfassets/attacher/libbpf_attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func attachLibbpfModule() (*bpf.Module, error) {
return nil, fmt.Errorf("failed to load module: %v", err)
}
// resize array entries
klog.Infof("%d CPU cores detected. Resizing eBPF Perf Event Arrays", cpuCores)
for _, arrayName := range bpfArrays {
err = resizeArrayEntries(arrayName, cpuCores)
if err != nil {
Expand Down

0 comments on commit ecb4e9a

Please sign in to comment.