From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVMqI-0001IJ-Ct for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVMqE-0005U0-IB for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVMqE-0005Tg-AP for qemu-devel@nongnu.org; Thu, 25 Apr 2013 10:08:06 -0400 From: Igor Mammedov Date: Thu, 25 Apr 2013 16:05:23 +0200 Message-Id: <1366898737-6201-2-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> Subject: [Qemu-devel] [PATCH 01/15] exec: add qemu_for_each_cpu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 wrapper will help to remove open-coded loops. pathc icludes random example of how it could be used. Signed-off-by: Michael S. Tsirkin Signed-off-by: Igor Mammedov --- Note: Will be used by ACPI table generation and cpu_exists() v2: * s/signal_cpu_creation()/tcg_signal_cpu_creation()/ --- cpus.c | 13 +++++++------ exec.c | 10 ++++++++++ include/qom/cpu.h | 8 ++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cpus.c b/cpus.c index 1d88761..a2d92c7 100644 --- a/cpus.c +++ b/cpus.c @@ -812,6 +812,12 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) static void tcg_exec_all(void); +static void tcg_signal_cpu_creation(CPUState *cpu, void *data) +{ + cpu->thread_id = qemu_get_thread_id(); + cpu->created = true; +} + static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; @@ -820,13 +826,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) qemu_tcg_init_cpu_signals(); qemu_thread_get_self(cpu->thread); - /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); - for (env = first_cpu; env != NULL; env = env->next_cpu) { - cpu = ENV_GET_CPU(env); - cpu->thread_id = qemu_get_thread_id(); - cpu->created = true; - } + qemu_for_each_cpu(tcg_signal_cpu_creation, NULL); qemu_cond_signal(&qemu_cpu_cond); /* wait for initial kick-off after machine start */ diff --git a/exec.c b/exec.c index fa1e0c3..19725db 100644 --- a/exec.c +++ b/exec.c @@ -265,6 +265,16 @@ CPUState *qemu_get_cpu(int index) return env ? cpu : NULL; } +void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data) +{ + CPUArchState *env = first_cpu; + + while (env) { + func(ENV_GET_CPU(env), data); + 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 1b4de17..f64727e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -215,6 +215,14 @@ bool cpu_is_stopped(CPUState *cpu); */ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); +/** qemu_for_each_cpu: + * @func: The function to be executed. + * @data: Data to pass to the function. + * + * Executes @func on all CPUs + */ +void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data); + /** * qemu_get_cpu: * @index: The CPUState@cpu_index value of the CPU to obtain. -- 1.7.1