From patchwork Fri Jul 15 02:47:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 648644 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rrHLC545fz9s6r for ; Fri, 15 Jul 2016 12:57:39 +1000 (AEST) Received: from localhost ([::1]:58061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNtJp-0008Ox-B9 for incoming@patchwork.ozlabs.org; Thu, 14 Jul 2016 22:57:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNtIL-0007Fq-Pg for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNtIJ-0006ld-8S for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:05 -0400 Received: from mga01.intel.com ([192.55.52.88]:34559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNtII-0006jt-U7 for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:03 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 14 Jul 2016 19:56:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,365,1464678000"; d="scan'208"; a="1022092934" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by fmsmga002.fm.intel.com with ESMTP; 14 Jul 2016 19:56:00 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Fri, 15 Jul 2016 10:47:28 +0800 Message-Id: <1468550849-22172-9-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> References: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [QEMU v2 8/9] kvm: Add two new arch specific functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Liang Li , kvm@vger.kernel.org, quintela@redhat.com, mst@redhat.com, dgilbert@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a new function to get the vm's max pfn and a new function to filter out the holes in the undressed free page bitmap to get a tight free page bitmap. They are implemented on X86 and should be implemented on other arches for live migration optimization. Signed-off-by: Liang Li --- include/sysemu/kvm.h | 18 ++++++++++++++++++ target-arm/kvm.c | 14 ++++++++++++++ target-i386/kvm.c | 37 +++++++++++++++++++++++++++++++++++++ target-mips/kvm.c | 14 ++++++++++++++ target-ppc/kvm.c | 14 ++++++++++++++ target-s390x/kvm.c | 14 ++++++++++++++ 6 files changed, 111 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index ad6f837..fd0956f 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -230,6 +230,24 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr, target_ulong len, int type); void kvm_remove_all_breakpoints(CPUState *cpu); int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap); + +/** + * tighten_guest_free_page_bmap - process the free page bitmap from + * guest to get a tight page bitmap which does not contain + * holes. + * @bmap: undressed guest free page bitmap + * Returns: a tight guest free page bitmap, the n th bit in the + * returned bitmap and the n th bit in the migration bitmap + * should correspond to the same guest RAM page. + */ +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap); + +/** + * get_guest_max_pfn - get the max pfn of guest + * Returns: the max pfn of guest + */ +unsigned long get_guest_max_pfn(void); + #ifndef _WIN32 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset); #endif diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 5c2bd7a..1cfccb3 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -626,3 +626,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 9327523..f0503dd 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3378,3 +3378,40 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +#define _4G (1ULL << 32) + +unsigned long get_guest_max_pfn(void) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + ram_addr_t above_4g_mem = pcms->above_4g_mem_size; + unsigned long max_pfn; + + if (above_4g_mem) { + max_pfn = (_4G + above_4g_mem) >> TARGET_PAGE_BITS; + } else { + max_pfn = pcms->below_4g_mem_size >> TARGET_PAGE_BITS; + } + + return max_pfn; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + ram_addr_t above_4g_mem = pcms->above_4g_mem_size; + + if (above_4g_mem) { + unsigned long *src, *dst, len, pos; + ram_addr_t below_4g_mem = pcms->below_4g_mem_size; + src = bmap + (_4G >> TARGET_PAGE_BITS) / BITS_PER_LONG; + dst = bmap + (below_4g_mem >> TARGET_PAGE_BITS) / BITS_PER_LONG; + bitmap_move(dst, src, above_4g_mem >> TARGET_PAGE_BITS); + + pos = (above_4g_mem + below_4g_mem) >> TARGET_PAGE_BITS; + len = (_4G - below_4g_mem) >> TARGET_PAGE_BITS; + bitmap_clear(bmap, pos, len); + } + + return bmap; +} diff --git a/target-mips/kvm.c b/target-mips/kvm.c index f3f832d..ba39827 100644 --- a/target-mips/kvm.c +++ b/target-mips/kvm.c @@ -1047,3 +1047,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 884d564..ff67b3e 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -2630,3 +2630,17 @@ int kvmppc_enable_hwrng(void) return kvmppc_enable_hcall(kvm_state, H_RANDOM); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +} diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 2991bff..2e5c763 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -2271,3 +2271,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +unsigned long get_guest_max_pfn(void) +{ + /* To be done */ + + return 0; +} + +unsigned long *tighten_guest_free_page_bmap(unsigned long *bmap) +{ + /* To be done */ + + return bmap; +}