Re: test_and_set_bit implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 13 Dec 2006, Zoltan Menyhart wrote:

> How much is the probability that the bit is not set?

Depends on the load on the system. Typically very much near 100%

> Adding a test can cost only a few cycles, say max 4.

But it reduces the performance of the commonly taken code path.

> For an atomic operation, you need to go out and snoop.
> 
> Let's have a look at e.g. the "bit_spin_lock()":
> 
> static inline void bit_spin_lock(int bitnum, unsigned long *addr)
> {
>        preempt_disable();
>        while (test_and_set_bit(bitnum, addr)) {
>                while (test_bit(bitnum, addr)) {
>                        preempt_enable();
>                        cpu_relax();
>                        preempt_disable();
>                }
>        }
>        __acquire(bitlock);
> }
> 
> By executing the atomic operation unconditionally, you kill
> the cache line all the other waiting processors looping at.

But note also that we optimize the common case, the case that the test and 
set bit are successful. Only if it was not successful will we do non 
atomic loads. This is done to avoid cachelines bouncing while the lock is 
contended.

-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Sparc Linux]     [DCCP]     [Linux ARM]     [Yosemite News]     [Linux SCSI]     [Linux x86_64]     [Linux for Ham Radio]

  Powered by Linux