Author: jhb
Date: Mon Nov  8 20:35:09 2010
New Revision: 215009
URL: http://svn.freebsd.org/changeset/base/215009

Log:
  Sync the APIC startup sequence with amd64:
  - Register APIC enumerators at SI_SUB_TUNABLES - 1 instead of SI_SUB_CPU - 1.
  - Probe CPUs at SI_SUB_TUNABLES - 1.  This allows i386 to set a truly
    accurate mp_maxid value rather than always setting it to MAXCPU - 1.

Modified:
  head/sys/i386/acpica/madt.c
  head/sys/i386/i386/mp_machdep.c
  head/sys/i386/xen/mptable.c
  head/sys/x86/x86/local_apic.c
  head/sys/x86/x86/mptable.c

Modified: head/sys/i386/acpica/madt.c
==============================================================================
--- head/sys/i386/acpica/madt.c Mon Nov  8 20:32:35 2010        (r215008)
+++ head/sys/i386/acpica/madt.c Mon Nov  8 20:35:09 2010        (r215009)
@@ -203,7 +203,7 @@ madt_register(void *dummy __unused)
 
        apic_register_enumerator(&madt_enumerator);
 }
-SYSINIT(madt_register, SI_SUB_CPU - 1, SI_ORDER_SECOND, madt_register, NULL);
+SYSINIT(madt_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, madt_register, 
NULL);
 
 /*
  * Call the handler routine for each entry in the MADT table.

Modified: head/sys/i386/i386/mp_machdep.c
==============================================================================
--- head/sys/i386/i386/mp_machdep.c     Mon Nov  8 20:32:35 2010        
(r215008)
+++ head/sys/i386/i386/mp_machdep.c     Mon Nov  8 20:35:09 2010        
(r215009)
@@ -465,8 +465,10 @@ cpu_add(u_int apic_id, char boot_cpu)
                boot_cpu_id = apic_id;
                cpu_info[apic_id].cpu_bsp = 1;
        }
-       if (mp_ncpus < MAXCPU)
+       if (mp_ncpus < MAXCPU) {
                mp_ncpus++;
+               mp_maxid = mp_ncpus - 1;
+       }
        if (bootverbose)
                printf("SMP: Added CPU %d (%s)\n", apic_id, boot_cpu ? "BSP" :
                    "AP");
@@ -476,7 +478,19 @@ void
 cpu_mp_setmaxid(void)
 {
 
-       mp_maxid = MAXCPU - 1;
+       /*
+        * mp_maxid should be already set by calls to cpu_add().
+        * Just sanity check its value here.
+        */
+       if (mp_ncpus == 0)
+               KASSERT(mp_maxid == 0,
+                   ("%s: mp_ncpus is zero, but mp_maxid is not", __func__));
+       else if (mp_ncpus == 1)
+               mp_maxid = 0;
+       else
+               KASSERT(mp_maxid >= mp_ncpus - 1,
+                   ("%s: counters out of sync: max %d, count %d", __func__,
+                       mp_maxid, mp_ncpus));
 }
 
 int
@@ -504,6 +518,7 @@ cpu_mp_probe(void)
                 * One CPU was found, so this must be a UP system with
                 * an I/O APIC.
                 */
+               mp_maxid = 0;
                return (0);
        }
 

Modified: head/sys/i386/xen/mptable.c
==============================================================================
--- head/sys/i386/xen/mptable.c Mon Nov  8 20:32:35 2010        (r215008)
+++ head/sys/i386/xen/mptable.c Mon Nov  8 20:35:09 2010        (r215009)
@@ -109,7 +109,7 @@ mptable_register(void *dummy __unused)
 
        apic_register_enumerator(&mptable_enumerator);
 }
-SYSINIT(mptable_register, SI_SUB_CPU - 1, SI_ORDER_FIRST, mptable_register,
+SYSINIT(mptable_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, 
mptable_register,
     NULL);
 
 

Modified: head/sys/x86/x86/local_apic.c
==============================================================================
--- head/sys/x86/x86/local_apic.c       Mon Nov  8 20:32:35 2010        
(r215008)
+++ head/sys/x86/x86/local_apic.c       Mon Nov  8 20:35:09 2010        
(r215009)
@@ -1285,7 +1285,7 @@ apic_init(void *dummy __unused)
        if (resource_disabled("apic", 0))
                return;
 
-       /* First, probe all the enumerators to find the best match. */
+       /* Probe all the enumerators to find the best match. */
        best_enum = NULL;
        best = 0;
        SLIST_FOREACH(enumerator, &enumerators, apic_next) {
@@ -1321,13 +1321,12 @@ apic_init(void *dummy __unused)
        }
 #endif
 
-       /* Second, probe the CPU's in the system. */
+       /* Probe the CPU's in the system. */
        retval = best_enum->apic_probe_cpus();
        if (retval != 0)
                printf("%s: Failed to probe CPUs: returned %d\n",
                    best_enum->apic_name, retval);
 
-#ifdef __amd64__
 }
 SYSINIT(apic_init, SI_SUB_TUNABLES - 1, SI_ORDER_SECOND, apic_init, NULL);
 
@@ -1342,19 +1341,14 @@ apic_setup_local(void *dummy __unused)
  
        if (best_enum == NULL)
                return;
-#endif
-       /* Third, initialize the local APIC. */
+
+       /* Initialize the local APIC. */
        retval = best_enum->apic_setup_local();
        if (retval != 0)
                printf("%s: Failed to setup the local APIC: returned %d\n",
                    best_enum->apic_name, retval);
 }
-#ifdef __amd64__
-SYSINIT(apic_setup_local, SI_SUB_CPU, SI_ORDER_SECOND, apic_setup_local,
-    NULL);
-#else
-SYSINIT(apic_init, SI_SUB_CPU, SI_ORDER_SECOND, apic_init, NULL);
-#endif
+SYSINIT(apic_setup_local, SI_SUB_CPU, SI_ORDER_SECOND, apic_setup_local, NULL);
 
 /*
  * Setup the I/O APICs.

Modified: head/sys/x86/x86/mptable.c
==============================================================================
--- head/sys/x86/x86/mptable.c  Mon Nov  8 20:32:35 2010        (r215008)
+++ head/sys/x86/x86/mptable.c  Mon Nov  8 20:35:09 2010        (r215009)
@@ -389,7 +389,7 @@ mptable_register(void *dummy __unused)
 
        apic_register_enumerator(&mptable_enumerator);
 }
-SYSINIT(mptable_register, SI_SUB_CPU - 1, SI_ORDER_FIRST, mptable_register,
+SYSINIT(mptable_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, 
mptable_register,
     NULL);
 
 /*
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to