2024-03-13 02:41:00

by Kassey Li

[permalink] [raw]
Subject: [PATCH] sched/headers: do not set last_queued to 0 in arrive

The pcount accounting for Task A missed in the step 4:

1. Task A enqueued
2. Task A arrive and hit CPU
3. Task B arrive and hit CPU, preempted Task A, Task A is still in rq
as TASK_RUNNING
4. Task A arrive and hit CPU again.

This change leaves enqueue/dequeue on last_queued only, and
correct the pcount accounting.

Signed-off-by: Kassey Li <[email protected]>
---
kernel/sched/stats.h | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index 38f3698f5e5b..3decd2261875 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -229,8 +229,17 @@ static void sched_info_arrive(struct rq *rq, struct task_struct *t)
return;

now = rq_clock(rq);
- delta = now - t->sched_info.last_queued;
- t->sched_info.last_queued = 0;
+
+ /*
+ * last_arrival > last_queued means a task in the rq, it is not the
+ * first time hits the CPU.
+ */
+
+ if(unlikely(t->sched_info.last_arrival > t->sched_info.last_queued))
+ delta = now - t->sched_info.last_arrival;
+ else
+ delta = now - t->sched_info.last_queued;
+
t->sched_info.run_delay += delta;
t->sched_info.last_arrival = now;
t->sched_info.pcount++;
--
2.25.1