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] [PULL 06/11] rcu: automatically unregister threads when they exit
Date: Thu, 16 Jul 2015 18:55:53 +0200	[thread overview]
Message-ID: <1437065758-4625-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1437065758-4625-1-git-send-email-pbonzini@redhat.com>

This simplifies management within the threads themselves.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/rcutorture.c | 10 ----------
 util/rcu.c         | 12 ++++++++++++
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/tests/rcutorture.c b/tests/rcutorture.c
index d6b304d..000b216 100644
--- a/tests/rcutorture.c
+++ b/tests/rcutorture.c
@@ -134,8 +134,6 @@ static void *rcu_read_perf_test(void *arg)
     qemu_mutex_lock(&counts_mutex);
     n_reads += n_reads_local;
     qemu_mutex_unlock(&counts_mutex);
-
-    rcu_unregister_thread();
     return NULL;
 }
 
@@ -157,8 +155,6 @@ static void *rcu_update_perf_test(void *arg)
     qemu_mutex_lock(&counts_mutex);
     n_updates += n_updates_local;
     qemu_mutex_unlock(&counts_mutex);
-
-    rcu_unregister_thread();
     return NULL;
 }
 
@@ -283,8 +279,6 @@ static void *rcu_read_stress_test(void *arg)
         rcu_stress_count[i] += rcu_stress_local[i];
     }
     qemu_mutex_unlock(&counts_mutex);
-
-    rcu_unregister_thread();
     return NULL;
 }
 
@@ -319,8 +313,6 @@ static void *rcu_update_stress_test(void *arg)
         synchronize_rcu();
         n_updates++;
     }
-
-    rcu_unregister_thread();
     return NULL;
 }
 
@@ -336,8 +328,6 @@ static void *rcu_fake_update_stress_test(void *arg)
         synchronize_rcu();
         g_usleep(1000);
     }
-
-    rcu_unregister_thread();
     return NULL;
 }
 
diff --git a/util/rcu.c b/util/rcu.c
index 7270151..8830295 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -268,12 +268,22 @@ void call_rcu1(struct rcu_head *node, void (*func)(struct rcu_head *node))
     qemu_event_set(&rcu_call_ready_event);
 }
 
+static __thread Notifier unregister_thread_notifier;
+
+static void rcu_unregister_thread_notify(Notifier *n, void *data)
+{
+    rcu_unregister_thread();
+}
+
 void rcu_register_thread(void)
 {
     assert(rcu_reader.ctr == 0);
     qemu_mutex_lock(&rcu_gp_lock);
     QLIST_INSERT_HEAD(&registry, &rcu_reader, node);
     qemu_mutex_unlock(&rcu_gp_lock);
+
+    unregister_thread_notifier.notify = rcu_unregister_thread_notify;
+    qemu_thread_atexit_add(&unregister_thread_notifier);
 }
 
 void rcu_unregister_thread(void)
@@ -281,6 +291,8 @@ void rcu_unregister_thread(void)
     qemu_mutex_lock(&rcu_gp_lock);
     QLIST_REMOVE(&rcu_reader, node);
     qemu_mutex_unlock(&rcu_gp_lock);
+
+    qemu_thread_atexit_remove(&unregister_thread_notifier);
 }
 
 static void rcu_init_complete(void)
-- 
2.4.3

  parent reply	other threads:[~2015-07-16 16:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16 16:55 [Qemu-devel] [PULL 00/11] RCU, KVM, memory API, crypto, Coverity fixes for 2.4.0-rc1 Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 01/11] mips/kvm: Fix Big endian 32-bit register access Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 02/11] mips/kvm: Sign extend registers written to KVM Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 03/11] ppc/spapr_drc: fix memory leak Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 04/11] arm/xlnx-zynqmp: " Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 05/11] RDMA: Fix error exits Paolo Bonzini
2015-07-16 16:55 ` Paolo Bonzini [this message]
2015-07-16 16:55 ` [Qemu-devel] [PULL 07/11] rcu: actually register threads that have RCU read-side critical sections Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 08/11] rcu: detect missing rcu_register_thread() Paolo Bonzini
2015-07-24  1:06   ` Wen Congyang
2015-07-16 16:55 ` [Qemu-devel] [PULL 09/11] memory: fix refcount leak in memory_region_present Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 10/11] crypto: fix build with nettle >= 3.0.0 Paolo Bonzini
2015-07-16 16:55 ` [Qemu-devel] [PULL 11/11] crypto: avoid undefined behavior in nettle calls Paolo Bonzini
2015-07-16 17:44 ` [Qemu-devel] [PULL 00/11] RCU, KVM, memory API, crypto, Coverity fixes for 2.4.0-rc1 Peter Maydell
2015-07-16 19:25   ` Peter Maydell

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=1437065758-4625-7-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).