From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFV-0002rX-22 for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQEFK-0006h3-5j for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:40 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:56214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFJ-0006gS-Hv for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:30 -0400 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Oct 2012 14:54:27 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9M9OKn726738718 for ; Mon, 22 Oct 2012 14:54:20 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9MEsBDd028279 for ; Mon, 22 Oct 2012 14:54:12 GMT From: Liu Ping Fan Date: Mon, 22 Oct 2012 17:23:51 +0800 Message-Id: <1350897839-29593-9-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [patch v4 08/16] QemuThread: make QemuThread as tls to store extra info List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Marcelo Tosatti , Avi Kivity , Anthony Liguori , Jan Kiszka , Paolo Bonzini If mmio dispatch out of big lock, some function's calling context (ie, holding big lock or not) are different. We need to trace these info in runtime, and use tls to store them. By this method, we can avoid to require big lock recursive. Signed-off-by: Liu Ping Fan --- cpus.c | 1 + qemu-thread-posix.c | 7 +++++++ qemu-thread-posix.h | 2 ++ qemu-thread.h | 1 + vl.c | 6 ++++++ 5 files changed, 17 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 #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..442479a 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,10 @@ int main(int argc, char **argv, char **envp) exit(1); } + qemu_thread_key_create(); + QemuThread *ioctx = g_malloc0(sizeof(QemuThread)); + pthread_setspecific(qemu_thread_key, ioctx); + os_set_line_buffering(); if (init_timer_alarm() < 0) { -- 1.7.4.4