Skip to content

Commit

Permalink
Expose libbpf_num_possible_cpus
Browse files Browse the repository at this point in the history
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 parca-dev/parca-agent#1696 (comment)

Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]>
  • Loading branch information
javierhonduco authored and rafaeldtinoco committed May 31, 2023
1 parent 80f41e1 commit 7c15abd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libbpfgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7c15abd

Please sign in to comment.