Author: sobomax
Date: Wed Feb 25 01:49:01 2009
New Revision: 189023
URL: http://svn.freebsd.org/changeset/base/189023

Log:
  Make machdep.hyperthreading_enabled tunable working with the SCHED_ULE.
  Unlike with SCHED_BSD, however, it can only be set to 0 at boot time,
  it's not possible to change it at runtime.
  
  Reviewed by:  jhb
  MFC after:    1 month

Modified:
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/i386/i386/mp_machdep.c

Modified: head/sys/amd64/amd64/mp_machdep.c
==============================================================================
--- head/sys/amd64/amd64/mp_machdep.c   Wed Feb 25 01:12:56 2009        
(r189022)
+++ head/sys/amd64/amd64/mp_machdep.c   Wed Feb 25 01:49:01 2009        
(r189023)
@@ -151,6 +151,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];
 int apic_cpuids[MAX_APIC_ID + 1];
@@ -353,11 +354,6 @@ cpu_mp_start(void)
        cpu_apic_ids[0] = boot_cpu_id;
        apic_cpuids[boot_cpu_id] = 0;
 
-       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)
@@ -404,6 +400,11 @@ cpu_mp_start(void)
                        hyperthreading_cpus = logical_cpus;
        }
 
+       assign_cpu_ids();
+
+       /* Start each Application Processor */
+       start_all_aps();
+
        set_interrupt_apic_ids();
 }
 
@@ -415,18 +416,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);
                }
        }
 }
@@ -642,11 +651,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;
@@ -1198,6 +1224,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
+        * tun time.
+        */
+       if (allowed != hyperthreading_allowed)
+               return (ENOTSUP);
+       return (error);
+#endif
+
        if (allowed)
                hlt_cpus_mask &= ~hyperthreading_cpus_mask;
        else
@@ -1242,8 +1278,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: head/sys/i386/i386/mp_machdep.c
==============================================================================
--- head/sys/i386/i386/mp_machdep.c     Wed Feb 25 01:12:56 2009        
(r189022)
+++ head/sys/i386/i386/mp_machdep.c     Wed Feb 25 01:49:01 2009        
(r189023)
@@ -204,6 +204,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];
 int apic_cpuids[MAX_APIC_ID + 1];
@@ -400,11 +401,6 @@ cpu_mp_start(void)
        cpu_apic_ids[0] = boot_cpu_id;
        apic_cpuids[boot_cpu_id] = 0;
 
-       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)
@@ -451,6 +447,11 @@ cpu_mp_start(void)
                        hyperthreading_cpus = logical_cpus;
        }
 
+       assign_cpu_ids();
+
+       /* Start each Application Processor */
+       start_all_aps();
+
        set_interrupt_apic_ids();
 }
 
@@ -462,18 +463,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);
                }
        }
 }
@@ -682,11 +691,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;
@@ -1369,6 +1395,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
+        * tun time.
+        */
+       if (allowed != hyperthreading_allowed)
+               return (ENOTSUP);
+       return (error);
+#endif
+
        if (allowed)
                hlt_cpus_mask &= ~hyperthreading_cpus_mask;
        else
@@ -1413,8 +1449,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