From f3249e77bdbc295d92411bbf94eca38a101beb35 Mon Sep 17 00:00:00 2001 From: Zide Chen Date: Tue, 21 Jan 2020 09:58:49 -0800 Subject: [PATCH] hv: enable early pr_xxx() logs Currently panic() and pr_xxx() statements before init_primary_pcpu_post() won't be printed, which is inconvenient and misleading for debugging. This patch makes pr_xxx() APIs working before init_pcpu_pre(): - clear .bss in init.c, which makes sense to clear .bss at the very beginning of initialization code. Also this makes it possible to call init_logmsg() before init_pcpu_pre(). - move parse_hv_cmdline() and uart16550_init(true) to init.c. - refine ticks_to_us() to handle the case that it's called before calibrate_tsc(). As a side effect, it prints "0us" in early pr_xxx() calls. - call init_debug_pre() in init_primary_pcpu() and after this point, both printf() and pr_xxx() APIs are available. However, this patch doesn't address the issue that pr_xxx() could be called on PCPUs that set_current_pcpu_id() hasn't been called, which implies that the PCPU ID shown in early logs may not be accurate. Tracked-On: #2987 Signed-off-by: Zide Chen Acked-by: Eddie Dong --- hypervisor/arch/x86/cpu.c | 11 ----------- hypervisor/arch/x86/init.c | 18 ++++++++++++++++-- hypervisor/arch/x86/timer.c | 8 +++++++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index feb427262..e78510876 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -108,16 +107,6 @@ void init_pcpu_pre(bool is_bsp) pcpu_id = BOOT_CPU_ID; start_tsc = rdtsc(); - /* Clear BSS */ - (void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start)); - - (void)parse_hv_cmdline(); - /* - * Enable UART as early as possible. - * Then we could use printf for debugging on early boot stage. - */ - uart16550_init(true); - /* Get CPU capabilities thru CPUID, including the physical address bit * limit which is required for initializing paging. */ diff --git a/hypervisor/arch/x86/init.c b/hypervisor/arch/x86/init.c index 5b1242df6..259e68050 100644 --- a/hypervisor/arch/x86/init.c +++ b/hypervisor/arch/x86/init.c @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include /* Push sp magic to top of stack for call trace */ #define SWITCH_TO(rsp, to) \ @@ -29,6 +32,12 @@ /*TODO: move into debug module */ static void init_debug_pre(void) { + /* + * Enable UART as early as possible. + * Then we could use printf for debugging on early boot stage. + */ + uart16550_init(true); + /* Initialize console */ console_init(); @@ -58,8 +67,6 @@ static void init_guest_mode(uint16_t pcpu_id) static void init_primary_pcpu_post(void) { - init_debug_pre(); - init_seed(); init_pcpu_post(BOOT_CPU_ID); @@ -78,6 +85,13 @@ void init_primary_pcpu(void) { uint64_t rsp; + /* Clear BSS */ + (void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start)); + + (void)parse_hv_cmdline(); + + init_debug_pre(); + init_pcpu_pre(true); /* Switch to run-time stack */ diff --git a/hypervisor/arch/x86/timer.c b/hypervisor/arch/x86/timer.c index 9944664d9..a7a9b5c4b 100644 --- a/hypervisor/arch/x86/timer.c +++ b/hypervisor/arch/x86/timer.c @@ -318,7 +318,13 @@ uint64_t us_to_ticks(uint32_t us) uint64_t ticks_to_us(uint64_t ticks) { - return (ticks * 1000UL) / (uint64_t)tsc_khz; + uint64_t us = 0UL; + + if (tsc_khz != 0U ) { + us = (ticks * 1000UL) / (uint64_t)tsc_khz; + } + + return us; } uint64_t ticks_to_ms(uint64_t ticks)