Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 1999 14:31:38 -0700
From:      Mike Smith <mike@smith.net.au>
To:        Luoqi Chen <luoqi@watermarkgroup.com>
Cc:        darius@dons.net.au, freebsd-smp@FreeBSD.ORG, peter@netplex.com.au, tlambert@primenet.com
Subject:   Re: Really slow SMP 
Message-ID:  <199904292131.OAA00867@dingo.cdrom.com>
In-Reply-To: Your message of "Thu, 29 Apr 1999 14:01:05 EDT." <199904291801.OAA17851@lor.watermarkgroup.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > 
> > Sorry, not sure I follow you here; there's no locking in 
> > mem_range_AP_init(), and it's where the MTRRs were being loaded before. 
> > The code path is a little more convoluted now, but has the same basic 
> > effect.
>
> IIRC, disable_intr() for SMP needs to get a lock to prevent intr from
> occuring on all cpus. In any case, it's safer to do it ap_init() when
> the AP holds the giant lock.

Point.  Here's a new diff; can the people with "slow SMP" problems try 
this one?

Index: i386/i386/i686_mem.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/i686_mem.c,v
retrieving revision 1.1
diff -u -r1.1 i686_mem.c
--- i686_mem.c	1999/04/07 03:57:45	1.1
+++ i686_mem.c	1999/04/26 05:34:23
@@ -62,21 +62,28 @@
 
 #define mrcopyflags(curr, new) (((curr) & ~MDF_ATTRMASK) | ((new) & MDF_ATTRMASK))
 
-static void			i686_mrinit(struct mem_range_softc *);
-static int			i686_mrset(struct mem_range_softc *,
-					   struct mem_range_desc *,
-					   int *);
+static void			i686_mrinit(struct mem_range_softc *sc);
+static int			i686_mrset(struct mem_range_softc *sc,
+					   struct mem_range_desc *mrd,
+					   int *arg);
+static void			i686_mrAPinit(struct mem_range_softc *sc);
 
 static struct mem_range_ops i686_mrops = {
     i686_mrinit,
-    i686_mrset
+    i686_mrset,
+    i686_mrAPinit
 };
 
+/* XXX for AP startup hook */
+extern struct mem_range_softc	mem_range_softc;
+static u_int64_t		mtrrcap, mtrrdef;
+
 static struct mem_range_desc	*mem_range_match(struct mem_range_softc *sc,
 						 struct mem_range_desc *mrd);
 static void			i686_mrfetch(struct mem_range_softc *sc);
 static int			i686_mtrrtype(int flags);
 static int			i686_mrstore(struct mem_range_softc *sc);
+static int			i686_mrstoreone(struct mem_range_softc *sc);
 static struct mem_range_desc	*i686_mtrrfixsearch(struct mem_range_softc *sc,
 						    u_int64_t addr);
 static int			i686_mrsetlow(struct mem_range_softc *sc,
@@ -226,10 +233,6 @@
 static int
 i686_mrstore(struct mem_range_softc *sc)
 {
-    struct mem_range_desc	*mrd;
-    u_int64_t			msrv;
-    int				i, j, msr;
-    u_int			cr4save;
 
 #ifdef SMP
     /*
@@ -241,6 +244,17 @@
     return(EOPNOTSUPP);
 #endif
 
+    return(i686_mrstoreone(sc));
+}
+
+static int
+i686_mrstoreone(struct mem_range_softc *sc)
+{
+    struct mem_range_desc	*mrd;
+    u_int64_t			msrv;
+    int				i, j, msr;
+    u_int			cr4save;
+
     disable_intr();				/* disable interrupts */
     cr4save = rcr4();				/* save cr4 */
     if (cr4save & CR4_PGE)
@@ -477,7 +491,6 @@
 i686_mrinit(struct mem_range_softc *sc)
 {
     struct mem_range_desc	*mrd;
-    u_int64_t			mtrrcap, mtrrdef;
     int				nmdesc = 0;
     int				i;
 
@@ -491,8 +504,12 @@
 	return;
     }
     nmdesc = mtrrcap & 0xff;
-    printf("Pentium Pro MTRR support enabled, default memory type is %s\n",
-	   i686_mtrrtotext[mtrrdef & 0xff]);
+    printf("Pentium Pro MTRR support enabled, default memory type is ");
+    if ((mtrrdef & 0xff) < (sizeof(i686_mtrrtotext) / sizeof(i686_mtrrtotext[0]))) {
+	printf("%s\n", i686_mtrrtotext[mtrrdef & 0xff]);
+    } else {
+	printf("unknown (0x%x)\n", mtrrdef & 0xff);
+    }
 
     /* If fixed MTRRs supported and enabled */
     if ((mtrrcap & 0x100) && (mtrrdef & 0x400)) {
@@ -537,6 +554,17 @@
 	if (mrd->mr_flags & MDF_ACTIVE)
 	    mrd->mr_flags |= MDF_FIRMWARE;
     }
+}
+
+/*
+ * Initialise MTRRs on an AP after the BSP has run the init code.
+ */
+static void
+i686_mrAPinit(struct mem_range_softc *sc)
+{
+    i686_mrstoreone(sc);			/* set MTRRs to match BSP */
+    wrmsr(MSR_MTRRcap, mtrrcap);	/* set MTRR behaviour to match BSP */
+    wrmsr(MSR_MTRRdefType, mtrrdef);
 }
 
 static void
Index: i386/i386/mem.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/mem.c,v
retrieving revision 1.55
diff -u -r1.55 mem.c
--- mem.c	1999/04/07 03:57:45	1.55
+++ mem.c	1999/04/26 00:46:11
@@ -527,6 +527,12 @@
 	return(mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg));
 }
 
+void
+mem_range_AP_init(void)
+{
+	return(mem_range_softc.mr_op->initAP(&mem_range_softc));
+}
+
 static int 
 random_ioctl(dev, cmd, data, flags, p)
 	dev_t dev;
Index: i386/i386/mp_machdep.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/mp_machdep.c,v
retrieving revision 1.97
diff -u -r1.97 mp_machdep.c
--- mp_machdep.c	1999/04/13 03:24:47	1.97
+++ mp_machdep.c	1999/04/29 21:28:19
@@ -496,11 +496,6 @@
 	PTD[0] = 0;
 	pmap_set_opt((unsigned *)PTD);
 
-#if 0
-	putmtrr();
-	pmap_setvidram();
-#endif
-
 	invltlb();
 }
 
@@ -2250,9 +2245,7 @@
 		panic("cpuid mismatch! boom!!");
 	}
 
-#if 0
-	getmtrr();
-#endif
+	mem_range_AP_init();		/* copy memory range attributes from the BSP */
 
 	/* Init local apic for irq's */
 	apic_initialize();
Index: sys/memrange.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/memrange.h,v
retrieving revision 1.1
diff -u -r1.1 memrange.h
--- memrange.h	1999/04/07 03:59:32	1.1
+++ memrange.h	1999/04/26 00:46:51
@@ -47,6 +47,7 @@
 {
 	void	(*init)(struct mem_range_softc *sc);
 	int	(*set)(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg);
+    	void	(*initAP)(struct mem_range_softc *sc);
 };
 
 struct mem_range_softc 
@@ -61,5 +62,6 @@
 
 extern void mem_range_attr_get(struct mem_range_desc *mrd, int *arg);
 extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg);
+extern void mem_range_AP_init(void);
 #endif
 

-- 
\\  Sometimes you're ahead,       \\  Mike Smith
\\  sometimes you're behind.      \\  mike@smith.net.au
\\  The race is long, and in the  \\  msmith@freebsd.org
\\  end it's only with yourself.  \\  msmith@cdrom.com




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904292131.OAA00867>