* Kernel Semaphores
@ 1999-12-06 16:02 Kevin D. Kissell
1999-12-06 19:08 ` Ralf Baechle
0 siblings, 1 reply; 4+ messages in thread
From: Kevin D. Kissell @ 1999-12-06 16:02 UTC (permalink / raw)
To: Linux SGI
This is for Ralf and any other MIPS/Linux kernel
hackers who may be on the list.
Some time ago, I fixed the assembler macros
for waking_non_zero_interruptable and down_trylock
to be correct(ish) for MIPSEL and MIPSEB, but
there remained the issue of their requiring the use
of 64-bit instructions to work - they "cheat" by using
the same ll/sc pair to update both the count and the
waking field of the semaphore.
To make it work on 32-bit CPUs, I looked at using
the x386 model, but that one uses interrupt disables
and is intrinsically SMP-unsafe. Now, looking at
the comments and studying the code a bit,
it *seems* that the issue is not so much a race
condition between updates of the waking and
count fields, but a race with other functions that
may be updating the waking field. CAN ANYONE
CONFIRM OR DENY THAT?
If it's true, it looks to me that by inventing one
new primitive in atomic.h, atomic_sub_and_return_if_gtz(),
one can:
a) Eliminate the need for an assembly macro dedicated
to waking_non_zero, which maps directly to the new macro.
b) Make it possible to do waking_non_zero_interruptible in
C, as all the examinations/updates of sem->waking can
be made atomic
c) Likewise simplify down_trylock() and
d) Make waking_non_zero_trylock() SMP safe.
I've coded this up for experimentation, and will provide
the sources (at least relative to 2.2.12) to any interested
parties, but I'd really like someone who has worked
intimately with the kernel semaphores to tell me if
there really are races between updates of sem->waking
and sem->count, and if they exist, what they are!
__
Kevin D. Kissell
MIPS Technologies European Architecture Lab
kevink@mips.com
Tel. +33.4.78.38.70.67
FAX. +33.4.78.38.70.68
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Kernel Semaphores
1999-12-06 16:02 Kernel Semaphores Kevin D. Kissell
@ 1999-12-06 19:08 ` Ralf Baechle
0 siblings, 0 replies; 4+ messages in thread
From: Ralf Baechle @ 1999-12-06 19:08 UTC (permalink / raw)
To: Kevin D. Kissell; +Cc: Linux SGI
On Mon, Dec 06, 1999 at 05:02:06PM +0100, Kevin D. Kissell wrote:
> Some time ago, I fixed the assembler macros
> for waking_non_zero_interruptable and down_trylock
> to be correct(ish) for MIPSEL and MIPSEB, but
> there remained the issue of their requiring the use
> of 64-bit instructions to work - they "cheat" by using
> the same ll/sc pair to update both the count and the
> waking field of the semaphore.
Btw, we have two variants for all the semaphore code as you know. We
can eleminate the little endian variant by just swapping the order of
the two atomic_t members in struct semaphore which will eleminate the
maintenance problems.
> To make it work on 32-bit CPUs, I looked at using
> the x386 model, but that one uses interrupt disables
> and is intrinsically SMP-unsafe.
semaphore-helper.h uses spin_lock_irqsave which is smp-safe. The way
we do things for 64-bit MIPS is just more performant.
Ralf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Kernel Semaphores
@ 1999-12-06 20:33 Kevin D. Kissell
1999-12-06 21:13 ` Ralf Baechle
0 siblings, 1 reply; 4+ messages in thread
From: Kevin D. Kissell @ 1999-12-06 20:33 UTC (permalink / raw)
To: Ralf Baechle; +Cc: Linux SGI
>> To make it work on 32-bit CPUs, I looked at using
>> the x386 model, but that one uses interrupt disables
>> and is intrinsically SMP-unsafe.
>
>semaphore-helper.h uses spin_lock_irqsave which is smp-safe. The way
>we do things for 64-bit MIPS is just more performant.
spin_lock_irqsave() in 2.2.12 for MIPS is just a save_and_cli().
The MIPS spin_lock macros all collapse the lock into nothingness.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Kernel Semaphores
1999-12-06 20:33 Kevin D. Kissell
@ 1999-12-06 21:13 ` Ralf Baechle
0 siblings, 0 replies; 4+ messages in thread
From: Ralf Baechle @ 1999-12-06 21:13 UTC (permalink / raw)
To: Kevin D. Kissell; +Cc: Ralf Baechle, Linux SGI
On Mon, Dec 06, 1999 at 09:33:38PM +0100, Kevin D. Kissell wrote:
> >> To make it work on 32-bit CPUs, I looked at using
> >> the x386 model, but that one uses interrupt disables
> >> and is intrinsically SMP-unsafe.
> >
> >semaphore-helper.h uses spin_lock_irqsave which is smp-safe. The way
> >we do things for 64-bit MIPS is just more performant.
>
> spin_lock_irqsave() in 2.2.12 for MIPS is just a save_and_cli().
> The MIPS spin_lock macros all collapse the lock into nothingness.
Spinlocks are SMP safe; it's just the MIPS implementation which doesn't
get this right so far.
Ralf
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1999-12-06 22:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-12-06 16:02 Kernel Semaphores Kevin D. Kissell
1999-12-06 19:08 ` Ralf Baechle
-- strict thread matches above, loose matches on Subject: below --
1999-12-06 20:33 Kevin D. Kissell
1999-12-06 21:13 ` Ralf Baechle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox