Skip to content
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

Merged

Conversation

javierhonduco
Copy link
Contributor

@javierhonduco javierhonduco commented May 31, 2023

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

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>
@rafaeldtinoco rafaeldtinoco self-requested a review May 31, 2023 13:13
Copy link
Contributor

@rafaeldtinoco rafaeldtinoco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rafaeldtinoco rafaeldtinoco merged commit 7c15abd into aquasecurity:main May 31, 2023
func NumPossibleCPUs() (int, error) {
numCPUs, _ := C.libbpf_num_possible_cpus()
if numCPUs < 0 {
return 0, fmt.Errorf("failed to retrieve the number of CPUs")
Copy link
Member

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:

https://github.com/aquasecurity/libbpfgo/blob/7c15abd453664293a200801392bfcc87162fe5b4/libbpfgo.go#L928-L930C3

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries at all.

Copy link
Contributor Author

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

Copy link
Member

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 javierhonduco deleted the add-num-possible-cpus branch June 1, 2023 07:53
@geyslan
Copy link
Member

geyslan commented Jun 3, 2023

@javierhonduco thanks for your contribution. It was shipped in v0.4.9-libbpf-1.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libbpf_num_possible_cpus support ?
3 participants