lkml.org 
[lkml]   [2021]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] schedule: SCHED_RR: Give a fresh time-slice to the task after after it suspends or relinquishes
Date
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
\
 
 \ /
  Last update: 2021-12-22 10:16    [W:0.219 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site