[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V3 09/11] vcpu: make QemuThread as tls to store thre
From: |
Liu Ping Fan |
Subject: |
[Qemu-devel] [PATCH V3 09/11] vcpu: make QemuThread as tls to store thread-self info |
Date: |
Tue, 11 Sep 2012 15:51:50 +0800 |
From: Liu Ping Fan <address@hidden>
We store the thread self info in QemuThread.
Signed-off-by: Liu Ping Fan <address@hidden>
---
cpus.c | 1 +
qemu-thread-posix.c | 7 +++++++
qemu-thread-posix.h | 2 ++
qemu-thread.h | 1 +
vl.c | 4 ++++
5 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/cpus.c b/cpus.c
index e476a3c..4cd7f85 100644
--- a/cpus.c
+++ b/cpus.c
@@ -735,6 +735,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
CPUState *cpu = ENV_GET_CPU(env);
int r;
+ pthread_setspecific(qemu_thread_key, cpu->thread);
qemu_mutex_lock(&qemu_global_mutex);
qemu_thread_get_self(cpu->thread);
env->thread_id = qemu_get_thread_id();
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index 8fbabda..f448fcb 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -19,6 +19,8 @@
#include <string.h>
#include "qemu-thread.h"
+pthread_key_t qemu_thread_key;
+
static void error_exit(int err, const char *msg)
{
fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
@@ -151,6 +153,11 @@ void qemu_thread_get_self(QemuThread *thread)
thread->thread = pthread_self();
}
+void qemu_thread_key_create(void)
+{
+ pthread_key_create(&qemu_thread_key, NULL);
+}
+
bool qemu_thread_is_self(QemuThread *thread)
{
return pthread_equal(pthread_self(), thread->thread);
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
index ee4618e..2607b1c 100644
--- a/qemu-thread-posix.h
+++ b/qemu-thread-posix.h
@@ -14,4 +14,6 @@ struct QemuThread {
pthread_t thread;
};
+extern pthread_key_t qemu_thread_key;
+
#endif
diff --git a/qemu-thread.h b/qemu-thread.h
index 05fdaaf..4a6427d 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -46,4 +46,5 @@ void qemu_thread_get_self(QemuThread *thread);
bool qemu_thread_is_self(QemuThread *thread);
void qemu_thread_exit(void *retval);
+void qemu_thread_key_create(void);
#endif
diff --git a/vl.c b/vl.c
index 7c577fa..44e2783 100644
--- a/vl.c
+++ b/vl.c
@@ -149,6 +149,7 @@ int main(int argc, char **argv)
#include "qemu-options.h"
#include "qmp-commands.h"
#include "main-loop.h"
+#include "qemu-thread.h"
#ifdef CONFIG_VIRTFS
#include "fsdev/qemu-fsdev.h"
#endif
@@ -2342,6 +2343,7 @@ int qemu_init_main_loop(void)
return main_loop_init();
}
+
int main(int argc, char **argv, char **envp)
{
int i;
@@ -3483,6 +3485,8 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
+ qemu_thread_key_create();
+
os_set_line_buffering();
if (init_timer_alarm() < 0) {
--
1.7.4.4
- Re: [Qemu-devel] [PATCH V3 10/11] vcpu: introduce lockmap, (continued)
- [Qemu-devel] [PATCH V3 11/11] vcpu: push mmio dispatcher out of big lock, Liu Ping Fan, 2012/09/11
- [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, Liu Ping Fan, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, Avi Kivity, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, liu ping fan, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, Avi Kivity, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, liu ping fan, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, Avi Kivity, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, liu ping fan, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 08/11] qom: introduce reclaimer to release obj in async, Avi Kivity, 2012/09/13
[Qemu-devel] [PATCH V3 09/11] vcpu: make QemuThread as tls to store thread-self info,
Liu Ping Fan <=
[Qemu-devel] [PATCH V3 06/11] memory: make mmio dispatch able to be out of biglock, Liu Ping Fan, 2012/09/11