From patchwork Fri Nov 9 03:14:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 197919 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 D4AB92C00DB for ; Fri, 9 Nov 2012 14:14:59 +1100 (EST) Received: from localhost ([::1]:38611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWf3Z-0006iH-T9 for incoming@patchwork.ozlabs.org; Thu, 08 Nov 2012 22:14:57 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWf3M-0006Z4-V9 for qemu-devel@nongnu.org; Thu, 08 Nov 2012 22:14:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TWf3L-0007cV-SP for qemu-devel@nongnu.org; Thu, 08 Nov 2012 22:14:44 -0500 Received: from mail-ob0-f173.google.com ([209.85.214.173]:35363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWf3L-0007cM-Ml for qemu-devel@nongnu.org; Thu, 08 Nov 2012 22:14:43 -0500 Received: by mail-ob0-f173.google.com with SMTP id wc18so3297058obb.4 for ; Thu, 08 Nov 2012 19:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=QEL0+tJO3xnZjNpyh3v49vWh5PMZa2A1h54+roNtWFM=; b=zyZ+H85vdtsz5rU/54sDxCHtAb7MvKvZSIeji4dzocOy6sflYVsmOUwxdb8JggRaqP TmmSdBW6adikai3h/agIpekzFIkKzk8Uj5SKtyfTFbwdXZatAJnhjyl6M7fHlXNPLGJ4 SLpcnxuiwxCh2nhxBpvuD3bPznja2sQcbJr0J368DiLuYT4aEAIOtrK8yNbYSFkJ7ENT BUMaGm++osqlzytOHbESusUTfHY80ee5VsCl+sYhxOSJQW+QZaFyascpc1+xEKifuPd9 ZxjJclV/rdjSsIaA+HIJeJM7+9HJf5c6ogn5SO0QaDxMbpogEa9nScGUpOPTli03Flis d9tQ== Received: by 10.60.11.162 with SMTP id r2mr6642645oeb.114.1352430882934; Thu, 08 Nov 2012 19:14:42 -0800 (PST) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPS id 9sm28440267obi.22.2012.11.08.19.14.40 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Nov 2012 19:14:42 -0800 (PST) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Fri, 9 Nov 2012 11:14:28 +0800 Message-Id: <1352430870-10129-2-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1352430870-10129-1-git-send-email-qemulist@gmail.com> References: <1352430870-10129-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.214.173 Cc: Vasilis Liaskovitis , Stefan Hajnoczi , Avi Kivity , Anthony Liguori Subject: [Qemu-devel] [RFC v1 1/3] bouce buffer has fine grain lock 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 From: Liu Ping Fan Signed-off-by: Liu Ping Fan --- exec.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index 73d5242..fe84718 100644 --- a/exec.c +++ b/exec.c @@ -3296,6 +3296,15 @@ void address_space_destroy_dispatch(AddressSpace *as) as->dispatch = NULL; } +typedef struct { + QemuMutex lock; + void *buffer; + target_phys_addr_t addr; + target_phys_addr_t len; +} BounceBuffer; + +static BounceBuffer bounce; + static void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); @@ -3308,6 +3317,8 @@ static void memory_map_init(void) address_space_init(&address_space_io, system_io); address_space_io.name = "I/O"; + qemu_mutex_init(&bounce.lock); + memory_listener_register(&core_memory_listener, &address_space_memory); memory_listener_register(&io_memory_listener, &address_space_io); memory_listener_register(&tcg_memory_listener, &address_space_memory); @@ -3671,14 +3682,6 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, } } -typedef struct { - void *buffer; - target_phys_addr_t addr; - target_phys_addr_t len; -} BounceBuffer; - -static BounceBuffer bounce; - typedef struct MapClient { void *opaque; void (*callback)(void *opaque); @@ -3747,6 +3750,7 @@ void *address_space_map(AddressSpace *as, section = &mr_obj; if (!(memory_region_is_ram(section->mr) && !section->readonly)) { + qemu_mutex_lock(&bounce.lock); if (todo || bounce.buffer) { break; } @@ -3807,6 +3811,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, target_phys_addr_t len, } qemu_vfree(bounce.buffer); bounce.buffer = NULL; + qemu_mutex_unlock(&bounce.lock); cpu_notify_map_clients(); }