Re: spin_unlock optimization(i386)

Andrea Arcangeli (andrea@suse.de)
Fri, 26 Nov 1999 19:17:36 +0100 (CET)


On Fri, 26 Nov 1999, Oliver Xymoron wrote:

>volatile int ready = 0;
>volatile int go = 0;

I don't like the ready/go stuff you left in.

To achieve readability I only had to change this:

--- movopt.cpp Fri Nov 26 16:42:23 1999
+++ movopt2.cpp Fri Nov 26 19:03:33 1999
@@ -27,8 +27,7 @@
volatile int current_state = 0;
volatile int lock = 1;

-volatile int ready = 0;
-volatile int go = 0;
+static volatile int nr_waits, __foo[7], nr_events;

void* threadfnc(void* param)
{
@@ -45,10 +44,9 @@
for(;i<50000000;i++) {
lock = 1;
current_state = 0;
- go = 0;
- while(!ready)
- ;
- go = 1;
+
+ nr_waits++;
+
for(j=0;j<delay;j++)
;
__asm__ __volatile(
@@ -77,11 +75,10 @@
exit(0);
cpu2:
for(;;) {
- ready = 1;
- while(!go)
- ;
- ready = 0;
- go = 0;
+ while (nr_events == nr_waits);
+
+ nr_events++;
+
for(j=0;j<delay2;j++)
;
__asm__ __volatile(

As far I can tell Manfred's userspace implementation of the wait_event
interface is correct and so without a locked mb() serialization between
the write and the following read the linux kernel would deadlock missing
events on i386 SMP WB. Unfortunately this is also the proof that 2.2.x is
effectively deadlock prone (_exactly_ as Manfred's proggy does) as I
noticed and fixed these SMP races in the wait_event() interface all over
the place only around 2.3.16 if I remeber well.

Anyway now we know the 2.3.x locking is necessary exactly as on Alpha (so
nothing has to be changed in asm-i386/system.h).

I think as last try before giving up with this issue (for now) I'll make
all userspace memory as uncached (forcing the PCD bit in mk_pte()) and
I'll try Manfred's testcase this way. It should work on UC memory even
without the lock if it's correct.

Andrea

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/