Date: Tue, 26 May 2009 14:13:12 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r192807 - in stable/7/sys: . amd64/amd64 contrib/pf dev/ath/ath_hal dev/cxgb i386/i386 Message-ID: <200905261413.n4QEDCvr060488@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Tue May 26 14:13:12 2009 New Revision: 192807 URL: http://svn.freebsd.org/changeset/base/192807 Log: MFC: Adjust the way we number CPUs on x86 so that we attempt to "group" all logical CPUs in a package. 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 Tue May 26 13:37:05 2009 (r192806) +++ stable/7/sys/amd64/amd64/mp_machdep.c Tue May 26 14:13:12 2009 (r192807) @@ -354,7 +354,6 @@ cpu_mp_start(void) } else KASSERT(boot_cpu_id == PCPU_GET(apic_id), ("BSP's APIC ID doesn't match boot_cpu_id")); - cpu_apic_ids[0] = boot_cpu_id; /* Setup the initial logical CPUs info. */ logical_cpus = logical_cpus_mask = 0; @@ -421,28 +420,30 @@ cpu_mp_start(void) void cpu_mp_announce(void) { - int i, x; const char *hyperthread; + int i; - /* List CPUs */ + /* List active CPUs first. */ 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) + for (i = 1; i < mp_ncpus; i++) { + if (cpu_info[cpu_apic_ids[i]].cpu_hyperthread) + hyperthread = "/HT"; + else + hyperthread = ""; + printf(" cpu%d (AP%s): APIC ID: %2d\n", i, hyperthread, + cpu_apic_ids[i]); + } + + /* List disabled CPUs last. */ + for (i = 0; i <= MAX_APIC_ID; i++) { + if (!cpu_info[i].cpu_present || !cpu_info[i].cpu_disabled) continue; - if (cpu_info[x].cpu_hyperthread) { + if (cpu_info[i].cpu_hyperthread) hyperthread = "/HT"; - } else { + else hyperthread = ""; - } - if (cpu_info[x].cpu_disabled) - 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%s): APIC ID: %2d\n", i++, - hyperthread, x); - } + printf(" cpu (AP%s): APIC ID: %2d (disabled)\n", hyperthread, + i); } } @@ -678,11 +679,18 @@ assign_cpu_ids(void) /* * Assign CPU IDs to local APIC IDs and disable any CPUs - * beyond MAXCPU. CPU 0 has already been assigned to the BSP, - * so we only have to assign IDs for APs. + * beyond MAXCPU. CPU 0 is always assigned to the BSP. + * + * To minimize confusion for userland, we attempt to number + * CPUs such that all threads and cores in a package are + * grouped together. For now we assume that the BSP is always + * the first thread in a package and just start adding APs + * starting with the BSP's APIC ID. */ mp_ncpus = 1; - for (i = 0; i <= MAX_APIC_ID; i++) { + cpu_apic_ids[0] = boot_cpu_id; + for (i = boot_cpu_id + 1; i != boot_cpu_id; + i == MAX_APIC_ID ? i = 0 : i++) { if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp || cpu_info[i].cpu_disabled) continue; Modified: stable/7/sys/i386/i386/mp_machdep.c ============================================================================== --- stable/7/sys/i386/i386/mp_machdep.c Tue May 26 13:37:05 2009 (r192806) +++ stable/7/sys/i386/i386/mp_machdep.c Tue May 26 14:13:12 2009 (r192807) @@ -404,7 +404,6 @@ cpu_mp_start(void) } else KASSERT(boot_cpu_id == PCPU_GET(apic_id), ("BSP's APIC ID doesn't match boot_cpu_id")); - cpu_apic_ids[0] = boot_cpu_id; /* Setup the initial logical CPUs info. */ logical_cpus = logical_cpus_mask = 0; @@ -471,28 +470,30 @@ cpu_mp_start(void) void cpu_mp_announce(void) { - int i, x; const char *hyperthread; + int i; - /* List CPUs */ + /* List active CPUs first. */ 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) + for (i = 1; i < mp_ncpus; i++) { + if (cpu_info[cpu_apic_ids[i]].cpu_hyperthread) + hyperthread = "/HT"; + else + hyperthread = ""; + printf(" cpu%d (AP%s): APIC ID: %2d\n", i, hyperthread, + cpu_apic_ids[i]); + } + + /* List disabled CPUs last. */ + for (i = 0; i <= MAX_APIC_ID; i++) { + if (!cpu_info[i].cpu_present || !cpu_info[i].cpu_disabled) continue; - if (cpu_info[x].cpu_hyperthread) { + if (cpu_info[i].cpu_hyperthread) hyperthread = "/HT"; - } else { + else hyperthread = ""; - } - if (cpu_info[x].cpu_disabled) - 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%s): APIC ID: %2d\n", i++, - hyperthread, x); - } + printf(" cpu (AP%s): APIC ID: %2d (disabled)\n", hyperthread, + i); } } @@ -731,11 +732,18 @@ assign_cpu_ids(void) /* * Assign CPU IDs to local APIC IDs and disable any CPUs - * beyond MAXCPU. CPU 0 has already been assigned to the BSP, - * so we only have to assign IDs for APs. + * beyond MAXCPU. CPU 0 is always assigned to the BSP. + * + * To minimize confusion for userland, we attempt to number + * CPUs such that all threads and cores in a package are + * grouped together. For now we assume that the BSP is always + * the first thread in a package and just start adding APs + * starting with the BSP's APIC ID. */ mp_ncpus = 1; - for (i = 0; i <= MAX_APIC_ID; i++) { + cpu_apic_ids[0] = boot_cpu_id; + for (i = boot_cpu_id + 1; i != boot_cpu_id; + i == MAX_APIC_ID ? i = 0 : i++) { if (!cpu_info[i].cpu_present || cpu_info[i].cpu_bsp || cpu_info[i].cpu_disabled) continue;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905261413.n4QEDCvr060488>