[PATCH 4/8] sched/deadline: Factor out the selecting of suitable max cpu

From: Byungchul Park
Date: Thu Mar 23 2017 - 06:35:40 EST


Currently, dl scheduler selects a cpu having the maximum dl on pushing.
On success, it would be a fast path, but it might fail because of the
task's affinity or dl value, so we need a slow path in case of failure.
As a first step in adding a slow path, factor out the selecting into
helper function, cpudl_fast_find().

Signed-off-by: Byungchul Park <byungchul.park@xxxxxxx>
---
kernel/sched/cpudeadline.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index f1a6ce4..f03479c 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -115,6 +115,19 @@ static inline u64 cpudl_maximum_dl(struct cpudl *cp)
return cp->elements[0].dl;
}

+static int cpudl_fast_find(struct cpudl *cp, struct task_struct *p)
+{
+ const struct sched_dl_entity *dl_se = &p->dl;
+ int max_cpu = cpudl_maximum_cpu(cp);
+ u64 max_dl = cpudl_maximum_dl(cp);
+
+ if (cpumask_test_cpu(max_cpu, &p->cpus_allowed) &&
+ dl_time_before(dl_se->deadline, max_dl))
+ return max_cpu;
+
+ return -1;
+}
+
/*
* cpudl_find - find the best (later-dl) CPU in the system
* @cp: the cpudl max-heap context
@@ -127,16 +140,14 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
struct cpumask *later_mask)
{
int best_cpu = -1;
- const struct sched_dl_entity *dl_se = &p->dl;

if (later_mask &&
cpumask_and(later_mask, cp->free_cpus, &p->cpus_allowed)) {
best_cpu = cpumask_any(later_mask);
goto out;
- } else if (cpumask_test_cpu(cpudl_maximum_cpu(cp), &p->cpus_allowed) &&
- dl_time_before(dl_se->deadline, cpudl_maximum_dl(cp))) {
- best_cpu = cpudl_maximum_cpu(cp);
- if (later_mask)
+ } else {
+ best_cpu = cpudl_fast_find(cp, p);
+ if (best_cpu != -1 && later_mask)
cpumask_set_cpu(best_cpu, later_mask);
}

--
1.9.1