public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* question about schedule_timeout
@ 2010-12-15 11:58 Julia Lawall
  2010-12-15 12:48 ` Matthew Wilcox
  2010-12-15 13:01 ` Julia Lawall
  0 siblings, 2 replies; 3+ messages in thread
From: Julia Lawall @ 2010-12-15 11:58 UTC (permalink / raw)
  To: kernel-janitors

I am wondering about the interaction between schedule_timeout and 
functions like local_irq_save, that turn off interrupts.  To my 
understanding, with schedule_timeout one sleeps until a timer interrupt is 
received.  But how can that be received if interrupts have been turned 
off?  I find this mostly in older code, but there are still some 
occurrences, and even in older code, I'm not sure to understand how it 
could have worked.

thanks,
julia

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

* Re: question about schedule_timeout
  2010-12-15 11:58 question about schedule_timeout Julia Lawall
@ 2010-12-15 12:48 ` Matthew Wilcox
  2010-12-15 13:01 ` Julia Lawall
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2010-12-15 12:48 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Dec 15, 2010 at 12:58:49PM +0100, Julia Lawall wrote:
> I am wondering about the interaction between schedule_timeout and 
> functions like local_irq_save, that turn off interrupts.  To my 
> understanding, with schedule_timeout one sleeps until a timer interrupt is 
> received.  But how can that be received if interrupts have been turned 
> off?  I find this mostly in older code, but there are still some 
> occurrences, and even in older code, I'm not sure to understand how it 
> could have worked.

My memory was that interrupts were reenabled when you called schedule(),
then restored when schedule() returned to you.  That turns out not to
be true today, and I don't know whether it was ever true.

What actually happens is this:

asmlinkage void __sched schedule(void)
{
...
        preempt_disable();
...
        raw_spin_lock_irq(&rq->lock);
...
                raw_spin_unlock_irq(&rq->lock);
...
        preempt_enable_no_resched();
}

(there are two paths which lead to the rq->lock being dropped, the other one
is slightly more complex than this).

So in plain english, if you call schedule(), or schedule_timeout(),
when it returns interrupts will be enabled.  It's almost certainly
a bug, and it'd be good to put a test for it in schedule(), possibly
under DEBUG_SPINLOCK_SLEEP.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

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

* Re: question about schedule_timeout
  2010-12-15 11:58 question about schedule_timeout Julia Lawall
  2010-12-15 12:48 ` Matthew Wilcox
@ 2010-12-15 13:01 ` Julia Lawall
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2010-12-15 13:01 UTC (permalink / raw)
  To: kernel-janitors

On Wed, 15 Dec 2010, Matthew Wilcox wrote:

> On Wed, Dec 15, 2010 at 12:58:49PM +0100, Julia Lawall wrote:
> > I am wondering about the interaction between schedule_timeout and 
> > functions like local_irq_save, that turn off interrupts.  To my 
> > understanding, with schedule_timeout one sleeps until a timer interrupt is 
> > received.  But how can that be received if interrupts have been turned 
> > off?  I find this mostly in older code, but there are still some 
> > occurrences, and even in older code, I'm not sure to understand how it 
> > could have worked.
> 
> My memory was that interrupts were reenabled when you called schedule(),
> then restored when schedule() returned to you.  That turns out not to
> be true today, and I don't know whether it was ever true.
> 
> What actually happens is this:
> 
> asmlinkage void __sched schedule(void)
> {
> ...
>         preempt_disable();
> ...
>         raw_spin_lock_irq(&rq->lock);
> ...
>                 raw_spin_unlock_irq(&rq->lock);
> ...
>         preempt_enable_no_resched();
> }
> 
> (there are two paths which lead to the rq->lock being dropped, the other one
> is slightly more complex than this).
> 
> So in plain english, if you call schedule(), or schedule_timeout(),
> when it returns interrupts will be enabled.  It's almost certainly
> a bug, and it'd be good to put a test for it in schedule(), possibly
> under DEBUG_SPINLOCK_SLEEP.

Very helpful.  Thanks!

julia

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

end of thread, other threads:[~2010-12-15 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-15 11:58 question about schedule_timeout Julia Lawall
2010-12-15 12:48 ` Matthew Wilcox
2010-12-15 13:01 ` Julia Lawall

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