From 1cf03770c75e9cecbb80f66bc75622e0438b6593 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 11 Jan 2024 14:10:39 +0100 Subject: [PATCH] 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 --- scheds/rust/scx_rustland/src/bpf.rs | 6 ++++-- scheds/rust/scx_rustland/src/bpf/intf.h | 1 + scheds/rust/scx_rustland/src/bpf/main.bpf.c | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scheds/rust/scx_rustland/src/bpf.rs b/scheds/rust/scx_rustland/src/bpf.rs index 610f5e4..409f3d2 100644 --- a/scheds/rust/scx_rustland/src/bpf.rs +++ b/scheds/rust/scx_rustland/src/bpf.rs @@ -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, } } diff --git a/scheds/rust/scx_rustland/src/bpf/intf.h b/scheds/rust/scx_rustland/src/bpf/intf.h index b653f99..973e08b 100644 --- a/scheds/rust/scx_rustland/src/bpf/intf.h +++ b/scheds/rust/scx_rustland/src/bpf/intf.h @@ -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 */ }; diff --git a/scheds/rust/scx_rustland/src/bpf/main.bpf.c b/scheds/rust/scx_rustland/src/bpf/main.bpf.c index 4221979..45729da 100644 --- a/scheds/rust/scx_rustland/src/bpf/main.bpf.c +++ b/scheds/rust/scx_rustland/src/bpf/main.bpf.c @@ -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); }