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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
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.

}
return int(numCPUs), nil
}