From: Glauber Costa Date: Tue, 9 Jun 2009 16:15:18 +0000 (-0400) Subject: provide cpu_index to env mapping X-Git-Tag: v0.11.0-rc0~353 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=950f147249643635289003d7dd291915ad330b29;p=qemu-xen-4.5-testing.git provide cpu_index to env mapping There are some people interested in, given a cpu number, pick its CPUState. KVM is an example, although not yet in tree. This patch provides a way of doing that. Signed-off-by: Glauber Costa Signed-off-by: Anthony Liguori --- diff --git a/cpu-all.h b/cpu-all.h index 8f078c415..48a9a2c11 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -743,6 +743,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags); void cpu_exec_init_all(unsigned long tb_size); CPUState *cpu_copy(CPUState *env); +CPUState *qemu_get_cpu(int cpu); void cpu_dump_state(CPUState *env, FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...), diff --git a/exec.c b/exec.c index 3023f4418..bbaf0b689 100644 --- a/exec.c +++ b/exec.c @@ -541,6 +541,19 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id) } #endif +CPUState *qemu_get_cpu(int cpu) +{ + CPUState *env = first_cpu; + + while (env) { + if (env->cpu_index == cpu) + break; + env = env->next_cpu; + } + + return env; +} + void cpu_exec_init(CPUState *env) { CPUState **penv;