diff mbox

[v2,5/6] sched/dl: Optimize select_task_rq_dl() for non-DL curr task

Message ID 1415099585-31174-5-git-send-email-pang.xunlei@linaro.org
State New
Headers show

Commit Message

pang.xunlei Nov. 4, 2014, 11:13 a.m. UTC
When selecting the cpu for a waking DL task, if curr is a non-DL
task which is bound only on this cpu, then we can give it a chance
to select a different cpu for this DL task to avoid curr starving.

Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
---
 kernel/sched/deadline.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Wanpeng Li Nov. 4, 2014, 11:24 a.m. UTC | #1
On 14/11/4 下午7:13, pang.xunlei wrote:
> When selecting the cpu for a waking DL task, if curr is a non-DL
> task which is bound only on this cpu, then we can give it a chance
> to select a different cpu for this DL task to avoid curr starving.
>
> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
> ---
>   kernel/sched/deadline.c |   14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 7b0b2d2..1f64d4a 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>   	struct task_struct *curr;
>   	struct rq *rq;
>   
> +	if (p->nr_cpus_allowed == 1)
> +		goto out;
> +
>   	if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
>   		goto out;

I don't think you use right branch of tip tree.

Regards,
Wanpeng Li

>   
> @@ -970,11 +973,14 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>   	 * can!) we prefer to send it somewhere else. On the
>   	 * other hand, if it has a shorter deadline, we
>   	 * try to make it stay here, it might be important.
> +	 *
> +	 * If the current task on @p's runqueue is a non-DL task,
> +	 * and this task is bound on current runqueue, then try to
> +	 * see if we can wake this DL task up on a different runqueue,
>   	 */
> -	if (unlikely(dl_task(curr)) &&
> -	    (curr->nr_cpus_allowed < 2 ||
> -	     !dl_entity_preempt(&p->dl, &curr->dl)) &&
> -	    (p->nr_cpus_allowed > 1)) {
> +	if (unlikely(curr->nr_cpus_allowed < 2) ||
> +		unlikely(dl_task(curr) &&
> +				!dl_entity_preempt(&p->dl, &curr->dl))) {
>   		int target = find_later_rq(p);
>   
>   		if (target != -1)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
pang.xunlei Nov. 4, 2014, 2:19 p.m. UTC | #2
On 4 November 2014 19:24, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> On 14/11/4 下午7:13, pang.xunlei wrote:
>>
>> When selecting the cpu for a waking DL task, if curr is a non-DL
>> task which is bound only on this cpu, then we can give it a chance
>> to select a different cpu for this DL task to avoid curr starving.
>>
>> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
>> ---
>>   kernel/sched/deadline.c |   14 ++++++++++----
>>   1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
>> index 7b0b2d2..1f64d4a 100644
>> --- a/kernel/sched/deadline.c
>> +++ b/kernel/sched/deadline.c
>> @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int
>> sd_flag, int flags)
>>         struct task_struct *curr;
>>         struct rq *rq;
>>   +     if (p->nr_cpus_allowed == 1)
>> +               goto out;
>> +
>>         if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
>>                 goto out;
>
>
> I don't think you use right branch of tip tree.
Hi Wanpeng, I'm using linux-3.18-rc3 as the base, does this have
something wrong? please point me out if any.
Thanks!
>
> Regards,
> Wanpeng Li
>
>>   @@ -970,11 +973,14 @@ select_task_rq_dl(struct task_struct *p, int cpu,
>> int sd_flag, int flags)
>>          * can!) we prefer to send it somewhere else. On the
>>          * other hand, if it has a shorter deadline, we
>>          * try to make it stay here, it might be important.
>> +        *
>> +        * If the current task on @p's runqueue is a non-DL task,
>> +        * and this task is bound on current runqueue, then try to
>> +        * see if we can wake this DL task up on a different runqueue,
>>          */
>> -       if (unlikely(dl_task(curr)) &&
>> -           (curr->nr_cpus_allowed < 2 ||
>> -            !dl_entity_preempt(&p->dl, &curr->dl)) &&
>> -           (p->nr_cpus_allowed > 1)) {
>> +       if (unlikely(curr->nr_cpus_allowed < 2) ||
>> +               unlikely(dl_task(curr) &&
>> +                               !dl_entity_preempt(&p->dl, &curr->dl))) {
>>                 int target = find_later_rq(p);
>>                 if (target != -1)
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Steven Rostedt Nov. 4, 2014, 2:45 p.m. UTC | #3
On Tue,  4 Nov 2014 19:13:04 +0800
"pang.xunlei" <pang.xunlei@linaro.org> wrote:

> When selecting the cpu for a waking DL task, if curr is a non-DL
> task which is bound only on this cpu, then we can give it a chance
> to select a different cpu for this DL task to avoid curr starving.
> 
> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
> ---
>  kernel/sched/deadline.c |   14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 7b0b2d2..1f64d4a 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>  	struct task_struct *curr;
>  	struct rq *rq;
>  
> +	if (p->nr_cpus_allowed == 1)
> +		goto out;
> +

This looks fine, and I'm wondering if we shouldn't just move this into
kernel/sched/core.c: select_task_rq(). Why bother calling the select_rq
code if the task is pinned?

This change will make fair.c, rt.c, and deadline.c all start with the
same logic. If this should be an optimization, just move it to core.c
and be done with it.


>  	if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
>  		goto out;
>  
> @@ -970,11 +973,14 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>  	 * can!) we prefer to send it somewhere else. On the
>  	 * other hand, if it has a shorter deadline, we
>  	 * try to make it stay here, it might be important.
> +	 *
> +	 * If the current task on @p's runqueue is a non-DL task,
> +	 * and this task is bound on current runqueue, then try to
> +	 * see if we can wake this DL task up on a different runqueue,
>  	 */
> -	if (unlikely(dl_task(curr)) &&
> -	    (curr->nr_cpus_allowed < 2 ||
> -	     !dl_entity_preempt(&p->dl, &curr->dl)) &&
> -	    (p->nr_cpus_allowed > 1)) {
> +	if (unlikely(curr->nr_cpus_allowed < 2) ||
> +		unlikely(dl_task(curr) &&
> +				!dl_entity_preempt(&p->dl, &curr->dl))) {

This has the same issue as the rt.c change.

-- Steve

>  		int target = find_later_rq(p);
>  
>  		if (target != -1)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Peter Zijlstra Nov. 4, 2014, 3:11 p.m. UTC | #4
On Tue, Nov 04, 2014 at 09:45:49AM -0500, Steven Rostedt wrote:
> > +++ b/kernel/sched/deadline.c
> > @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
> >  	struct task_struct *curr;
> >  	struct rq *rq;
> >  
> > +	if (p->nr_cpus_allowed == 1)
> > +		goto out;
> > +
> 
> This looks fine, and I'm wondering if we shouldn't just move this into
> kernel/sched/core.c: select_task_rq(). Why bother calling the select_rq
> code if the task is pinned?
> 
> This change will make fair.c, rt.c, and deadline.c all start with the
> same logic. If this should be an optimization, just move it to core.c
> and be done with it.

Yeah, that makes sense. Back when, in the olden days, nr_cpus_allowed
was specific to the rt class, but we fixed that.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Wanpeng Li Nov. 4, 2014, 11:30 p.m. UTC | #5
Hi Xunlei,

On 14/11/4 下午10:19, pang.xunlei wrote:
> On 4 November 2014 19:24, Wanpeng Li <kernellwp@gmail.com> wrote:
>> On 14/11/4 下午7:13, pang.xunlei wrote:
>>> When selecting the cpu for a waking DL task, if curr is a non-DL
>>> task which is bound only on this cpu, then we can give it a chance
>>> to select a different cpu for this DL task to avoid curr starving.
>>>
>>> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
>>> ---
>>>    kernel/sched/deadline.c |   14 ++++++++++----
>>>    1 file changed, 10 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
>>> index 7b0b2d2..1f64d4a 100644
>>> --- a/kernel/sched/deadline.c
>>> +++ b/kernel/sched/deadline.c
>>> @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int
>>> sd_flag, int flags)
>>>          struct task_struct *curr;
>>>          struct rq *rq;
>>>    +     if (p->nr_cpus_allowed == 1)
>>> +               goto out;
>>> +
>>>          if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
>>>                  goto out;
>>
>> I don't think you use right branch of tip tree.
> Hi Wanpeng, I'm using linux-3.18-rc3 as the base, does this have
> something wrong? please point me out if any.

I have already do this, my patch merged in tip tree, you can check it.

Regards,
Wanpeng Li

> Thanks!
>> Regards,
>> Wanpeng Li
>>
>>>    @@ -970,11 +973,14 @@ select_task_rq_dl(struct task_struct *p, int cpu,
>>> int sd_flag, int flags)
>>>           * can!) we prefer to send it somewhere else. On the
>>>           * other hand, if it has a shorter deadline, we
>>>           * try to make it stay here, it might be important.
>>> +        *
>>> +        * If the current task on @p's runqueue is a non-DL task,
>>> +        * and this task is bound on current runqueue, then try to
>>> +        * see if we can wake this DL task up on a different runqueue,
>>>           */
>>> -       if (unlikely(dl_task(curr)) &&
>>> -           (curr->nr_cpus_allowed < 2 ||
>>> -            !dl_entity_preempt(&p->dl, &curr->dl)) &&
>>> -           (p->nr_cpus_allowed > 1)) {
>>> +       if (unlikely(curr->nr_cpus_allowed < 2) ||
>>> +               unlikely(dl_task(curr) &&
>>> +                               !dl_entity_preempt(&p->dl, &curr->dl))) {
>>>                  int target = find_later_rq(p);
>>>                  if (target != -1)
>>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Wanpeng Li Nov. 4, 2014, 11:33 p.m. UTC | #6
Hi Steven,
On 14/11/4 下午10:45, Steven Rostedt wrote:
> On Tue,  4 Nov 2014 19:13:04 +0800
> "pang.xunlei" <pang.xunlei@linaro.org> wrote:
>
>> When selecting the cpu for a waking DL task, if curr is a non-DL
>> task which is bound only on this cpu, then we can give it a chance
>> to select a different cpu for this DL task to avoid curr starving.
>>
>> Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
>> ---
>>   kernel/sched/deadline.c |   14 ++++++++++----
>>   1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
>> index 7b0b2d2..1f64d4a 100644
>> --- a/kernel/sched/deadline.c
>> +++ b/kernel/sched/deadline.c
>> @@ -954,6 +954,9 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>>   	struct task_struct *curr;
>>   	struct rq *rq;
>>   
>> +	if (p->nr_cpus_allowed == 1)
>> +		goto out;
>> +
> This looks fine, and I'm wondering if we shouldn't just move this into
> kernel/sched/core.c: select_task_rq(). Why bother calling the select_rq
> code if the task is pinned?
>
> This change will make fair.c, rt.c, and deadline.c all start with the
> same logic. If this should be an optimization, just move it to core.c
> and be done with it.

Actually I have already do this for dl class and patch merged in tip 
tree currently, maybe pang.xunlei miss it. I will send a patch to move 
them all to core.c soon.

Regards,
Wanpeng Li

>
>
>>   	if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
>>   		goto out;
>>   
>> @@ -970,11 +973,14 @@ select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
>>   	 * can!) we prefer to send it somewhere else. On the
>>   	 * other hand, if it has a shorter deadline, we
>>   	 * try to make it stay here, it might be important.
>> +	 *
>> +	 * If the current task on @p's runqueue is a non-DL task,
>> +	 * and this task is bound on current runqueue, then try to
>> +	 * see if we can wake this DL task up on a different runqueue,
>>   	 */
>> -	if (unlikely(dl_task(curr)) &&
>> -	    (curr->nr_cpus_allowed < 2 ||
>> -	     !dl_entity_preempt(&p->dl, &curr->dl)) &&
>> -	    (p->nr_cpus_allowed > 1)) {
>> +	if (unlikely(curr->nr_cpus_allowed < 2) ||
>> +		unlikely(dl_task(curr) &&
>> +				!dl_entity_preempt(&p->dl, &curr->dl))) {
> This has the same issue as the rt.c change.
>
> -- Steve
>
>>   		int target = find_later_rq(p);
>>   
>>   		if (target != -1)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 7b0b2d2..1f64d4a 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -954,6 +954,9 @@  select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
 	struct task_struct *curr;
 	struct rq *rq;
 
+	if (p->nr_cpus_allowed == 1)
+		goto out;
+
 	if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
 		goto out;
 
@@ -970,11 +973,14 @@  select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
 	 * can!) we prefer to send it somewhere else. On the
 	 * other hand, if it has a shorter deadline, we
 	 * try to make it stay here, it might be important.
+	 *
+	 * If the current task on @p's runqueue is a non-DL task,
+	 * and this task is bound on current runqueue, then try to
+	 * see if we can wake this DL task up on a different runqueue,
 	 */
-	if (unlikely(dl_task(curr)) &&
-	    (curr->nr_cpus_allowed < 2 ||
-	     !dl_entity_preempt(&p->dl, &curr->dl)) &&
-	    (p->nr_cpus_allowed > 1)) {
+	if (unlikely(curr->nr_cpus_allowed < 2) ||
+		unlikely(dl_task(curr) &&
+				!dl_entity_preempt(&p->dl, &curr->dl))) {
 		int target = find_later_rq(p);
 
 		if (target != -1)