[PATCH 1/3] sched: Allow hrticks to work with core scheduling

From: Alexander Graf
Date: Wed Aug 26 2020 - 20:44:41 EST


The core scheduling logic bypasses the scheduling class's
pick_next_task() which starts the hrtick logic usually. Instead,
it explicitly calls set_next_task() or leaves the current task
running without any callback into the CFS scheduler.

To ensure that we still configure the hrtick timer properly when we
know which task we want to run, let's add an explicit callback to
the scheduler class which can then be triggered from the core's
pick_next_task().

With this patch, core scheduling with HRTICK enabled does see
improved responsiveness on scheduling decisions.

Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
---
kernel/sched/core.c | 13 +++++++++++++
kernel/sched/fair.c | 9 +++++++++
kernel/sched/sched.h | 4 ++++
3 files changed, 26 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0362102fa3d2..72bf837422bf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4486,6 +4486,12 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
set_next_task(rq, next);
}

+#ifdef CONFIG_SCHED_HRTICK
+ /* Trigger next hrtick after task selection */
+ if (next->sched_class->hrtick_update)
+ next->sched_class->hrtick_update(rq);
+#endif
+
trace_printk("pick pre selected (%u %u %u): %s/%d %lx\n",
rq->core->core_task_seq,
rq->core->core_pick_seq,
@@ -4667,6 +4673,13 @@ next_class:;

done:
set_next_task(rq, next);
+
+#ifdef CONFIG_SCHED_HRTICK
+ /* Trigger next hrtick after task selection */
+ if (next->sched_class->hrtick_update)
+ next->sched_class->hrtick_update(rq);
+#endif
+
return next;
}

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 435b460d3c3f..0d4ff3ab2572 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5512,6 +5512,11 @@ static inline void hrtick_update(struct rq *rq)
}
#endif

+static void hrtick_update_fair(struct rq *rq)
+{
+ hrtick_update(rq);
+}
+
#ifdef CONFIG_SMP
static inline unsigned long cpu_util(int cpu);

@@ -11391,6 +11396,10 @@ const struct sched_class fair_sched_class = {
#ifdef CONFIG_UCLAMP_TASK
.uclamp_enabled = 1,
#endif
+
+#ifdef CONFIG_SCHED_HRTICK
+ .hrtick_update = hrtick_update_fair,
+#endif
};

#ifdef CONFIG_SCHED_DEBUG
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6445943d3215..b382e0ee0c87 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1942,6 +1942,10 @@ struct sched_class {
#ifdef CONFIG_FAIR_GROUP_SCHED
void (*task_change_group)(struct task_struct *p, int type);
#endif
+
+#ifdef CONFIG_SCHED_HRTICK
+ void (*hrtick_update)(struct rq *rq);
+#endif
};

static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
--
2.26.2




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879