From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ME3yw-0003Nc-9P for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:15:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ME3yr-0003LH-8g for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:15:25 -0400 Received: from [199.232.76.173] (port=36726 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ME3yr-0003LE-1R for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:15:21 -0400 Received: from mx2.redhat.com ([66.187.237.31]:37495) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1ME3yq-00011G-LT for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:15:20 -0400 From: Glauber Costa Date: Tue, 9 Jun 2009 12:15:18 -0400 Message-Id: <1244564118-428-1-git-send-email-glommer@redhat.com> Subject: [Qemu-devel] [PATCH] provide cpu_index to env mapping List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com 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 --- cpu-all.h | 1 + exec.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index dc9b034..8990be3 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -741,6 +741,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 52f4e89..6c26cb6 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; -- 1.5.6.6