public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Scheduler RR, first time slice wrong?
@ 2008-11-06  7:22 Andreas Huber
  2008-11-06  7:44 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Huber @ 2008-11-06  7:22 UTC (permalink / raw)
  To: linux-kernel

Hi,

when starting a real-time process with the round-robin scheduler, the
first time slice is set to HZ (1 second).
When starting two such processes at the same time of the same static
priority, the second one started is first executed after 1 second.
(supposing the first process is heavy on cpu load).
After both have exhausted this first time slice, it is set to
DEF_TIMESLICE (which is 100ms).

Is this behavior as it is supposed to be?

Please add me in CC.

Regards,
Andreas


Relevant parts in the code:
include/linux/init_task.h
#define INIT_TASK(tsk) \
	.rt	= { \
		.time_slice = HZ,

kernel/sched.c
#define DEF_TIMESLICE   (100 * HZ / 1000)

kernel/sched_rt.c
static void task_tick_rt(struct rq *rq, struct task_struct *p, int
queued)
  if (--p->rt.time_slice)
    return;

  p->rt.time_slice = DEF_TIMESLICE;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Scheduler RR, first time slice wrong?
  2008-11-06  7:22 Scheduler RR, first time slice wrong? Andreas Huber
@ 2008-11-06  7:44 ` Ingo Molnar
  2008-11-06  8:46   ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2008-11-06  7:44 UTC (permalink / raw)
  To: Andreas Huber
  Cc: linux-kernel, Peter Zijlstra, Mike Galbraith, Dmitry Adamushko


(added Cc:s)

* Andreas Huber <andreas.huber@keymile.com> wrote:

> Hi,
> 
> when starting a real-time process with the round-robin scheduler, the
> first time slice is set to HZ (1 second).
> When starting two such processes at the same time of the same static
> priority, the second one started is first executed after 1 second.
> (supposing the first process is heavy on cpu load).
> After both have exhausted this first time slice, it is set to
> DEF_TIMESLICE (which is 100ms).
> 
> Is this behavior as it is supposed to be?
> 
> Please add me in CC.
> 
> Regards,
> Andreas
> 
> 
> Relevant parts in the code:
> include/linux/init_task.h
> #define INIT_TASK(tsk) \
> 	.rt	= { \
> 		.time_slice = HZ,
> 
> kernel/sched.c
> #define DEF_TIMESLICE   (100 * HZ / 1000)
> 
> kernel/sched_rt.c
> static void task_tick_rt(struct rq *rq, struct task_struct *p, int
> queued)
>   if (--p->rt.time_slice)
>     return;
> 
>   p->rt.time_slice = DEF_TIMESLICE;
> 
> --
> 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Scheduler RR, first time slice wrong?
  2008-11-06  7:44 ` Ingo Molnar
@ 2008-11-06  8:46   ` Peter Zijlstra
  2008-11-07  9:19     ` Ingo Oeser
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2008-11-06  8:46 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andreas Huber, linux-kernel, Mike Galbraith, Dmitry Adamushko

On Thu, 2008-11-06 at 08:44 +0100, Ingo Molnar wrote:
> (added Cc:s)
> 
> * Andreas Huber <andreas.huber@keymile.com> wrote:
> 
> > Hi,
> > 
> > when starting a real-time process with the round-robin scheduler, the
> > first time slice is set to HZ (1 second).
> > When starting two such processes at the same time of the same static
> > priority, the second one started is first executed after 1 second.
> > (supposing the first process is heavy on cpu load).
> > After both have exhausted this first time slice, it is set to
> > DEF_TIMESLICE (which is 100ms).
> > 
> > Is this behavior as it is supposed to be?
> > 
> > Please add me in CC.
> > 
> > Regards,
> > Andreas
> > 
> > 
> > Relevant parts in the code:
> > include/linux/init_task.h
> > #define INIT_TASK(tsk) \
> > 	.rt	= { \
> > 		.time_slice = HZ,
> > 
> > kernel/sched.c
> > #define DEF_TIMESLICE   (100 * HZ / 1000)
> > 
> > kernel/sched_rt.c
> > static void task_tick_rt(struct rq *rq, struct task_struct *p, int
> > queued)
> >   if (--p->rt.time_slice)
> >     return;
> > 
> >   p->rt.time_slice = DEF_TIMESLICE;
> > 

How does this work?


---
Subject: sched: reset RR timeslice on fork

Currently we inherit the RR time-slice from our parent. In case that is
init we inherit the 1s value set by default, in case its an already
running RR task, we inherit whatever is left.

Fix both these by resetting the time-slice on fork.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
diff --git a/kernel/sched.c b/kernel/sched.c
index 241fd85..e7d69a0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2337,6 +2337,7 @@ static void __sched_fork(struct task_struct *p)
 #endif
 
 	INIT_LIST_HEAD(&p->rt.run_list);
+	p->rt.time_slice = DEF_TIMESLICE;
 	p->se.on_rq = 0;
 	INIT_LIST_HEAD(&p->se.group_node);
 



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Scheduler RR, first time slice wrong?
  2008-11-06  8:46   ` Peter Zijlstra
@ 2008-11-07  9:19     ` Ingo Oeser
  2008-11-07 12:31       ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Oeser @ 2008-11-07  9:19 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Andreas Huber, linux-kernel, Mike Galbraith,
	Dmitry Adamushko

Hi Peter,

On Thursday 06 November 2008, Peter Zijlstra wrote:
> Currently we inherit the RR time-slice from our parent. In case that is
> init we inherit the 1s value set by default, in case its an already
> running RR task, we inherit whatever is left.
> 
> Fix both these by resetting the time-slice on fork.

I remember that this MIGHT be on purpose to mitigate fork bombs.

Behaviour was, that you could starve others, if you fork, 
do little or no work and fork again before your timeslice is over.

But I'm not sure this applies here...


Best Regards

Ingo Oeser

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Scheduler RR, first time slice wrong?
  2008-11-07  9:19     ` Ingo Oeser
@ 2008-11-07 12:31       ` Peter Zijlstra
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2008-11-07 12:31 UTC (permalink / raw)
  To: Ingo Oeser
  Cc: Ingo Molnar, Andreas Huber, linux-kernel, Mike Galbraith,
	Dmitry Adamushko

On Fri, 2008-11-07 at 10:19 +0100, Ingo Oeser wrote:
> Hi Peter,
> 
> On Thursday 06 November 2008, Peter Zijlstra wrote:
> > Currently we inherit the RR time-slice from our parent. In case that is
> > init we inherit the 1s value set by default, in case its an already
> > running RR task, we inherit whatever is left.
> > 
> > Fix both these by resetting the time-slice on fork.
> 
> I remember that this MIGHT be on purpose to mitigate fork bombs.
> 
> Behaviour was, that you could starve others, if you fork, 
> do little or no work and fork again before your timeslice is over.
> 
> But I'm not sure this applies here...

Right, RT tasks have it easy starving stuff ;-)




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-07 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-06  7:22 Scheduler RR, first time slice wrong? Andreas Huber
2008-11-06  7:44 ` Ingo Molnar
2008-11-06  8:46   ` Peter Zijlstra
2008-11-07  9:19     ` Ingo Oeser
2008-11-07 12:31       ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox