From patchwork Thu Apr 25 14:05:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 239521 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 736342C00F1 for ; Fri, 26 Apr 2013 00:16:36 +1000 (EST) Received: from localhost ([::1]:41920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVMsM-0003eo-RW for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2013 10:10:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVMqI-0001Ix-IA for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVMqF-0005U6-0Q for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56710) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVMqE-0005Tq-Od for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:06 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3PE81Di010004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Apr 2013 10:08:01 -0400 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3PE7rFS006589; Thu, 25 Apr 2013 10:07:59 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 25 Apr 2013 16:05:24 +0200 Message-Id: <1366898737-6201-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1366898737-6201-1-git-send-email-imammedo@redhat.com> References: <1366898737-6201-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, ehabkost@redhat.com, mst@redhat.com, stefano.stabellini@eu.citrix.com, quintela@redhat.com, anthony.perard@citrix.com, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 02/15] 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 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 f64727e..4c44f06 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 9a4457b..3f79398 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);