The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] schedule: SCHED_RR: Give a fresh time-slice to the task after after it suspends or relinquishes
@ 2021-12-22  9:15 zhaoxiu.zeng
  2021-12-22 10:40 ` Peter Zijlstra
  2021-12-22 18:41 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: zhaoxiu.zeng @ 2021-12-22  9:15 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, bristot,
	linux-kernel

Assuming the sched_rr_timeslice is 100ms, there are several tasks with the
same priority t1, t2, t3, ..., and t1 sleeps every 80ms, the scheduling
timing may be:
    t1  t2   t3        t1  t2   t3        t1  t2   t3        t1  t2   t3
    80, 100, 100, ..., 20, 100, 100, ..., 60, 100, 100, ..., 40, 100, 100

After applying this patch, the scheduling timing may be:
    t1  t2   t3        t1  t2   t3        t1  t2   t3        t1  t2   t3
    80, 100, 100, ..., 80, 100, 100, ..., 80, 100, 100, ..., 80, 100, 100


Signed-off-by: zhaoxiu.zeng <zhaoxiu.zeng@gmail.com>
---
 kernel/sched/rt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index b48baaba2fc2..51798fefcb36 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1491,9 +1491,13 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
 {
 	struct sched_rt_entity *rt_se = &p->rt;
 
-	if (flags & ENQUEUE_WAKEUP)
+	if (flags & ENQUEUE_WAKEUP) {
 		rt_se->timeout = 0;
 
+		if (p->policy == SCHED_RR)
+			p->rt.time_slice = sched_rr_timeslice;
+	}
+
 	check_schedstat_required();
 	update_stats_wait_start_rt(rt_rq_of_se(rt_se), rt_se);
 
@@ -1544,7 +1548,12 @@ static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
 
 static void yield_task_rt(struct rq *rq)
 {
-	requeue_task_rt(rq, rq->curr, 0);
+	struct task_struct *p = rq->curr;
+
+	if (p->policy == SCHED_RR)
+		p->rt.time_slice = sched_rr_timeslice;
+
+	requeue_task_rt(rq, p, 0);
 }
 
 #ifdef CONFIG_SMP
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-24  2:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-22  9:15 [PATCH] schedule: SCHED_RR: Give a fresh time-slice to the task after after it suspends or relinquishes zhaoxiu.zeng
2021-12-22 10:40 ` Peter Zijlstra
2021-12-24  1:58   ` Zhaoxiu Zeng
2021-12-22 18:41 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox