[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/11] rcu: handle forks safely
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 05/11] rcu: handle forks safely |
Date: |
Tue, 10 Mar 2015 11:37:54 +0100 |
After forking, only the calling thread is duplicated in the child process.
The call_rcu thread has to be recreated in the child. Exploit the fact
that only one thread exists (same as when constructors run), and just redo
the entire initialization to ensure the threads are in the proper state.
The only additional things to do are emptying the list of threads
registered with RCU, and unlocking the lock that was taken in the prepare
callback (implementations are allowed to fail pthread_mutex_init()
if the mutex is still locked).
Signed-off-by: Paolo Bonzini <address@hidden>
---
util/rcu.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/util/rcu.c b/util/rcu.c
index bd73b8e..27802a4 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -283,7 +283,7 @@ void rcu_unregister_thread(void)
qemu_mutex_unlock(&rcu_gp_lock);
}
-static void __attribute__((__constructor__)) rcu_init(void)
+static void rcu_init_complete(void)
{
QemuThread thread;
@@ -291,8 +291,39 @@ static void __attribute__((__constructor__)) rcu_init(void)
qemu_event_init(&rcu_gp_event, true);
qemu_event_init(&rcu_call_ready_event, false);
+
+ /* The caller is assumed to have iothread lock, so the call_rcu thread
+ * must have been quiescent even after forking, just recreate it.
+ */
qemu_thread_create(&thread, "call_rcu", call_rcu_thread,
NULL, QEMU_THREAD_DETACHED);
rcu_register_thread();
}
+
+#ifdef CONFIG_POSIX
+static void rcu_init_lock(void)
+{
+ qemu_mutex_lock(&rcu_gp_lock);
+}
+
+static void rcu_init_unlock(void)
+{
+ qemu_mutex_unlock(&rcu_gp_lock);
+}
+
+static void rcu_init_child(void)
+{
+ qemu_mutex_unlock(&rcu_gp_lock);
+ memset(®istry, 0, sizeof(registry));
+ rcu_init_complete();
+}
+#endif
+
+static void __attribute__((__constructor__)) rcu_init(void)
+{
+#ifdef CONFIG_POSIX
+ pthread_atfork(rcu_init_lock, rcu_init_unlock, rcu_init_child);
+#endif
+ rcu_init_complete();
+}
--
2.3.0
- [Qemu-devel] [PULL 00/11] scsi, RCU, KVM, x86 changes for 2015-03-10, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 01/11] iscsi: Fix check for username, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 03/11] kvm_stat: add kvm_stat.1 man page, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 04/11] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 05/11] rcu: handle forks safely,
Paolo Bonzini <=
- [Qemu-devel] [PULL 08/11] hw: Propagate errors through qdev_prop_set_drive(), Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 06/11] cpus: initialize cpu->memory_dispatch, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 02/11] kvm_stat: add column headers to text UI, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 09/11] scsi: Improve error reporting for invalid drive property, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 07/11] scsi: Clean up duplicated error in legacy if=scsi code, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 11/11] x86: fix SS selector in SYSRET, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 10/11] scsi: Convert remaining PCI HBAs to realize(), Paolo Bonzini, 2015/03/10
- Re: [Qemu-devel] [PULL 00/11] scsi, RCU, KVM, x86 changes for 2015-03-10, Peter Maydell, 2015/03/10