-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BPF features detection and info subcommand
Signed-off-by: Francisco Javier Honduvilla Coto <javierhonduco@gmail.com>
- Loading branch information
1 parent
26a9e0c
commit e81748a
Showing
12 changed files
with
160 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
/target | ||
src/bpf/mod.rs | ||
src/bpf/rbperf.rs | ||
src/bpf/features.rs | ||
|
||
rbperf_out* | ||
rbperf_flame* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "vmlinux.h" | ||
|
||
#include <bpf/bpf_core_read.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_tracing.h> | ||
|
||
bool feature_has_run = false; | ||
|
||
bool feature_is_jited = false; | ||
bool feature_has_stats = false; | ||
bool feature_has_tail_call = false; | ||
bool feature_has_ringbuf = false; | ||
bool feature_bpf_loop = false; | ||
|
||
SEC("kprobe/hrtimer_start_range_ns") | ||
int features_entry() { | ||
static struct bpf_prog *bpf_prog = NULL; | ||
feature_has_run = true; | ||
|
||
feature_is_jited = bpf_core_field_exists(bpf_prog->jited); | ||
feature_has_stats = bpf_core_field_exists(bpf_prog->stats); | ||
feature_has_ringbuf = bpf_core_enum_value_exists(enum bpf_map_type, BPF_MAP_TYPE_RINGBUF); | ||
feature_has_tail_call = bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_tail_call); | ||
feature_has_ringbuf = bpf_core_enum_value_exists(enum bpf_map_type, BPF_MAP_TYPE_RINGBUF); | ||
feature_bpf_loop = bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_loop); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod features; | ||
pub mod rbperf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::bpf::features::FeaturesSkelBuilder; | ||
use anyhow::{anyhow, Result}; | ||
use nix::sys::utsname::uname; | ||
use std::fs::File; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
pub struct SystemInfo { | ||
pub os_release: String, | ||
pub debug_fs: bool, | ||
} | ||
|
||
pub struct BpfFeatures { | ||
pub is_jited: bool, | ||
pub has_stats: bool, | ||
pub has_tail_call: bool, | ||
pub has_ringbuf: bool, | ||
pub has_bpf_loop: bool, | ||
} | ||
|
||
pub struct Info { | ||
pub system: SystemInfo, | ||
pub bpf: Result<BpfFeatures>, | ||
} | ||
|
||
pub fn info() -> Result<Info> { | ||
let skel_builder = FeaturesSkelBuilder::default(); | ||
let open_skel = skel_builder.open().unwrap(); | ||
let mut bpf = open_skel.load().unwrap(); | ||
bpf.attach().unwrap(); | ||
|
||
thread::sleep(Duration::from_millis(50)); | ||
|
||
let bpf_features = if bpf.bss().feature_has_run { | ||
Ok(BpfFeatures { | ||
is_jited: bpf.bss().feature_is_jited, | ||
has_stats: bpf.bss().feature_has_stats, | ||
has_tail_call: bpf.bss().feature_has_tail_call, | ||
has_ringbuf: bpf.bss().feature_has_ringbuf, | ||
has_bpf_loop: bpf.bss().feature_bpf_loop, | ||
}) | ||
} else { | ||
Err(anyhow!("Could not find out supported BPF features")) | ||
}; | ||
|
||
Ok(Info { | ||
system: SystemInfo { | ||
os_release: uname().release().to_string(), | ||
debug_fs: File::open("/sys/kernel/debug/").is_ok(), | ||
}, | ||
bpf: bpf_features, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters