scx_bpfland: report interactive tasks to stdout

Keep track of the CPUs that are running interactive tasks and report
their amount to stdout.

Tested-by: Piotr Gorski <lucjan.lucjanov@gmail.com>
Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
This commit is contained in:
Andrea Righi 2024-07-07 21:20:10 +02:00
parent 1a1a16b9e9
commit 3a47b484af
2 changed files with 29 additions and 4 deletions

View File

@ -84,7 +84,7 @@ volatile u64 nr_direct_dispatches, nr_kthread_dispatches,
/*
* Amount of currently running tasks.
*/
volatile u64 nr_running;
volatile u64 nr_running, nr_interactive;
/*
* Exit information.
@ -586,6 +586,12 @@ void BPF_STRUCT_OPS(bpfland_dispatch, s32 cpu, struct task_struct *prev)
void BPF_STRUCT_OPS(bpfland_running, struct task_struct *p)
{
struct task_ctx *tctx;
tctx = lookup_task_ctx(p);
if (!tctx)
return;
/* Update global vruntime */
if (vtime_before(vtime_now, p->scx.dsq_vtime))
vtime_now = p->scx.dsq_vtime;
@ -597,6 +603,10 @@ void BPF_STRUCT_OPS(bpfland_running, struct task_struct *p)
if (p->scx.slice > slice_ns)
p->scx.slice = slice_ns;
/* Update CPU interactive state */
if (tctx->is_interactive)
__sync_fetch_and_add(&nr_interactive, 1);
__sync_fetch_and_add(&nr_running, 1);
}
@ -615,6 +625,9 @@ void BPF_STRUCT_OPS(bpfland_stopping, struct task_struct *p, bool runnable)
if (!tctx)
return;
if (tctx->is_interactive)
__sync_fetch_and_sub(&nr_interactive, 1);
/*
* Update task vruntime, charging the weighted used time slice.
*
@ -722,6 +735,8 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(bpfland_init)
mask = offline_cpumask;
if (!mask)
err = -ENOMEM;
if (err)
return err;
return err;
}

View File

@ -101,6 +101,7 @@ struct Opts {
struct Metrics {
nr_running: Gauge,
nr_interactive: Gauge,
nr_kthread_dispatches: Gauge,
nr_direct_dispatches: Gauge,
nr_prio_dispatches: Gauge,
@ -113,6 +114,9 @@ impl Metrics {
nr_running: gauge!(
"nr_running", "info" => "Number of running tasks"
),
nr_interactive: gauge!(
"nr_interactive", "info" => "Number of running interactive tasks"
),
nr_kthread_dispatches: gauge!(
"nr_kthread_dispatches", "info" => "Number of kthread direct dispatches"
),
@ -203,14 +207,19 @@ 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_interactive = self.skel.bss().nr_interactive;
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_running
.set(nr_running as f64);
self.metrics
.nr_interactive
.set(nr_interactive as f64);
self.metrics
.nr_kthread_dispatches
.set(nr_kthread_dispatches as f64);
@ -225,9 +234,10 @@ impl<'a> Scheduler<'a> {
.set(nr_shared_dispatches as f64);
// Log scheduling statistics.
info!("running: {:>4}/{:<4} | kthread: {:<6} | direct: {:<6} | prio: {:<6} | shared: {:<6}",
info!("running: {:>4}/{:<4} interactive: {:>4} | kthread: {:<6} | direct: {:<6} | prio: {:<6} | shared: {:<6}",
nr_running,
nr_cpus,
nr_interactive,
nr_kthread_dispatches,
nr_direct_dispatches,
nr_prio_dispatches,