Skip to content

Commit 3082e4c

Browse files
authored
Merge pull request #2950 from multics69/lavd-ftrace-futex
scx_utils, scx_lavd: Harden the futex tracing.
2 parents 76e8564 + 8f20db1 commit 3082e4c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

rust/scx_utils/src/compat.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,31 @@ pub fn debugfs_mount() -> Result<std::path::PathBuf> {
214214
mounts.into_iter().next().context("No debugfs mount found")
215215
}
216216

217+
pub fn tracer_available(tracer: &str) -> Result<bool> {
218+
let base_path = tracefs_mount().unwrap_or_else(|_| debugfs_mount().unwrap().join("tracing"));
219+
let file = match std::fs::File::open(base_path.join("available_tracers")) {
220+
Ok(f) => f,
221+
Err(_) => return Ok(false),
222+
};
223+
let reader = std::io::BufReader::new(file);
224+
225+
for line in reader.lines() {
226+
for tc in line.unwrap().split_whitespace() {
227+
if tracer == tc {
228+
return Ok(true);
229+
}
230+
}
231+
}
232+
233+
Ok(false)
234+
}
235+
217236
pub fn tracepoint_exists(tracepoint: &str) -> Result<bool> {
218237
let base_path = tracefs_mount().unwrap_or_else(|_| debugfs_mount().unwrap().join("tracing"));
219-
let file = std::fs::File::open(base_path.join("available_events"))?;
238+
let file = match std::fs::File::open(base_path.join("available_events")) {
239+
Ok(f) => f,
240+
Err(_) => return Ok(false),
241+
};
220242
let reader = std::io::BufReader::new(file);
221243

222244
for line in reader.lines() {

scheds/rust/scx_lavd/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ impl<'a> Scheduler<'a> {
455455
("futex_unlock_pi", &skel.progs.fexit_futex_unlock_pi),
456456
];
457457

458+
if compat::tracer_available("function_graph")? == false {
459+
info!("Ftrace is not enabled in the kernel.");
460+
return Ok(false);
461+
}
462+
458463
compat::cond_kprobes_enable(ftraces)
459464
}
460465

0 commit comments

Comments
 (0)