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

libbpf-rs: Addressed API code review #1

Merged
merged 5 commits into from
Apr 30, 2020
Merged

libbpf-rs: Addressed API code review #1

merged 5 commits into from
Apr 30, 2020

Conversation

danobi
Copy link
Member

@danobi danobi commented Apr 24, 2020

No description provided.

@danobi
Copy link
Member Author

danobi commented Apr 24, 2020

cc @anakryiko .

One thing I'm wondering is if we want an Object being dropped to unload the Programs or if we want to instead refcount LoadedMap and unload the program when all LoadedMap instances are dropped. It could probably map cleanly to libbpf b/c there's already a bpf_program__unload function.

Not sure if that would be necessary for LoadedMap. I'm looking at libbpf code and it doesn't look like there's any closing of map FDs. I'm guessing that's b/c the kernel will hold a refcount as long as the prog is active.

unimplemented!();
}

pub fn poll(&mut self, _timeout: Duration) {
Copy link
Member

Choose a reason for hiding this comment

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

can fail, also doesn't need mutable reference, probably

Copy link
Member Author

Choose a reason for hiding this comment

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

If callbacks receive a mutable ref to PerfBuffer, I think it makes sense to keep this as mutable.

Copy link
Member

Choose a reason for hiding this comment

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

do callbacks need mutable reference? what for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need a reference back to the PerfBuffer at all? We don't currently have any properties that can really be changed after construction.

If we wanna add it later we can easily add a poll_mut() or poll_ref() method. But TBH I can't see a use case.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I don't have specific use case to have any kind of references, but it's usually a good idea to have reference to an "object" that's calling a callback function. E.g., just in case someone has multiple PerfBuffers, but the same callback. Having reference to PerfBuffer would allow to differentiate between them, if necessary.

But I think we are talking about different things here. PerfBuffer::poll needs &self -- I don't think PerfBuffer needs to be modified as a result of poll operation. What I was describing above is what should be passed to user-provided callback. There, I think, having PerfBuffer reference is useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds reasonable

@anakryiko
Copy link
Member

cc @anakryiko .

One thing I'm wondering is if we want an Object being dropped to unload the Programs or if we want to instead refcount LoadedMap and unload the program when all LoadedMap instances are dropped. It could probably map cleanly to libbpf b/c there's already a bpf_program__unload function.

I think unloading unconditionally. Map and Program are owned by Object, they can't leave outside of Object. libbpf doesn't do anything special here, when object is closed/destroyed, all map and program FDs are closed (see bpf_object__unload()). If map is referenced from some other program, it will be kept around by kernel.

Not sure if that would be necessary for LoadedMap. I'm looking at libbpf code and it doesn't look like there's any closing of map FDs. I'm guessing that's b/c the kernel will hold a refcount as long as the prog is active.

@danobi
Copy link
Member Author

danobi commented Apr 25, 2020

I think unloading unconditionally. Map and Program are owned by Object, they can't leave outside of Object.

Ok. We can make Object the guy that owns everything.

@danobi
Copy link
Member Author

danobi commented Apr 30, 2020

I'm gonna merge this and start implementing everything. Feel free to leave more comments on here if you see anything later.

I'll put up a PR for the implementation as well.

@anakryiko
Copy link
Member

@danobi, sounds good, I think currently it looks good. You'll probably find some inconsistencies or missing things along the way, but nothing is set in stone and we can adjust and revisit as needed. Thanks for working on this!

@danobi danobi merged commit 0c987ed into master Apr 30, 2020
@danobi danobi deleted the api_review_1 branch December 30, 2020 00:46
mmullin-halcyon added a commit to mmullin-halcyon/libbpf-rs that referenced this pull request Jul 18, 2023
See: libbpf/libbpf-sys#64

The "static" feature will now get libbpf-sys to do all the static compilation
of the libraries required by libbpf rather than the application developer
statically compiling these libraries themselves, or relying on the
distribution to provide static versions.

The default feature will no longer link libbpf statically.  All libbpf
libraries, including libbpf, will now be dynamically linked to
distribution provided shared libraries

CHANGELOG NOTE libbpf#1: feature "static" allows libelf and zlib to be statically
linked. Completely static binaries can now be compiled via the command
`RUSTFLAGS='-C target-feature=+crt-static' cargo build --target
x86_64-unknown-linux-gnu`.
CHANGELOG NOTE libbpf#2: "static" feature will not work with musl.

Signed-off-by: Michael Mullin <[email protected]>
mmullin-halcyon added a commit to mmullin-halcyon/libbpf-rs that referenced this pull request Jul 29, 2023
See: libbpf/libbpf-sys#64

The "static" feature will now get libbpf-sys to do all the static compilation
of the libraries required by libbpf rather than the application developer
statically compiling these libraries themselves, or relying on the
distribution to provide static versions.

The default feature will no longer link libbpf statically.  All libbpf
libraries, including libbpf, will now be dynamically linked to
distribution provided shared libraries

CHANGELOG NOTE libbpf#1: feature "static" allows libelf and zlib to be statically
linked. Completely static binaries can now be compiled via the command
`RUSTFLAGS='-C target-feature=+crt-static' cargo build --target
x86_64-unknown-linux-gnu`.
CHANGELOG NOTE libbpf#2: "static" feature will not work with musl.

Signed-off-by: Michael Mullin <[email protected]>
danielocfb pushed a commit that referenced this pull request Apr 2, 2024
All items in the "High level workflow" are labeled #1. While they appear
correct in the rendered documentation, it is confusing when reading the
source code.
Number them correctly.

Signed-off-by: Daniel Müller <[email protected]>
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.

2 participants