===================================================================
@@ -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; \
\
===================================================================
@@ -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();
===================================================================
@@ -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();
===================================================================
@@ -44,6 +44,10 @@
extern int madvise(caddr_t, size_t, int);
#endif
+#ifdef CONFIG_LINUX
+#include <sys/syscall.h>
+#endif
+
#ifdef CONFIG_EVENTFD
#include <sys/eventfd.h>
#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. */
===================================================================
@@ -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);
===================================================================
@@ -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);
}
commit ce6325ff1af34dbaee91c8d28e792277e43f1227 Author: Glauber Costa <gcosta@redhat.com> 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 <mtosatti@redhat.com>