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

Andrea Arcangeli (arcangeli@mbox.queen.it)
Sun, 31 May 1998 20:23:19 +0200 (CEST)


On Sun, 31 May 1998 ralf@uni-koblenz.de wrote:

>On Sun, May 31, 1998 at 02:34:11PM +0200, Andrea Arcangeli wrote:
>
>> Woops, I think that test_and_set_bit() has to be atomic only in respect of
>> SMP (as i386 implementation). Maybe "atomic" is not the best word to
>> describe test_and_set_bit(), "SMP safe" should feel better...
>
>Nuff, see Ethernet drivers' transmit function:
>
> /* Block a timer-based transmit from overlapping. This could better be
> done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
> if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
> printk("%s: Transmitter access conflict.\n", dev->name);
> return 1;
> }

It' s clear that tbusy is managed also inside interrupt function so it
really seems that test_and_set_bit() has to be atomic _also_ in respect of
interrupt handlers.

In the i386 implementation of test_and_set_bit() the unknown "sbbl %0,%0"
asm instruction doesn' t take the return value from memory so I suppose it
takes the return value from the CPU state that of course is preserved from
interrut handlers so it seems to be irq atomic too!

Since all ethernet card device driver assume test_and_set_bit() atomic for
interrupts it' s clear that if some Linux port doesn' t implement it as
atomic in respect of irq, that port is buggy and need to be fixed (maybe
simply disabling interrupts inside that function).

Thanks Ralf.

Andrea[s] Arcangeli

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