Received: from eggs.gnu.org ([208.118.235.92]:56962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUYf7-0006Ou-Rj for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:33:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUYf6-0001rG-K3 for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:33:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUYf6-0001r4-BF for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:33:16 -0400 From: Igor Mammedov Date: Tue, 23 Apr 2013 10:29:43 +0200 Message-Id: <1366705795-24732-10-git-send-email-imammedo@redhat.com> In-Reply-To: <1366705795-24732-1-git-send-email-imammedo@redhat.com> References: <1366705795-24732-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH 09/21] cpu: add helper cpu_exists(), to check if CPU with specified id exists List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, gleb@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, lcapitulino@redhat.com, blauwirbel@gmail.com, kraxel@redhat.com, quintela@redhat.com, armbru@redhat.com, yang.z.zhang@intel.com, ehabkost@redhat.com, stefano.stabellini@eu.citrix.com, aderumier@odiso.com, anthony.perard@citrix.com, alex.williamson@redhat.com, rth@twiddle.net, kwolf@redhat.com, aliguori@us.ibm.com, claudio.fontana@huawei.com, pbonzini@redhat.com, afaerber@suse.de Signed-off-by: Igor Mammedov --- v3: * use qemu_for_each_cpu() instead of recursion v2: * s/get_firmware_id()/get_arch_id()/ rebase fixup * remove check for get_arch_id being NULL, since it's always defined --- include/qom/cpu.h | 10 ++++++++++ qom/cpu.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index d4a21f4..7ba65a5 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -233,6 +233,16 @@ void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data); */ CPUState *qemu_get_cpu(int index); +/** + * cpu_exists: + * @id - guest exposed CPU ID to lookup + * + * Search for CPU with specified ID. + * + * Returns: true - CPU is found, false - CPU isn't found + */ +bool cpu_exists(int64_t id); + #ifndef CONFIG_USER_ONLY typedef void (*CPUInterruptHandler)(CPUState *, int); diff --git a/qom/cpu.c b/qom/cpu.c index d44f987..fcc34aa 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -24,6 +24,32 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" +typedef struct CPU_exists_args { + int64_t id; + bool found; +} CPU_exists_args; + +static void cpu_exist_cb(CPUState *cpu, void *data) +{ + CPUClass *klass = CPU_GET_CLASS(cpu); + CPU_exists_args *arg = data; + + if (klass->get_arch_id(cpu) == arg->id) { + arg->found = true; + } +} + +bool cpu_exists(int64_t id) +{ + CPU_exists_args data = { + .id = id, + .found = false, + }; + + qemu_for_each_cpu(cpu_exist_cb, &data); + return data.found; +} + /* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers = NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); -- 1.7.1