Skip to content

Commit

Permalink
Let print_bpfmap_id be non-zero
Browse files Browse the repository at this point in the history
By adding 1 to bpf_get_smp_processor_id(), we can safely rely on
"if event.PrintBpfmapId > 0" to decide whether there is bpfmap data to
read.

Signed-off-by: gray <gray.liang@isovalent.com>
  • Loading branch information
jschwinger233 committed Jan 5, 2025
1 parent 037396b commit 8cb08f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bpf/kprobe_pwru.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static __always_inline u64
sync_fetch_and_add(void *id_map) {
u32 *id = bpf_map_lookup_elem(id_map, &ZERO);
if (id)
return ((*id)++) | ((u64)bpf_get_smp_processor_id() << 32);
return ((*id)++) | ((u64)(bpf_get_smp_processor_id() + 1) << 32);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pwru/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (o *output) Print(event *Event) {
fmt.Fprintf(o.writer, "%s", getShinfoData(event, o))
}

if o.flags.OutputBpfmap {
if o.flags.OutputBpfmap && event.PrintBpfmapId > 0 {
fmt.Fprintf(o.writer, "%s", getBpfMapData(event, o))
}

Expand Down

0 comments on commit 8cb08f5

Please sign in to comment.