test_and_set_bit() not atomic forever? [cli/sti in char/vt.c [patch]]

Andrea Arcangeli (arcangeli@mbox.queen.it)
Sat, 30 May 1998 15:55:14 +0200 (CEST)


On Fri, 29 May 1998, Pavel Machek wrote:

>Don't think so. Well, it is safe on i386, but on other architectures,
>test_and_set_bit is not guaranteed to be atomic. [And I'm afraid that

Arggh I thought that test_and_set_bit() was atomic on all ports (since I
looked only its i386 implementation)!

I used test_and_set_bit() in lp to avoid races for SMP in lp_open() (not a
very critical part of the kernel though, since nobody noticed the race
also before I put test_and_set_bit() there; probably because /dev/lp0
usually is opened only from the printer spooler...).

At first I can see test_and_set_bit() very more helpful if
implemented atomic.

As second since it' s declared _not_ atomic in Linux, why i386 implement
it atomic?

extern __inline__ int test_and_set_bit(int nr, volatile void * addr)
{
int oldbit;

__asm__ __volatile__( LOCK_PREFIX
^^^^^^^^^^^ why to lock in SMP if it' s not atomic?
"btsl %2,%1\n\tsbbl %0,%0"
:"=r" (oldbit),"=m" (ADDR)
:"ir" (nr));
return oldbit;
}

So I' d like to know if test_and_set_bit() will forever remain declared
not atomic for all ports to know if I need to refix lp_open()...

Andrea[s] Arcangeli

PS. I explicit mentioned the use of test_and_set_bit() to fix not atomic
operation in lp_open() as first point in the patch comments I sent to
Linus with the patch itself.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu