scx_lavd: Apply API updates

This commit is contained in:
Tejun Heo 2024-04-02 09:05:04 -10:00
parent 0c07f382b1
commit dfa978d166
3 changed files with 34 additions and 37 deletions

View File

@ -31,6 +31,6 @@ scx_utils = { path = "../../../rust/scx_utils", version = "0.6" }
enable_backtrace = []
[patch.crates-io]
libbpf-sys = { git = "https://github.com/libbpf/libbpf-sys.git", rev = "75042c653ee956b8c262e41ca4bcfcb0e2c461a1" }
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git", rev = "560641a5aff2c613dff6ae02147b0000558e4945" }
libbpf-sys = { git = "https://github.com/libbpf/libbpf-sys.git", rev = "125444300e2db452131dd6453101599c1a277784" }
libbpf-rs = { git = "https://github.com/libbpf/libbpf-rs.git", rev = "7745f2e43c2bde59920b8b7400d62f66b906f05b" }
libbpf-cargo = { git = "https://github.com/libbpf/libbpf-rs.git", rev = "7745f2e43c2bde59920b8b7400d62f66b906f05b" }

View File

@ -123,10 +123,10 @@ volatile u64 nr_cpus_onln;
static struct sys_cpu_util __sys_cpu_util[2];
static volatile int __sys_cpu_util_idx;
struct user_exit_info uei;
const volatile u8 verbose;
UEI_DEFINE(uei);
#define debugln(fmt, ...) \
({ \
if (verbose > 0) \
@ -1779,33 +1779,30 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(lavd_init)
/*
* Switch all tasks to scx tasks.
*/
scx_bpf_switch_all();
__COMPAT_scx_bpf_switch_all();
return err;
}
void BPF_STRUCT_OPS(lavd_exit, struct scx_exit_info *ei)
{
uei_record(&uei, ei);
UEI_RECORD(uei, ei);
}
SEC(".struct_ops.link")
struct sched_ext_ops lavd_ops = {
.select_cpu = (void *)lavd_select_cpu,
.enqueue = (void *)lavd_enqueue,
.dispatch = (void *)lavd_dispatch,
.runnable = (void *)lavd_runnable,
.running = (void *)lavd_running,
.stopping = (void *)lavd_stopping,
.quiescent = (void *)lavd_quiescent,
.cpu_online = (void *)lavd_cpu_online,
.cpu_offline = (void *)lavd_cpu_offline,
.update_idle = (void *)lavd_update_idle,
.init_task = (void *)lavd_init_task,
.init = (void *)lavd_init,
.exit = (void *)lavd_exit,
.flags = SCX_OPS_KEEP_BUILTIN_IDLE,
.timeout_ms = 5000U,
.name = "lavd",
};
SCX_OPS_DEFINE(lavd_ops,
.select_cpu = (void *)lavd_select_cpu,
.enqueue = (void *)lavd_enqueue,
.dispatch = (void *)lavd_dispatch,
.runnable = (void *)lavd_runnable,
.running = (void *)lavd_running,
.stopping = (void *)lavd_stopping,
.quiescent = (void *)lavd_quiescent,
.cpu_online = (void *)lavd_cpu_online,
.cpu_offline = (void *)lavd_cpu_offline,
.update_idle = (void *)lavd_update_idle,
.init_task = (void *)lavd_init_task,
.init = (void *)lavd_init,
.exit = (void *)lavd_exit,
.flags = SCX_OPS_KEEP_BUILTIN_IDLE,
.timeout_ms = 5000U,
.name = "lavd");

View File

@ -23,9 +23,10 @@ use anyhow::Context;
use anyhow::Result;
use clap::Parser;
use libbpf_rs::skel::OpenSkel as _;
use libbpf_rs::skel::Skel as _;
use libbpf_rs::skel::SkelBuilder as _;
use log::info;
use scx_utils::scx_ops_attach;
use scx_utils::scx_ops_load;
use scx_utils::uei_exited;
use scx_utils::uei_report;
use scx_utils::Topology;
@ -51,6 +52,10 @@ struct Opts {
#[clap(short = 'p', long, default_value = "0")]
pid_traced: u64,
/// Exit debug dump buffer length. 0 indicates default.
#[clap(long, default_value = "0")]
exit_dump_len: u32,
/// Enable verbose output including libbpf details. Specify multiple
/// times to increase verbosity.
#[clap(short = 'v', long, action = clap::ArgAction::Count)]
@ -111,18 +116,13 @@ impl<'a> Scheduler<'a> {
let topo = Topology::new().expect("Failed to build host topology");
let nr_cpus_onln = topo.span().weight() as u64;
skel.bss_mut().nr_cpus_onln = nr_cpus_onln;
skel.struct_ops.lavd_ops_mut().exit_dump_len = opts.exit_dump_len;
skel.rodata_mut().verbose = opts.verbose;
let intrspc = introspec::init(opts);
// Attach.
let mut skel = skel.load().context("Failed to load BPF program")?;
skel.attach().context("Failed to attach BPF program")?;
let struct_ops = Some(
skel.maps_mut()
.lavd_ops()
.attach_struct_ops()
.context("Failed to attach scx_lavd struct ops")?,
);
let mut skel = scx_ops_load!(skel, lavd_ops, uei)?;
let struct_ops = Some(scx_ops_attach!(skel, lavd_ops)?);
// Build a ring buffer for instrumentation
let mut maps = skel.maps_mut();
@ -262,7 +262,7 @@ impl<'a> Scheduler<'a> {
}
fn running(&mut self) -> bool {
RUNNING.load(Ordering::Relaxed) && !uei_exited!(&self.skel.bss().uei)
RUNNING.load(Ordering::Relaxed) && !uei_exited!(&self.skel, uei)
}
fn run(&mut self) -> Result<()> {
@ -275,7 +275,7 @@ impl<'a> Scheduler<'a> {
self.rb_mgr.consume().unwrap();
self.struct_ops.take();
uei_report!(&self.skel.bss().uei)
uei_report!(&self.skel, uei)
}
}