From patchwork Wed Oct 6 17:34:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 66948 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 D24A8B70D9 for ; Thu, 7 Oct 2010 04:43:21 +1100 (EST) Received: from localhost ([127.0.0.1]:37255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3Y1O-0002gB-I4 for incoming@patchwork.ozlabs.org; Wed, 06 Oct 2010 13:43:18 -0400 Received: from [140.186.70.92] (port=35908 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3Xy7-0001N2-7L for qemu-devel@nongnu.org; Wed, 06 Oct 2010 13:39:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3Xy6-00078l-0q for qemu-devel@nongnu.org; Wed, 06 Oct 2010 13:39:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3Xy5-00078X-PG for qemu-devel@nongnu.org; Wed, 06 Oct 2010 13:39:53 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o96HdqK2032470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Oct 2010 13:39:52 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o96HdpIs030648; Wed, 6 Oct 2010 13:39:52 -0400 Received: from amt.cnet (vpn-8-65.rdu.redhat.com [10.11.8.65]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o96HdoNH016086; Wed, 6 Oct 2010 13:39:50 -0400 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id B5BCD68A085; Wed, 6 Oct 2010 14:38:50 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id o96HcnFF007231; Wed, 6 Oct 2010 14:38:49 -0300 Message-Id: <20101006173609.419029478@redhat.com> User-Agent: quilt/0.47-1 Date: Wed, 06 Oct 2010 14:34:27 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20101006173424.425523999@redhat.com> Content-Disposition: inline; filename=thread-id X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Dean Nelson , Marcelo Tosatti , Huang Ying Subject: [Qemu-devel] [patch uq/master 3/8] 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 commit ce6325ff1af34dbaee91c8d28e792277e43f1227 Author: Glauber Costa Date: Wed Mar 5 17:01:10 2008 -0300 Augment info cpus This patch exposes the thread id associated with each cpu through the already well known 'info cpus' interface. Signed-off-by: Marcelo Tosatti Index: qemu/cpu-defs.h =================================================================== --- qemu.orig/cpu-defs.h +++ qemu/cpu-defs.h @@ -197,6 +197,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; \ \ Index: qemu/cpus.c =================================================================== --- qemu.orig/cpus.c +++ qemu/cpus.c @@ -539,6 +539,7 @@ static void *kvm_cpu_thread_fn(void *arg qemu_mutex_lock(&qemu_global_mutex); qemu_thread_self(env->thread); + env->thread_id = get_thread_id(); if (kvm_enabled()) kvm_init_vcpu(env); @@ -578,6 +579,10 @@ static void *tcg_cpu_thread_fn(void *arg while (!qemu_system_ready) qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); + for (env = first_cpu; env != NULL; env = env->next_cpu) { + env->thread_id = get_thread_id(); + } + while (1) { cpu_exec_all(); qemu_tcg_wait_io_event(); Index: qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -637,6 +637,7 @@ void cpu_exec_init(CPUState *env) env->numa_node = 0; QTAILQ_INIT(&env->breakpoints); QTAILQ_INIT(&env->watchpoints); + env->thread_id = get_thread_id(); *penv = env; #if defined(CONFIG_USER_ONLY) cpu_list_unlock(); Index: qemu/osdep.c =================================================================== --- qemu.orig/osdep.c +++ qemu/osdep.c @@ -44,6 +44,10 @@ extern int madvise(caddr_t, size_t, int); #endif +#ifdef CONFIG_LINUX +#include +#endif + #ifdef CONFIG_EVENTFD #include #endif @@ -200,6 +204,17 @@ int qemu_create_pidfile(const char *file return 0; } +int get_thread_id(void) +{ +#if defined (_WIN32) + return GetCurrentThreadId(); +#elif defined (__linux__) + return syscall(SYS_gettid); +#else + return getpid(); +#endif +} + #ifdef _WIN32 /* mingw32 needs ffs for compilations without optimization. */ Index: qemu/osdep.h =================================================================== --- qemu.orig/osdep.h +++ qemu/osdep.h @@ -126,6 +126,7 @@ void qemu_vfree(void *ptr); int qemu_madvise(void *addr, size_t len, int advice); int qemu_create_pidfile(const char *filename); +int get_thread_id(void); #ifdef _WIN32 int ffs(int i); Index: qemu/monitor.c =================================================================== --- qemu.orig/monitor.c +++ qemu/monitor.c @@ -878,6 +878,9 @@ static void print_cpu_iter(QObject *obj, monitor_printf(mon, " (halted)"); } + monitor_printf(mon, " thread_id=%" PRId64 " ", + qdict_get_int(cpu, "thread_id")); + monitor_printf(mon, "\n"); } @@ -922,6 +925,7 @@ static void do_info_cpus(Monitor *mon, Q #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); }