From ec24e8d42e7dbe46b83dcb61e40d3bf8800af6d9 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 13 Nov 2009 13:07:01 +0000 Subject: [PATCH] Amd64 init_secondary() calls initializecpu() while curthread is still not properly set up. r199067 added the call to TUNABLE_INT_FETCH() to initializecpu() that results in hang because AP are started when kernel environment is already dynamic and thus needs to acquire mutex, that is too early in AP start sequence to work. Extract the code that should be executed only once, because it sets up global variables, from initializecpu() to initializecpucache(), and call the later only from hammer_time() executed on BSP. Now, TUNABLE_INT_FETCH() is done only once at BSP at the early boot stage. In collaboration with: Mykola Dzham Reviewed by: jhb Tested by: ed, battlez --- sys/amd64/amd64/initcpu.c | 5 +++++ sys/amd64/amd64/machdep.c | 1 + sys/amd64/include/md_var.h | 1 + 3 files changed, 7 insertions(+) diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c index 19b784cc83cb..c97ad3dbbb19 100644 --- a/sys/amd64/amd64/initcpu.c +++ b/sys/amd64/amd64/initcpu.c @@ -163,6 +163,11 @@ initializecpu(void) CPUID_TO_FAMILY(cpu_id) == 0x6 && CPUID_TO_MODEL(cpu_id) >= 0xf) init_via(); +} + +void +initializecpucache() +{ /* * CPUID with %eax = 1, %ebx returns diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index ebb7805b337c..c4130a453f91 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1663,6 +1663,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) identify_cpu(); /* Final stage of CPU initialization */ initializecpu(); /* Initialize CPU registers */ + initializecpucache(); /* make an initial tss so cpu can get interrupt stack on syscall! */ common_tss[0].tss_rsp0 = thread0.td_kstack + \ diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h index c66fc9fdb367..15df851ee312 100644 --- a/sys/amd64/include/md_var.h +++ b/sys/amd64/include/md_var.h @@ -89,6 +89,7 @@ void gs_load_fault(void) __asm(__STRING(gs_load_fault)); void dump_add_page(vm_paddr_t); void dump_drop_page(vm_paddr_t); void initializecpu(void); +void initializecpucache(void); void fillw(int /*u_short*/ pat, void *base, size_t cnt); void fpstate_drop(struct thread *td); int is_physical_memory(vm_paddr_t addr);