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

Adapts to lower kernels, no BPF_STATS_RUN_TIME, but has "/proc/sys/kernel/bpf_stats_enabled" #21

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

zf1575192187
Copy link

Adapts to lower kernels, no BPF_STATS_RUN_TIME, but has "/proc/sys/kernel/bpf_stats_enabled"

@jfernandez jfernandez self-requested a review March 7, 2024 02:56
src/main.rs Outdated
@@ -97,6 +103,10 @@ fn main() -> Result<()> {
app.start_background_thread();
let res = run_draw_loop(&mut terminal, app);

if fd < 0 {
fs::write(BPF_STATS_ENABLED, b"0")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the app panics, this line is not guaranteed to run and stats will remain enabled. This is not an issue with the _owned_fd approach since it will auto close when the app exits. We need another approach that guarantees we disable stats if the app panics.

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated
@@ -78,11 +81,14 @@ fn main() -> Result<()> {
// Try to enable BPF stats
let fd = unsafe { bpf_enable_stats(libbpf_sys::BPF_STATS_RUN_TIME) };
if fd < 0 {
return Err(anyhow!("Failed to enable BPF stats"));
if let Err(err) = fs::write(BPF_STATS_ENABLED, b"1") {
Copy link
Contributor

Choose a reason for hiding this comment

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

My preferred approach would be to find a way to detect that the Kernel supports the BPF_STATS_RUN_TIME bpf syscall, like checking the Kernel version.

Falling back to the BPF_STATS_ENABLED path if the syscall fails feels brittle. The syscall may have failed for a different reason and the user should know. We should only do the fallback way if we know the user is on an older kernel.

Copy link
Contributor

@jfernandez jfernandez Mar 10, 2024

Choose a reason for hiding this comment

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

@zf1575192187 I pushed a change to this branch to only enable stats via procfs if the Kernel version is below 5.8 6ef956d

Copy link
Author

Choose a reason for hiding this comment

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

Ok, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you pull that change into your branch and push it to this PR?

Copy link
Author

Choose a reason for hiding this comment

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

Could you pull that change into your branch and push it to this PR?

OK, and do you have any good suggestions for app panics?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't right now. But we can address that in a follow-up PR since there is already a lot of changes here. It may require refactoring the main func.

The kernel version is lower than 5.8, there is no unsupported
BPF_STATS_RUN_TIME, set "/proc/sys/kernel/bpf_stats_enabled".

Signed-off-by: Feng Zhou <[email protected]>
@jfernandez jfernandez merged commit 37ac873 into Netflix:main Mar 12, 2024
1 check 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