scx_rustland: expose voluntary context switches to the scheduler

Provide the number of voluntary context switches (nvcsw) for each task
to the user-space scheduler.

This extra information can then be used by the scheduler to enhance its
decision-making process when scheduling tasks.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Andrea Righi 2024-01-11 14:10:39 +01:00
parent 30c25ff30e
commit 1cf03770c7
3 changed files with 6 additions and 2 deletions

View File

@ -127,8 +127,9 @@ const SCHED_EXT: i32 = 7;
pub struct QueuedTask {
pub pid: i32, // pid that uniquely identifies a task
pub cpu: i32, // CPU where the task is running (-1 = exiting)
pub sum_exec_runtime: u64, // Total cpu time */
pub weight: u64, // Task static priority */
pub sum_exec_runtime: u64, // Total cpu time
pub nvcsw: u64, // Voluntary context switches
pub weight: u64, // Task static priority
}
// Task queued for dispatching to the BPF component (see bpf_intf::dispatched_task_ctx).
@ -159,6 +160,7 @@ impl EnqueuedMessage {
pid: self.inner.pid,
cpu: self.inner.cpu,
sum_exec_runtime: self.inner.sum_exec_runtime,
nvcsw: self.inner.nvcsw,
weight: self.inner.weight,
}
}

View File

@ -35,6 +35,7 @@ struct queued_task_ctx {
s32 pid;
s32 cpu; /* CPU where the task is running (-1 = exiting) */
u64 sum_exec_runtime; /* Total cpu time */
u64 nvcsw; /* Voluntary context switches */
u64 weight; /* Task static priority */
};

View File

@ -386,6 +386,7 @@ static void get_task_info(struct queued_task_ctx *task,
return;
}
task->sum_exec_runtime = p->se.sum_exec_runtime;
task->nvcsw = p->nvcsw;
task->weight = p->scx.weight;
task->cpu = scx_bpf_task_cpu(p);
}