From patchwork Fri Mar 4 10:20:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 608371 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p24AKmOV024356 for ; Fri, 4 Mar 2011 10:20:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759425Ab1CDKUh (ORCPT ); Fri, 4 Mar 2011 05:20:37 -0500 Received: from thoth.sbs.de ([192.35.17.2]:17507 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759401Ab1CDKU3 (ORCPT ); Fri, 4 Mar 2011 05:20:29 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id p24AKFn2017916; Fri, 4 Mar 2011 11:20:15 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p24AKCXU008671; Fri, 4 Mar 2011 11:20:15 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH 15/15] Expose thread_id in info cpus Date: Fri, 4 Mar 2011 11:20:12 +0100 Message-Id: <3a108671c8b1def3f69523717f464766a2871486.1299233998.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 04 Mar 2011 10:20:49 +0000 (UTC) diff --git a/cpu-defs.h b/cpu-defs.h index 2b59fa6..db48a7a 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -203,6 +203,7 @@ typedef struct CPUWatchpoint { int nr_cores; /* number of cores within this CPU package */ \ int nr_threads;/* number of threads within this CPU */ \ int running; /* Nonzero if cpu is currently running(usermode). */ \ + int thread_id; \ /* user data */ \ void *opaque; \ \ diff --git a/cpus.c b/cpus.c index 66f6b5a..30fe568 100644 --- a/cpus.c +++ b/cpus.c @@ -810,6 +810,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) qemu_mutex_lock(&qemu_global_mutex); qemu_thread_self(env->thread); + env->thread_id = qemu_get_thread_id(); r = kvm_init_vcpu(env); if (r < 0) { @@ -851,6 +852,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); for (env = first_cpu; env != NULL; env = env->next_cpu) { + env->thread_id = qemu_get_thread_id(); env->created = 1; } qemu_cond_signal(&qemu_cpu_cond); diff --git a/exec.c b/exec.c index a733acd..0b7a7b2 100644 --- a/exec.c +++ b/exec.c @@ -638,6 +638,9 @@ void cpu_exec_init(CPUState *env) env->numa_node = 0; QTAILQ_INIT(&env->breakpoints); QTAILQ_INIT(&env->watchpoints); +#ifndef CONFIG_USER_ONLY + env->thread_id = qemu_get_thread_id(); +#endif *penv = env; #if defined(CONFIG_USER_ONLY) cpu_list_unlock(); diff --git a/monitor.c b/monitor.c index ae20927..481572d 100644 --- a/monitor.c +++ b/monitor.c @@ -897,6 +897,9 @@ static void print_cpu_iter(QObject *obj, void *opaque) monitor_printf(mon, " (halted)"); } + monitor_printf(mon, " thread_id=%" PRId64 " ", + qdict_get_int(cpu, "thread_id")); + monitor_printf(mon, "\n"); } @@ -941,6 +944,7 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) #elif defined(TARGET_MIPS) qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); #endif + qdict_put(cpu, "thread_id", qint_from_int(env->thread_id)); qlist_append(cpu_list, cpu); } diff --git a/os-posix.c b/os-posix.c index 38c29d1..7971f86 100644 --- a/os-posix.c +++ b/os-posix.c @@ -41,6 +41,7 @@ #ifdef CONFIG_LINUX #include +#include #endif #ifdef CONFIG_EVENTFD @@ -382,3 +383,12 @@ int qemu_create_pidfile(const char *filename) return 0; } + +int qemu_get_thread_id(void) +{ +#if defined (__linux__) + return syscall(SYS_gettid); +#else + return getpid(); +#endif +} diff --git a/os-win32.c b/os-win32.c index b214e6a..dd5517e 100644 --- a/os-win32.c +++ b/os-win32.c @@ -264,3 +264,8 @@ int qemu_create_pidfile(const char *filename) } return 0; } + +int qemu_get_thread_id(void) +{ + return GetCurrentThreadId(); +} diff --git a/osdep.h b/osdep.h index 27eedcf..748df54 100644 --- a/osdep.h +++ b/osdep.h @@ -130,5 +130,6 @@ void qemu_vfree(void *ptr); int qemu_madvise(void *addr, size_t len, int advice); int qemu_create_pidfile(const char *filename); +int qemu_get_thread_id(void); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index df40a3d..1f72a8d 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1194,6 +1194,7 @@ Return a json-array. Each CPU is represented by a json-object, which contains: "nip": PPC (json-int) "pc" and "npc": sparc (json-int) "PC": mips (json-int) +- "thread_id": ID of the underlying host thread (json-int) Example: @@ -1205,12 +1206,14 @@ Example: "current":true, "halted":false, "pc":3227107138 + "thread_id":3134 }, { "CPU":1, "current":false, "halted":true, "pc":7108165 + "thread_id":3135 } ] }