scx_bpfland: split direct dispatches and kthread dispatches

Show separate statistics for direct dispatches and kthread direct
dispatches.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Andrea Righi 2024-07-04 17:33:10 +02:00
parent 86d2f50230
commit f9d7844b2e
2 changed files with 21 additions and 7 deletions

View File

@ -78,7 +78,8 @@ static u64 starvation_prio_ts;
/*
* Scheduling statistics.
*/
volatile u64 nr_direct_dispatches, nr_shared_dispatches, nr_prio_dispatches;
volatile u64 nr_direct_dispatches, nr_kthread_dispatches,
nr_shared_dispatches, nr_prio_dispatches;
/*
* Amount of currently running tasks.
@ -272,7 +273,6 @@ static int dispatch_direct_cpu(struct task_struct *p, s32 cpu)
return -EINVAL;
scx_bpf_dispatch_vtime(p, dsq_id, slice, vtime, 0);
__sync_fetch_and_add(&nr_direct_dispatches, 1);
/*
* Wake-up the target CPU to make sure that the task is consumed as
@ -402,8 +402,10 @@ s32 BPF_STRUCT_OPS(bpfland_select_cpu, struct task_struct *p, s32 prev_cpu, u64
s32 cpu;
cpu = pick_idle_cpu(p, prev_cpu, wake_flags);
if (cpu >= 0 && !dispatch_direct_cpu(p, cpu))
if (cpu >= 0 && !dispatch_direct_cpu(p, cpu)) {
__sync_fetch_and_add(&nr_direct_dispatches, 1);
return cpu;
}
return prev_cpu;
}
@ -432,8 +434,10 @@ void BPF_STRUCT_OPS(bpfland_enqueue, struct task_struct *p, u64 enq_flags)
*/
if (is_kthread(p) && p->nr_cpus_allowed == 1) {
s32 cpu = scx_bpf_task_cpu(p);
dispatch_direct_cpu(p, cpu);
return;
if (!dispatch_direct_cpu(p, cpu)) {
__sync_fetch_and_add(&nr_kthread_dispatches, 1);
return;
}
}
tctx = lookup_task_ctx(p);

View File

@ -102,6 +102,7 @@ struct Opts {
struct Metrics {
nr_running: Gauge,
nr_kthread_dispatches: Gauge,
nr_direct_dispatches: Gauge,
nr_prio_dispatches: Gauge,
nr_shared_dispatches: Gauge,
@ -113,8 +114,11 @@ impl Metrics {
nr_running: gauge!(
"nr_running", "info" => "Number of running tasks"
),
nr_kthread_dispatches: gauge!(
"nr_kthread_dispatches", "info" => "Number of kthread direct dispatches"
),
nr_direct_dispatches: gauge!(
"nr_direct_dispatches", "info" => "Number of direct dispatches"
"nr_direct_dispatches", "info" => "Number of task direct dispatches"
),
nr_prio_dispatches: gauge!(
"nr_prio_dispatches", "info" => "Number of interactive task dispatches"
@ -195,12 +199,17 @@ impl<'a> Scheduler<'a> {
fn update_stats(&mut self) {
let nr_cpus = libbpf_rs::num_possible_cpus().unwrap();
let nr_running = self.skel.bss().nr_running;
let nr_kthread_dispatches = self.skel.bss().nr_kthread_dispatches;
let nr_direct_dispatches = self.skel.bss().nr_direct_dispatches;
let nr_prio_dispatches = self.skel.bss().nr_prio_dispatches;
let nr_shared_dispatches = self.skel.bss().nr_shared_dispatches;
// Update Prometheus statistics.
self.metrics.nr_running.set(nr_running as f64);
self.metrics
.nr_kthread_dispatches
.set(nr_kthread_dispatches as f64);
self.metrics
.nr_direct_dispatches
.set(nr_direct_dispatches as f64);
@ -212,9 +221,10 @@ impl<'a> Scheduler<'a> {
.set(nr_shared_dispatches as f64);
// Log scheduling statistics.
info!("running={}/{} direct_dispatches={} prio_dispatches={} shared_dispatches={}",
info!("running={}/{} kthread_dispatches={} direct_dispatches={} prio_dispatches={} shared_dispatches={}",
nr_running,
nr_cpus,
nr_kthread_dispatches,
nr_direct_dispatches,
nr_prio_dispatches,
nr_shared_dispatches);