Re: test_and_set_bit implementation

From: Zoltan Menyhart <>
Date: 2006-12-13 21:20:00
Christoph Lameter wrote:

> I think this will work. However, usually you execute bit test and test 
> because the bit is not set and you want to set it. This change would 
> optimize a rarely taken path. Probably not worth it.

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

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

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)
        while (test_and_set_bit(bitnum, addr)) {
                while (test_bit(bitnum, addr)) {

By executing the atomic operation unconditionally, you kill
the cache line all the other waiting processors looping at.


Zoltán Menyhárt
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to
More majordomo info at
Received on Wed Dec 13 21:22:24 2006

This archive was generated by hypermail 2.1.8 : 2006-12-13 21:22:42 EST