Skip to content

Commit 7b8abe1

Browse files
shiqinggacrnsi
authored andcommitted
hv: refine 'init_percpu_lapic_id'
This patch refines 'init_percpu_lapic_id' to move the error handling to 'init_pcpu_pre'. Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
1 parent dbb4157 commit 7b8abe1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,26 @@ static void print_hv_banner(void);
4545
static uint16_t get_pcpu_id_from_lapic_id(uint32_t lapic_id);
4646
static uint64_t start_tsc __attribute__((__section__(".bss_noinit")));
4747

48-
static void init_percpu_lapic_id(void)
48+
static bool init_percpu_lapic_id(void)
4949
{
5050
uint16_t i;
5151
uint16_t pcpu_num;
5252
uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM];
53+
bool success = false;
5354

5455
/* Save all lapic_id detected via parse_mdt in lapic_id_array */
5556
pcpu_num = parse_madt(lapic_id_array);
56-
if (pcpu_num == 0U) {
57-
/* failed to get the physcial cpu number */
58-
panic("failed to get the physcial cpu number");
59-
}
6057

61-
phys_cpu_num = pcpu_num;
58+
if (pcpu_num != 0U) {
59+
phys_cpu_num = pcpu_num;
6260

63-
for (i = 0U; (i < pcpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
64-
per_cpu(lapic_id, i) = lapic_id_array[i];
61+
for (i = 0U; (i < pcpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
62+
per_cpu(lapic_id, i) = lapic_id_array[i];
63+
}
64+
success = true;
6565
}
66+
67+
return success;
6668
}
6769

6870
static void pcpu_set_current_state(uint16_t pcpu_id, enum pcpu_boot_state state)
@@ -132,7 +134,9 @@ void init_pcpu_pre(uint16_t pcpu_id_args)
132134

133135
early_init_lapic();
134136

135-
init_percpu_lapic_id();
137+
if (!init_percpu_lapic_id()) {
138+
panic("failed to init_percpu_lapic_id!");
139+
}
136140

137141
ret = init_ioapic_id_info();
138142
if (ret != 0) {

0 commit comments

Comments
 (0)