From patchwork Sun Jun 23 20:05:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chegu Vinod X-Patchwork-Id: 253615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0492E2C0385 for ; Mon, 24 Jun 2013 12:09:37 +1000 (EST) Received: from localhost ([::1]:52701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqwDm-0004hB-V5 for incoming@patchwork.ozlabs.org; Sun, 23 Jun 2013 22:09:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqwDG-0004dk-DX for qemu-devel@nongnu.org; Sun, 23 Jun 2013 22:09:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UqwDE-0005Uk-AA for qemu-devel@nongnu.org; Sun, 23 Jun 2013 22:09:02 -0400 Received: from g6t0184.atlanta.hp.com ([15.193.32.61]:5514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UqwDE-0005Uf-4e for qemu-devel@nongnu.org; Sun, 23 Jun 2013 22:09:00 -0400 Received: from g5t0030.atlanta.hp.com (g5t0030.atlanta.hp.com [16.228.8.142]) by g6t0184.atlanta.hp.com (Postfix) with ESMTP id E4A96C05F; Mon, 24 Jun 2013 02:08:59 +0000 (UTC) Received: from hydra11.kio (dhcp-ios.usa.hp.com [15.198.0.12]) by g5t0030.atlanta.hp.com (Postfix) with ESMTP id 59CE814DA7; Mon, 24 Jun 2013 02:08:59 +0000 (UTC) From: Chegu Vinod To: eblake@redhat.com, anthony@codemonkey.ws, quintela@redhat.com, owasserm@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com Date: Sun, 23 Jun 2013 14:05:40 -0600 Message-Id: <1372017942-133812-2-git-send-email-chegu_vinod@hp.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1372017942-133812-1-git-send-email-chegu_vinod@hp.com> References: <1372017942-133812-1-git-send-email-chegu_vinod@hp.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 15.193.32.61 Cc: chegu_vinod@hp.com Subject: [Qemu-devel] [PATCH v7 1/3] Introduce async_run_on_cpu() 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 Introduce an asynchronous version of run_on_cpu() i.e. the caller doesn't have to block till the call back routine finishes execution on the target vcpu. Signed-off-by: Chegu Vinod Reviewed-by: Paolo Bonzini --- cpus.c | 29 +++++++++++++++++++++++++++++ include/qemu-common.h | 1 + include/qom/cpu.h | 10 ++++++++++ 3 files changed, 40 insertions(+), 0 deletions(-) diff --git a/cpus.c b/cpus.c index c8bc8ad..c7c90d0 100644 --- a/cpus.c +++ b/cpus.c @@ -653,6 +653,7 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) wi.func = func; wi.data = data; + wi.free = false; if (cpu->queued_work_first == NULL) { cpu->queued_work_first = &wi; } else { @@ -671,6 +672,31 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) } } +void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) +{ + struct qemu_work_item *wi; + + if (qemu_cpu_is_self(cpu)) { + func(data); + return; + } + + wi = g_malloc0(sizeof(struct qemu_work_item)); + wi->func = func; + wi->data = data; + wi->free = true; + if (cpu->queued_work_first == NULL) { + cpu->queued_work_first = wi; + } else { + cpu->queued_work_last->next = wi; + } + cpu->queued_work_last = wi; + wi->next = NULL; + wi->done = false; + + qemu_cpu_kick(cpu); +} + static void flush_queued_work(CPUState *cpu) { struct qemu_work_item *wi; @@ -683,6 +709,9 @@ static void flush_queued_work(CPUState *cpu) cpu->queued_work_first = wi->next; wi->func(wi->data); wi->done = true; + if (wi->free) { + g_free(wi); + } } cpu->queued_work_last = NULL; qemu_cond_broadcast(&qemu_work_cond); diff --git a/include/qemu-common.h b/include/qemu-common.h index 3c91375..9834dcb 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -291,6 +291,7 @@ struct qemu_work_item { void (*func)(void *data); void *data; int done; + bool free; }; #ifdef CONFIG_USER_ONLY diff --git a/include/qom/cpu.h b/include/qom/cpu.h index a5bb515..b555c22 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -288,6 +288,16 @@ bool cpu_is_stopped(CPUState *cpu); void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); /** + * async_run_on_cpu: + * @cpu: The vCPU to run on. + * @func: The function to be executed. + * @data: Data to pass to the function. + * + * Schedules the function @func for execution on the vCPU @cpu asynchronously. + */ +void async_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.