From: Ingo Molnar <mingo@elte.hu>
To: Chen Shang <shangcs@gmail.com>
Cc: Con Kolivas <kernel@kolivas.org>,
Nick Piggin <nickpiggin@yahoo.com.au>,
linux-kernel@vger.kernel.org, rml@tech9.net,
Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] kernel <linux-2.6.11.10> kernel/sched.c
Date: Mon, 23 May 2005 09:11:03 +0200 [thread overview]
Message-ID: <20050523071103.GA30016@elte.hu> (raw)
In-Reply-To: <855e4e460505212141105e6b43@mail.gmail.com>
* Chen Shang <shangcs@gmail.com> wrote:
> /*===== ISSUE ====*/
> My second version of patch has a defect.
>
> + if (unlikely(old_prio != next->prio)) {
> + dequeue_task(next, array); --> ### dequeue should against
> old_prio, NOT next->prio ###
> + enqueue_task(next, array);
> + }
indeed...
> unforunately, dequeue_task does not accept the third parameter to make
> adjustment. Personally, I feel it's good to add extra function as my
> first version of patch to combine dequeue and enqueue together.
> Reasons as following:
> 1) adding the third parameter to dequeue_task() would cause other
> places' code change;
> 2) for schedule functions, performance is the first consideration.
> Notice both dequeue_task() and enqueue_task() are NOT inline.
> Combining those two in one saves one function call overhead;
the real problem comes from recalc_task_prio() having a side-effect,
which makes requeueing of tasks harder. The solution is to return the
prio from recalc_task_prio() - see the tested patch below. Agreed?
Ingo
--
micro-optimize task requeueing in schedule() & clean up
recalc_task_prio().
From: Chen Shang <shangcs@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
--- linux/kernel/sched.c.orig
+++ linux/kernel/sched.c
@@ -675,7 +675,7 @@ static inline void __activate_idle_task(
rq->nr_running++;
}
-static void recalc_task_prio(task_t *p, unsigned long long now)
+static int recalc_task_prio(task_t *p, unsigned long long now)
{
/* Caller must always ensure 'now >= p->timestamp' */
unsigned long long __sleep_time = now - p->timestamp;
@@ -734,7 +734,7 @@ static void recalc_task_prio(task_t *p,
}
}
- p->prio = effective_prio(p);
+ return effective_prio(p);
}
/*
@@ -757,7 +757,7 @@ static void activate_task(task_t *p, run
}
#endif
- recalc_task_prio(p, now);
+ p->prio = recalc_task_prio(p, now);
/*
* This checks to make sure it's not an uninterruptible task
@@ -2751,7 +2751,7 @@ asmlinkage void __sched schedule(void)
struct list_head *queue;
unsigned long long now;
unsigned long run_time;
- int cpu, idx;
+ int cpu, idx, new_prio;
/*
* Test if we are atomic. Since do_exit() needs to call into
@@ -2873,9 +2873,14 @@ go_idle:
delta = delta * (ON_RUNQUEUE_WEIGHT * 128 / 100) / 128;
array = next->array;
- dequeue_task(next, array);
- recalc_task_prio(next, next->timestamp + delta);
- enqueue_task(next, array);
+ new_prio = recalc_task_prio(next, next->timestamp + delta);
+
+ if (unlikely(next->prio != new_prio)) {
+ dequeue_task(next, array);
+ next->prio = new_prio;
+ enqueue_task(next, array);
+ } else
+ requeue_task(next, array);
}
next->activated = 0;
switch_tasks:
next prev parent reply other threads:[~2005-05-23 7:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-19 16:56 [PATCH] kernel <linux-2.6.11.10> kernel/sched.c chen Shang
2005-05-20 3:26 ` Nick Piggin
2005-05-20 4:17 ` chen Shang
2005-05-20 4:32 ` Lee Revell
2005-05-20 5:13 ` Nick Piggin
2005-05-20 7:12 ` chen Shang
2005-05-20 7:21 ` Nick Piggin
2005-05-20 7:36 ` Con Kolivas
2005-05-20 13:41 ` chen Shang
2005-05-20 9:49 ` Ingo Molnar
2005-05-20 10:40 ` Con Kolivas
2005-05-20 11:34 ` Ingo Molnar
2005-05-22 4:41 ` Chen Shang
2005-05-23 7:11 ` Ingo Molnar [this message]
2005-05-23 14:45 ` Chen Shang
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=20050523071103.GA30016@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@osdl.org \
--cc=kernel@kolivas.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
--cc=rml@tech9.net \
--cc=shangcs@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