lkml.org 
[lkml]   [2006]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX
From
Date
 > 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-03-03 02:01    [W:0.843 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site