* question on spinlocks
@ 2002-09-01 17:27 Oliver Neukum
2002-09-01 19:05 ` Ralf Baechle
0 siblings, 1 reply; 13+ messages in thread
From: Oliver Neukum @ 2002-09-01 17:27 UTC (permalink / raw)
To: linux-kernel
Hi,
is the following sequence legal ?
spin_lock_irqsave(...);
...
spin_unlock(...);
schedule();
spin_lock(...);
...
spin_unlock_irqrestore(...);
TIA
Oliver
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 17:27 question on spinlocks Oliver Neukum
@ 2002-09-01 19:05 ` Ralf Baechle
2002-09-01 21:53 ` Thunder from the hill
0 siblings, 1 reply; 13+ messages in thread
From: Ralf Baechle @ 2002-09-01 19:05 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-kernel
On Sun, Sep 01, 2002 at 07:27:53PM +0200, Oliver Neukum wrote:
> is the following sequence legal ?
>
> spin_lock_irqsave(...);
> ...
> spin_unlock(...);
> schedule();
> spin_lock(...);
> ...
> spin_unlock_irqrestore(...);
No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
have to be used in matching pairs.
Ralf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 19:05 ` Ralf Baechle
@ 2002-09-01 21:53 ` Thunder from the hill
2002-09-01 22:02 ` Oliver Neukum
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Thunder from the hill @ 2002-09-01 21:53 UTC (permalink / raw)
To: Ralf Baechle; +Cc: Oliver Neukum, linux-kernel
Hi,
On Sun, 1 Sep 2002, Ralf Baechle wrote:
> On Sun, Sep 01, 2002 at 07:27:53PM +0200, Oliver Neukum wrote:
> > is the following sequence legal ?
> >
> > spin_lock_irqsave(...);
> > ...
> > spin_unlock(...);
> > schedule();
> > spin_lock(...);
> > ...
> > spin_unlock_irqrestore(...);
>
> No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
> have to be used in matching pairs.
If it was his least problem! He'll run straight into a "schedule w/IRQs
disabled" bug.
Thunder
--
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 21:53 ` Thunder from the hill
@ 2002-09-01 22:02 ` Oliver Neukum
2002-09-01 22:09 ` Thunder from the hill
2002-09-01 22:11 ` Robert Love
2002-09-01 22:08 ` Robert Love
[not found] ` <mailman.1030918200.24262.linux-kernel2news@redhat.com>
2 siblings, 2 replies; 13+ messages in thread
From: Oliver Neukum @ 2002-09-01 22:02 UTC (permalink / raw)
To: Thunder from the hill, Ralf Baechle; +Cc: linux-kernel
> > No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
> > have to be used in matching pairs.
>
> If it was his least problem! He'll run straight into a "schedule w/IRQs
> disabled" bug.
OK, how do I drop an irqsave spinlock if I don't have flags?
Regards
Oliver
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 21:53 ` Thunder from the hill
2002-09-01 22:02 ` Oliver Neukum
@ 2002-09-01 22:08 ` Robert Love
2002-09-01 22:16 ` Thunder from the hill
[not found] ` <mailman.1030918200.24262.linux-kernel2news@redhat.com>
2 siblings, 1 reply; 13+ messages in thread
From: Robert Love @ 2002-09-01 22:08 UTC (permalink / raw)
To: Thunder from the hill; +Cc: Ralf Baechle, Oliver Neukum, linux-kernel
On Sun, 2002-09-01 at 17:53, Thunder from the hill wrote:
> If it was his least problem! He'll run straight into a "schedule w/IRQs
> disabled" bug.
No, the "schedule with irqs disabled" message is on involuntary
reschedule (e.g. kernel preemption) when interrupts are disabled.
It "safe" (maybe not sane) to call schedule() with interrupts disabled -
some system calls and scheduler code do it since interrupts will be
unconditionally enabled when rescheduled or upon returning to
user-space. E.g., see sys_sched_yield().
The actual problem with the above is that when schedule() returns,
interrupts will be on and that is probably not the intention of the
author. What Oliver probably wants to do is:
spin_lock_irq(&lck);
...
spin_unlock(&lck);
schedule();
spin_lock_irq(&lck);
...
spin_unlock_irq(&lck);
The first unlock not having the irq-enable is an optimization as
described above. Also note I did not use irqsave... if there is a
chance interrupts were previously disabled and you have who-knows-what
sort of call-chain behind you, it is probably not safe to go calling
schedule() and reenabling interrupts anyhow.
Robert Love
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:02 ` Oliver Neukum
@ 2002-09-01 22:09 ` Thunder from the hill
2002-09-01 22:11 ` Robert Love
2002-09-01 22:33 ` Oliver Neukum
2002-09-01 22:11 ` Robert Love
1 sibling, 2 replies; 13+ messages in thread
From: Thunder from the hill @ 2002-09-01 22:09 UTC (permalink / raw)
To: Oliver Neukum; +Cc: Thunder from the hill, Ralf Baechle, linux-kernel
Hi,
On Mon, 2 Sep 2002, Oliver Neukum wrote:
> > > No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
> > > have to be used in matching pairs.
> >
> > If it was his least problem! He'll run straight into a "schedule w/IRQs
> > disabled" bug.
>
> OK, how do I drop an irqsave spinlock if I don't have flags?
IMHO you might even ask "How do I start a car when I don't have the keys?"
You might find a way, but it's not desired. Are you sure you want to
reschedule in an interrupt handler? If it's none, are you sure you want to
disable interrupts?
Thunder
--
--./../...-/. -.--/---/..-/.-./..././.-../..-. .---/..-/.../- .-
--/../-./..-/-/./--..-- ../.----./.-../.-.. --./../...-/. -.--/---/..-
.- -/---/--/---/.-./.-./---/.--/.-.-.-
--./.-/-.../.-./.././.-../.-.-.-
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:02 ` Oliver Neukum
2002-09-01 22:09 ` Thunder from the hill
@ 2002-09-01 22:11 ` Robert Love
1 sibling, 0 replies; 13+ messages in thread
From: Robert Love @ 2002-09-01 22:11 UTC (permalink / raw)
To: Oliver Neukum; +Cc: Thunder from the hill, Ralf Baechle, linux-kernel
On Sun, 2002-09-01 at 18:02, Oliver Neukum wrote:
>
> > > No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
> > > have to be used in matching pairs.
> >
> > If it was his least problem! He'll run straight into a "schedule w/IRQs
> > disabled" bug.
>
> OK, how do I drop an irqsave spinlock if I don't have flags?
See my previous message.
Do not do what you are trying to do. Dropping a lock and calling
schedule is fine. Ditto with the interrupt part.
But note:
- interrupts will be reenabled when you reschedule and still
enabled when your task is finally running again.
- Since interrupts are going to magically restore, if you are
worried about the state of interrupts previous to your
function... you have a problem.
OK?
Robert Love
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:09 ` Thunder from the hill
@ 2002-09-01 22:11 ` Robert Love
2002-09-01 22:33 ` Oliver Neukum
1 sibling, 0 replies; 13+ messages in thread
From: Robert Love @ 2002-09-01 22:11 UTC (permalink / raw)
To: Thunder from the hill; +Cc: Oliver Neukum, Ralf Baechle, linux-kernel
On Sun, 2002-09-01 at 18:09, Thunder from the hill wrote:
> IMHO you might even ask "How do I start a car when I don't have the keys?"
>
> You might find a way, but it's not desired. Are you sure you want to
> reschedule in an interrupt handler? If it's none, are you sure you want to
> disable interrupts?
I do not think he is in an interrupt handler.
If he were, the system would die when he called schedule().
Robert Love
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:08 ` Robert Love
@ 2002-09-01 22:16 ` Thunder from the hill
0 siblings, 0 replies; 13+ messages in thread
From: Thunder from the hill @ 2002-09-01 22:16 UTC (permalink / raw)
To: Robert Love; +Cc: Ralf Baechle, Oliver Neukum, Linux Kernel Mailing List
Hi,
On 1 Sep 2002, Robert Love wrote:
> spin_lock_irq(&lck);
> ...
> spin_unlock(&lck);
> schedule();
> spin_lock_irq(&lck);
> ...
> spin_unlock_irq(&lck);
That makes me understand his intention a lot more. I must have got beaten
up by the "irqsave".
Thunder
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:09 ` Thunder from the hill
2002-09-01 22:11 ` Robert Love
@ 2002-09-01 22:33 ` Oliver Neukum
2002-09-02 22:30 ` Jan Hudec
2002-09-03 22:13 ` george anzinger
1 sibling, 2 replies; 13+ messages in thread
From: Oliver Neukum @ 2002-09-01 22:33 UTC (permalink / raw)
To: Thunder from the hill; +Cc: Thunder from the hill, Ralf Baechle, linux-kernel
Am Montag, 2. September 2002 00:09 schrieb Thunder from the hill:
> Hi,
>
> On Mon, 2 Sep 2002, Oliver Neukum wrote:
> > > > No; spin_lock_irqsave/spin_unlock_irqrestore and
> > > > spin_lock/spin_unlock have to be used in matching pairs.
> > >
> > > If it was his least problem! He'll run straight into a "schedule
> > > w/IRQs disabled" bug.
> >
> > OK, how do I drop an irqsave spinlock if I don't have flags?
>
> IMHO you might even ask "How do I start a car when I don't have the
> keys?"
Break off the lock, touch some cables ... ;-)
> You might find a way, but it's not desired. Are you sure you want to
> reschedule in an interrupt handler? If it's none, are you sure you want
> to disable interrupts?
I am not in an interrupt handler. It's not my fault that the scsi layer
calls queuecommand with a spinlock held. But I need to sleep,
I have to get rid of that spinlock's effects. If possible I even want
interrupts to be enabled.
Regards
Oliver
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:33 ` Oliver Neukum
@ 2002-09-02 22:30 ` Jan Hudec
2002-09-03 22:13 ` george anzinger
1 sibling, 0 replies; 13+ messages in thread
From: Jan Hudec @ 2002-09-02 22:30 UTC (permalink / raw)
To: Oliver Neukum; +Cc: Thunder from the hill, Ralf Baechle, linux-kernel
On Mon, Sep 02, 2002 at 12:33:23AM +0200, Oliver Neukum wrote:
> Am Montag, 2. September 2002 00:09 schrieb Thunder from the hill:
> > Hi,
> >
> > On Mon, 2 Sep 2002, Oliver Neukum wrote:
> > > > > No; spin_lock_irqsave/spin_unlock_irqrestore and
> > > > > spin_lock/spin_unlock have to be used in matching pairs.
> > > >
> > > > If it was his least problem! He'll run straight into a "schedule
> > > > w/IRQs disabled" bug.
> > >
> > > OK, how do I drop an irqsave spinlock if I don't have flags?
> >
> > IMHO you might even ask "How do I start a car when I don't have the
> > keys?"
>
> Break off the lock, touch some cables ... ;-)
>
> > You might find a way, but it's not desired. Are you sure you want to
> > reschedule in an interrupt handler? If it's none, are you sure you want
> > to disable interrupts?
>
> I am not in an interrupt handler. It's not my fault that the scsi layer
> calls queuecommand with a spinlock held. But I need to sleep,
> I have to get rid of that spinlock's effects. If possible I even want
> interrupts to be enabled.
If it's calling it with spinlock held, it probably relies on that it
won't be sleeping. So you either have to avoid sleeping (start now,
finish in tasklet) or patch the calling code.
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
[not found] ` <mailman.1030918200.24262.linux-kernel2news@redhat.com>
@ 2002-09-03 20:09 ` Pete Zaitcev
0 siblings, 0 replies; 13+ messages in thread
From: Pete Zaitcev @ 2002-09-03 20:09 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-kernel
>> > No; spin_lock_irqsave/spin_unlock_irqrestore and spin_lock/spin_unlock
>> > have to be used in matching pairs.
>[...]
> OK, how do I drop an irqsave spinlock if I don't have flags?
It was a good thing you didn't have flags, because everything
that passes flags as arguments blows up on sparc immediately.
Most likely answer is "restructure your locking".
-- Pete
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question on spinlocks
2002-09-01 22:33 ` Oliver Neukum
2002-09-02 22:30 ` Jan Hudec
@ 2002-09-03 22:13 ` george anzinger
1 sibling, 0 replies; 13+ messages in thread
From: george anzinger @ 2002-09-03 22:13 UTC (permalink / raw)
To: Oliver Neukum; +Cc: Thunder from the hill, Ralf Baechle, linux-kernel
Oliver Neukum wrote:
>
> Am Montag, 2. September 2002 00:09 schrieb Thunder from the hill:
> > Hi,
> >
> > On Mon, 2 Sep 2002, Oliver Neukum wrote:
> > > > > No; spin_lock_irqsave/spin_unlock_irqrestore and
> > > > > spin_lock/spin_unlock have to be used in matching pairs.
> > > >
> > > > If it was his least problem! He'll run straight into a "schedule
> > > > w/IRQs disabled" bug.
> > >
> > > OK, how do I drop an irqsave spinlock if I don't have flags?
> >
> > IMHO you might even ask "How do I start a car when I don't have the
> > keys?"
>
> Break off the lock, touch some cables ... ;-)
>
> > You might find a way, but it's not desired. Are you sure you want to
> > reschedule in an interrupt handler? If it's none, are you sure you want
> > to disable interrupts?
>
> I am not in an interrupt handler. It's not my fault that the scsi layer
> calls queuecommand with a spinlock held. But I need to sleep,
> I have to get rid of that spinlock's effects. If possible I even want
> interrupts to be enabled.
I don't know scsi, but if the coder decided that the lock
and irq were needed, I suspect that messing with them will
get you in big trouble. I think you need to rethink this
thing at the scsi layer...
-g
>
> Regards
> Oliver
>
> -
> 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/
--
George Anzinger george@mvista.com
High-res-timers:
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-09-04 8:02 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-01 17:27 question on spinlocks Oliver Neukum
2002-09-01 19:05 ` Ralf Baechle
2002-09-01 21:53 ` Thunder from the hill
2002-09-01 22:02 ` Oliver Neukum
2002-09-01 22:09 ` Thunder from the hill
2002-09-01 22:11 ` Robert Love
2002-09-01 22:33 ` Oliver Neukum
2002-09-02 22:30 ` Jan Hudec
2002-09-03 22:13 ` george anzinger
2002-09-01 22:11 ` Robert Love
2002-09-01 22:08 ` Robert Love
2002-09-01 22:16 ` Thunder from the hill
[not found] ` <mailman.1030918200.24262.linux-kernel2news@redhat.com>
2002-09-03 20:09 ` Pete Zaitcev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox