qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mike Day <ncmike@ncultra.org>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 07/14] rcu: allow nested calls to rcu_thread_offline/rcu_thread_online
Date: Wed, 14 Aug 2013 11:50:43 -0400	[thread overview]
Message-ID: <1376495450-5133-8-git-send-email-ncmike@ncultra.org> (raw)
In-Reply-To: <1376495450-5133-1-git-send-email-ncmike@ncultra.org>

From: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Mike Day <ncmike@ncultra.org>
---
 docs/rcu.txt       |  5 +++++
 include/qemu/rcu.h | 21 +++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/docs/rcu.txt b/docs/rcu.txt
index d7c4f0b..4e7cde3 100644
--- a/docs/rcu.txt
+++ b/docs/rcu.txt
@@ -187,6 +187,11 @@ Marking quiescent states is done with the following three APIs:
         thread.
 
 
+rcu_thread_offline() and rcu_thread_online() can be nested.  The end of
+the extended quiescent state will coincide with the outermost call to
+rcu_thread_online().
+
+
 The following APIs can be used to use RCU in a thread that is not
 created with qemu_thread_create():
 
diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h
index e43b912..3a55045 100644
--- a/include/qemu/rcu.h
+++ b/include/qemu/rcu.h
@@ -77,6 +77,9 @@ struct rcu_reader_data {
     unsigned long ctr;
     bool waiting;
 
+    /* Data used by reader only */
+    unsigned offline;
+
     /* Data used for registry, protected by rcu_gp_lock */
     QLIST_ENTRY(rcu_reader_data) node;
 };
@@ -127,9 +130,14 @@ static inline void rcu_read_unlock(void)
 static inline void rcu_quiescent_state(void)
 {
     struct rcu_reader_data *p_rcu_reader = get_rcu_reader();
+    unsigned ctr;
+
+    if (p_rcu_reader->offline > 0) {
+        return;
+    }
 
     /* Reuses smp_rmb() in the last rcu_read_unlock().  */
-    unsigned ctr = atomic_read(&rcu_gp_ctr);
+    ctr = atomic_read(&rcu_gp_ctr);
     atomic_xchg(&p_rcu_reader->ctr, ctr);
     if (atomic_read(&p_rcu_reader->waiting)) {
         atomic_set(&p_rcu_reader->waiting, false);
@@ -141,6 +149,10 @@ static inline void rcu_thread_offline(void)
 {
     struct rcu_reader_data *p_rcu_reader = get_rcu_reader();
 
+    if (p_rcu_reader->offline++ > 0) {
+        return;
+    }
+
     atomic_xchg(&p_rcu_reader->ctr, 0);
     if (atomic_read(&p_rcu_reader->waiting)) {
         atomic_set(&p_rcu_reader->waiting, false);
@@ -150,7 +162,12 @@ static inline void rcu_thread_offline(void)
 
 static inline void rcu_thread_online(void)
 {
-    rcu_quiescent_state();
+    struct rcu_reader_data *p_rcu_reader = get_rcu_reader();
+
+    assert(p_rcu_reader->offline != 0);
+    if (--p_rcu_reader->offline == 0) {
+        rcu_quiescent_state();
+    }
 }
 
 extern void synchronize_rcu(void);
-- 
1.8.3.1

  parent reply	other threads:[~2013-08-14 15:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 15:50 [Qemu-devel] [RFC PATCH 00/14] RCU Implementation for Qemu Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 01/14] qemu-thread: add QemuEvent Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 02/14] rcu: add rcu library Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 03/14] fix #include directive for rcu header Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 04/14] qemu-thread: register threads with RCU Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 05/14] rcu: add call_rcu Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 06/14] rcu: add rcutorture Mike Day
2013-08-14 15:50 ` Mike Day [this message]
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 08/14] qemu-thread: report RCU quiescent states Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 09/14] event loop: " Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 10/14] cpus: " Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 11/14] block: " Mike Day
2013-08-14 15:50 ` [Qemu-devel] [RFC PATCH 12/14] migration: " Mike Day
2013-08-14 15:50 ` [Qemu-devel] [PATCH 13/14] include osdep.h for definition of glue(a, b) Mike Day
2013-08-14 15:50 ` [Qemu-devel] [PATCH 14/14] fix pointer reference to rcu_assign_pointer Mike Day

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=1376495450-5133-8-git-send-email-ncmike@ncultra.org \
    --to=ncmike@ncultra.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).