mirror of https://github.com/xemu-project/xemu.git
Expose thread_id in info cpus
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 <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
This commit is contained in:
parent
f2574737f6
commit
dc7a09cfe4
|
@ -203,6 +203,7 @@ typedef struct CPUWatchpoint {
|
||||||
int nr_cores; /* number of cores within this CPU package */ \
|
int nr_cores; /* number of cores within this CPU package */ \
|
||||||
int nr_threads;/* number of threads within this CPU */ \
|
int nr_threads;/* number of threads within this CPU */ \
|
||||||
int running; /* Nonzero if cpu is currently running(usermode). */ \
|
int running; /* Nonzero if cpu is currently running(usermode). */ \
|
||||||
|
int thread_id; \
|
||||||
/* user data */ \
|
/* user data */ \
|
||||||
void *opaque; \
|
void *opaque; \
|
||||||
\
|
\
|
||||||
|
|
2
cpus.c
2
cpus.c
|
@ -776,6 +776,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
|
||||||
|
|
||||||
qemu_mutex_lock(&qemu_global_mutex);
|
qemu_mutex_lock(&qemu_global_mutex);
|
||||||
qemu_thread_get_self(env->thread);
|
qemu_thread_get_self(env->thread);
|
||||||
|
env->thread_id = qemu_get_thread_id();
|
||||||
|
|
||||||
r = kvm_init_vcpu(env);
|
r = kvm_init_vcpu(env);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
@ -817,6 +818,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||||
/* signal CPU creation */
|
/* signal CPU creation */
|
||||||
qemu_mutex_lock(&qemu_global_mutex);
|
qemu_mutex_lock(&qemu_global_mutex);
|
||||||
for (env = first_cpu; env != NULL; env = env->next_cpu) {
|
for (env = first_cpu; env != NULL; env = env->next_cpu) {
|
||||||
|
env->thread_id = qemu_get_thread_id();
|
||||||
env->created = 1;
|
env->created = 1;
|
||||||
}
|
}
|
||||||
qemu_cond_signal(&qemu_cpu_cond);
|
qemu_cond_signal(&qemu_cpu_cond);
|
||||||
|
|
3
exec.c
3
exec.c
|
@ -638,6 +638,9 @@ void cpu_exec_init(CPUState *env)
|
||||||
env->numa_node = 0;
|
env->numa_node = 0;
|
||||||
QTAILQ_INIT(&env->breakpoints);
|
QTAILQ_INIT(&env->breakpoints);
|
||||||
QTAILQ_INIT(&env->watchpoints);
|
QTAILQ_INIT(&env->watchpoints);
|
||||||
|
#ifndef CONFIG_USER_ONLY
|
||||||
|
env->thread_id = qemu_get_thread_id();
|
||||||
|
#endif
|
||||||
*penv = env;
|
*penv = env;
|
||||||
#if defined(CONFIG_USER_ONLY)
|
#if defined(CONFIG_USER_ONLY)
|
||||||
cpu_list_unlock();
|
cpu_list_unlock();
|
||||||
|
|
|
@ -897,6 +897,9 @@ static void print_cpu_iter(QObject *obj, void *opaque)
|
||||||
monitor_printf(mon, " (halted)");
|
monitor_printf(mon, " (halted)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor_printf(mon, " thread_id=%" PRId64 " ",
|
||||||
|
qdict_get_int(cpu, "thread_id"));
|
||||||
|
|
||||||
monitor_printf(mon, "\n");
|
monitor_printf(mon, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,6 +944,7 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data)
|
||||||
#elif defined(TARGET_MIPS)
|
#elif defined(TARGET_MIPS)
|
||||||
qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC));
|
qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC));
|
||||||
#endif
|
#endif
|
||||||
|
qdict_put(cpu, "thread_id", qint_from_int(env->thread_id));
|
||||||
|
|
||||||
qlist_append(cpu_list, cpu);
|
qlist_append(cpu_list, cpu);
|
||||||
}
|
}
|
||||||
|
|
10
os-posix.c
10
os-posix.c
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#ifdef CONFIG_LINUX
|
#ifdef CONFIG_LINUX
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_EVENTFD
|
#ifdef CONFIG_EVENTFD
|
||||||
|
@ -382,3 +383,12 @@ int qemu_create_pidfile(const char *filename)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int qemu_get_thread_id(void)
|
||||||
|
{
|
||||||
|
#if defined (__linux__)
|
||||||
|
return syscall(SYS_gettid);
|
||||||
|
#else
|
||||||
|
return getpid();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -266,3 +266,8 @@ int qemu_create_pidfile(const char *filename)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int qemu_get_thread_id(void)
|
||||||
|
{
|
||||||
|
return GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
|
1
osdep.h
1
osdep.h
|
@ -130,5 +130,6 @@ void qemu_vfree(void *ptr);
|
||||||
int qemu_madvise(void *addr, size_t len, int advice);
|
int qemu_madvise(void *addr, size_t len, int advice);
|
||||||
|
|
||||||
int qemu_create_pidfile(const char *filename);
|
int qemu_create_pidfile(const char *filename);
|
||||||
|
int qemu_get_thread_id(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1194,6 +1194,7 @@ Return a json-array. Each CPU is represented by a json-object, which contains:
|
||||||
"nip": PPC (json-int)
|
"nip": PPC (json-int)
|
||||||
"pc" and "npc": sparc (json-int)
|
"pc" and "npc": sparc (json-int)
|
||||||
"PC": mips (json-int)
|
"PC": mips (json-int)
|
||||||
|
- "thread_id": ID of the underlying host thread (json-int)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -1205,12 +1206,14 @@ Example:
|
||||||
"current":true,
|
"current":true,
|
||||||
"halted":false,
|
"halted":false,
|
||||||
"pc":3227107138
|
"pc":3227107138
|
||||||
|
"thread_id":3134
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"CPU":1,
|
"CPU":1,
|
||||||
"current":false,
|
"current":false,
|
||||||
"halted":true,
|
"halted":true,
|
||||||
"pc":7108165
|
"pc":7108165
|
||||||
|
"thread_id":3135
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue