From 7c15abd453664293a200801392bfcc87162fe5b4 Mon Sep 17 00:00:00 2001 From: Francisco Javier Honduvilla Coto Date: Wed, 31 May 2023 11:42:06 +0100 Subject: [PATCH] Expose libbpf_num_possible_cpus To fetch the number of "possible" (`/sys/devices/system/cpu/possible`) CPUs. This is needed in various PERCPU structures to compute the value size. More details in https://github.com/parca-dev/parca-agent/issues/1696#issuecomment-1568736923 Signed-off-by: Francisco Javier Honduvilla Coto --- libbpfgo.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libbpfgo.go b/libbpfgo.go index 5b7613c5..d13e16dc 100644 --- a/libbpfgo.go +++ b/libbpfgo.go @@ -2089,3 +2089,11 @@ func BPFProgramTypeIsSupported(progType BPFProgType) (bool, error) { } return cSupported == 1, nil } + +func NumPossibleCPUs() (int, error) { + numCPUs, _ := C.libbpf_num_possible_cpus() + if numCPUs < 0 { + return 0, fmt.Errorf("failed to retrieve the number of CPUs") + } + return int(numCPUs), nil +}