Skip to content

Commit e52917f

Browse files
KaigeFuwenlingz
authored andcommitted
HV: Reshuffle start_cpus and start_cpu
This patch makes the following changes: - Add one parameter 'mask' to start_cpus for later use. - Set cpu state as DEAD instead of dead loop when fail to start cpu. - Panic when there are any failures when start cpus in init_cpu_post and host_enter_s3. Tracked-On: #2991 Signed-off-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent cfe8637 commit e52917f

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define CPU_UP_TIMEOUT 100U /* millisecond */
3131
#define CPU_DOWN_TIMEOUT 100U /* millisecond */
3232

33+
#define AP_MASK (((1UL << phys_cpu_num) - 1UL) & ~(1UL << 0U))
34+
3335
struct per_cpu_region per_cpu_data[CONFIG_MAX_PCPU_NUM] __aligned(PAGE_SIZE);
3436
static uint16_t phys_cpu_num = 0U;
3537
static uint64_t pcpu_sync = 0UL;
@@ -229,7 +231,9 @@ void init_cpu_post(uint16_t pcpu_id)
229231

230232
/* Start all secondary cores */
231233
startup_paddr = prepare_trampoline();
232-
start_cpus();
234+
if (!start_cpus(AP_MASK)) {
235+
panic("Failed to start all secondary cores!");
236+
}
233237

234238
ASSERT(get_cpu_id() == BOOT_CPU_ID, "");
235239
} else {
@@ -287,32 +291,45 @@ static void start_cpu(uint16_t pcpu_id)
287291

288292
/* Check to see if expected CPU is actually up */
289293
if (!is_pcpu_active(pcpu_id)) {
290-
/* Print error */
291-
pr_fatal("Secondary CPUs failed to come up");
292-
293-
/* Error condition - loop endlessly for now */
294-
do {
295-
} while (1);
294+
pr_fatal("Secondary CPU%hu failed to come up", pcpu_id);
295+
cpu_set_current_state(pcpu_id, PCPU_STATE_DEAD);
296296
}
297297
}
298298

299-
void start_cpus(void)
299+
300+
/**
301+
* @brief Start all cpus if the bit is set in mask except itself
302+
*
303+
* @param[in] mask bits mask of cpus which should be started
304+
*
305+
* @return true if all cpus set in mask are started
306+
* @return false if there are any cpus set in mask aren't started
307+
*/
308+
bool start_cpus(uint64_t mask)
300309
{
301310
uint16_t i;
311+
uint16_t pcpu_id = get_cpu_id();
312+
uint64_t expected_start_mask = mask;
302313

303314
/* secondary cpu start up will wait for pcpu_sync -> 0UL */
304315
atomic_store64(&pcpu_sync, 1UL);
305316

306-
for (i = 0U; i < phys_cpu_num; i++) {
307-
if (get_cpu_id() == i) {
308-
continue;
317+
i = ffs64(expected_start_mask);
318+
while (i != INVALID_BIT_INDEX) {
319+
bitmap_clear_nolock(i, &expected_start_mask);
320+
321+
if (pcpu_id == i) {
322+
continue; /* Avoid start itself */
309323
}
310324

311325
start_cpu(i);
326+
i = ffs64(expected_start_mask);
312327
}
313328

314329
/* Trigger event to allow secondary CPUs to continue */
315330
atomic_store64(&pcpu_sync, 0UL);
331+
332+
return ((pcpu_active_bitmap & mask) == mask);
316333
}
317334

318335
void stop_cpus(void)

hypervisor/arch/x86/pm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <lapic.h>
2121
#include <vcpu.h>
2222

23+
#define AP_MASK (((1UL << get_pcpu_nums()) - 1UL) & ~(1UL << 0U))
24+
2325
struct cpu_context cpu_ctx;
2426

2527
/* The values in this structure should come from host ACPI table */
@@ -186,5 +188,7 @@ void host_enter_s3(struct pm_s_state_data *sstate_data, uint32_t pm1a_cnt_val, u
186188
clac();
187189

188190
/* online all APs again */
189-
start_cpus();
191+
if (!start_cpus(AP_MASK)) {
192+
panic("Failed to start all APs!");
193+
}
190194
}

hypervisor/include/arch/x86/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void trampoline_start16(void);
259259
void load_cpu_state_data(void);
260260
void init_cpu_pre(uint16_t pcpu_id_args);
261261
void init_cpu_post(uint16_t pcpu_id);
262-
void start_cpus(void);
262+
bool start_cpus(uint64_t mask);
263263
void stop_cpus(void);
264264
void wait_sync_change(uint64_t *sync, uint64_t wake_sync);
265265

0 commit comments

Comments
 (0)