Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Use the hypervisor to copy/zero pages. This saves u...



details:   https://anonhg.NetBSD.org/src/rev/a339c085a17b
branches:  trunk
changeset: 329092:a339c085a17b
user:      cherry <cherry%NetBSD.org@localhost>
date:      Tue May 06 04:26:23 2014 +0000

description:
Use the hypervisor to copy/zero pages. This saves us the extra overheads
of setting up temporary kernel mapping/unmapping.

riz@ reports savings of about 2s on a 120s kernel build.

diffstat:

 sys/arch/x86/x86/pmap.c        |  16 +++++++++++-----
 sys/arch/xen/include/xenpmap.h |   4 +++-
 sys/arch/xen/x86/x86_xpmap.c   |  33 +++++++++++++++++++++++++++++++--
 3 files changed, 45 insertions(+), 8 deletions(-)

diffs (135 lines):

diff -r 4d5e0f22b68e -r a339c085a17b sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Tue May 06 00:41:26 2014 +0000
+++ b/sys/arch/x86/x86/pmap.c   Tue May 06 04:26:23 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.181 2013/11/06 20:19:03 mrg Exp $   */
+/*     $NetBSD: pmap.c,v 1.182 2014/05/06 04:26:23 cherry Exp $        */
 
 /*-
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.181 2013/11/06 20:19:03 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.182 2014/05/06 04:26:23 cherry Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -3011,8 +3011,10 @@
 void
 pmap_zero_page(paddr_t pa)
 {
-#ifdef __HAVE_DIRECT_MAP
+#if defined(__HAVE_DIRECT_MAP)
        pagezero(PMAP_DIRECT_MAP(pa));
+#elif defined(XEN)
+       xen_pagezero(pa);
 #else
        pt_entry_t *zpte;
        void *zerova;
@@ -3089,11 +3091,13 @@
 void
 pmap_copy_page(paddr_t srcpa, paddr_t dstpa)
 {
-#ifdef __HAVE_DIRECT_MAP
+#if defined(__HAVE_DIRECT_MAP)
        vaddr_t srcva = PMAP_DIRECT_MAP(srcpa);
        vaddr_t dstva = PMAP_DIRECT_MAP(dstpa);
 
        memcpy((void *)dstva, (void *)srcva, PAGE_SIZE);
+#elif defined(XEN)
+       xen_copy_page(srcpa, dstpa);
 #else
        pt_entry_t *spte;
        pt_entry_t *dpte;
@@ -4103,6 +4107,8 @@
                        panic("pmap_get_physpage: out of memory");
 #ifdef __HAVE_DIRECT_MAP
                pagezero(PMAP_DIRECT_MAP(*paddrp));
+#elif defined(XEN)
+               xen_pagezero(*paddrp);
 #else
                kpreempt_disable();
                pmap_pte_set(early_zero_pte,
@@ -4110,7 +4116,7 @@
                pmap_pte_flush();
                pmap_update_pg((vaddr_t)early_zerop);
                memset(early_zerop, 0, PAGE_SIZE);
-#if defined(DIAGNOSTIC) || defined (XEN)
+#if defined(DIAGNOSTIC)
                pmap_pte_set(early_zero_pte, 0);
                pmap_pte_flush();
 #endif /* defined(DIAGNOSTIC) */
diff -r 4d5e0f22b68e -r a339c085a17b sys/arch/xen/include/xenpmap.h
--- a/sys/arch/xen/include/xenpmap.h    Tue May 06 00:41:26 2014 +0000
+++ b/sys/arch/xen/include/xenpmap.h    Tue May 06 04:26:23 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xenpmap.h,v 1.37 2012/06/30 22:50:36 jym Exp $ */
+/*     $NetBSD: xenpmap.h,v 1.38 2014/05/06 04:26:24 cherry Exp $      */
 
 /*
  *
@@ -55,6 +55,8 @@
 void xen_bcast_tlbflush(void);
 void xen_mcast_invlpg(vaddr_t, kcpuset_t *);
 void xen_bcast_invlpg(vaddr_t);
+void xen_copy_page(paddr_t, paddr_t);
+void xen_pagezero(paddr_t);
 
 void pmap_xen_resume(void);
 void pmap_xen_suspend(void);
diff -r 4d5e0f22b68e -r a339c085a17b sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c      Tue May 06 00:41:26 2014 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c      Tue May 06 04:26:23 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_xpmap.c,v 1.52 2013/11/10 01:19:13 jnemeth Exp $   */
+/*     $NetBSD: x86_xpmap.c,v 1.53 2014/05/06 04:26:24 cherry Exp $    */
 
 /*
  * Copyright (c) 2006 Mathieu Ropert <mro%adviseo.fr@localhost>
@@ -69,7 +69,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.52 2013/11/10 01:19:13 jnemeth Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.53 2014/05/06 04:26:24 cherry Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -490,6 +490,35 @@
        return;
 }
 
+/* Copy a page */
+void
+xen_copy_page(paddr_t srcpa, paddr_t dstpa)
+{
+       mmuext_op_t op;
+
+       op.cmd = MMUEXT_COPY_PAGE;
+       op.arg1.mfn = xpmap_ptom(dstpa) >> PAGE_SHIFT;
+       op.arg2.src_mfn = xpmap_ptom(srcpa) >> PAGE_SHIFT;
+
+       if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) {
+               panic(__func__);
+       }
+}
+
+/* Zero a physical page */
+void
+xen_pagezero(paddr_t pa)
+{
+       mmuext_op_t op;
+
+       op.cmd = MMUEXT_CLEAR_PAGE;
+       op.arg1.mfn = xpmap_ptom(pa) >> PAGE_SHIFT;
+
+       if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) {
+               panic(__func__);
+       }
+}
+
 int
 xpq_update_foreign(paddr_t ptr, pt_entry_t val, int dom)
 {



Home | Main Index | Thread Index | Old Index