Re: [PATCH v2] sched: Accelerate "pick_next_entity" under special condition
From: Xiaotian Feng
Date: Mon Jan 16 2012 - 21:58:17 EST
On Tue, Jan 17, 2012 at 10:36 AM, Michael Wang
<wangyun@xxxxxxxxxxxxxxxxxx> wrote:
> From: wangyun <wangyun@xxxxxxxxxxxxxxxxxx>
>
> 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?
>
> v2:
> Â Â Â Â1. do not use ugly macro any more.
> Â Â Â Â2. add more description.
>
> Signed-off-by: Michael Wang <wangyun@xxxxxxxxxxxxxxxxxx>
> ---
> Â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@xxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/