kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Avi Kivity <avi@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 7/8] Move IO APIC to its own lock.
Date: Thu, 13 Aug 2009 08:15:45 -0700	[thread overview]
Message-ID: <20090813151544.GA6744@linux.vnet.ibm.com> (raw)
In-Reply-To: <4A83EE76.9020001@redhat.com>

On Thu, Aug 13, 2009 at 01:44:06PM +0300, Avi Kivity wrote:
> On 08/13/2009 01:09 PM, Gleb Natapov wrote:
>>> There's also srcu.
>>>      
>> What are the disadvantages? There should be some, otherwise why not use
>> it all the time.
>
> I think it incurs an atomic op in the read path, but not much overhead 
> otherwise.  Paul?

There are not atomic operations in srcu_read_lock():

	int srcu_read_lock(struct srcu_struct *sp)
	{
		int idx;

		preempt_disable();
		idx = sp->completed & 0x1;
		barrier();  /* ensure compiler looks -once- at sp->completed. */
		per_cpu_ptr(sp->per_cpu_ref, smp_processor_id())->c[idx]++;
		srcu_barrier();  /* ensure compiler won't misorder critical section. */
		preempt_enable();
		return idx;
	}

There is a preempt_disable() and a preempt_enable(), which
non-atomically manipulate a field in the thread_info structure.
There is a barrier() and an srcu_barrier(), which are just compiler
directives (no code generated).  Other than that, simple arithmetic
and array accesses.  Shouldn't even be any cache misses in the common
case (the uncommon case being where synchronize_srcu() executing on
some other CPU).

There is even less in srcu_read_unlock():

	void srcu_read_unlock(struct srcu_struct *sp, int idx)
	{
		preempt_disable();
		srcu_barrier();  /* ensure compiler won't misorder critical section. */
		per_cpu_ptr(sp->per_cpu_ref, smp_processor_id())->c[idx]--;
		preempt_enable();
	}

So SRCU should have pretty low overhead.  And, as with other forms
of RCU, legal use of the read-side primitives cannot possibly
participate in deadlocks.

So, to answer the question above, what are the disadvantages?

o	On the update side, synchronize_srcu() does takes some time,
	mostly blocking in synchronize_sched().  So, like other
	forms of RCU, you would use SRCU in read-mostly situations.

o	Just as with RCU, reads and updates run concurrently, with
	all the good and bad that this implies.  For an example
	of the good, srcu_read_lock() executes deterministically,
	no blocking or spinning.  For an example of the bad, there
	is no way to shut down SRCU readers.  These are opposite
	sides of the same coin.  ;-)

o	Although srcu_read_lock() and srcu_read_unlock() are light
	weight, they are expensive compared to other forms of RCU.

o	In contrast to other forms of RCU, SRCU requires that the
	return value from srcu_read_lock() be passed into
	srcu_read_unlock().  Usually not a problem, but does place
	another constraint on the code.

Please keep in mind that I have no idea about what you are thinking of
using SRCU for, so the above advice is necessarily quite generic.  ;-)

							Thanx, Paul

  reply	other threads:[~2009-08-13 15:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-12 12:17 [PATCH v3 0/8] make interrupt injection lockless (almost) Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 1/8] Do not call ack notifiers on PIC reset Gleb Natapov
2009-08-13  9:11   ` Marcelo Tosatti
2009-08-13  9:39     ` Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 2/8] Change irq routing table to use gsi indexed array Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 3/8] Maintain back mapping from irqchip/pin to gsi Gleb Natapov
2009-08-17  9:43   ` Avi Kivity
2009-08-12 12:17 ` [PATCH v3 4/8] Move irq routing data structure to rcu locking Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 5/8] Move irq ack notifier list to arch independent code Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 6/8] Convert irq notifiers lists to RCU locking Gleb Natapov
2009-08-12 12:17 ` [PATCH v3 7/8] Move IO APIC to its own lock Gleb Natapov
2009-08-13  9:13   ` Marcelo Tosatti
2009-08-13  9:48     ` Gleb Natapov
2009-08-13  9:49       ` Avi Kivity
2009-08-13 10:09         ` Gleb Natapov
2009-08-13 10:44           ` Avi Kivity
2009-08-13 15:15             ` Paul E. McKenney [this message]
2009-08-12 12:17 ` [PATCH v3 8/8] Drop kvm->irq_lock lock from irq injection path Gleb Natapov
2009-08-17  9:46 ` [PATCH v3 0/8] make interrupt injection lockless (almost) Avi Kivity

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=20090813151544.GA6744@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).