All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: Tilman Schmidt <tilman@imap.cc>
Cc: Arjan van de Ven <arjan@infradead.org>,
	Hansjoerg Lipp <hjlipp@web.de>, Karsten Keil <kkeil@suse.de>,
	i4ldeveloper@listserv.isdn4linux.de,
	linux-usb-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX
Date: Thu, 02 Mar 2006 16:58:54 -0800	[thread overview]
Message-ID: <adapsl4s5rl.fsf@cisco.com> (raw)
In-Reply-To: <440779AF.5060202@imap.cc> (Tilman Schmidt's message of "Fri, 03 Mar 2006 00:03:11 +0100")

 > 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.

  reply	other threads:[~2006-03-03  0:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-27  6:23 [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX Hansjoerg Lipp
2006-02-27  6:23 ` [PATCH 1/7] isdn4linux: Siemens Gigaset drivers - common module Hansjoerg Lipp
2006-02-27  6:23   ` [PATCH 2/7] isdn4linux: Siemens Gigaset drivers - event layer Hansjoerg Lipp
2006-02-27  6:23     ` [PATCH 3/7] isdn4linux: Siemens Gigaset drivers - subsystem interfaces Hansjoerg Lipp
2006-02-27  6:23       ` [PATCH 4/7] isdn4linux: Siemens Gigaset drivers - direct USB connection Hansjoerg Lipp
2006-02-27  6:23         ` [PATCH 5/7] isdn4linux: Siemens Gigaset drivers - isochronous data handler Hansjoerg Lipp
2006-02-27  6:23           ` [PATCH 6/7] isdn4linux: Siemens Gigaset drivers - M105 USB DECT adapter Hansjoerg Lipp
2006-02-27  6:23             ` [PATCH 7/7] isdn4linux: Siemens Gigaset drivers - Kconfigs and Makefiles Hansjoerg Lipp
2006-02-27  8:01     ` [PATCH 2/7] isdn4linux: Siemens Gigaset drivers - event layer Arjan van de Ven
2006-02-27  8:02     ` Arjan van de Ven
2006-02-27  7:52   ` [PATCH 1/7] isdn4linux: Siemens Gigaset drivers - common module Arjan van de Ven
2006-02-27  8:00   ` Arjan van de Ven
2006-02-27  9:29 ` [PATCH 0/7] isdn4linux: add drivers for Siemens Gigaset ISDN DECT PABX Arjan van de Ven
2006-03-02 23:03   ` Tilman Schmidt
2006-03-03  0:58     ` Roland Dreier [this message]
2006-03-03  6:53     ` Arjan van de Ven
2006-03-03  9:44       ` Karsten Keil
2006-03-03 14:54       ` Tilman Schmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adapsl4s5rl.fsf@cisco.com \
    --to=rdreier@cisco.com \
    --cc=arjan@infradead.org \
    --cc=gregkh@suse.de \
    --cc=hjlipp@web.de \
    --cc=i4ldeveloper@listserv.isdn4linux.de \
    --cc=kkeil@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=tilman@imap.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.