lkml.org 
[lkml]   [2021]   [Feb]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH V2] sched: pull tasks when CPU is about to run SCHED_IDLE tasks
Date
From: Chen Xiaoguang <xiaoggchen@tencent.com>

In order to use the computer efficiently we usually deploy online
tasks and offline tasks in the same computer.

The online tasks are more important than the offline tasks and are
latency sensitive we should make sure the online tasks preempt the
offline tasks as soon as possible while there are online tasks
waiting to run.

Online tasks using the SCHED_NORMAL policy and offline tasks using
the SCHED_ILDE policy. This patch decrease the latency of online
tasks by doing a load balance before a offline tasks to run.

Signed-off-by: Chen Xiaoguang <xiaoggchen@tencent.com>
Signed-off-by: Chen He <heddchen@tencent.com>
---
v1 -> v2:
- Add checking in balance_fair
- Remove task state checking in pick_next_task_fair
- Add comment about the change
---
kernel/sched/fair.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8a8bd7b..80b69a2 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6833,7 +6833,13 @@ static void task_dead_fair(struct task_struct *p)
static int
balance_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
{
- if (rq->nr_running)
+ /*
+ * Return if SCHED_NORMAL tasks exist.
+ * Else if only SCHED_IDLE tasks in rq then do a load balance trying
+ * to pull SCHED_NORMAL tasks to run so as to reduce the latency of
+ * SCHED_NORMAL task.
+ */
+ if (rq->nr_running && !sched_idle_rq(rq))
return 1;

return newidle_balance(rq, rf) != 0;
@@ -7013,6 +7019,14 @@ struct task_struct *
struct task_struct *p;
int new_tasks;

+ /*
+ * Before a CPU switches from running SCHED_NORMAL task to SCHED_IDLE
+ * task, do a load balance trying to pull SCHED_NORMAL tasks to run
+ * so as to reduce the latency of SCHED_NORMAL task.
+ */
+ if (sched_idle_rq(rq) && prev && prev->policy != SCHED_IDLE)
+ goto idle;
+
again:
if (!sched_fair_runnable(rq))
goto idle;
--
1.8.3.1
\
 
 \ /
  Last update: 2021-02-22 12:31    [W:0.025 / U:16.604 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site