Skip to content

Commit f3249e7

Browse files
ZideChen0wenlingz
authored andcommitted
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 <zide.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent db6fe1e commit f3249e7

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <vmx.h>
2323
#include <msr.h>
2424
#include <ptdev.h>
25-
#include <ld_sym.h>
2625
#include <logmsg.h>
2726
#include <cat.h>
2827
#include <vboot.h>
@@ -108,16 +107,6 @@ void init_pcpu_pre(bool is_bsp)
108107
pcpu_id = BOOT_CPU_ID;
109108
start_tsc = rdtsc();
110109

111-
/* Clear BSS */
112-
(void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start));
113-
114-
(void)parse_hv_cmdline();
115-
/*
116-
* Enable UART as early as possible.
117-
* Then we could use printf for debugging on early boot stage.
118-
*/
119-
uart16550_init(true);
120-
121110
/* Get CPU capabilities thru CPUID, including the physical address bit
122111
* limit which is required for initializing paging.
123112
*/

hypervisor/arch/x86/init.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <vm.h>
1616
#include <logmsg.h>
1717
#include <seed.h>
18+
#include <uart16550.h>
19+
#include <ld_sym.h>
20+
#include <vboot.h>
1821

1922
/* Push sp magic to top of stack for call trace */
2023
#define SWITCH_TO(rsp, to) \
@@ -29,6 +32,12 @@
2932
/*TODO: move into debug module */
3033
static void init_debug_pre(void)
3134
{
35+
/*
36+
* Enable UART as early as possible.
37+
* Then we could use printf for debugging on early boot stage.
38+
*/
39+
uart16550_init(true);
40+
3241
/* Initialize console */
3342
console_init();
3443

@@ -58,8 +67,6 @@ static void init_guest_mode(uint16_t pcpu_id)
5867

5968
static void init_primary_pcpu_post(void)
6069
{
61-
init_debug_pre();
62-
6370
init_seed();
6471

6572
init_pcpu_post(BOOT_CPU_ID);
@@ -78,6 +85,13 @@ void init_primary_pcpu(void)
7885
{
7986
uint64_t rsp;
8087

88+
/* Clear BSS */
89+
(void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start));
90+
91+
(void)parse_hv_cmdline();
92+
93+
init_debug_pre();
94+
8195
init_pcpu_pre(true);
8296

8397
/* Switch to run-time stack */

hypervisor/arch/x86/timer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ uint64_t us_to_ticks(uint32_t us)
318318

319319
uint64_t ticks_to_us(uint64_t ticks)
320320
{
321-
return (ticks * 1000UL) / (uint64_t)tsc_khz;
321+
uint64_t us = 0UL;
322+
323+
if (tsc_khz != 0U ) {
324+
us = (ticks * 1000UL) / (uint64_t)tsc_khz;
325+
}
326+
327+
return us;
322328
}
323329

324330
uint64_t ticks_to_ms(uint64_t ticks)

0 commit comments

Comments
 (0)