From patchwork Tue Mar 15 21:50:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 87112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD88FB7252 for ; Wed, 16 Mar 2011 09:39:20 +1100 (EST) Received: from localhost ([127.0.0.1]:35407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzctZ-0008E7-Nu for incoming@patchwork.ozlabs.org; Tue, 15 Mar 2011 18:39:17 -0400 Received: from [140.186.70.92] (port=35184 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzcLV-0002Kf-F1 for qemu-devel@nongnu.org; Tue, 15 Mar 2011 18:04:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzcLS-0004xh-O0 for qemu-devel@nongnu.org; Tue, 15 Mar 2011 18:04:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzcLS-0004xG-FK for qemu-devel@nongnu.org; Tue, 15 Mar 2011 18:04:02 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2FM41iw008973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Mar 2011 18:04:01 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2FM41Xl007794; Tue, 15 Mar 2011 18:04:01 -0400 Received: from amt.cnet (vpn1-5-191.ams2.redhat.com [10.36.5.191]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p2FM3xIw024384; Tue, 15 Mar 2011 18:04:00 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 62C6D68A043; Tue, 15 Mar 2011 18:53:38 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p2FLrZ8B002188; Tue, 15 Mar 2011 18:53:35 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Tue, 15 Mar 2011 18:50:49 -0300 Message-Id: <7813bc5acc464d494bc0dc2883be9846eb0f8b8d.1300225848.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 35/35] Expose thread_id in info cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka Based on patch by Glauber Costa: To allow management applications like libvirt to apply CPU affinities to the VCPU threads, expose their ID via info cpus. This patch provides the pre-existing and used interface from qemu-kvm. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- cpu-defs.h | 1 + cpus.c | 2 ++ exec.c | 3 +++ monitor.c | 4 ++++ os-posix.c | 10 ++++++++++ os-win32.c | 5 +++++ osdep.h | 1 + qmp-commands.hx | 3 +++ 8 files changed, 29 insertions(+), 0 deletions(-) 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 d310b7e..28c2da2 100644 --- a/cpus.c +++ b/cpus.c @@ -776,6 +776,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) qemu_mutex_lock(&qemu_global_mutex); qemu_thread_get_self(env->thread); + env->thread_id = qemu_get_thread_id(); r = kvm_init_vcpu(env); if (r < 0) { @@ -817,6 +818,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 12ea582..4721f04 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 c971d92..d6d54c6 100644 --- a/os-win32.c +++ b/os-win32.c @@ -266,3 +266,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 } ] }