Index: head/sys/amd64/amd64/mp_machdep.c =================================================================== --- head/sys/amd64/amd64/mp_machdep.c +++ head/sys/amd64/amd64/mp_machdep.c @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef GPROF #include #endif @@ -59,6 +60,8 @@ #include #include #include +#include +#include #include #include @@ -75,6 +78,9 @@ #include #include +#include +#include + #define WARMBOOT_TARGET 0 #define WARMBOOT_OFF (KERNBASE + 0x0467) #define WARMBOOT_SEG (KERNBASE + 0x0469) @@ -384,6 +390,25 @@ * local functions and data */ +#ifdef NUMA +static void +mp_realloc_pcpu(int cpuid, int domain) +{ + vm_page_t m; + vm_offset_t oa, na; + + oa = (vm_offset_t)&__pcpu[cpuid]; + if (_vm_phys_domain(pmap_kextract(oa)) == domain) + return; + m = vm_page_alloc_domain(NULL, 0, domain, + VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_ZERO); + na = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)); + pagecopy((void *)oa, (void *)na); + pmap_enter(kernel_pmap, oa, m, VM_PROT_READ | VM_PROT_WRITE, 0, 0); + /* XXX old pcpu page leaked. */ +} +#endif + /* * start each AP in our list */ @@ -392,7 +417,7 @@ { u_int64_t *pt4, *pt3, *pt2; u_int32_t mpbioswarmvec; - int apic_id, cpu, i; + int apic_id, cpu, domain, i; u_char mpbiosreason; mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN); @@ -431,21 +456,41 @@ outb(CMOS_REG, BIOS_RESET); outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */ + /* Relocate pcpu areas to the correct domain. */ +#ifdef NUMA + if (vm_ndomains > 1) + for (cpu = 1; cpu < mp_ncpus; cpu++) { + apic_id = cpu_apic_ids[cpu]; + domain = acpi_pxm_get_cpu_locality(apic_id); + mp_realloc_pcpu(cpu, domain); + } +#endif + /* start each AP */ + domain = 0; for (cpu = 1; cpu < mp_ncpus; cpu++) { apic_id = cpu_apic_ids[cpu]; - +#ifdef NUMA + if (vm_ndomains > 1) + domain = acpi_pxm_get_cpu_locality(apic_id); +#endif /* allocate and set up an idle stack data page */ - bootstacks[cpu] = (void *)kmem_malloc(kstack_pages * PAGE_SIZE, + bootstacks[cpu] = (void *)kmem_malloc_domainset( + DOMAINSET_FIXED(domain), kstack_pages * PAGE_SIZE, M_WAITOK | M_ZERO); - doublefault_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK | - M_ZERO); - mce_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK | M_ZERO); - nmi_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK | M_ZERO); - dbg_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK | M_ZERO); - dpcpu = (void *)kmem_malloc(DPCPU_SIZE, M_WAITOK | M_ZERO); + doublefault_stack = (char *)kmem_malloc_domainset( + DOMAINSET_FIXED(domain), PAGE_SIZE, M_WAITOK | M_ZERO); + mce_stack = (char *)kmem_malloc_domainset( + DOMAINSET_FIXED(domain), PAGE_SIZE, M_WAITOK | M_ZERO); + nmi_stack = (char *)kmem_malloc_domainset( + DOMAINSET_FIXED(domain), PAGE_SIZE, M_WAITOK | M_ZERO); + dbg_stack = (char *)kmem_malloc_domainset( + DOMAINSET_FIXED(domain), PAGE_SIZE, M_WAITOK | M_ZERO); + dpcpu = (void *)kmem_malloc_domainset(DOMAINSET_FIXED(domain), + DPCPU_SIZE, M_WAITOK | M_ZERO); - bootSTK = (char *)bootstacks[cpu] + kstack_pages * PAGE_SIZE - 8; + bootSTK = (char *)bootstacks[cpu] + + kstack_pages * PAGE_SIZE - 8; bootAP = cpu; /* attempt to start the Application Processor */ Index: head/sys/dev/acpica/acpi_pxm.c =================================================================== --- head/sys/dev/acpica/acpi_pxm.c +++ head/sys/dev/acpica/acpi_pxm.c @@ -653,6 +653,17 @@ } } +int +acpi_pxm_get_cpu_locality(int apic_id) +{ + struct cpu_info *cpu; + + cpu = cpu_find(apic_id); + if (cpu == NULL) + panic("SRAT: CPU with ID %u is not known", apic_id); + return (cpu->domain); +} + /* * Free data structures allocated during acpi_pxm_init. */ Index: head/sys/dev/acpica/acpivar.h =================================================================== --- head/sys/dev/acpica/acpivar.h +++ head/sys/dev/acpica/acpivar.h @@ -532,6 +532,7 @@ void acpi_pxm_parse_tables(void); void acpi_pxm_set_mem_locality(void); void acpi_pxm_set_cpu_locality(void); +int acpi_pxm_get_cpu_locality(int apic_id); void acpi_pxm_free(void); /*