Skip to content

libbpf-rs: Add suport for repeat and duration in Program{Input,Output} #1159

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

Merged
merged 1 commit into from
May 2, 2025

Conversation

chantra
Copy link
Contributor

@chantra chantra commented May 1, 2025

The former, when non-zero, is used to run the program repeat times. The latter is the number of ns a run took on average.

A test was added to confirm the behaviour. The program bumps a counter, said counter is verified to match repeat.

@chantra
Copy link
Contributor Author

chantra commented May 1, 2025

looking at the contribution guidelines:

Add a CHANGELOG note. If your change is user facing or otherwise notable, it should likely be mentioned in the respective CHANGELOG.md files of the crates being touched.

let me know if you think it is worthy to add a note there.

@chantra chantra force-pushed the libbpf_rs_repeat branch from a95ec82 to d09053c Compare May 1, 2025 04:42
Copy link
Collaborator

@danielocfb danielocfb left a comment

Choose a reason for hiding this comment

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

This seems mostly fine to me, thanks! Left a few comments.

Regarding CHANGELOG entry: yeah, it's probably worth mentioning, given that it may be of interest to other users.

@@ -604,6 +605,8 @@ pub struct Input<'dat> {
pub cpu: u32,
/// The 'flags' value passed to the kernel.
pub flags: u32,
/// How many times to repeat the test run.
pub repeat: c_int,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do negative values have a meaning of sorts? We try to only non-FFI types in the public interface. Let's go with u32/i32/usize/isize or something along those lines?

Also, what would happen if it is zero? Would the test not run at all? If so (and probably even if not), that seems like a questionable default (and yet it is the current default). If zero is garbage, then let's perhaps use some NonZero{U,I}* thingy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so this is, down the stack, a u32: https://elixir.bootlin.com/linux/v6.2.11/source/include/uapi/linux/bpf.h#L1430

but not in its interface: https://elixir.bootlin.com/linux/v6.2.11/source/tools/lib/bpf/bpf.h#L446

Also, what would happen if it is zero? Would the test not run at all? If so (and probably even if not), that seems like a questionable default (and yet it is the current default). If zero is garbage, then let's perhaps use some NonZero{U,I}* thingy?

A value of 0 is forced to 1: https://elixir.bootlin.com/linux/v6.2.11/source/net/bpf/test_run.c#L352 at every single test_run_* entrypoints.

What do you want to do here? Let 0 slip through? which could be the default value? If using NonZeroU32, my understanding is that this would become a Option<NonZero<u32>> but we would still need to handle it and default it to 0 when passing down to libbpf?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for checking and the references. I don't think it would need to be an Option<NonZero<...>>. Just NonZero would be sufficient and cleaner, in my opinion. You'd have to manually implement Default from what I can tell. I have a slight preference for the NonZero variant, but acknowledge that UX is a bit degraded in that case if you want to change the member, so u32 + a comment saying that 0 will still result in a run is okay as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, pushed the u32 and Duration change. I am not psyched about what using the NonZero interface would look like.
https://gist.github.com/chantra/8c662df93036953f622bc1e8ce93e196

I may be missing something that would make it simpler, but given that 0 is a "fine" default, it feels the use of NonZero will be an eyesore.

@chantra chantra force-pushed the libbpf_rs_repeat branch 2 times, most recently from 2dfcea0 to 26383eb Compare May 2, 2025 00:53
…gramOutput

The former, when non-zero, is used to run the program `repeat` times.
The latter is the number of ns a run took on average.

A test was added to confirm the behaviour. The program bumps a counter, said
counter is verified to match `repeat`.

Signed-off-by: Manu Bretelle <[email protected]>
@chantra chantra force-pushed the libbpf_rs_repeat branch from 26383eb to 699a34d Compare May 2, 2025 04:05
Copy link
Collaborator

@danielocfb danielocfb left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@danielocfb danielocfb merged commit bcb682d into libbpf:master May 2, 2025
14 checks passed
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