-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose libbpf_num_possible_cpus #331
Expose libbpf_num_possible_cpus #331
Conversation
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 <javierhonduco@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
func NumPossibleCPUs() (int, error) { | ||
numCPUs, _ := C.libbpf_num_possible_cpus() | ||
if numCPUs < 0 { | ||
return 0, fmt.Errorf("failed to retrieve the number of CPUs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review.
Shouldn't this error have errno information? For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it wasn't late and I should have pinged you @geyslan before. I'm sorry! Feel free to fix this with Javier if needed and merge! Sorry again for the fast pace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check for errno here, the only error path from the function is here, but let me know if you think that's not correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check for errno here, the only error path from the function is here, but let me know if you think that's not correct
We standardized returns taking into account possible changes in libbpf. Perhaps currently libbpf does not have a clear set of errno in this function, but it may be different in the future. And above all, as cgo provides us errno in C calls is always good to make use of it.
@javierhonduco thanks for your contribution. It was shipped in v0.4.9-libbpf-1.2.0. |
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)
Fixes: #195