All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span
@ 2014-11-19 15:46 pang.xunlei
  2014-11-19 15:46 ` [PATCH v2 2/4] sched/deadline: Fix wrong cpudl_find() in check_preempt_equal_dl() pang.xunlei
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: pang.xunlei @ 2014-11-19 15:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, pang.xunlei

Currently, cpudl.free_cpus contains all cpus during init(see cpudl_init()),
so when calling cpudl_find() we have to add rd->span cpumask(cpus_allowed is
undependable when performing clustered scheduling using the cpuset) to avoid
selecting the cpu outside current root domain, see find_later_rq().

This patch adds cpudl_set_freecpu() to initialize cpudl.free_cpus when doing
rq_attach_root(), so we can avoid the extra rd->span operation when calling
cpudl_find().

Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
---
 kernel/sched/core.c        |    2 ++
 kernel/sched/cpudeadline.c |   18 ++++++++++++++----
 kernel/sched/cpudeadline.h |    1 +
 kernel/sched/deadline.c    |    3 ---
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 240157c..1b417de 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5584,6 +5584,8 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd)
 	rq->rd = rd;
 
 	cpumask_set_cpu(rq->cpu, rd->span);
+	cpudl_set_freecpu(&rd->cpudl, rq->cpu);
+
 	if (cpumask_test_cpu(rq->cpu, cpu_active_mask))
 		set_rq_online(rq);
 
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 539ca3c..c79f0d7 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -107,7 +107,9 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	int best_cpu = -1;
 	const struct sched_dl_entity *dl_se = &p->dl;
 
-	if (later_mask && cpumask_and(later_mask, later_mask, cp->free_cpus)) {
+	if (later_mask &&
+	    cpumask_and(later_mask, cp->free_cpus, &p->cpus_allowed) &&
+	    cpumask_and(later_mask, later_mask, cpu_active_mask)) {
 		best_cpu = cpumask_any(later_mask);
 		goto out;
 	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
@@ -186,6 +188,16 @@ out:
 }
 
 /*
+ * cpudl_set_freecpu - Set the cpudl.free_cpus
+ * @cp: the cpudl max-heap context
+ * @cpu: rd attached cpu
+ */
+void cpudl_set_freecpu(struct cpudl *cp, int cpu)
+{
+	cpumask_set_cpu(cpu, cp->free_cpus);
+}
+
+/*
  * cpudl_init - initialize the cpudl structure
  * @cp: the cpudl max-heap context
  */
@@ -203,7 +215,7 @@ int cpudl_init(struct cpudl *cp)
 	if (!cp->elements)
 		return -ENOMEM;
 
-	if (!alloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) {
+	if (!zalloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) {
 		kfree(cp->elements);
 		return -ENOMEM;
 	}
@@ -211,8 +223,6 @@ int cpudl_init(struct cpudl *cp)
 	for_each_possible_cpu(i)
 		cp->elements[i].idx = IDX_INVALID;
 
-	cpumask_setall(cp->free_cpus);
-
 	return 0;
 }
 
diff --git a/kernel/sched/cpudeadline.h b/kernel/sched/cpudeadline.h
index 020039b..4a10a65 100644
--- a/kernel/sched/cpudeadline.h
+++ b/kernel/sched/cpudeadline.h
@@ -24,6 +24,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	       struct cpumask *later_mask);
 void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid);
 int cpudl_init(struct cpudl *cp);
+void cpudl_set_freecpu(struct cpudl *cp, int cpu);
 void cpudl_cleanup(struct cpudl *cp);
 #endif /* CONFIG_SMP */
 
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 5285332..bd83272 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1187,9 +1187,6 @@ static int find_later_rq(struct task_struct *task)
 	 * We have to consider system topology and task affinity
 	 * first, then we can look for a suitable cpu.
 	 */
-	cpumask_copy(later_mask, task_rq(task)->rd->span);
-	cpumask_and(later_mask, later_mask, cpu_active_mask);
-	cpumask_and(later_mask, later_mask, &task->cpus_allowed);
 	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
 			task, later_mask);
 	if (best_cpu == -1)
-- 
1.7.9.5


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

* [PATCH v2 2/4] sched/deadline: Fix wrong cpudl_find() in check_preempt_equal_dl()
  2014-11-19 15:46 [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span pang.xunlei
@ 2014-11-19 15:46 ` pang.xunlei
  2014-11-19 15:46 ` [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find() pang.xunlei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: pang.xunlei @ 2014-11-19 15:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, pang.xunlei

In check_preempt_equal_dl(), cpudl_find() is called with a NULL later_mask,
thus cpudl_find() here doesn't check cpudl.free_cpus at all.

This patch takles this issue by always passing a non-NULL cpumask to cpudl_find(),
and assigns later_mask in this function.

Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
---
 kernel/sched/cpudeadline.c |   10 ++++------
 kernel/sched/deadline.c    |   10 ++++++----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index c79f0d7..c01b3aa 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -97,7 +97,7 @@ static inline int cpudl_maximum(struct cpudl *cp)
  * cpudl_find - find the best (later-dl) CPU in the system
  * @cp: the cpudl max-heap context
  * @p: the task
- * @later_mask: a mask to fill in with the selected CPUs (or NULL)
+ * @later_mask: a mask to fill in with the selected CPUs (not NULL)
  *
  * Returns: int - best CPU (heap maximum if suitable)
  */
@@ -107,16 +107,14 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	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) &&
-	    cpumask_and(later_mask, later_mask, cpu_active_mask)) {
+	cpumask_and(later_mask, cpu_active_mask, &p->cpus_allowed);
+	if (cpumask_and(later_mask, later_mask, cp->free_cpus)) {
 		best_cpu = cpumask_any(later_mask);
 		goto out;
 	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
 			dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
 		best_cpu = cpudl_maximum(cp);
-		if (later_mask)
-			cpumask_set_cpu(best_cpu, later_mask);
+		cpumask_set_cpu(best_cpu, later_mask);
 	}
 
 out:
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index bd83272..3ecf838 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -965,14 +965,18 @@ out:
 	return cpu;
 }
 
+static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl);
+
 static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 {
+	struct cpumask *later_mask = this_cpu_cpumask_var_ptr(local_cpu_mask_dl);
+
 	/*
 	 * Current can't be migrated, useless to reschedule,
 	 * let's hope p can move out.
 	 */
 	if (rq->curr->nr_cpus_allowed == 1 ||
-	    cpudl_find(&rq->rd->cpudl, rq->curr, NULL) == -1)
+	    cpudl_find(&rq->rd->cpudl, rq->curr, later_mask) == -1)
 		return;
 
 	/*
@@ -980,7 +984,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 	 * see if it is pushed or pulled somewhere else.
 	 */
 	if (p->nr_cpus_allowed != 1 &&
-	    cpudl_find(&rq->rd->cpudl, p, NULL) != -1)
+	    cpudl_find(&rq->rd->cpudl, p, later_mask) != -1)
 		return;
 
 	resched_curr(rq);
@@ -1167,8 +1171,6 @@ next_node:
 	return NULL;
 }
 
-static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl);
-
 static int find_later_rq(struct task_struct *task)
 {
 	struct sched_domain *sd;
-- 
1.7.9.5


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

* [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find()
  2014-11-19 15:46 [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span pang.xunlei
  2014-11-19 15:46 ` [PATCH v2 2/4] sched/deadline: Fix wrong cpudl_find() in check_preempt_equal_dl() pang.xunlei
@ 2014-11-19 15:46 ` pang.xunlei
  2014-11-19 16:24   ` Steven Rostedt
  2014-11-19 15:46 ` [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu pang.xunlei
  2014-11-20  9:00 ` [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span Wanpeng Li
  3 siblings, 1 reply; 9+ messages in thread
From: pang.xunlei @ 2014-11-19 15:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, pang.xunlei

The call site of cpudl_find() in check_preempt_equal_dl() doesn't
use later_mask, so add this extra argument to distinquish the case.

Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
---
 kernel/sched/cpudeadline.c |    6 ++++--
 kernel/sched/cpudeadline.h |    2 +-
 kernel/sched/deadline.c    |    6 +++---
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index c01b3aa..3047846 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -98,11 +98,12 @@ static inline int cpudl_maximum(struct cpudl *cp)
  * @cp: the cpudl max-heap context
  * @p: the task
  * @later_mask: a mask to fill in with the selected CPUs (not NULL)
+ * @set_flag: indicate if later_mask should be set
  *
  * Returns: int - best CPU (heap maximum if suitable)
  */
 int cpudl_find(struct cpudl *cp, struct task_struct *p,
-	       struct cpumask *later_mask)
+	       struct cpumask *later_mask, int set_flag)
 {
 	int best_cpu = -1;
 	const struct sched_dl_entity *dl_se = &p->dl;
@@ -114,7 +115,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
 			dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
 		best_cpu = cpudl_maximum(cp);
-		cpumask_set_cpu(best_cpu, later_mask);
+		if (set_flag)
+			cpumask_set_cpu(best_cpu, later_mask);
 	}
 
 out:
diff --git a/kernel/sched/cpudeadline.h b/kernel/sched/cpudeadline.h
index 4a10a65..a3a85e8 100644
--- a/kernel/sched/cpudeadline.h
+++ b/kernel/sched/cpudeadline.h
@@ -22,7 +22,7 @@ struct cpudl {
 #ifdef CONFIG_SMP
 int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	       struct cpumask *later_mask);
-void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid);
+void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid, int set_flag);
 int cpudl_init(struct cpudl *cp);
 void cpudl_set_freecpu(struct cpudl *cp, int cpu);
 void cpudl_cleanup(struct cpudl *cp);
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 3ecf838..e8208d0 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -976,7 +976,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 	 * let's hope p can move out.
 	 */
 	if (rq->curr->nr_cpus_allowed == 1 ||
-	    cpudl_find(&rq->rd->cpudl, rq->curr, later_mask) == -1)
+	    cpudl_find(&rq->rd->cpudl, rq->curr, later_mask, 0) == -1)
 		return;
 
 	/*
@@ -984,7 +984,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 	 * see if it is pushed or pulled somewhere else.
 	 */
 	if (p->nr_cpus_allowed != 1 &&
-	    cpudl_find(&rq->rd->cpudl, p, later_mask) != -1)
+	    cpudl_find(&rq->rd->cpudl, p, later_mask, 0) != -1)
 		return;
 
 	resched_curr(rq);
@@ -1190,7 +1190,7 @@ static int find_later_rq(struct task_struct *task)
 	 * first, then we can look for a suitable cpu.
 	 */
 	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
-			task, later_mask);
+			task, later_mask, 1);
 	if (best_cpu == -1)
 		return -1;
 
-- 
1.7.9.5


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

* [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu
  2014-11-19 15:46 [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span pang.xunlei
  2014-11-19 15:46 ` [PATCH v2 2/4] sched/deadline: Fix wrong cpudl_find() in check_preempt_equal_dl() pang.xunlei
  2014-11-19 15:46 ` [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find() pang.xunlei
@ 2014-11-19 15:46 ` pang.xunlei
  2014-11-19 16:30   ` Steven Rostedt
  2014-11-20  9:00 ` [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span Wanpeng Li
  3 siblings, 1 reply; 9+ messages in thread
From: pang.xunlei @ 2014-11-19 15:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, pang.xunlei

cpudl_find() is not a good place to select the best cpu, so leave
this role to its call site, currently it is find_later_rq() where
we can do the election of the best cpu according to sd topology.

Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
---
 kernel/sched/cpudeadline.c |   15 +++++----------
 kernel/sched/deadline.c    |   17 ++++++-----------
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 3047846..41d3578 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -100,29 +100,24 @@ static inline int cpudl_maximum(struct cpudl *cp)
  * @later_mask: a mask to fill in with the selected CPUs (not NULL)
  * @set_flag: indicate if later_mask should be set
  *
- * Returns: int - best CPU (heap maximum if suitable)
+ * Return: (int)bool - CPUs were found
  */
 int cpudl_find(struct cpudl *cp, struct task_struct *p,
 	       struct cpumask *later_mask, int set_flag)
 {
-	int best_cpu = -1;
 	const struct sched_dl_entity *dl_se = &p->dl;
 
 	cpumask_and(later_mask, cpu_active_mask, &p->cpus_allowed);
 	if (cpumask_and(later_mask, later_mask, cp->free_cpus)) {
-		best_cpu = cpumask_any(later_mask);
-		goto out;
+		return 1;
 	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
 			dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
-		best_cpu = cpudl_maximum(cp);
 		if (set_flag)
-			cpumask_set_cpu(best_cpu, later_mask);
+			cpumask_set_cpu(cpudl_maximum(cp), later_mask);
+		return 1;
 	}
 
-out:
-	WARN_ON(best_cpu != -1 && !cpu_present(best_cpu));
-
-	return best_cpu;
+	return 0;
 }
 
 /*
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index e8208d0..3e82cf3 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -976,7 +976,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 	 * let's hope p can move out.
 	 */
 	if (rq->curr->nr_cpus_allowed == 1 ||
-	    cpudl_find(&rq->rd->cpudl, rq->curr, later_mask, 0) == -1)
+	    !cpudl_find(&rq->rd->cpudl, rq->curr, later_mask, 0))
 		return;
 
 	/*
@@ -984,7 +984,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
 	 * see if it is pushed or pulled somewhere else.
 	 */
 	if (p->nr_cpus_allowed != 1 &&
-	    cpudl_find(&rq->rd->cpudl, p, later_mask, 0) != -1)
+	    cpudl_find(&rq->rd->cpudl, p, later_mask, 0))
 		return;
 
 	resched_curr(rq);
@@ -1189,9 +1189,7 @@ static int find_later_rq(struct task_struct *task)
 	 * We have to consider system topology and task affinity
 	 * first, then we can look for a suitable cpu.
 	 */
-	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
-			task, later_mask, 1);
-	if (best_cpu == -1)
+	if (!cpudl_find(&task_rq(task)->rd->cpudl, task, later_mask, 1))
 		return -1;
 
 	/*
@@ -1230,12 +1228,9 @@ static int find_later_rq(struct task_struct *task)
 				return this_cpu;
 			}
 
-			/*
-			 * Last chance: if best_cpu is valid and is
-			 * in the mask, that becomes our choice.
-			 */
-			if (best_cpu < nr_cpu_ids &&
-			    cpumask_test_cpu(best_cpu, sched_domain_span(sd))) {
+			best_cpu = cpumask_first_and(lowest_mask,
+						sched_domain_span(sd));
+			if (best_cpu < nr_cpu_ids) {
 				rcu_read_unlock();
 				return best_cpu;
 			}
-- 
1.7.9.5


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

* Re: [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find()
  2014-11-19 15:46 ` [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find() pang.xunlei
@ 2014-11-19 16:24   ` Steven Rostedt
  2014-11-20 14:58     ` pang.xunlei
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2014-11-19 16:24 UTC (permalink / raw)
  To: pang.xunlei; +Cc: linux-kernel, Peter Zijlstra, Juri Lelli

On Wed, 19 Nov 2014 23:46:21 +0800
"pang.xunlei" <pang.xunlei@linaro.org> wrote:

> The call site of cpudl_find() in check_preempt_equal_dl() doesn't
> use later_mask, so add this extra argument to distinquish the case.
> 
> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
> ---
>  kernel/sched/cpudeadline.c |    6 ++++--
>  kernel/sched/cpudeadline.h |    2 +-
>  kernel/sched/deadline.c    |    6 +++---
>  3 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
> index c01b3aa..3047846 100644
> --- a/kernel/sched/cpudeadline.c
> +++ b/kernel/sched/cpudeadline.c
> @@ -98,11 +98,12 @@ static inline int cpudl_maximum(struct cpudl *cp)
>   * @cp: the cpudl max-heap context
>   * @p: the task
>   * @later_mask: a mask to fill in with the selected CPUs (not NULL)
> + * @set_flag: indicate if later_mask should be set
>   *
>   * Returns: int - best CPU (heap maximum if suitable)
>   */
>  int cpudl_find(struct cpudl *cp, struct task_struct *p,
> -	       struct cpumask *later_mask)
> +	       struct cpumask *later_mask, int set_flag)

set_flag should be a bool type.

>  {
>  	int best_cpu = -1;
>  	const struct sched_dl_entity *dl_se = &p->dl;
> @@ -114,7 +115,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
>  	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
>  			dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
>  		best_cpu = cpudl_maximum(cp);
> -		cpumask_set_cpu(best_cpu, later_mask);
> +		if (set_flag)
> +			cpumask_set_cpu(best_cpu, later_mask);

I'm not sure this is worth it. cpumask_set_cpu() is rather efficient.

>  	}
>  
>  out:


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

* Re: [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu
  2014-11-19 15:46 ` [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu pang.xunlei
@ 2014-11-19 16:30   ` Steven Rostedt
  0 siblings, 0 replies; 9+ messages in thread
From: Steven Rostedt @ 2014-11-19 16:30 UTC (permalink / raw)
  To: pang.xunlei; +Cc: linux-kernel, Peter Zijlstra, Juri Lelli

On Wed, 19 Nov 2014 23:46:22 +0800
"pang.xunlei" <pang.xunlei@linaro.org> wrote:

> cpudl_find() is not a good place to select the best cpu, so leave
> this role to its call site, currently it is find_later_rq() where
> we can do the election of the best cpu according to sd topology.
> 
> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
> ---
>  kernel/sched/cpudeadline.c |   15 +++++----------
>  kernel/sched/deadline.c    |   17 ++++++-----------
>  2 files changed, 11 insertions(+), 21 deletions(-)
> 
> diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
> index 3047846..41d3578 100644
> --- a/kernel/sched/cpudeadline.c
> +++ b/kernel/sched/cpudeadline.c
> @@ -100,29 +100,24 @@ static inline int cpudl_maximum(struct cpudl *cp)
>   * @later_mask: a mask to fill in with the selected CPUs (not NULL)
>   * @set_flag: indicate if later_mask should be set
>   *
> - * Returns: int - best CPU (heap maximum if suitable)
> + * Return: (int)bool - CPUs were found
>   */
>  int cpudl_find(struct cpudl *cp, struct task_struct *p,
>  	       struct cpumask *later_mask, int set_flag)
>  {
> -	int best_cpu = -1;
>  	const struct sched_dl_entity *dl_se = &p->dl;
>  
>  	cpumask_and(later_mask, cpu_active_mask, &p->cpus_allowed);
>  	if (cpumask_and(later_mask, later_mask, cp->free_cpus)) {
> -		best_cpu = cpumask_any(later_mask);
> -		goto out;
> +		return 1;
>  	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
>  			dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
> -		best_cpu = cpudl_maximum(cp);
>  		if (set_flag)
> -			cpumask_set_cpu(best_cpu, later_mask);
> +			cpumask_set_cpu(cpudl_maximum(cp), later_mask);
> +		return 1;
>  	}
>  
> -out:
> -	WARN_ON(best_cpu != -1 && !cpu_present(best_cpu));

You lost this warning. It should be moved too.

> -
> -	return best_cpu;
> +	return 0;
>  }
>  
>  /*
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index e8208d0..3e82cf3 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -976,7 +976,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
>  	 * let's hope p can move out.
>  	 */
>  	if (rq->curr->nr_cpus_allowed == 1 ||
> -	    cpudl_find(&rq->rd->cpudl, rq->curr, later_mask, 0) == -1)
> +	    !cpudl_find(&rq->rd->cpudl, rq->curr, later_mask, 0))
>  		return;
>  
>  	/*
> @@ -984,7 +984,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
>  	 * see if it is pushed or pulled somewhere else.
>  	 */
>  	if (p->nr_cpus_allowed != 1 &&
> -	    cpudl_find(&rq->rd->cpudl, p, later_mask, 0) != -1)
> +	    cpudl_find(&rq->rd->cpudl, p, later_mask, 0))
>  		return;
>  
>  	resched_curr(rq);
> @@ -1189,9 +1189,7 @@ static int find_later_rq(struct task_struct *task)
>  	 * We have to consider system topology and task affinity
>  	 * first, then we can look for a suitable cpu.
>  	 */
> -	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
> -			task, later_mask, 1);
> -	if (best_cpu == -1)
> +	if (!cpudl_find(&task_rq(task)->rd->cpudl, task, later_mask, 1))
>  		return -1;
>  
>  	/*
> @@ -1230,12 +1228,9 @@ static int find_later_rq(struct task_struct *task)
>  				return this_cpu;
>  			}
>  
> -			/*
> -			 * Last chance: if best_cpu is valid and is
> -			 * in the mask, that becomes our choice.
> -			 */
> -			if (best_cpu < nr_cpu_ids &&
> -			    cpumask_test_cpu(best_cpu, sched_domain_span(sd))) {
> +			best_cpu = cpumask_first_and(lowest_mask,
> +						sched_domain_span(sd));

Sometimes that 80 character rule isn't the best for readability. But
that is Peter's or Juri's call.

> +			if (best_cpu < nr_cpu_ids) {

The warning should probably go here.

-- Steve

>  				rcu_read_unlock();
>  				return best_cpu;
>  			}


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

* Re: [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span
  2014-11-19 15:46 [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span pang.xunlei
                   ` (2 preceding siblings ...)
  2014-11-19 15:46 ` [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu pang.xunlei
@ 2014-11-20  9:00 ` Wanpeng Li
  3 siblings, 0 replies; 9+ messages in thread
From: Wanpeng Li @ 2014-11-20  9:00 UTC (permalink / raw)
  To: pang.xunlei, linux-kernel
  Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, Wanpeng Li

Hi,
On 11/19/14, 11:46 PM, pang.xunlei wrote:
> Currently, cpudl.free_cpus contains all cpus during init(see cpudl_init()),
> so when calling cpudl_find() we have to add rd->span cpumask(cpus_allowed is
> undependable when performing clustered scheduling using the cpuset) to avoid
> selecting the cpu outside current root domain, see find_later_rq().
>
> This patch adds cpudl_set_freecpu() to initialize cpudl.free_cpus when doing
> rq_attach_root(), so we can avoid the extra rd->span operation when calling
> cpudl_find().
>
> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>

Reviewed-by: Wanpeng Li <wanpeng.li@linux.intel.com>

I think this patch solve one problem I meet in my progress to handle dl 
task migration during cpu hotplug. 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg770579.html

Regards,
Wanpeng Li

> ---
>   kernel/sched/core.c        |    2 ++
>   kernel/sched/cpudeadline.c |   18 ++++++++++++++----
>   kernel/sched/cpudeadline.h |    1 +
>   kernel/sched/deadline.c    |    3 ---
>   4 files changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 240157c..1b417de 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5584,6 +5584,8 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd)
>   	rq->rd = rd;
>   
>   	cpumask_set_cpu(rq->cpu, rd->span);
> +	cpudl_set_freecpu(&rd->cpudl, rq->cpu);
> +
>   	if (cpumask_test_cpu(rq->cpu, cpu_active_mask))
>   		set_rq_online(rq);
>   
> diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
> index 539ca3c..c79f0d7 100644
> --- a/kernel/sched/cpudeadline.c
> +++ b/kernel/sched/cpudeadline.c
> @@ -107,7 +107,9 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
>   	int best_cpu = -1;
>   	const struct sched_dl_entity *dl_se = &p->dl;
>   
> -	if (later_mask && cpumask_and(later_mask, later_mask, cp->free_cpus)) {
> +	if (later_mask &&
> +	    cpumask_and(later_mask, cp->free_cpus, &p->cpus_allowed) &&
> +	    cpumask_and(later_mask, later_mask, cpu_active_mask)) {
>   		best_cpu = cpumask_any(later_mask);
>   		goto out;
>   	} else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
> @@ -186,6 +188,16 @@ out:
>   }
>   
>   /*
> + * cpudl_set_freecpu - Set the cpudl.free_cpus
> + * @cp: the cpudl max-heap context
> + * @cpu: rd attached cpu
> + */
> +void cpudl_set_freecpu(struct cpudl *cp, int cpu)
> +{
> +	cpumask_set_cpu(cpu, cp->free_cpus);
> +}
> +
> +/*
>    * cpudl_init - initialize the cpudl structure
>    * @cp: the cpudl max-heap context
>    */
> @@ -203,7 +215,7 @@ int cpudl_init(struct cpudl *cp)
>   	if (!cp->elements)
>   		return -ENOMEM;
>   
> -	if (!alloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) {
> +	if (!zalloc_cpumask_var(&cp->free_cpus, GFP_KERNEL)) {
>   		kfree(cp->elements);
>   		return -ENOMEM;
>   	}
> @@ -211,8 +223,6 @@ int cpudl_init(struct cpudl *cp)
>   	for_each_possible_cpu(i)
>   		cp->elements[i].idx = IDX_INVALID;
>   
> -	cpumask_setall(cp->free_cpus);
> -
>   	return 0;
>   }
>   
> diff --git a/kernel/sched/cpudeadline.h b/kernel/sched/cpudeadline.h
> index 020039b..4a10a65 100644
> --- a/kernel/sched/cpudeadline.h
> +++ b/kernel/sched/cpudeadline.h
> @@ -24,6 +24,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
>   	       struct cpumask *later_mask);
>   void cpudl_set(struct cpudl *cp, int cpu, u64 dl, int is_valid);
>   int cpudl_init(struct cpudl *cp);
> +void cpudl_set_freecpu(struct cpudl *cp, int cpu);
>   void cpudl_cleanup(struct cpudl *cp);
>   #endif /* CONFIG_SMP */
>   
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 5285332..bd83272 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1187,9 +1187,6 @@ static int find_later_rq(struct task_struct *task)
>   	 * We have to consider system topology and task affinity
>   	 * first, then we can look for a suitable cpu.
>   	 */
> -	cpumask_copy(later_mask, task_rq(task)->rd->span);
> -	cpumask_and(later_mask, later_mask, cpu_active_mask);
> -	cpumask_and(later_mask, later_mask, &task->cpus_allowed);
>   	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
>   			task, later_mask);
>   	if (best_cpu == -1)


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

* Re: [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find()
  2014-11-19 16:24   ` Steven Rostedt
@ 2014-11-20 14:58     ` pang.xunlei
  2014-11-20 15:06       ` pang.xunlei
  0 siblings, 1 reply; 9+ messages in thread
From: pang.xunlei @ 2014-11-20 14:58 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: lkml, Peter Zijlstra, Juri Lelli

On 20 November 2014 00:24, Steven Rostedt <rostedt@goodmis.org> wrote:
> On Wed, 19 Nov 2014 23:46:21 +0800
> "pang.xunlei" <pang.xunlei@linaro.org> wrote:
>
>> The call site of cpudl_find() in check_preempt_equal_dl() doesn't
>> use later_mask, so add this extra argument to distinquish the case.
>>
>> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
>> ---
>>  kernel/sched/cpudeadline.c |    6 ++++--
>>  kernel/sched/cpudeadline.h |    2 +-
>>  kernel/sched/deadline.c    |    6 +++---
>>  3 files changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
>> index c01b3aa..3047846 100644
>> --- a/kernel/sched/cpudeadline.c
>> +++ b/kernel/sched/cpudeadline.c
>> @@ -98,11 +98,12 @@ static inline int cpudl_maximum(struct cpudl *cp)
>>   * @cp: the cpudl max-heap context
>>   * @p: the task
>>   * @later_mask: a mask to fill in with the selected CPUs (not NULL)
>> + * @set_flag: indicate if later_mask should be set
>>   *
>>   * Returns: int - best CPU (heap maximum if suitable)
>>   */
>>  int cpudl_find(struct cpudl *cp, struct task_struct *p,
>> -            struct cpumask *later_mask)
>> +            struct cpumask *later_mask, int set_flag)
>
> set_flag should be a bool type.
>
>>  {
>>       int best_cpu = -1;
>>       const struct sched_dl_entity *dl_se = &p->dl;
>> @@ -114,7 +115,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
>>       } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
>>                       dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
>>               best_cpu = cpudl_maximum(cp);
>> -             cpumask_set_cpu(best_cpu, later_mask);
>> +             if (set_flag)
>> +                     cpumask_set_cpu(best_cpu, later_mask);
>
> I'm not sure this is worth it. cpumask_set_cpu() is rather efficient.
HI Steve,

Thanks for your commenting, I've rethinked this a bit.
We can do a little trick with its return value, then could avoid this
extra cpumask_set_cpu() without this extra set_flag:
1) define macros for the return values of cpudl_find(), like:
#define    CPUDL_FIND_NONE          -2  /* no available cpus */
#define    CPUDL_FIND_CPUMASK   -1  /* available cpus in later_mask */

then, with the return value >=0, means it returns the only one available cpu.

2) In the leg of "if", it can just return CPUDL_FIND_CPUMASK, as we
want to select the best_cpu in find_later_rq().
In the leg of "else if", just returns cpudl_maximum(cp), apparently
there is no need to set the later_mask, since we will definitely
select this cpu as the best_cpu in find_later_rq() .

int cpudl_find(struct cpudl *cp, struct task_struct *p,
           struct cpumask *later_mask)
{
    const struct sched_dl_entity *dl_se = &p->dl;

    cpumask_and(later_mask, &p->cpus_allowed, &p->cpus_allowed);
    if (cpumask_and(later_mask, later_mask, cp->free_cpus)) {
        return CPUDL_FIND_CPUMASK;
    } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
                dl_time_before(dl_se->deadline, cp->elements[0].dl))
        int cpu;

        cpu = cpudl_maximum(cp);
        WARN_ON(!cpu_present(cpu));
        return cpu;
    }

out:

    return CPUDL_FIND_NONE;
}

Thus, in find_later_rq() we can change the call site code like:
    best_cpu = cpudl_find(&task_rq(task)->rd->cpudl, task,
                           later_mask);
    if (best_cpu == CPUDL_FIND_NONE)
        return -1;
    if (best_cpu != CPUDL_FIND_CPUMASK)
        return best_cpu;

    /* adjust the following code as that in RT find_lowest_rq(), omit here... */

What's your view about this?

Thanks,
Xunlei
>
>>       }
>>
>>  out:
>

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

* Re: [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find()
  2014-11-20 14:58     ` pang.xunlei
@ 2014-11-20 15:06       ` pang.xunlei
  0 siblings, 0 replies; 9+ messages in thread
From: pang.xunlei @ 2014-11-20 15:06 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: lkml, Peter Zijlstra, Juri Lelli

On 20 November 2014 22:58, pang.xunlei <pang.xunlei@linaro.org> wrote:
> On 20 November 2014 00:24, Steven Rostedt <rostedt@goodmis.org> wrote:
>> On Wed, 19 Nov 2014 23:46:21 +0800
>> "pang.xunlei" <pang.xunlei@linaro.org> wrote:
>>
>>> The call site of cpudl_find() in check_preempt_equal_dl() doesn't
>>> use later_mask, so add this extra argument to distinquish the case.
>>>
>>> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
>>> ---
>>>  kernel/sched/cpudeadline.c |    6 ++++--
>>>  kernel/sched/cpudeadline.h |    2 +-
>>>  kernel/sched/deadline.c    |    6 +++---
>>>  3 files changed, 8 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
>>> index c01b3aa..3047846 100644
>>> --- a/kernel/sched/cpudeadline.c
>>> +++ b/kernel/sched/cpudeadline.c
>>> @@ -98,11 +98,12 @@ static inline int cpudl_maximum(struct cpudl *cp)
>>>   * @cp: the cpudl max-heap context
>>>   * @p: the task
>>>   * @later_mask: a mask to fill in with the selected CPUs (not NULL)
>>> + * @set_flag: indicate if later_mask should be set
>>>   *
>>>   * Returns: int - best CPU (heap maximum if suitable)
>>>   */
>>>  int cpudl_find(struct cpudl *cp, struct task_struct *p,
>>> -            struct cpumask *later_mask)
>>> +            struct cpumask *later_mask, int set_flag)
>>
>> set_flag should be a bool type.
>>
>>>  {
>>>       int best_cpu = -1;
>>>       const struct sched_dl_entity *dl_se = &p->dl;
>>> @@ -114,7 +115,8 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
>>>       } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
>>>                       dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
>>>               best_cpu = cpudl_maximum(cp);
>>> -             cpumask_set_cpu(best_cpu, later_mask);
>>> +             if (set_flag)
>>> +                     cpumask_set_cpu(best_cpu, later_mask);
>>
>> I'm not sure this is worth it. cpumask_set_cpu() is rather efficient.
> HI Steve,
>
> Thanks for your commenting, I've rethinked this a bit.
> We can do a little trick with its return value, then could avoid this
> extra cpumask_set_cpu() without this extra set_flag:
> 1) define macros for the return values of cpudl_find(), like:
> #define    CPUDL_FIND_NONE          -2  /* no available cpus */
> #define    CPUDL_FIND_CPUMASK   -1  /* available cpus in later_mask */
>
> then, with the return value >=0, means it returns the only one available cpu.
>
> 2) In the leg of "if", it can just return CPUDL_FIND_CPUMASK, as we
> want to select the best_cpu in find_later_rq().
> In the leg of "else if", just returns cpudl_maximum(cp), apparently
> there is no need to set the later_mask, since we will definitely
> select this cpu as the best_cpu in find_later_rq() .
>
> int cpudl_find(struct cpudl *cp, struct task_struct *p,
>            struct cpumask *later_mask)
> {
>     const struct sched_dl_entity *dl_se = &p->dl;
>
>     cpumask_and(later_mask, &p->cpus_allowed, &p->cpus_allowed);
Apologies for this typo, it should be:
cpumask_and(later_mask, cpu_active_mask, &p->cpus_allowed);

>     if (cpumask_and(later_mask, later_mask, cp->free_cpus)) {
>         return CPUDL_FIND_CPUMASK;
>     } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
>                 dl_time_before(dl_se->deadline, cp->elements[0].dl))
>         int cpu;
>
>         cpu = cpudl_maximum(cp);
>         WARN_ON(!cpu_present(cpu));
>         return cpu;
>     }
>
> out:
also delete this lable.
>
>     return CPUDL_FIND_NONE;
> }
>
> Thus, in find_later_rq() we can change the call site code like:
>     best_cpu = cpudl_find(&task_rq(task)->rd->cpudl, task,
>                            later_mask);
>     if (best_cpu == CPUDL_FIND_NONE)
>         return -1;
>     if (best_cpu != CPUDL_FIND_CPUMASK)
>         return best_cpu;
>
>     /* adjust the following code as that in RT find_lowest_rq(), omit here... */
>
> What's your view about this?
>
> Thanks,
> Xunlei
>>
>>>       }
>>>
>>>  out:
>>

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

end of thread, other threads:[~2014-11-20 15:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-19 15:46 [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span pang.xunlei
2014-11-19 15:46 ` [PATCH v2 2/4] sched/deadline: Fix wrong cpudl_find() in check_preempt_equal_dl() pang.xunlei
2014-11-19 15:46 ` [PATCH v2 3/4] sched/deadline: add the "set_flag" argument to cpudl_find() pang.xunlei
2014-11-19 16:24   ` Steven Rostedt
2014-11-20 14:58     ` pang.xunlei
2014-11-20 15:06       ` pang.xunlei
2014-11-19 15:46 ` [PATCH v2 4/4] sched/deadline: change cpudl_find() to return bool instead of best_cpu pang.xunlei
2014-11-19 16:30   ` Steven Rostedt
2014-11-20  9:00 ` [PATCH v2 1/4] sched/deadline: Modify cpudl.free_cpus to reflect rd->span Wanpeng Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.