Author: sobomax
Date: Sun Apr 12 23:06:23 2009
New Revision: 190980
URL: http://svn.freebsd.org/changeset/base/190980

Log:
  MFC: Make machdep.hyperthreading_allowed working.
  
  Approved by:    re (kib)

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/amd64/amd64/mp_machdep.c
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/i386/i386/mp_machdep.c

Modified: stable/7/sys/amd64/amd64/mp_machdep.c
==============================================================================
--- stable/7/sys/amd64/amd64/mp_machdep.c       Sun Apr 12 22:16:14 2009        
(r190979)
+++ stable/7/sys/amd64/amd64/mp_machdep.c       Sun Apr 12 23:06:23 2009        
(r190980)
@@ -153,6 +153,7 @@ struct cpu_info {
        int     cpu_present:1;
        int     cpu_bsp:1;
        int     cpu_disabled:1;
+       int     cpu_hyperthread:1;
 } static cpu_info[MAX_APIC_ID + 1];
 int cpu_apic_ids[MAXCPU];
 
@@ -355,11 +356,6 @@ cpu_mp_start(void)
                    ("BSP's APIC ID doesn't match boot_cpu_id"));
        cpu_apic_ids[0] = boot_cpu_id;
 
-       assign_cpu_ids();
-
-       /* Start each Application Processor */
-       start_all_aps();
-
        /* Setup the initial logical CPUs info. */
        logical_cpus = logical_cpus_mask = 0;
        if (cpu_feature & CPUID_HTT)
@@ -407,6 +403,11 @@ cpu_mp_start(void)
                        hyperthreading_cpus = logical_cpus;
        }
 
+       assign_cpu_ids();
+
+       /* Start each Application Processor */
+       start_all_aps();
+
        set_interrupt_apic_ids();
 
        /* Last, setup the cpu topology now that we have probed CPUs */
@@ -421,18 +422,26 @@ void
 cpu_mp_announce(void)
 {
        int i, x;
+       const char *hyperthread;
 
        /* List CPUs */
        printf(" cpu0 (BSP): APIC ID: %2d\n", boot_cpu_id);
        for (i = 1, x = 0; x <= MAX_APIC_ID; x++) {
                if (!cpu_info[x].cpu_present || cpu_info[x].cpu_bsp)
                        continue;
+               if (cpu_info[x].cpu_hyperthread) {
+                       hyperthread = "/HT";
+               } else {
+                       hyperthread = "";
+               }
                if (cpu_info[x].cpu_disabled)
-                       printf("  cpu (AP): APIC ID: %2d (disabled)\n", x);
+                       printf("  cpu (AP%s): APIC ID: %2d (disabled)\n",
+                           hyperthread, x);
                else {
                        KASSERT(i < mp_ncpus,
                            ("mp_ncpus and actual cpus are out of whack"));
-                       printf(" cpu%d (AP): APIC ID: %2d\n", i++, x);
+                       printf(" cpu%d (AP%s): APIC ID: %2d\n", i++,
+                           hyperthread, x);
                }
        }
 }
@@ -638,11 +647,28 @@ assign_cpu_ids(void)
 {
        u_int i;
 
+       TUNABLE_INT_FETCH("machdep.hyperthreading_allowed",
+           &hyperthreading_allowed);
+
        /* Check for explicitly disabled CPUs. */
        for (i = 0; i <= MAX_APIC_ID; i++) {
                if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp)
                        continue;
 
+               if (hyperthreading_cpus > 1 && i % hyperthreading_cpus != 0) {
+                       cpu_info[i].cpu_hyperthread = 1;
+#if defined(SCHED_ULE)
+                       /*
+                        * Don't use HT CPU if it has been disabled by a
+                        * tunable.
+                        */
+                       if (hyperthreading_allowed == 0) {
+                               cpu_info[i].cpu_disabled = 1;
+                               continue;
+                       }
+#endif
+               }
+
                /* Don't use this CPU if it has been disabled by a tunable. */
                if (resource_disabled("lapic", i)) {
                        cpu_info[i].cpu_disabled = 1;
@@ -1229,6 +1255,16 @@ sysctl_hyperthreading_allowed(SYSCTL_HAN
        if (error || !req->newptr)
                return (error);
 
+#ifdef SCHED_ULE
+       /*
+        * SCHED_ULE doesn't allow enabling/disabling HT cores at
+        * run-time.
+        */
+       if (allowed != hyperthreading_allowed)
+               return (ENOTSUP);
+       return (error);
+#endif
+
        if (allowed)
                hlt_cpus_mask &= ~hyperthreading_cpus_mask;
        else
@@ -1273,8 +1309,6 @@ cpu_hlt_setup(void *dummy __unused)
                 * of hlt_logical_cpus.
                 */
                if (hyperthreading_cpus_mask) {
-                       TUNABLE_INT_FETCH("machdep.hyperthreading_allowed",
-                           &hyperthreading_allowed);
                        SYSCTL_ADD_PROC(&logical_cpu_clist,
                            SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
                            "hyperthreading_allowed", CTLTYPE_INT|CTLFLAG_RW,

Modified: stable/7/sys/i386/i386/mp_machdep.c
==============================================================================
--- stable/7/sys/i386/i386/mp_machdep.c Sun Apr 12 22:16:14 2009        
(r190979)
+++ stable/7/sys/i386/i386/mp_machdep.c Sun Apr 12 23:06:23 2009        
(r190980)
@@ -209,6 +209,7 @@ struct cpu_info {
        int     cpu_present:1;
        int     cpu_bsp:1;
        int     cpu_disabled:1;
+       int     cpu_hyperthread:1;
 } static cpu_info[MAX_APIC_ID + 1];
 int cpu_apic_ids[MAXCPU];
 
@@ -405,11 +406,6 @@ cpu_mp_start(void)
                    ("BSP's APIC ID doesn't match boot_cpu_id"));
        cpu_apic_ids[0] = boot_cpu_id;
 
-       assign_cpu_ids();
-
-       /* Start each Application Processor */
-       start_all_aps();
-
        /* Setup the initial logical CPUs info. */
        logical_cpus = logical_cpus_mask = 0;
        if (cpu_feature & CPUID_HTT)
@@ -457,6 +453,11 @@ cpu_mp_start(void)
                        hyperthreading_cpus = logical_cpus;
        }
 
+       assign_cpu_ids();
+
+       /* Start each Application Processor */
+       start_all_aps();
+
        set_interrupt_apic_ids();
 
        /* Last, setup the cpu topology now that we have probed CPUs */
@@ -471,18 +472,26 @@ void
 cpu_mp_announce(void)
 {
        int i, x;
+       const char *hyperthread;
 
        /* List CPUs */
        printf(" cpu0 (BSP): APIC ID: %2d\n", boot_cpu_id);
        for (i = 1, x = 0; x <= MAX_APIC_ID; x++) {
                if (!cpu_info[x].cpu_present || cpu_info[x].cpu_bsp)
                        continue;
+               if (cpu_info[x].cpu_hyperthread) {
+                       hyperthread = "/HT";
+               } else {
+                       hyperthread = "";
+               }
                if (cpu_info[x].cpu_disabled)
-                       printf("  cpu (AP): APIC ID: %2d (disabled)\n", x);
+                       printf("  cpu (AP%s): APIC ID: %2d (disabled)\n",
+                           hyperthread, x);
                else {
                        KASSERT(i < mp_ncpus,
                            ("mp_ncpus and actual cpus are out of whack"));
-                       printf(" cpu%d (AP): APIC ID: %2d\n", i++, x);
+                       printf(" cpu%d (AP%s): APIC ID: %2d\n", i++,
+                           hyperthread, x);
                }
        }
 }
@@ -691,11 +700,28 @@ assign_cpu_ids(void)
 {
        u_int i;
 
+       TUNABLE_INT_FETCH("machdep.hyperthreading_allowed",
+           &hyperthreading_allowed);
+
        /* Check for explicitly disabled CPUs. */
        for (i = 0; i <= MAX_APIC_ID; i++) {
                if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp)
                        continue;
 
+               if (hyperthreading_cpus > 1 && i % hyperthreading_cpus != 0) {
+                       cpu_info[i].cpu_hyperthread = 1;
+#if defined(SCHED_ULE)
+                       /*
+                        * Don't use HT CPU if it has been disabled by a
+                        * tunable.
+                        */
+                       if (hyperthreading_allowed == 0) {
+                               cpu_info[i].cpu_disabled = 1;
+                               continue;
+                       }
+#endif
+               }
+
                /* Don't use this CPU if it has been disabled by a tunable. */
                if (resource_disabled("lapic", i)) {
                        cpu_info[i].cpu_disabled = 1;
@@ -1410,6 +1436,16 @@ sysctl_hyperthreading_allowed(SYSCTL_HAN
        if (error || !req->newptr)
                return (error);
 
+#ifdef SCHED_ULE
+       /*
+        * SCHED_ULE doesn't allow enabling/disabling HT cores at
+        * run-time.
+        */
+       if (allowed != hyperthreading_allowed)
+               return (ENOTSUP);
+       return (error);
+#endif
+
        if (allowed)
                hlt_cpus_mask &= ~hyperthreading_cpus_mask;
        else
@@ -1454,8 +1490,6 @@ cpu_hlt_setup(void *dummy __unused)
                 * of hlt_logical_cpus.
                 */
                if (hyperthreading_cpus_mask) {
-                       TUNABLE_INT_FETCH("machdep.hyperthreading_allowed",
-                           &hyperthreading_allowed);
                        SYSCTL_ADD_PROC(&logical_cpu_clist,
                            SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
                            "hyperthreading_allowed", CTLTYPE_INT|CTLFLAG_RW,
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to