From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URrec-0005tn-9E for qemu-devel@nongnu.org; Mon, 15 Apr 2013 18:13:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URreb-0008C7-5F for qemu-devel@nongnu.org; Mon, 15 Apr 2013 18:13:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65466) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URrea-0008By-Rx for qemu-devel@nongnu.org; Mon, 15 Apr 2013 18:13:37 -0400 From: Igor Mammedov Date: Tue, 16 Apr 2013 00:12:48 +0200 Message-Id: <1366063976-4909-9-git-send-email-imammedo@redhat.com> In-Reply-To: <1366063976-4909-1-git-send-email-imammedo@redhat.com> References: <1366063976-4909-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH 08/16] 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: aliguori@us.ibm.com, ehabkost@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, claudio.fontana@huawei.com, aderumier@odiso.com, lcapitulino@redhat.com, jfrei@linux.vnet.ibm.com, yang.z.zhang@intel.com, pbonzini@redhat.com, afaerber@suse.de, lig.fnst@cn.fujitsu.com, rth@twiddle.net ... it should be used only on slow path since it does recursive search on /machine QOM tree for objects of TYPE_CPU Signed-off-by: Igor Mammedov Reviewed-by: Paolo Bonzini --- 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 | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 428aaf0..33d5e91 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -225,6 +225,16 @@ void run_on_cpu(CPUState *cpu, void (*func)(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 a13ddda..02fab9a 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -24,6 +24,27 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" +static int cpu_exist_cb(Object *obj, void *opaque) +{ + int64_t id = *(int64_t *)opaque; + Object *cpu_obj = object_dynamic_cast(obj, TYPE_CPU); + + if (cpu_obj) { + CPUState *cpu = CPU(cpu_obj); + CPUClass *klass = CPU_GET_CLASS(cpu); + + if (klass->get_arch_id(cpu) == id) { + return 1; + } + } + return object_child_foreach(obj, cpu_exist_cb, opaque); +} + +bool cpu_exists(int64_t id) +{ + return cpu_exist_cb(qdev_get_machine(), &id) ? true : false; +} + /* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers = NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); -- 1.8.2