From: Mike Galbraith <efault@gmx.de>
To: Paolo Ornati <ornati@fastwebnet.it>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Con Kolivas <kernel@kolivas.org>, Ingo Molnar <mingo@elte.hu>,
Nick Piggin <nickpiggin@yahoo.com.au>,
Peter Williams <pwil3058@bigpond.net.au>
Subject: Re: [SCHED] wrong priority calc - SIMPLE test case
Date: Tue, 10 Jan 2006 14:01:36 +0100 [thread overview]
Message-ID: <5.2.1.1.2.20060110135846.00bfd0a8@pop.gmx.net> (raw)
In-Reply-To: <20060110135617.020f82fb@localhost>
[-- Attachment #1: Type: text/plain, Size: 365 bytes --]
At 01:56 PM 1/10/2006 +0100, Paolo Ornati wrote:
>On Tue, 10 Jan 2006 13:07:33 +0100
>Mike Galbraith <efault@gmx.de> wrote:
>
> > Can you please try this version? It tries harder to correct any
>
>It seems that you have forgotten the to attach the patch...
Drat. At least I'm not the first to ever do so :)
(double checks) It's now attached.
-Mike
[-- Attachment #2: sched_throttle2 --]
[-- Type: application/octet-stream, Size: 4422 bytes --]
--- linux-2.6.15/include/linux/sched.h.org Tue Jan 3 09:26:50 2006
+++ linux-2.6.15/include/linux/sched.h Sat Jan 7 14:45:37 2006
@@ -701,8 +701,8 @@
unsigned short ioprio;
- unsigned long sleep_avg;
- unsigned long long timestamp, last_ran;
+ unsigned long sleep_avg, slice_avg;
+ unsigned long long timestamp, last_ran, last_slice;
unsigned long long sched_time; /* sched_clock time spent running */
int activated;
--- linux-2.6.15/kernel/sched.c.org Sat Jan 7 16:22:13 2006
+++ linux-2.6.15/kernel/sched.c Tue Jan 10 13:59:44 2006
@@ -127,6 +127,20 @@
(NS_TO_JIFFIES((p)->sleep_avg) * MAX_BONUS / \
MAX_SLEEP_AVG)
+/*
+ * If a task's sleep_avg strays too far from it's slice_avg, this
+ * task is using more cpu than it's sleep_avg would indicate. When
+ * such a disparity is detected, prevent additional sleep time from
+ * being added to the existing imbalance, and increase the rate at
+ * which sleep_average is consumed.
+ */
+#define SLEEP_AVG_IMBALANCE(p) \
+ ((p)->sleep_avg > (p)->slice_avg + (NS_MAX_SLEEP_AVG/10))
+
+#define CPU_PENALTY(p) \
+ (NS_TO_JIFFIES(min((p)->sleep_avg, (p)->slice_avg)) * MAX_BONUS / \
+ MAX_SLEEP_AVG)
+
#define GRANULARITY (10 * HZ / 1000 ? : 1)
#ifdef CONFIG_SMP
@@ -744,7 +758,7 @@
else
sleep_time = (unsigned long)__sleep_time;
- if (likely(sleep_time > 0)) {
+ if (likely(sleep_time > 0 && !SLEEP_AVG_IMBALANCE(p))) {
/*
* User tasks that sleep a long time are categorised as
* idle and will get just interactive status to stay active &
@@ -1353,7 +1367,7 @@
out_activate:
#endif /* CONFIG_SMP */
- if (old_state == TASK_UNINTERRUPTIBLE) {
+ if (old_state & TASK_UNINTERRUPTIBLE) {
rq->nr_uninterruptible--;
/*
* Tasks on involuntary sleep don't earn
@@ -1368,7 +1382,7 @@
* sleep is handled in a priority-neutral manner, no priority
* boost and no penalty.)
*/
- if (old_state & TASK_NONINTERACTIVE)
+ if (old_state & TASK_NONINTERACTIVE || SLEEP_AVG_IMBALANCE(p))
__activate_task(p, rq);
else
activate_task(p, rq, cpu == this_cpu);
@@ -1492,6 +1506,8 @@
*/
p->sleep_avg = JIFFIES_TO_NS(CURRENT_BONUS(p) *
CHILD_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS);
+ p->slice_avg = NS_MAX_SLEEP_AVG;
+ p->last_slice = sched_clock();
p->prio = effective_prio(p);
@@ -2679,6 +2695,7 @@
if ((p->policy == SCHED_RR) && !--p->time_slice) {
p->time_slice = task_timeslice(p);
p->first_time_slice = 0;
+ p->last_slice = now;
set_tsk_need_resched(p);
/* put it at the end of the queue: */
@@ -2687,12 +2704,33 @@
goto out_unlock;
}
if (!--p->time_slice) {
+ unsigned long long nsecs = now - p->last_slice;
+ unsigned long idle, ticks;
+ int w = 10;
+
dequeue_task(p, rq->active);
set_tsk_need_resched(p);
p->prio = effective_prio(p);
p->time_slice = task_timeslice(p);
p->first_time_slice = 0;
+ if (nsecs > ~0UL)
+ nsecs = ~0UL;
+ ticks = NS_TO_JIFFIES((unsigned long) nsecs);
+ if (ticks < p->time_slice)
+ ticks = p->time_slice;
+ idle = 100 - (100 * p->time_slice / ticks);
+ p->slice_avg /= NS_MAX_SLEEP_AVG / 100;
+ /*
+ * If the task is lowering it's cpu usage, speed up the
+ * effect on slice_avg so we don't over throttle.
+ */
+ if (idle > p->slice_avg + 10)
+ w -= (100 * p->slice_avg / idle) / 10;
+ p->slice_avg = (w * p->slice_avg + idle) / (w + 1);
+ p->slice_avg *= NS_MAX_SLEEP_AVG / 100;
+ p->last_slice = now;
+
if (!rq->expired_timestamp)
rq->expired_timestamp = jiffies;
if (!TASK_INTERACTIVE(p) || EXPIRED_STARVING(rq)) {
@@ -2996,7 +3034,7 @@
* Tasks charged proportionately less run_time at high sleep_avg to
* delay them losing their interactive status
*/
- run_time /= (CURRENT_BONUS(prev) ? : 1);
+ run_time /= (CPU_PENALTY(prev) ? : 1);
spin_lock_irq(&rq->lock);
@@ -3010,7 +3048,7 @@
unlikely(signal_pending(prev))))
prev->state = TASK_RUNNING;
else {
- if (prev->state == TASK_UNINTERRUPTIBLE)
+ if (prev->state & TASK_UNINTERRUPTIBLE)
rq->nr_uninterruptible++;
deactivate_task(prev, rq);
}
@@ -3095,6 +3133,12 @@
prev->sleep_avg -= run_time;
if ((long)prev->sleep_avg <= 0)
prev->sleep_avg = 0;
+ /*
+ * Enable detection of the beginning of a slice at tick time.
+ */
+ if (!rt_task(next) && !(next->time_slice % DEF_TIMESLICE))
+ next->last_slice = now;
+
prev->timestamp = prev->last_ran = now;
sched_info_switch(prev, next);
next prev parent reply other threads:[~2006-01-10 13:01 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-27 18:09 [SCHED] Totally WRONG prority calculation with specific test-case (since 2.6.10-bk12) Paolo Ornati
2005-12-27 21:48 ` Paolo Ornati
2005-12-27 23:26 ` Con Kolivas
2005-12-28 11:01 ` Paolo Ornati
2005-12-28 11:19 ` Con Kolivas
2005-12-28 11:35 ` Paolo Ornati
2005-12-28 17:23 ` Paolo Ornati
2005-12-28 17:39 ` Paolo Ornati
2005-12-30 13:52 ` [SCHED] wrong priority calc - SIMPLE test case Paolo Ornati
2005-12-31 2:06 ` Peter Williams
2005-12-31 10:34 ` Paolo Ornati
2005-12-31 10:52 ` Paolo Ornati
2005-12-31 11:12 ` Con Kolivas
2005-12-31 13:44 ` Peter Williams
2005-12-31 16:31 ` Paolo Ornati
2005-12-31 22:04 ` Peter Williams
2005-12-31 8:13 ` Mike Galbraith
2005-12-31 11:00 ` Paolo Ornati
2005-12-31 15:11 ` Paolo Ornati
2005-12-31 16:37 ` Mike Galbraith
2005-12-31 17:24 ` Paolo Ornati
2005-12-31 17:42 ` Paolo Ornati
2006-01-01 11:39 ` Paolo Ornati
2006-01-02 9:15 ` Mike Galbraith
2006-01-02 9:50 ` Paolo Ornati
2006-01-09 11:11 ` Mike Galbraith
2006-01-09 15:52 ` Mike Galbraith
2006-01-09 16:08 ` Con Kolivas
2006-01-09 18:14 ` Mike Galbraith
2006-01-09 20:00 ` Paolo Ornati
2006-01-09 20:23 ` Paolo Ornati
2006-01-10 7:08 ` Mike Galbraith
2006-01-10 12:07 ` Mike Galbraith
2006-01-10 12:56 ` Paolo Ornati
2006-01-10 13:01 ` Mike Galbraith [this message]
2006-01-10 13:53 ` Paolo Ornati
2006-01-10 15:18 ` Mike Galbraith
2006-01-13 1:13 ` Con Kolivas
2006-01-13 1:32 ` Con Kolivas
2006-01-13 10:46 ` Paolo Ornati
2006-01-13 10:51 ` Con Kolivas
2006-01-13 13:01 ` Mike Galbraith
2006-01-13 14:34 ` Con Kolivas
2006-01-13 16:15 ` Mike Galbraith
2006-01-14 2:05 ` Con Kolivas
2006-01-14 2:56 ` Mike Galbraith
2005-12-27 23:59 ` [SCHED] Totally WRONG prority calculation with specific test-case (since 2.6.10-bk12) Peter Williams
2005-12-28 10:20 ` Paolo Ornati
2005-12-28 13:38 ` Peter Williams
2005-12-28 19:45 ` Paolo Ornati
2005-12-29 3:13 ` Nick Piggin
2005-12-29 3:35 ` Peter Williams
2005-12-29 8:11 ` Nick Piggin
2006-01-27 16:57 [SCHED] wrong priority calc - SIMPLE test case Con Kolivas
2006-01-27 20:06 ` MIke Galbraith
2006-01-27 23:18 ` Con Kolivas
2006-01-28 0:01 ` Peter Williams
2006-01-28 3:43 ` MIke Galbraith
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=5.2.1.1.2.20060110135846.00bfd0a8@pop.gmx.net \
--to=efault@gmx.de \
--cc=kernel@kolivas.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=ornati@fastwebnet.it \
--cc=pwil3058@bigpond.net.au \
/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
all inboxes | Powered by JetHome®