From 2a387f0750891a3031990ace6a2cda8c47dc9ab3 Mon Sep 17 00:00:00 2001 From: gray Date: Sun, 5 Jan 2025 19:20:20 +0800 Subject: [PATCH] Let print_bpfmap_id be non-zero 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 --- bpf/kprobe_pwru.c | 2 +- internal/pwru/output.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bpf/kprobe_pwru.c b/bpf/kprobe_pwru.c index ec6e4761..68a8fed8 100644 --- a/bpf/kprobe_pwru.c +++ b/bpf/kprobe_pwru.c @@ -368,7 +368,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; } diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 24421af4..2414afc8 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -466,7 +466,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)) }