qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 09/13] rcu: avoid repeated system calls
Date: Mon, 15 Aug 2011 14:08:36 -0700	[thread overview]
Message-ID: <1313442520-12062-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1313442520-12062-1-git-send-email-pbonzini@redhat.com>

Optimization posted to upstream mailing list.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rcu.c |    5 +++++
 rcu.h |   22 ++++++++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/rcu.c b/rcu.c
index e2f347a..aaf53ad 100644
--- a/rcu.c
+++ b/rcu.c
@@ -91,6 +91,11 @@ static void update_counter_and_wait(void)
 		 * while we walk the list.
 		 */
 		qemu_event_reset(&rcu_gp_event);
+		QLIST_FOREACH(index, &registry, node) {
+			ACCESS_ONCE(index->waiting) = true;
+		}
+		__sync_synchronize();
+
 		QLIST_FOREACH_SAFE(index, &registry, node, tmp) {
 			if (!rcu_gp_ongoing(&index->ctr)) {
 				QLIST_REMOVE(index, node);
diff --git a/rcu.h b/rcu.h
index 86a1fea..96ce9d3 100644
--- a/rcu.h
+++ b/rcu.h
@@ -74,6 +74,8 @@ extern QemuEvent rcu_gp_event;
 struct rcu_reader {
 	/* Data used by both reader and synchronize_rcu() */
 	unsigned long ctr;
+	bool waiting;
+
 	/* Data used for registry */
 	QLIST_ENTRY(rcu_reader) node;
 };
@@ -93,24 +95,24 @@ static inline void rcu_quiescent_state(void)
 {
 	smp_mb();
 	ACCESS_ONCE(rcu_reader.ctr) = ACCESS_ONCE(rcu_gp_ctr);
-#if 0
-	/* write rcu_reader.ctr before read futex.  Included in
-	 * qemu_event_set. */
+	/* write rcu_reader.ctr before read waiting.  */
 	smp_mb();
-#endif
-	qemu_event_set(&rcu_gp_event);
+	if (ACCESS_ONCE(rcu_reader.waiting)) {
+		ACCESS_ONCE(rcu_reader.waiting) = false;
+		qemu_event_set(&rcu_gp_event);
+	}
 }
 
 static inline void rcu_thread_offline(void)
 {
 	smp_mb();
 	ACCESS_ONCE(rcu_reader.ctr) = 0;
-#if 0
-	/* write rcu_reader.ctr before read futex.  Included in
-	 * qemu_event_set. */
+	/* write rcu_reader.ctr before read waiting.  */
 	smp_mb();
-#endif
-	qemu_event_set(&rcu_gp_event);
+	if (ACCESS_ONCE(rcu_reader.waiting)) {
+		ACCESS_ONCE(rcu_reader.waiting) = false;
+		qemu_event_set(&rcu_gp_event);
+	}
 }
 
 static inline void rcu_thread_online(void)
-- 
1.7.6

  parent reply	other threads:[~2011-08-15 21:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 21:08 [Qemu-devel] [RFC PATCH 00/13] RCU implementation for QEMU Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 01/13] add smp_mb() Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 02/13] rename qemu_event_{init,read} Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 03/13] qemu-threads: add QemuEvent Paolo Bonzini
2011-08-17 17:09   ` Blue Swirl
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 04/13] qemu-threads: add QemuOnce Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 05/13] add rcu library Paolo Bonzini
2011-08-17 17:04   ` Blue Swirl
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 06/13] rcu: add rcutorture Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 07/13] osdep: add qemu_msleep Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 08/13] add call_rcu support Paolo Bonzini
2011-08-15 21:08 ` Paolo Bonzini [this message]
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 10/13] rcu: report quiescent states Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 11/13] rcuify iohandlers Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 12/13] split MRU ram list Paolo Bonzini
2011-08-15 21:08 ` [Qemu-devel] [RFC PATCH 13/13] RCUify ram_list Paolo Bonzini

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=1313442520-12062-10-git-send-email-pbonzini@redhat.com \
    --to=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).