From patchwork Mon Apr 22 10:28:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 238424 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 757C72C01C0 for ; Mon, 22 Apr 2013 20:29:06 +1000 (EST) Received: from localhost ([::1]:38437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUDzc-0001dt-G4 for incoming@patchwork.ozlabs.org; Mon, 22 Apr 2013 06:29:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUDzK-0001dY-HE for qemu-devel@nongnu.org; Mon, 22 Apr 2013 06:28:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUDzI-0005Cu-2G for qemu-devel@nongnu.org; Mon, 22 Apr 2013 06:28:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUDzH-0005Cp-Q8 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 06:28:43 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3MASQGU030558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Apr 2013 06:28:26 -0400 Received: from redhat.com (vpn1-5-64.ams2.redhat.com [10.36.5.64]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r3MASLMp003148; Mon, 22 Apr 2013 06:28:22 -0400 Date: Mon, 22 Apr 2013 13:28:12 +0300 From: "Michael S. Tsirkin" To: Igor Mammedov Message-ID: <20130422102812.GD3808@redhat.com> References: <1366063976-4909-1-git-send-email-imammedo@redhat.com> <1366063976-4909-9-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1366063976-4909-9-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 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, jan.kiszka@siemens.com, claudio.fontana@huawei.com, qemu-devel@nongnu.org, 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: Re: [Qemu-devel] [PATCH 08/16] 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 On Tue, Apr 16, 2013 at 12:12:48AM +0200, Igor Mammedov wrote: > ... 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 I would prefer qemu_for_each_cpu, that is also useful for ACPI. And do we need to scan all QOM? This will take a while to repeat if there are many devices. How about the below? You can add a wrapper that sets a bit if CPU exists. commit 4ff1332ff56069574f450bb44819156bd91bd105 Author: Michael S. Tsirkin Date: Sun Apr 21 15:44:47 2013 +0300 exec: add qemu_for_each_cpu Will be used by ACPI table generation. Signed-off-by: Michael S. Tsirkin diff --git a/exec.c b/exec.c index fa1e0c3..2b44cbe 100644 --- a/exec.c +++ b/exec.c @@ -265,6 +265,19 @@ CPUState *qemu_get_cpu(int index) return env ? cpu : NULL; } +void qemu_for_each_cpu( void (*func)( CPUState *c, void *arg), void *arg) +{ + CPUArchState *env = first_cpu; + CPUState *cpu; + + while (env) { + cpu = ENV_GET_CPU(env); + func(cpu, arg); + env = env->next_cpu; + } +} + + void cpu_exec_init(CPUArchState *env) { CPUState *cpu = ENV_GET_CPU(env); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 3664a1b..db857e3 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -223,6 +223,8 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); */ CPUState *qemu_get_cpu(int index); +void qemu_for_each_cpu( void (*func)( CPUState *c, void *arg), void *arg); + #ifndef CONFIG_USER_ONLY typedef void (*CPUInterruptHandler)(CPUState *, int);