mirror of
https://github.com/JakeHillion/scx.git
synced 2024-11-24 02:30:22 +00:00
scx_rustland: Apply API updates and add --exit-dump-len option to scx_rustland
This commit is contained in:
parent
06fdae177f
commit
f3e20ae9b3
@ -26,6 +26,6 @@ walkdir = "2.4"
|
||||
scx_utils = { path = "../scx_utils", version = "0.6" }
|
||||
|
||||
[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" }
|
||||
|
@ -10,12 +10,14 @@ use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
|
||||
use libbpf_rs::skel::OpenSkel as _;
|
||||
use libbpf_rs::skel::Skel as _;
|
||||
use libbpf_rs::skel::SkelBuilder as _;
|
||||
|
||||
use libc::{sched_param, sched_setscheduler};
|
||||
|
||||
use scx_utils::compat;
|
||||
use scx_utils::init_libbpf_logging;
|
||||
use scx_utils::scx_ops_attach;
|
||||
use scx_utils::scx_ops_load;
|
||||
use scx_utils::uei_exited;
|
||||
use scx_utils::uei_report;
|
||||
|
||||
@ -83,7 +85,7 @@ impl DispatchedTask {
|
||||
pid: task.pid,
|
||||
cpu: task.cpu,
|
||||
cpumask_cnt: task.cpumask_cnt,
|
||||
slice_ns: 0 // use default time slice
|
||||
slice_ns: 0, // use default time slice
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,6 +179,7 @@ impl<'cb> BpfScheduler<'cb> {
|
||||
slice_us: u64,
|
||||
nr_cpus_online: i32,
|
||||
partial: bool,
|
||||
exit_dump_len: u32,
|
||||
full_user: bool,
|
||||
debug: bool,
|
||||
) -> Result<Self> {
|
||||
@ -231,6 +234,11 @@ impl<'cb> BpfScheduler<'cb> {
|
||||
skel.rodata_mut().num_possible_cpus = nr_cpus_online;
|
||||
|
||||
// Set scheduler options (defined in the BPF part).
|
||||
if partial {
|
||||
skel.struct_ops.rustland_mut().flags |= *compat::SCX_OPS_SWITCH_PARTIAL;
|
||||
}
|
||||
skel.struct_ops.rustland_mut().exit_dump_len = exit_dump_len;
|
||||
|
||||
skel.bss_mut().usersched_pid = std::process::id();
|
||||
skel.rodata_mut().slice_ns = slice_us * 1000;
|
||||
skel.rodata_mut().switch_partial = partial;
|
||||
@ -238,14 +246,8 @@ impl<'cb> BpfScheduler<'cb> {
|
||||
skel.rodata_mut().full_user = full_user;
|
||||
|
||||
// Attach BPF scheduler.
|
||||
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()
|
||||
.rustland()
|
||||
.attach_struct_ops()
|
||||
.context("Failed to attach struct ops")?,
|
||||
);
|
||||
let mut skel = scx_ops_load!(skel, rustland, uei)?;
|
||||
let struct_ops = Some(scx_ops_attach!(skel, rustland)?);
|
||||
|
||||
// Build the ring buffer of queued tasks.
|
||||
let binding = skel.maps();
|
||||
@ -395,13 +397,13 @@ impl<'cb> BpfScheduler<'cb> {
|
||||
|
||||
// Read exit code from the BPF part.
|
||||
pub fn exited(&mut self) -> bool {
|
||||
uei_exited!(&self.skel.bss().uei)
|
||||
uei_exited!(&self.skel, uei)
|
||||
}
|
||||
|
||||
// Called on exit to shutdown and report exit message from the BPF part.
|
||||
pub fn shutdown_and_report(&mut self) -> Result<()> {
|
||||
self.struct_ops.take();
|
||||
uei_report!(self.skel.bss().uei)
|
||||
uei_report!(&self.skel, uei)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
struct user_exit_info uei;
|
||||
UEI_DEFINE(uei);
|
||||
|
||||
/*
|
||||
* Maximum amount of CPUs supported by this scheduler (this defines the size of
|
||||
@ -394,7 +394,7 @@ dispatch_task(struct task_struct *p, u64 dsq_id,
|
||||
p->pid, p->comm, dsq_id);
|
||||
|
||||
/* Wake up the target CPU (only if idle) */
|
||||
__COMPAT_scx_bpf_kick_cpu_IDLE(cpu);
|
||||
scx_bpf_kick_cpu(cpu, __COMPAT_SCX_KICK_IDLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -863,7 +863,7 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(rustland_init)
|
||||
if (err)
|
||||
return err;
|
||||
if (!switch_partial)
|
||||
scx_bpf_switch_all();
|
||||
__COMPAT_scx_bpf_switch_all();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -873,14 +873,13 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(rustland_init)
|
||||
*/
|
||||
void BPF_STRUCT_OPS(rustland_exit, struct scx_exit_info *ei)
|
||||
{
|
||||
uei_record(&uei, ei);
|
||||
UEI_RECORD(uei, ei);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scheduling class declaration.
|
||||
*/
|
||||
SEC(".struct_ops.link")
|
||||
struct sched_ext_ops rustland = {
|
||||
SCX_OPS_DEFINE(rustland,
|
||||
.select_cpu = (void *)rustland_select_cpu,
|
||||
.enqueue = (void *)rustland_enqueue,
|
||||
.dispatch = (void *)rustland_dispatch,
|
||||
@ -895,5 +894,4 @@ struct sched_ext_ops rustland = {
|
||||
.exit = (void *)rustland_exit,
|
||||
.flags = SCX_OPS_ENQ_LAST | SCX_OPS_KEEP_BUILTIN_IDLE,
|
||||
.timeout_ms = 5000,
|
||||
.name = "rustland",
|
||||
};
|
||||
.name = "rustland");
|
||||
|
@ -22,6 +22,6 @@ scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "0.1"
|
||||
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" }
|
||||
|
@ -26,7 +26,7 @@ struct Scheduler<'a> {
|
||||
impl<'a> Scheduler<'a> {
|
||||
fn init() -> Result<Self> {
|
||||
let topo = Topology::new().expect("Failed to build host topology");
|
||||
let bpf = BpfScheduler::init(5000, topo.nr_cpus_possible() as i32, false, false, false)?;
|
||||
let bpf = BpfScheduler::init(5000, topo.nr_cpus_possible() as i32, false, 0, false, false)?;
|
||||
Ok(Self { bpf })
|
||||
}
|
||||
|
||||
@ -75,9 +75,12 @@ impl<'a> Scheduler<'a> {
|
||||
|
||||
println!(
|
||||
"user={} kernel={} cancel={} bounce={} fail={} cong={}",
|
||||
nr_user_dispatches, nr_kernel_dispatches,
|
||||
nr_cancel_dispatches, nr_bounce_dispatches,
|
||||
nr_failed_dispatches, nr_sched_congested,
|
||||
nr_user_dispatches,
|
||||
nr_kernel_dispatches,
|
||||
nr_cancel_dispatches,
|
||||
nr_bounce_dispatches,
|
||||
nr_failed_dispatches,
|
||||
nr_sched_congested,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,6 @@ scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "0.1"
|
||||
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" }
|
||||
|
@ -122,6 +122,10 @@ struct Opts {
|
||||
#[clap(short = 'p', long, action = clap::ArgAction::SetTrue)]
|
||||
partial: bool,
|
||||
|
||||
/// Exit debug dump buffer length. 0 indicates default.
|
||||
#[clap(long, default_value = "0")]
|
||||
exit_dump_len: u32,
|
||||
|
||||
/// If specified, all the BPF scheduling events will be reported in
|
||||
/// debugfs (e.g., /sys/kernel/debug/tracing/trace_pipe).
|
||||
#[clap(short = 'd', long, action = clap::ArgAction::SetTrue)]
|
||||
@ -269,6 +273,7 @@ impl<'a> Scheduler<'a> {
|
||||
opts.slice_us,
|
||||
nr_online_cpus as i32,
|
||||
opts.partial,
|
||||
opts.exit_dump_len,
|
||||
opts.full_user,
|
||||
opts.debug,
|
||||
)?;
|
||||
|
Loading…
Reference in New Issue
Block a user