linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Wang <wangyun@linux.vnet.ibm.com>
To: Xiaotian Feng <xtfeng@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] sched: Accelerate "pick_next_entity" under special condition
Date: Tue, 17 Jan 2012 11:04:46 +0800	[thread overview]
Message-ID: <4F14E54E.80904@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAJn8CcHhaSA5kF9KVjMorzt_2NM-dTPc5mTr3-A9GvR54VRo=A@mail.gmail.com>

On 01/17/2012 10:58 AM, Xiaotian Feng wrote:

> On Tue, Jan 17, 2012 at 10:36 AM, Michael Wang
> <wangyun@linux.vnet.ibm.com> wrote:
>> From: wangyun <wangyun@linux.vnet.ibm.com>
>>
>> In original code, we get the next entity in this way:
>>
>>        if(condition1)
>>                result=value1;
>>        if(condition2)
>>                result=value2;
>>        if(condition3)
>>                result=value3;
>>        return result;
>>
>> So if condition3 is true, we will get value3, but still
>> need to check condition1 and condition2, this will waste
>> our time.
>>
>> This patch will change the way like:
>>
>>        if(condition3) {
>>                result=value3;
>>                goto out;
>>        }
>>        if(condition2) {
>>                result=value2;
>>                goto out;
>>        }
>>        if(condition1) {
>>                result=value1;
>>                goto out;
>>        }
>>
>>        out:
>>        return result;
>>
>> So we can avoid check condition2 and condition1 when
>> condition3 is true now.
> 
> Then what if condition 1 is true now?


Hi, Xiaotian

Thanks for your reply.

We can see in original code, even condition 1 is true, we
still will use value3 if condition3 is true, like this:

original:

condition1	condition3	result
true		true		value3
true		false		value1

That means if condition3 is true, we don't care whether
condition1 is true or not because we will finally use value3.

Regards,
Michael Wang

> 
>>
>> v2:
>>        1. do not use ugly macro any more.
>>        2. add more description.
>>
>> Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
>> ---
>>  kernel/sched/fair.c |   26 +++++++++++++++-----------
>>  1 files changed, 15 insertions(+), 11 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 84adb2d..e8a72b2 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -1308,29 +1308,33 @@ static struct sched_entity
>> *pick_next_entity(struct cfs_rq *cfs_rq)
>>        struct sched_entity *left = se;
>>
>>        /*
>> -        * Avoid running the skip buddy, if running something else can
>> -        * be done without getting too unfair.
>> +        * Someone really wants this to run. If it's not unfair, run it.
>>         */
>> -       if (cfs_rq->skip == se) {
>> -               struct sched_entity *second = __pick_next_entity(se);
>> -               if (second && wakeup_preempt_entity(second, left) < 1)
>> -                       se = second;
>> +       if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
>> +               se = cfs_rq->next;
>> +               goto out;
>>        }
>>
>>        /*
>>         * Prefer last buddy, try to return the CPU to a preempted task.
>>         */
>> -       if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
>> +       if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
>>                se = cfs_rq->last;
>> +               goto out;
>> +       }
>>
>>        /*
>> -        * Someone really wants this to run. If it's not unfair, run it.
>> +        * Avoid running the skip buddy, if running something else can
>> +        * be done without getting too unfair.
>>         */
>> -       if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
>> -               se = cfs_rq->next;
>> +       if (cfs_rq->skip == se) {
>> +               struct sched_entity *second = __pick_next_entity(se);
>> +               if (second && wakeup_preempt_entity(second, left) < 1)
>> +                       se = second;
>> +       }
>>
>> +out:
>>        clear_buddies(cfs_rq, se);
>> -
>>        return se;
>>  }
>>
>> --
>> 1.7.4.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/
> 



  reply	other threads:[~2012-01-17  3:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-16  9:37 [PATCH] sched: Accelerate "pick_next_entity" under special condition Michael Wang
2012-01-16  9:50 ` Michael Wang
2012-01-16  9:51 ` Peter Zijlstra
2012-01-16 10:34   ` Michael Wang
2012-01-17  2:36   ` [PATCH v2] " Michael Wang
2012-01-17  2:41     ` Michael Wang
2012-01-17  2:58     ` Xiaotian Feng
2012-01-17  3:04       ` Michael Wang [this message]
2012-01-25 15:55         ` Peter Zijlstra
2012-01-26 10:04           ` Ingo Molnar
2012-01-27  1:22             ` Michael Wang
2012-01-27  4:42               ` Cong Wang
2012-01-29  6:32                 ` Michael Wang
2012-01-29 16:33                   ` Ingo Molnar
2012-01-30  3:18                     ` Michael Wang
2012-01-30  3:25                       ` Cong Wang
2012-01-30  5:47                         ` Michael Wang
2012-07-03  6:34                           ` [PATCH] sched: remove useless code in yield_to Michael Wang
2012-07-12  5:45                             ` Michael Wang
2012-07-12 14:07                             ` Peter Zijlstra
2012-07-12 18:44                               ` Mike Galbraith
2012-07-16  2:39                               ` Michael Wang
2012-08-17  6:56                               ` Michael Wang
2012-08-17  9:43                                 ` Peter Zijlstra
2012-08-10  3:05                             ` Michael Wang
2012-08-10  3:10                               ` Michael Wang
2012-08-10  5:52                                 ` Mike Galbraith
2012-09-04 18:50                             ` [tip:sched/core] sched: Remove useless code in yield_to() tip-bot for Michael Wang
2012-01-27  0:56           ` [PATCH v2] sched: Accelerate "pick_next_entity" under special condition Michael Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F14E54E.80904@linux.vnet.ibm.com \
    --to=wangyun@linux.vnet.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=xtfeng@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).