From patchwork Fri Apr 5 14:37:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 234159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 932022C00CF for ; Sat, 6 Apr 2013 01:43:30 +1100 (EST) Received: from localhost ([::1]:58266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7rU-0007O5-Bd for incoming@patchwork.ozlabs.org; Fri, 05 Apr 2013 10:43:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7o5-00035M-Gl for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:40:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UO7o3-0004VS-N7 for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:39:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7o3-0004V4-EW for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:39:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r35EcGHC031208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Apr 2013 10:38:16 -0400 Received: from thinkpad.mammed.com (vpn-238-59.phx2.redhat.com [10.3.238.59]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r35EbKxG031798; Fri, 5 Apr 2013 10:38:12 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 5 Apr 2013 16:37:04 +0200 Message-Id: <1365172636-28628-13-git-send-email-imammedo@redhat.com> In-Reply-To: <1365172636-28628-1-git-send-email-imammedo@redhat.com> References: <1365172636-28628-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, ehabkost@redhat.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 Subject: [Qemu-devel] [PATCH 12/22] cpu: add helper cpu_exists(), to check if CPU with specified id exists X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ... 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 --- 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 0d33009..5cac79b 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -227,6 +227,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 a54d4d1..46b77d3 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_firmware_id && klass->get_firmware_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);