From patchwork Tue Mar 16 10:53:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 86118 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 o2GAuSdP002382 for ; Tue, 16 Mar 2010 10:56:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937736Ab0CPK4X (ORCPT ); Tue, 16 Mar 2010 06:56:23 -0400 Received: from sh.osrg.net ([192.16.179.4]:49162 "EHLO sh.osrg.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937726Ab0CPK4V (ORCPT ); Tue, 16 Mar 2010 06:56:21 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o2GAu1S3024560; Tue, 16 Mar 2010 19:56:01 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id 29EA31B8002; Tue, 16 Mar 2010 19:56:01 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: avi@redhat.com, anthony@codemonkey.ws, ohmura.kei@lab.ntt.co.jp, Yoshiaki Tamura Subject: [PATCH 4/6] qemu-kvm: Introduce cpu_physical_memory_get_dirty_range(). Date: Tue, 16 Mar 2010 19:53:57 +0900 Message-Id: <1268736839-27371-5-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1268736839-27371-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1268736839-27371-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 98 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 16 Mar 2010 10:56:31 +0000 (UTC) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 16 Mar 2010 19:56:02 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/exec.c b/exec.c index b31c349..87056a6 100644 --- a/exec.c +++ b/exec.c @@ -1961,6 +1961,79 @@ static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry, } } +/* It checks the first row and puts dirty addrs in the array. + If the first row is empty, it skips to the first non-dirty row + or the end addr, and put the length in the first entry of the array. */ +int cpu_physical_memory_get_dirty_range(ram_addr_t start, ram_addr_t end, + ram_addr_t *dirty_rams, int length, + int dirty_flag) +{ + unsigned long phys_ram_dirty, page_number, *p; + ram_addr_t addr; + int s_idx = (start >> TARGET_PAGE_BITS) / HOST_LONG_BITS; + int e_idx = (end >> TARGET_PAGE_BITS) / HOST_LONG_BITS; + int i, j, offset; + + switch (dirty_flag) { + case VGA_DIRTY_FLAG: + p = phys_ram_vga_dirty; + break; + case CODE_DIRTY_FLAG: + p = phys_ram_code_dirty; + break; + case MIGRATION_DIRTY_FLAG: + p = phys_ram_migration_dirty; + break; + default: + abort(); + } + + /* mask bits before the start addr */ + offset = (start >> TARGET_PAGE_BITS) & (HOST_LONG_BITS - 1); + phys_ram_dirty = p[s_idx] & ~((1UL << offset) - 1); + + if (s_idx == e_idx) { + /* mask bits after the end addr */ + offset = (end >> TARGET_PAGE_BITS) & (HOST_LONG_BITS - 1); + phys_ram_dirty &= (1UL << offset) - 1; + } + + if (phys_ram_dirty == 0) { + /* when the row is empty */ + ram_addr_t skip; + if (s_idx == e_idx) + skip = end; + else { + /* skip empty rows */ + while (s_idx < e_idx && p[++s_idx] == 0); + skip = (s_idx * HOST_LONG_BITS * TARGET_PAGE_SIZE); + } + dirty_rams[0] = skip - start; + i = 0; + + } else if (phys_ram_dirty == ~0UL) { + /* when the row is fully dirtied */ + addr = start; + for (i = 0; i < length; i++) { + dirty_rams[i] = addr; + addr += TARGET_PAGE_SIZE; + } + } else { + /* when the row is partially dirtied */ + i = 0; + do { + j = ffsl(phys_ram_dirty) - 1; + phys_ram_dirty &= ~(1UL << j); + page_number = s_idx * HOST_LONG_BITS + j; + addr = page_number * TARGET_PAGE_SIZE; + dirty_rams[i] = addr; + i++; + } while (phys_ram_dirty != 0 && i < length); + } + + return i; +} + /* Note: start and end must be within the same ram block. */ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end, int dirty_flags)