Re: [RFC PATCH V3 1/6] sched: Unify runtime accounting across classes

From: Valentin Schneider
Date: Fri Jun 16 2023 - 10:31:51 EST


On 08/06/23 17:58, Daniel Bristot de Oliveira wrote:
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>
> All classes use sched_entity::exec_start to track runtime and have
> copies of the exact same code around to compute runtime.
>
> Collapse all that.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>

This one's been around for a while, John also carries it for PE [1] because it
makes things simpler. We should just get it in :-)

The three-layered if (unlikely(delta_exec <= 0)) is unfortunate, but I think we
can live with it. Tiny factorization appended below, but regardless:

Reviewed-by: Valentin Schneider <vschneid@xxxxxxxxxx>

[1]: http://lore.kernel.org/r/20230601055846.2349566-2-jstultz@xxxxxxxxxx

---
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index e7fcf558dc4bc..e52e609724482 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -914,6 +914,14 @@ static s64 update_curr_se(struct rq *rq, struct sched_entity *curr)
return delta_exec;
}

+static inline void
+account_curr_runtime(struct task_struct *curr, s64 runtime, u64 vruntime)
+{
+ trace_sched_stat_runtime(curr, runtime, vruntime);
+ account_group_exec_runtime(curr, runtime);
+ cgroup_account_cputime(curr, runtime);
+}
+
/*
* Used by other classes to account runtime.
*/
@@ -926,10 +934,7 @@ s64 update_curr_common(struct rq *rq)
if (unlikely(delta_exec <= 0))
return delta_exec;

- trace_sched_stat_runtime(curr, delta_exec, 0);
-
- account_group_exec_runtime(curr, delta_exec);
- cgroup_account_cputime(curr, delta_exec);
+ account_curr_runtime(curr, delta_exec, 0);

return delta_exec;
}
@@ -955,9 +960,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
if (entity_is_task(curr)) {
struct task_struct *curtask = task_of(curr);

- trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
- cgroup_account_cputime(curtask, delta_exec);
- account_group_exec_runtime(curtask, delta_exec);
+ account_curr_runtime(curtask, delta_exec, curr->vruntime);
}

account_cfs_rq_runtime(cfs_rq, delta_exec);