Source-Changes-HG archive

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

[src/cherry-xenmp]: src/sys/arch Add per-cpu mmu queues



details:   https://anonhg.NetBSD.org/src/rev/92bdfbef443e
branches:  cherry-xenmp
changeset: 765635:92bdfbef443e
user:      cherry <cherry%NetBSD.org@localhost>
date:      Tue Aug 30 12:53:45 2011 +0000

description:
Add per-cpu mmu queues

diffstat:

 sys/arch/i386/i386/machdep.c |  13 +++++++++++--
 sys/arch/xen/x86/cpu.c       |  14 +++++++++++---
 sys/arch/xen/x86/x86_xpmap.c |  31 ++++++++++++++++++++++++-------
 3 files changed, 46 insertions(+), 12 deletions(-)

diffs (188 lines):

diff -r 84c1147083e1 -r 92bdfbef443e sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Fri Aug 26 13:33:34 2011 +0000
+++ b/sys/arch/i386/i386/machdep.c      Tue Aug 30 12:53:45 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.702.2.5 2011/08/20 19:22:46 cherry Exp $ */
+/*     $NetBSD: machdep.c,v 1.702.2.6 2011/08/30 12:53:45 cherry Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.702.2.5 2011/08/20 19:22:46 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.702.2.6 2011/08/30 12:53:45 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -539,6 +539,9 @@
 }
 
 #ifdef XEN
+/* Shim for curcpu() until %fs is ready */
+extern struct cpu_info * (*xpq_cpu)(void);
+
 /*
  * Switch context:
  * - honor CR0_TS in saved CR0 and request DNA exception on FPU use
@@ -566,6 +569,12 @@
        update_descriptor(&ci->ci_gdt[GUGS_SEL], 
                          (union descriptor *) &pcb->pcb_gsd);
 
+       /* setup curcpu() to use %fs now */
+       /* XXX: find a way to do this, just once */
+       if (__predict_false(xpq_cpu != x86_curcpu)) {
+               xpq_cpu = x86_curcpu;
+       }
+
        physop.cmd = PHYSDEVOP_SET_IOPL;
        physop.u.set_iopl.iopl = pcb->pcb_iopl;
        HYPERVISOR_physdev_op(&physop);
diff -r 84c1147083e1 -r 92bdfbef443e sys/arch/xen/x86/cpu.c
--- a/sys/arch/xen/x86/cpu.c    Fri Aug 26 13:33:34 2011 +0000
+++ b/sys/arch/xen/x86/cpu.c    Tue Aug 30 12:53:45 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $      */
+/*     $NetBSD: cpu.c,v 1.56.2.9 2011/08/30 12:53:46 cherry Exp $      */
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.56.2.9 2011/08/30 12:53:46 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -1104,7 +1104,14 @@
 
 }
 
-void
+/* curcpu() uses %fs - shim for until cpu_init_msrs(), below */
+static struct cpu_info *cpu_primary(void)
+{
+       return &cpu_info_primary;
+}
+struct cpu_info        * (*xpq_cpu)(void) = cpu_primary;
+
+       void
 cpu_init_msrs(struct cpu_info *ci, bool full)
 {
 #ifdef __x86_64__
@@ -1112,6 +1119,7 @@
                HYPERVISOR_set_segment_base (SEGBASE_FS, 0);
                HYPERVISOR_set_segment_base (SEGBASE_GS_KERNEL, (uint64_t) ci);
                HYPERVISOR_set_segment_base (SEGBASE_GS_USER, 0);
+               xpq_cpu = x86_curcpu;
        }
 #endif /* __x86_64__ */
 
diff -r 84c1147083e1 -r 92bdfbef443e sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c      Fri Aug 26 13:33:34 2011 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c      Tue Aug 30 12:53:45 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_xpmap.c,v 1.26.2.7 2011/08/20 19:22:47 cherry Exp $        */
+/*     $NetBSD: x86_xpmap.c,v 1.26.2.8 2011/08/30 12:53:46 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.26.2.7 2011/08/20 19:22:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.26.2.8 2011/08/30 12:53:46 cherry Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -164,12 +164,14 @@
 #endif
 
 #define XPQUEUE_SIZE 2048
-static mmu_update_t xpq_queue[XPQUEUE_SIZE];
-static int xpq_idx = 0;
+static mmu_update_t xpq_queue_array[MAXCPUS][XPQUEUE_SIZE];
+static int xpq_idx_array[MAXCPUS];
 
 #ifdef MULTIPROCESSOR
 static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
 
+extern struct cpu_info * (*xpq_cpu)(void);
+
 void
 xpq_queue_lock(void)
 {
@@ -195,7 +197,11 @@
 {
        int i, ok, ret;
 
+       mmu_update_t *xpq_queue = xpq_queue_array[xpq_cpu()->ci_cpuid];
+       int xpq_idx = xpq_idx_array[xpq_cpu()->ci_cpuid];
+
        KASSERT(xpq_queue_locked());
+
        XENPRINTK2(("flush queue %p entries %d\n", xpq_queue, xpq_idx));
        for (i = 0; i < xpq_idx; i++)
                XENPRINTK2(("%d: 0x%08" PRIx64 " 0x%08" PRIx64 "\n", i,
@@ -211,7 +217,7 @@
                           xpq_queue[i].ptr, xpq_queue[i].val);
                panic("HYPERVISOR_mmu_update failed, ret: %d\n", ret);
        }
-       xpq_idx = 0;
+       xpq_idx_array[xpq_cpu()->ci_cpuid] = 0;
 }
 
 /* Must be called with xpq_lock held */
@@ -220,14 +226,17 @@
 {
 
        KASSERT(xpq_queue_locked());
-       xpq_idx++;
-       if (__predict_false(xpq_idx == XPQUEUE_SIZE))
+
+       if (__predict_false(++xpq_idx_array[xpq_cpu()->ci_cpuid] == XPQUEUE_SIZE))
                xpq_flush_queue();
 }
 
 void
 xpq_queue_machphys_update(paddr_t ma, paddr_t pa)
 {
+       mmu_update_t *xpq_queue = xpq_queue_array[xpq_cpu()->ci_cpuid];
+       int xpq_idx = xpq_idx_array[xpq_cpu()->ci_cpuid];
+
        XENPRINTK2(("xpq_queue_machphys_update ma=0x%" PRIx64 " pa=0x%" PRIx64
            "\n", (int64_t)ma, (int64_t)pa));
        KASSERT(xpq_queue_locked());
@@ -243,6 +252,9 @@
 xpq_queue_pte_update(paddr_t ptr, pt_entry_t val)
 {
 
+       mmu_update_t *xpq_queue = xpq_queue_array[xpq_cpu()->ci_cpuid];
+       int xpq_idx = xpq_idx_array[xpq_cpu()->ci_cpuid];
+
        KASSERT((ptr & 3) == 0);
        KASSERT(xpq_queue_locked());
        xpq_queue[xpq_idx].ptr = (paddr_t)ptr | MMU_NORMAL_PT_UPDATE;
@@ -507,6 +519,9 @@
 {
        int i;
 
+       mmu_update_t *xpq_queue = xpq_queue_array[xpq_cpu()->ci_cpuid];
+       int xpq_idx = xpq_idx_array[xpq_cpu()->ci_cpuid];
+
        XENPRINTK2(("idx: %d\n", xpq_idx));
        for (i = 0; i < xpq_idx; i++) {
                snprintf(XBUF, sizeof(XBUF), "%" PRIx64 " %08" PRIx64,
@@ -578,6 +593,8 @@
        long mapsize;
        vaddr_t bootstrap_tables, init_tables;
 
+       memset(xpq_idx_array, 0, sizeof xpq_idx_array);
+       
        xpmap_phys_to_machine_mapping =
            (unsigned long *)xen_start_info.mfn_list;
        init_tables = xen_start_info.pt_base;



Home | Main Index | Thread Index | Old Index