public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Pekka Enberg <penberg@kernel.org>, Avi Kivity <avi@redhat.com>,
	Ingo Molnar <mingo@elte.hu>,
	john@jfloren.net, kvm@vger.kernel.org, asias.hejun@gmail.com,
	gorcunov@gmail.com, prasadjoshi124@gmail.com,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Phil Howard <csbetterthanjava@gmail.com>
Subject: Re: [PATCH 4/6] kvm tools: Add rwlock wrapper
Date: Fri, 27 May 2011 09:14:00 -0400	[thread overview]
Message-ID: <20110527131400.GC29744@Krystal> (raw)
In-Reply-To: <1306491547.3217.9.camel@lappy>

* Sasha Levin (levinsasha928@gmail.com) wrote:
> On Thu, 2011-05-26 at 19:09 -0400, Mathieu Desnoyers wrote:
> > * Sasha Levin (levinsasha928@gmail.com) wrote:
> > > On Thu, 2011-05-26 at 21:21 +0300, Pekka Enberg wrote:
> > > > On Thu, May 26, 2011 at 9:11 PM, Avi Kivity <avi@redhat.com> wrote:
> > > > > On 05/26/2011 09:05 PM, Ingo Molnar wrote:
> > > > >>
> > > > >> >
> > > > >> >  I've added some rwlocks because of what Ingo said yesterday about
> > > > >> >  adding/removing devices after the first initialization phase.
> > > > >> >
> > > > >> >  Take MMIO lock for example: Since we can now run SMP guests, we may
> > > > >> >  have multiple MMIO exits (one from each VCPU thread). Each of those
> > > > >> >  exits leads to searching the MMIO rbtree.
> > > > >> >
> > > > >> >  We can use a mutex to lock it, but it just means that those threads
> > > > >> >  will be blocked there instead of concurrently searching the MMIO
> > > > >> >  tree which makes the search linear instead of parallel.
> > > > >> >
> > > > >> >  It's hard to bring 'real' numbers at this stage because the only
> > > > >> >  'real' device we have which uses MMIO is the VESA driver, and we
> > > > >> >  can't really simulate many VCPUs writing to it :)
> > > > >>
> > > > >> I'd suggest keeping it simple first - rwlocks are nasty and will
> > > > >> bounce a cacheline just as much.
> > > > >
> > > > > Well, this is the first case where tools/kvm can do better than qemu with
> > > > > its global lock, so I think it's worth it.
> > > > >
> > > > >> If lookup scalability is an issue we can extend RCU to tools/kvm/.
> > > > >
> > > > > Definitely rcu is a perfect patch for mmio dispatch.
> > > > 
> > > > Userspace RCU code is here, Sasha, if you feel like tackling this:
> > > > 
> > > > http://lttng.org/urcu
> > > > 
> > > > :-)
> > > > 
> > > > I'm CC'ing Paul and Mathieu as well for urcu.
> > > 
> > > Sounds good!
> > > 
> > > Should be quite an addition and could be used in more places than just
> > > the MMIO dispatcher.
> > 
> > Hi Sasha,
> > 
> > Feel free to let me know if you need any help, have questions, or need
> > improvements to liburcu. I'd be interested to know about the specifics
> > of you read vs update workload rate. Also, if you need more thorough
> > information, we have a paper describing all the liburcu flavors. It
> > might help you choose the one better suited for your needs. (if you
> > don't care that much about fine-tuning, my recommendation is to stick
> > with the "urcu.h"/"liburcu" flavor). Link to the paper preprint can be
> > found at http://www.efficios.com/publications
> 
> Hi Mathieu!
> 
> In tools/kvm/ we use a rb-tree (same one used by the kernel) with the
> augmentation feature to support an interval rb-tree - which means that
> every update to the tree not only updates the nodes directly related to
> the updated node but also all the nodes on the path to the root of the
> tree.

Cool !!

I'm adding in copy Phil Howard who has been working on RCU RB tree for
much longer than myself.

> I see that in liburcu there is an implementation of a rcu linked list
> but no implementation of a rb-tree.
> 
> Are you currently working on one? or maybe I should try writing one and
> sending it to you?

Actually, I started working on one last year, but had to interrupt my
effort before I got it even working right. The state of this
(disclaimer: unfinished!!) work is available in the "rbtree" branch of
the urcu library. This tree has insertion/removals protected by a mutex,
and uses a RCU read lock to protect traversal. The main problem I was
facing when I had to stop working on that code is that the "nil" node:

  56 /* Sentinel (bottom nodes).
  57  * Don't care about p, left, right, pos and key values */
  58 struct rcu_rbtree_node rcu_rbtree_nil = {
  59         .color = COLOR_BLACK,
  60 };

ended up being written to as temporary node by the algorithm presented
in CLRS, chap. 12.  So sharing it as a common node, as proposed in their
book, made sense only if you consider you have no concurrency, but seems
to break left and right in the presence of concurrency, and I did not
have time to review their entire algo to find out where I should check
for accesses to this nil node.

This implementation is trying to think of the RB tree in terms of how
each operation is affecting the read-side visibility of the tree nodes.
It uses the fact that readers only ever go down into the tree
extensively.

I'd be glad to help out if someone want to have a look and try to
complete that work, which should only be considered as "work in
progress" level of (in)completeness.

We'd have to see how we can go from this implementation of a standard RB
tree to an interval RB tree too. I guess it will depend whether you need
the updates from the target node up to the root to be done "all at once"
from a reader perspective (then you would probably need to replace a
copy of a part of the tree all at once), or if you can allow the update
to be done piece-wise on a node-by-node basis as readers go through the
tree (from root to leafs).

Thanks,

Mathieu


-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

  parent reply	other threads:[~2011-05-27 13:14 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 14:25 [PATCH 1/6] kvm tools: Prevent double assignment of guest memory info Sasha Levin
2011-05-26 14:25 ` [PATCH 2/6] kvm tools: Exit VCPU thread only when SIGKVMEXIT is received Sasha Levin
2011-05-26 14:25 ` [PATCH 3/6] kvm tools: Protect IRQ allocations by a mutex Sasha Levin
2011-05-26 14:25 ` [PATCH 4/6] kvm tools: Add rwlock wrapper Sasha Levin
2011-05-26 16:02   ` Pekka Enberg
2011-05-26 16:19     ` Sasha Levin
2011-05-26 18:05       ` Ingo Molnar
2011-05-26 18:11         ` Avi Kivity
2011-05-26 18:21           ` Pekka Enberg
2011-05-26 18:57             ` Sasha Levin
2011-05-26 23:09               ` Mathieu Desnoyers
2011-05-27 10:19                 ` Sasha Levin
2011-05-27 10:36                   ` Ingo Molnar
2011-05-27 15:52                     ` Sasha Levin
2011-05-27 17:10                       ` Ingo Molnar
2011-05-27 20:19                         ` Sasha Levin
2011-05-28 15:24                           ` Ingo Molnar
2011-05-28 16:44                             ` Paul E. McKenney
2011-05-28 19:45                             ` Sasha Levin
2011-05-29  6:47                               ` Avi Kivity
2011-05-29  7:19                                 ` Ingo Molnar
2011-05-29 15:31                                   ` Paul E. McKenney
2011-05-29 15:51                                     ` Paul E. McKenney
2011-05-29 19:54                                       ` Ingo Molnar
2011-05-30  3:12                                         ` Paul E. McKenney
2011-05-29 16:22                                     ` Sasha Levin
2011-05-27 13:14                   ` Mathieu Desnoyers [this message]
2011-05-29 17:01                     ` RCU red-black tree (was: Re: [PATCH 4/6] kvm tools: Add rwlock wrapper) Mathieu Desnoyers
2011-05-29 17:48                       ` Sasha Levin
2011-05-30  2:54                         ` Mathieu Desnoyers
2011-05-30  6:07                           ` Sasha Levin
2011-05-30 11:30                             ` Mathieu Desnoyers
2011-05-30 17:38                             ` Mathieu Desnoyers
2011-05-30 17:50                               ` Mathieu Desnoyers
2011-05-30 17:52                               ` Sasha Levin
2011-05-30 18:57                                 ` Mathieu Desnoyers
2011-05-30 19:11                                   ` Sasha Levin
2011-05-31 13:05                                   ` Sasha Levin
2011-05-31 13:09                                     ` Ingo Molnar
2011-05-31 13:20                                       ` Sasha Levin
2011-05-31 15:25                                         ` Ingo Molnar
2011-05-31 19:09                                           ` Prasad Joshi
2011-05-31 19:31                                             ` Ingo Molnar
2011-06-02 14:55                                     ` Mathieu Desnoyers
2011-05-30  3:38                       ` Paul E. McKenney
2011-05-30 11:18                         ` Mathieu Desnoyers
2011-05-26 20:25             ` [PATCH 4/6] kvm tools: Add rwlock wrapper Ingo Molnar
2011-05-26 23:05               ` Mathieu Desnoyers
2011-05-27  0:58                 ` Paul E. McKenney
2011-05-27  9:12                   ` Ingo Molnar
2011-05-27 12:48                     ` Mathieu Desnoyers
2011-05-27 13:19                       ` Ingo Molnar
2011-05-27 13:29                         ` Mathieu Desnoyers
2011-05-27 13:36                           ` Ingo Molnar
2011-05-27 17:22                     ` Paul E. McKenney
2011-05-27 10:25                 ` Ingo Molnar
2011-05-27 11:07                   ` Ingo Molnar
2011-05-27 11:10                     ` Ingo Molnar
2011-05-27 11:24                       ` Ingo Molnar
2011-05-27 14:18                         ` Mathieu Desnoyers
2011-05-27 14:11                     ` Mathieu Desnoyers
2011-05-28 18:12                     ` Avi Kivity
2011-05-28 18:32                       ` Ingo Molnar
2011-05-29  6:41                         ` Avi Kivity
2011-05-29  7:35                           ` Ingo Molnar
2011-05-29  7:54                             ` Avi Kivity
2011-05-29 12:37                               ` Ingo Molnar
2011-05-29 12:48                                 ` Avi Kivity
2011-05-29 14:27                                   ` Ingo Molnar
2011-05-29 15:00                                     ` Avi Kivity
2011-05-29 15:38                                       ` Paul E. McKenney
2011-05-29 19:33                                         ` Ingo Molnar
2011-05-30  3:07                                           ` Paul E. McKenney
2011-05-30  8:12                                             ` Ingo Molnar
2011-05-27 13:22                   ` Mathieu Desnoyers
2011-05-27 13:31                     ` Ingo Molnar
2011-05-28 18:14                       ` Avi Kivity
2011-05-27 13:07                 ` Ingo Molnar
2011-05-26 14:25 ` [PATCH 5/6] kvm tools: Protect MMIO tree by rwsem Sasha Levin
2011-05-26 14:25 ` [PATCH 6/6] kvm tools: Protect IOPORT " Sasha Levin
2011-05-26 16:01   ` Pekka Enberg
2011-05-26 16:19     ` Sasha Levin

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=20110527131400.GC29744@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    --cc=asias.hejun@gmail.com \
    --cc=avi@redhat.com \
    --cc=csbetterthanjava@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=john@jfloren.net \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.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