Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 23 additions & 1 deletion rust/scx_utils/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,31 @@ pub fn debugfs_mount() -> Result<std::path::PathBuf> {
mounts.into_iter().next().context("No debugfs mount found")
}

pub fn tracer_available(tracer: &str) -> Result<bool> {
let base_path = tracefs_mount().unwrap_or_else(|_| debugfs_mount().unwrap().join("tracing"));
let file = match std::fs::File::open(base_path.join("available_tracers")) {
Ok(f) => f,
Err(_) => return Ok(false),
};
let reader = std::io::BufReader::new(file);

for line in reader.lines() {
for tc in line.unwrap().split_whitespace() {
if tracer == tc {
return Ok(true);
}
}
}

Ok(false)
}

pub fn tracepoint_exists(tracepoint: &str) -> Result<bool> {
let base_path = tracefs_mount().unwrap_or_else(|_| debugfs_mount().unwrap().join("tracing"));
let file = std::fs::File::open(base_path.join("available_events"))?;
let file = match std::fs::File::open(base_path.join("available_events")) {
Ok(f) => f,
Err(_) => return Ok(false),
};
let reader = std::io::BufReader::new(file);

for line in reader.lines() {
Expand Down
5 changes: 5 additions & 0 deletions scheds/rust/scx_lavd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ impl<'a> Scheduler<'a> {
("futex_unlock_pi", &skel.progs.fexit_futex_unlock_pi),
];

if compat::tracer_available("function_graph")? == false {
info!("Ftrace is not enabled in the kernel.");
return Ok(false);
}

compat::cond_kprobes_enable(ftraces)
}

Expand Down