From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXtgA-000302-G4 for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXtg3-0004WB-NA for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:10 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46617 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXtg3-0004Vc-Gt for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:03 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 2 May 2013 15:35:36 +0200 Message-Id: <1367501755-32272-11-git-send-email-afaerber@suse.de> In-Reply-To: <1367501755-32272-1-git-send-email-afaerber@suse.de> References: <1367501755-32272-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 10/29] 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: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Igor Mammedov Signed-off-by: Igor Mammedov Signed-off-by: Andreas F=C3=A4rber --- include/qom/cpu.h | 10 ++++++++++ qom/cpu.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index a28e5ff..e54579b 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -234,6 +234,16 @@ void qemu_for_each_cpu(void (*func)(CPUState *cpu, v= oid *data), void *data); */ CPUState *qemu_get_cpu(int index); =20 +/** + * 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 =20 typedef void (*CPUInterruptHandler)(CPUState *, int); diff --git a/qom/cpu.c b/qom/cpu.c index 9a4457b..3dc8208 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -24,6 +24,32 @@ #include "qemu/notify.h" #include "sysemu/sysemu.h" =20 +typedef struct CPUExistsArgs { + int64_t id; + bool found; +} CPUExistsArgs; + +static void cpu_exist_cb(CPUState *cpu, void *data) +{ + CPUClass *klass =3D CPU_GET_CLASS(cpu); + CPUExistsArgs *arg =3D data; + + if (klass->get_arch_id(cpu) =3D=3D arg->id) { + arg->found =3D true; + } +} + +bool cpu_exists(int64_t id) +{ + CPUExistsArgs data =3D { + .id =3D id, + .found =3D false, + }; + + qemu_for_each_cpu(cpu_exist_cb, &data); + return data.found; +} + /* CPU hot-plug notifiers */ static NotifierList cpu_added_notifiers =3D NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); --=20 1.8.1.4