From patchwork Wed Aug 17 03:56:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umesh Deshpande X-Patchwork-Id: 1072852 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7H3vVxF017280 for ; Wed, 17 Aug 2011 03:57:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753260Ab1HQD5N (ORCPT ); Tue, 16 Aug 2011 23:57:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7309 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674Ab1HQD5I (ORCPT ); Tue, 16 Aug 2011 23:57:08 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7H3v7ud004919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 16 Aug 2011 23:57:07 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7H3v6pI030534; Tue, 16 Aug 2011 23:57:06 -0400 Received: from umeshhome.redhat.com (vpn-9-14.rdu.redhat.com [10.11.9.14]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p7H3v4Z6002051; Tue, 16 Aug 2011 23:57:06 -0400 From: Umesh Deshpande To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: pbonzini@redhat.com, quintela@redhat.com, mtosatti@redhat.com, Umesh Deshpande Subject: [RFC PATCH v4 2/5] ramlist mutex Date: Tue, 16 Aug 2011 23:56:37 -0400 Message-Id: <8f99d56f3a48b6255cf70425bc435d8f231f5352.1313552764.git.udeshpan@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 17 Aug 2011 03:57:32 +0000 (UTC) ramlist mutex is implemented to protect the RAMBlock list traversal in the migration thread from their addition/removal from the iothread. Signed-off-by: Umesh Deshpande --- cpu-all.h | 2 ++ exec.c | 19 +++++++++++++++++++ qemu-common.h | 2 ++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 6b217a2..eab9803 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -21,6 +21,7 @@ #include "qemu-common.h" #include "cpu-common.h" +#include "qemu-thread.h" /* some important defines: * @@ -932,6 +933,7 @@ typedef struct RAMBlock { } RAMBlock; typedef struct RAMList { + QemuMutex mutex; uint8_t *phys_dirty; QLIST_HEAD(ram, RAMBlock) blocks; QLIST_HEAD(, RAMBlock) blocks_mru; diff --git a/exec.c b/exec.c index c5c247c..404d8ea 100644 --- a/exec.c +++ b/exec.c @@ -582,6 +582,7 @@ void cpu_exec_init_all(unsigned long tb_size) code_gen_alloc(tb_size); code_gen_ptr = code_gen_buffer; page_init(); + qemu_mutex_init(&ram_list.mutex); #if !defined(CONFIG_USER_ONLY) io_mem_init(); #endif @@ -2802,6 +2803,16 @@ static long gethugepagesize(const char *path) return fs.f_bsize; } +void qemu_mutex_lock_ramlist(void) +{ + qemu_mutex_lock(&ram_list.mutex); +} + +void qemu_mutex_unlock_ramlist(void) +{ + qemu_mutex_unlock(&ram_list.mutex); +} + static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, const char *path) @@ -2976,6 +2987,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, } new_block->length = size; + qemu_mutex_lock_ramlist(); + QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); QLIST_INSERT_HEAD(&ram_list.blocks_mru, new_block, next_mru); @@ -2984,6 +2997,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), 0xff, size >> TARGET_PAGE_BITS); + qemu_mutex_unlock_ramlist(); + if (kvm_enabled()) kvm_setup_guest_memory(new_block->host, size); @@ -3001,8 +3016,10 @@ void qemu_ram_free_from_ptr(ram_addr_t addr) QLIST_FOREACH(block, &ram_list.blocks, next) { if (addr == block->offset) { + qemu_mutex_lock_ramlist(); QLIST_REMOVE(block, next); QLIST_REMOVE(block, next_mru); + qemu_mutex_unlock_ramlist(); qemu_free(block); return; } @@ -3015,8 +3032,10 @@ void qemu_ram_free(ram_addr_t addr) QLIST_FOREACH(block, &ram_list.blocks, next) { if (addr == block->offset) { + qemu_mutex_lock_ramlist(); QLIST_REMOVE(block, next); QLIST_REMOVE(block, next_mru); + qemu_mutex_unlock_ramlist(); if (block->flags & RAM_PREALLOC_MASK) { ; } else if (mem_path) { diff --git a/qemu-common.h b/qemu-common.h index abd7a75..b802883 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -212,6 +212,8 @@ char *qemu_strndup(const char *str, size_t size); void qemu_mutex_lock_iothread(void); void qemu_mutex_unlock_iothread(void); +void qemu_mutex_lock_ramlist(void); +void qemu_mutex_unlock_ramlist(void); int qemu_open(const char *name, int flags, ...); ssize_t qemu_write_full(int fd, const void *buf, size_t count)