> 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.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel