Re: [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX

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

 



 > So you are saying that, for example
 > 
 > 	spin_lock_irqsave(&cs->ev_lock, flags);
 > 	head = cs->ev_head;
 > 	tail = cs->ev_tail;
 > 	spin_unlock_irqrestore(&cs->ev_lock, flags);
 > 
 > is (mutatis mutandis) actually cheaper than
 > 
 > 	head = atomic_read(&cs->ev_head);
 > 	tail = atomic_read(&cs->ev_tail);
 > 
 > ? That's interesting. I wouldn't have expected that after reading
 > Documentation/atomic_ops.txt and Documentation/spinlock.txt.

No, atomic_read() is cheap because it doesn't have to do a locked
operation.  However, operations like atomic_inc() that do need to do
something special are quite expensive.

For example, on x86, each atomic_inc()/atomic_dec() is the same cost
as a spin_lock(), since they all have to do some sort of "lock ; incX"
or "lock ; decX".  But then spin_unlock() is cheap, because it can do
a simple unlocked mov.

So in other words,

 	spin_lock_irqsave(&lock, flags);
 	++head1;
 	++head2;
 	spin_unlock_irqrestore(&lock, flags);
 
should be cheaper than

 	atomic_inc(&head1);
 	atomic_inc(&head2);

On the other hand, if you use the spinlock variant, then you do incur
an extra cost by requiring the lock for both reads and writes, instead
of the cheap atomic_read().

But complex use of atomic_t is very hard to get right, so it's usually
better to use a spinlock.

 - R.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux