From patchwork Mon Feb 15 06:12:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: OHMURA Kei X-Patchwork-Id: 79356 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1F6CeQw009338 for ; Mon, 15 Feb 2010 06:12:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850Ab0BOGMi (ORCPT ); Mon, 15 Feb 2010 01:12:38 -0500 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]:39059 "EHLO tama500.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753379Ab0BOGMh (ORCPT ); Mon, 15 Feb 2010 01:12:37 -0500 Received: from mfs6.rdh.ecl.ntt.co.jp (mfs6.rdh.ecl.ntt.co.jp [129.60.39.149]) by tama500.ecl.ntt.co.jp (8.14.3/8.14.3) with ESMTP id o1F6CCse006692; Mon, 15 Feb 2010 15:12:12 +0900 (JST) Received: from mfs6.rdh.ecl.ntt.co.jp (localhost [127.0.0.1]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 32C0A65F8; Mon, 15 Feb 2010 15:12:12 +0900 (JST) Received: from dmailsv1.y.ecl.ntt.co.jp (dmailsv1.y.ecl.ntt.co.jp [129.60.53.14]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id EB25B5C66; Mon, 15 Feb 2010 15:12:11 +0900 (JST) Received: from mailsv02.y.ecl.ntt.co.jp by dmailsv1.y.ecl.ntt.co.jp (8.14.3/dmailsv1-2.1) with ESMTP id o1F6CBSP010184; Mon, 15 Feb 2010 15:12:11 +0900 (JST) Received: from localhost by mailsv02.y.ecl.ntt.co.jp (8.14.3/Lab-1.7) with ESMTP id o1F6CB8h012224; Mon, 15 Feb 2010 15:12:11 +0900 (JST) Message-ID: <4B78E5C5.80802@lab.ntt.co.jp> Date: Mon, 15 Feb 2010 15:12:21 +0900 From: OHMURA Kei User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Avi Kivity , "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" CC: Anthony Liguori , drepper@redhat.com, mtosatti@redhat.com, Yoshiaki Tamura , ohmura.kei@lab.ntt.co.jp Subject: Re: [PATCH v2] qemu-kvm: Speed up of the dirty-bitmap-traveling References: <4B728FF9.6010707@lab.ntt.co.jp> <4B72B28E.6010801@redhat.com> <4B72D706.3070602@codemonkey.ws> <4B74B70A.4030805@lab.ntt.co.jp> <4B77EDC2.7000401@redhat.com> In-Reply-To: <4B77EDC2.7000401@redhat.com> 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.3 (demeter.kernel.org [140.211.167.41]); Mon, 15 Feb 2010 06:12:40 +0000 (UTC) diff --git a/bswap.h b/bswap.h index 4558704..1f87e6d 100644 --- a/bswap.h +++ b/bswap.h @@ -205,8 +205,10 @@ static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) #ifdef HOST_WORDS_BIGENDIAN #define cpu_to_32wu cpu_to_be32wu +#define leul_to_cpu(v) le ## HOST_LONG_BITS ## _to_cpu(v) #else #define cpu_to_32wu cpu_to_le32wu +#define leul_to_cpu(v) (v) #endif #undef le_bswap diff --git a/qemu-kvm.c b/qemu-kvm.c index a305907..6952aa5 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -2434,31 +2434,32 @@ int kvm_physical_memory_set_dirty_tracking(int enable) /* get kvm's dirty pages bitmap and update qemu's */ static int kvm_get_dirty_pages_log_range(unsigned long start_addr, - unsigned char *bitmap, + unsigned long *bitmap, unsigned long offset, unsigned long mem_size) { - unsigned int i, j, n = 0; - unsigned char c; - unsigned long page_number, addr, addr1; + unsigned int i, j; + unsigned long page_number, addr, addr1, c; ram_addr_t ram_addr; - unsigned int len = ((mem_size / TARGET_PAGE_SIZE) + 7) / 8; + unsigned int len = ((mem_size / TARGET_PAGE_SIZE) + HOST_LONG_BITS - 1) / + HOST_LONG_BITS; /* * bitmap-traveling is faster than memory-traveling (for addr...) * especially when most of the memory is not dirty. */ for (i = 0; i < len; i++) { - c = bitmap[i]; - while (c > 0) { - j = ffsl(c) - 1; - c &= ~(1u << j); - page_number = i * 8 + j; - addr1 = page_number * TARGET_PAGE_SIZE; - addr = offset + addr1; - ram_addr = cpu_get_physical_page_desc(addr); - cpu_physical_memory_set_dirty(ram_addr); - n++; + if (bitmap[i] != 0) { + c = leul_to_cpu(bitmap[i]); + do { + j = ffsl(c) - 1; + c &= ~(1ul << j); + page_number = i * HOST_LONG_BITS + j; + addr1 = page_number * TARGET_PAGE_SIZE; + addr = offset + addr1; + ram_addr = cpu_get_physical_page_desc(addr); + cpu_physical_memory_set_dirty(ram_addr); + } while (c != 0); } } return 0;