mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-16 10:47:26 +00:00
HV:treewide:Update cpu_id type as uint_16
There are extra type conversion in the HV since cpu_id type is uint32_t and the return value type of get_cpu_id is uint16_t. BTW, the name of cpu_id is not clear enough to express its usage. So the following updates are made in this patch: Update cpu_id type as unit_16 to reduce type casting; Update related temporary variables type; Update related print argument; Change the input parameter name of interrupt_init as cpu_id to keep align with function implement; Rename cpu_id as pcpu_id as needed. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
188210ab03
commit
b76c92bf3e
@ -31,22 +31,22 @@ struct vcpu *get_ever_run_vcpu(uint16_t pcpu_id)
|
||||
* for physical CPU 1 : vcpu->pcpu_id = 1, vcpu->vcpu_id = 1, vmid = 1;
|
||||
*
|
||||
***********************************************************************/
|
||||
int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
|
||||
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
ASSERT(vm != NULL, "");
|
||||
ASSERT(rtn_vcpu_handle != NULL, "");
|
||||
|
||||
pr_info("Creating VCPU %d", cpu_id);
|
||||
pr_info("Creating VCPU %hu", pcpu_id);
|
||||
|
||||
/* Allocate memory for VCPU */
|
||||
vcpu = calloc(1, sizeof(struct vcpu));
|
||||
ASSERT(vcpu != NULL, "");
|
||||
|
||||
/* Initialize the physical CPU ID for this VCPU */
|
||||
vcpu->pcpu_id = cpu_id;
|
||||
per_cpu(ever_run_vcpu, cpu_id) = vcpu;
|
||||
vcpu->pcpu_id = pcpu_id;
|
||||
per_cpu(ever_run_vcpu, pcpu_id) = vcpu;
|
||||
|
||||
/* Initialize the parent VM reference */
|
||||
vcpu->vm = vm;
|
||||
@ -72,7 +72,7 @@ int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
|
||||
ASSERT(vcpu->vcpu_id < vm->hw.num_vcpus,
|
||||
"Allocated vcpu_id is out of range!");
|
||||
|
||||
per_cpu(vcpu, cpu_id) = vcpu;
|
||||
per_cpu(vcpu, pcpu_id) = vcpu;
|
||||
|
||||
pr_info("PCPU%d is working as VM%d VCPU%d, Role: %s",
|
||||
vcpu->pcpu_id, vcpu->vm->attr.id, vcpu->vcpu_id,
|
||||
|
@ -376,19 +376,19 @@ int init_default_irqs(uint16_t cpu_id)
|
||||
|
||||
void dispatch_exception(struct intr_excp_ctx *ctx)
|
||||
{
|
||||
unsigned int cpu_id = get_cpu_id();
|
||||
uint16_t pcpu_id = get_cpu_id();
|
||||
|
||||
/* Obtain lock to ensure exception dump doesn't get corrupted */
|
||||
spinlock_obtain(&exception_spinlock);
|
||||
|
||||
/* Dump exception context */
|
||||
dump_exception(ctx, cpu_id);
|
||||
dump_exception(ctx, pcpu_id);
|
||||
|
||||
/* Release lock to let other CPUs handle exception */
|
||||
spinlock_release(&exception_spinlock);
|
||||
|
||||
/* Halt the CPU */
|
||||
cpu_dead(cpu_id);
|
||||
cpu_dead(pcpu_id);
|
||||
}
|
||||
|
||||
void handle_spurious_interrupt(uint32_t vector)
|
||||
@ -710,19 +710,19 @@ void get_cpu_interrupt_info(char *str, int str_max)
|
||||
}
|
||||
#endif /* HV_DEBUG */
|
||||
|
||||
int interrupt_init(uint32_t cpu_id)
|
||||
int interrupt_init(uint16_t pcpu_id)
|
||||
{
|
||||
struct host_idt_descriptor *idtd = &HOST_IDTR;
|
||||
int status;
|
||||
|
||||
set_idt(idtd);
|
||||
|
||||
status = init_lapic(cpu_id);
|
||||
status = init_lapic(pcpu_id);
|
||||
ASSERT(status == 0, "lapic init failed");
|
||||
if (status != 0)
|
||||
return -ENODEV;
|
||||
|
||||
status = init_default_irqs(cpu_id);
|
||||
status = init_default_irqs(pcpu_id);
|
||||
ASSERT(status == 0, "irqs init failed");
|
||||
if (status != 0)
|
||||
return -ENODEV;
|
||||
|
@ -211,11 +211,11 @@ int early_init_lapic(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int init_lapic(uint16_t cpu_id)
|
||||
int init_lapic(uint16_t pcpu_id)
|
||||
{
|
||||
/* Set the Logical Destination Register */
|
||||
write_lapic_reg32(LAPIC_LOGICAL_DESTINATION_REGISTER,
|
||||
((1U << cpu_id) << 24));
|
||||
((1U << pcpu_id) << 24U));
|
||||
|
||||
/* Set the Destination Format Register */
|
||||
write_lapic_reg32(LAPIC_DESTINATION_FORMAT_REGISTER, 0xf << 28);
|
||||
|
@ -18,11 +18,11 @@ void enable_softirq(uint16_t cpu_id)
|
||||
|
||||
void init_softirq(void)
|
||||
{
|
||||
uint16_t cpu_id;
|
||||
uint16_t pcpu_id;
|
||||
|
||||
for (cpu_id = 0; cpu_id < phys_cpu_num; cpu_id++) {
|
||||
per_cpu(softirq_pending, cpu_id) = 0;
|
||||
bitmap_set(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, cpu_id));
|
||||
for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++) {
|
||||
per_cpu(softirq_pending, pcpu_id) = 0;
|
||||
bitmap_set(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, pcpu_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,33 +104,33 @@ static bool is_vm0_bsp(uint16_t pcpu_id)
|
||||
return pcpu_id == vm0_desc.vm_hw_logical_core_ids[0];
|
||||
}
|
||||
|
||||
int32_t hv_main(uint16_t cpu_id)
|
||||
int32_t hv_main(uint16_t pcpu_id)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
pr_info("%s, Starting common entry point for CPU %d",
|
||||
__func__, cpu_id);
|
||||
pr_info("%s, Starting common entry point for CPU %hu",
|
||||
__func__, pcpu_id);
|
||||
|
||||
if (cpu_id >= phys_cpu_num) {
|
||||
pr_err("%s, cpu_id %d out of range %d\n",
|
||||
__func__, cpu_id, phys_cpu_num);
|
||||
if (pcpu_id >= phys_cpu_num) {
|
||||
pr_err("%s, cpu_id %hu out of range %d\n",
|
||||
__func__, pcpu_id, phys_cpu_num);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (cpu_id != get_cpu_id()) {
|
||||
pr_err("%s, cpu_id %d mismatch\n", __func__, cpu_id);
|
||||
if (pcpu_id != get_cpu_id()) {
|
||||
pr_err("%s, cpu_id %hu mismatch\n", __func__, pcpu_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Enable virtualization extensions */
|
||||
ret = exec_vmxon_instr(cpu_id);
|
||||
ret = exec_vmxon_instr(pcpu_id);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* X2APIC mode is disabled by default. */
|
||||
x2apic_enabled = false;
|
||||
|
||||
if (is_vm0_bsp(cpu_id)) {
|
||||
if (is_vm0_bsp(pcpu_id)) {
|
||||
ret = prepare_vm0();
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
@ -167,11 +167,11 @@ static void show_guest_call_trace(struct vcpu *vcpu)
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
static void dump_guest_context(uint32_t cpu_id)
|
||||
static void dump_guest_context(uint16_t pcpu_id)
|
||||
{
|
||||
struct vcpu *vcpu;
|
||||
|
||||
vcpu = per_cpu(vcpu, cpu_id);
|
||||
vcpu = per_cpu(vcpu, pcpu_id);
|
||||
if (vcpu != NULL) {
|
||||
dump_guest_reg(vcpu);
|
||||
dump_guest_stack(vcpu);
|
||||
@ -179,13 +179,13 @@ static void dump_guest_context(uint32_t cpu_id)
|
||||
}
|
||||
}
|
||||
|
||||
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
|
||||
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint16_t pcpu_id)
|
||||
{
|
||||
uint32_t i = 0U;
|
||||
uint32_t cb_hierarchy = 0U;
|
||||
uint64_t *sp = (uint64_t *)rsp;
|
||||
|
||||
printf("\r\nHost Stack: CPU_ID = %d\r\n", cpu_id);
|
||||
printf("\r\nHost Stack: CPU_ID = %hu\r\n", pcpu_id);
|
||||
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
|
||||
printf("addr(0x%llx) 0x%016llx 0x%016llx 0x%016llx "
|
||||
"0x%016llx\r\n", (rsp+i*32U), sp[i*4U], sp[i*4U+1U],
|
||||
@ -195,8 +195,8 @@ static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
|
||||
|
||||
printf("Host Call Trace:\r\n");
|
||||
if (rsp >
|
||||
(uint64_t)&per_cpu(stack, cpu_id)[CONFIG_STACK_SIZE - 1]
|
||||
|| rsp < (uint64_t)&per_cpu(stack, cpu_id)[0]) {
|
||||
(uint64_t)&per_cpu(stack, pcpu_id)[CONFIG_STACK_SIZE - 1]
|
||||
|| rsp < (uint64_t)&per_cpu(stack, pcpu_id)[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
|
||||
* if the address is invalid, it will cause hv page fault
|
||||
* then halt system */
|
||||
while ((rbp <=
|
||||
(uint64_t)&per_cpu(stack, cpu_id)[CONFIG_STACK_SIZE - 1])
|
||||
&& (rbp >= (uint64_t)&per_cpu(stack, cpu_id)[0])
|
||||
(uint64_t)&per_cpu(stack, pcpu_id)[CONFIG_STACK_SIZE - 1])
|
||||
&& (rbp >= (uint64_t)&per_cpu(stack, pcpu_id)[0])
|
||||
&& (cb_hierarchy++ < CALL_TRACE_HIERARCHY_MAX)) {
|
||||
printf("----> 0x%016llx\r\n",
|
||||
*(uint64_t *)(rbp + sizeof(uint64_t)));
|
||||
@ -230,14 +230,14 @@ static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
|
||||
|
||||
void __assert(uint32_t line, const char *file, char *txt)
|
||||
{
|
||||
uint32_t cpu_id = get_cpu_id();
|
||||
uint16_t pcpu_id = get_cpu_id();
|
||||
uint64_t rsp = cpu_rsp_get();
|
||||
uint64_t rbp = cpu_rbp_get();
|
||||
|
||||
pr_fatal("Assertion failed in file %s,line %u : %s",
|
||||
file, line, txt);
|
||||
show_host_call_trace(rsp, rbp, cpu_id);
|
||||
dump_guest_context(cpu_id);
|
||||
show_host_call_trace(rsp, rbp, pcpu_id);
|
||||
dump_guest_context(pcpu_id);
|
||||
do {
|
||||
asm volatile ("pause" ::: "memory");
|
||||
} while (1);
|
||||
@ -278,14 +278,14 @@ void dump_intr_excp_frame(struct intr_excp_ctx *ctx)
|
||||
printf("===========================\n");
|
||||
}
|
||||
|
||||
void dump_exception(struct intr_excp_ctx *ctx, uint32_t cpu_id)
|
||||
void dump_exception(struct intr_excp_ctx *ctx, uint16_t pcpu_id)
|
||||
{
|
||||
/* Dump host context */
|
||||
dump_intr_excp_frame(ctx);
|
||||
/* Show host stack */
|
||||
show_host_call_trace(ctx->rsp, ctx->rbp, cpu_id);
|
||||
show_host_call_trace(ctx->rsp, ctx->rbp, pcpu_id);
|
||||
/* Dump guest context */
|
||||
dump_guest_context(cpu_id);
|
||||
dump_guest_context(pcpu_id);
|
||||
|
||||
/* Save registers*/
|
||||
crash_ctx = ctx;
|
||||
|
@ -20,24 +20,24 @@ struct logmsg {
|
||||
|
||||
static struct logmsg logmsg;
|
||||
|
||||
static inline void alloc_earlylog_sbuf(uint32_t cpu_id)
|
||||
static inline void alloc_earlylog_sbuf(uint16_t pcpu_id)
|
||||
{
|
||||
uint32_t ele_size = LOG_ENTRY_SIZE;
|
||||
uint32_t ele_num = ((HVLOG_BUF_SIZE >> 1) / phys_cpu_num
|
||||
- SBUF_HEAD_SIZE) / ele_size;
|
||||
|
||||
per_cpu(earlylog_sbuf, cpu_id) = sbuf_allocate(ele_num, ele_size);
|
||||
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
|
||||
printf("failed to allcate sbuf for hvlog - %d\n", cpu_id);
|
||||
per_cpu(earlylog_sbuf, pcpu_id) = sbuf_allocate(ele_num, ele_size);
|
||||
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
|
||||
printf("failed to allcate sbuf for hvlog - %hu\n", pcpu_id);
|
||||
}
|
||||
|
||||
static inline void free_earlylog_sbuf(uint32_t cpu_id)
|
||||
static inline void free_earlylog_sbuf(uint16_t pcpu_id)
|
||||
{
|
||||
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
|
||||
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
|
||||
return;
|
||||
|
||||
free(per_cpu(earlylog_sbuf, cpu_id));
|
||||
per_cpu(earlylog_sbuf, cpu_id) = NULL;
|
||||
free(per_cpu(earlylog_sbuf, pcpu_id));
|
||||
per_cpu(earlylog_sbuf, pcpu_id) = NULL;
|
||||
}
|
||||
|
||||
static int do_copy_earlylog(struct shared_buf *dst_sbuf,
|
||||
@ -69,21 +69,21 @@ static int do_copy_earlylog(struct shared_buf *dst_sbuf,
|
||||
|
||||
void init_logmsg(__unused uint32_t mem_size, uint32_t flags)
|
||||
{
|
||||
int32_t idx;
|
||||
int16_t pcpu_id;
|
||||
|
||||
logmsg.flags = flags;
|
||||
logmsg.seq = 0;
|
||||
|
||||
/* allocate sbuf for log before sos booting */
|
||||
for (idx = 0; idx < phys_cpu_num; idx++)
|
||||
alloc_earlylog_sbuf(idx);
|
||||
for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++)
|
||||
alloc_earlylog_sbuf(pcpu_id);
|
||||
}
|
||||
|
||||
void do_logmsg(uint32_t severity, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
uint64_t timestamp;
|
||||
uint32_t cpu_id;
|
||||
uint16_t pcpu_id;
|
||||
bool do_console_log;
|
||||
bool do_mem_log;
|
||||
char *buffer;
|
||||
@ -104,14 +104,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
|
||||
timestamp = ticks_to_us(timestamp);
|
||||
|
||||
/* Get CPU ID */
|
||||
cpu_id = get_cpu_id();
|
||||
buffer = per_cpu(logbuf, cpu_id);
|
||||
pcpu_id = get_cpu_id();
|
||||
buffer = per_cpu(logbuf, pcpu_id);
|
||||
|
||||
memset(buffer, 0, LOG_MESSAGE_MAX_SIZE);
|
||||
/* Put time-stamp, CPU ID and severity into buffer */
|
||||
snprintf(buffer, LOG_MESSAGE_MAX_SIZE,
|
||||
"[%lluus][cpu=%u][sev=%u][seq=%u]:",
|
||||
timestamp, cpu_id, severity,
|
||||
"[%lluus][cpu=%hu][sev=%u][seq=%u]:",
|
||||
timestamp, pcpu_id, severity,
|
||||
atomic_inc_return(&logmsg.seq));
|
||||
|
||||
/* Put message into remaining portion of local buffer */
|
||||
@ -135,14 +135,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
|
||||
if (do_mem_log) {
|
||||
int i, msg_len;
|
||||
struct shared_buf *sbuf = (struct shared_buf *)
|
||||
per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
|
||||
struct shared_buf *early_sbuf = per_cpu(earlylog_sbuf, cpu_id);
|
||||
per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
|
||||
struct shared_buf *early_sbuf = per_cpu(earlylog_sbuf, pcpu_id);
|
||||
|
||||
if (early_sbuf != NULL) {
|
||||
if (sbuf != NULL) {
|
||||
/* switch to sbuf from sos */
|
||||
do_copy_earlylog(sbuf, early_sbuf);
|
||||
free_earlylog_sbuf(cpu_id);
|
||||
free_earlylog_sbuf(pcpu_id);
|
||||
} else
|
||||
/* use earlylog sbuf if no sbuf from sos */
|
||||
sbuf = early_sbuf;
|
||||
@ -160,7 +160,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
void print_logmsg_buffer(uint32_t cpu_id)
|
||||
void print_logmsg_buffer(uint16_t pcpu_id)
|
||||
{
|
||||
spinlock_rflags;
|
||||
char buffer[LOG_ENTRY_SIZE + 1];
|
||||
@ -168,20 +168,20 @@ void print_logmsg_buffer(uint32_t cpu_id)
|
||||
struct shared_buf **sbuf;
|
||||
int is_earlylog = 0;
|
||||
|
||||
if (cpu_id >= (uint32_t)phys_cpu_num)
|
||||
if (pcpu_id >= phys_cpu_num)
|
||||
return;
|
||||
|
||||
if (per_cpu(earlylog_sbuf, cpu_id) != NULL) {
|
||||
sbuf = &per_cpu(earlylog_sbuf, cpu_id);
|
||||
if (per_cpu(earlylog_sbuf, pcpu_id) != NULL) {
|
||||
sbuf = &per_cpu(earlylog_sbuf, pcpu_id);
|
||||
is_earlylog = 1;
|
||||
} else
|
||||
sbuf = (struct shared_buf **)
|
||||
&per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
|
||||
&per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
|
||||
|
||||
spinlock_irqsave_obtain(&(logmsg.lock));
|
||||
if ((*sbuf) != NULL)
|
||||
printf("CPU%d: head: 0x%x, tail: 0x%x %s\n\r",
|
||||
cpu_id, (*sbuf)->head, (*sbuf)->tail,
|
||||
printf("CPU%hu: head: 0x%x, tail: 0x%x %s\n\r",
|
||||
pcpu_id, (*sbuf)->head, (*sbuf)->tail,
|
||||
(is_earlylog != 0) ? "[earlylog]" : "");
|
||||
spinlock_irqrestore_release(&(logmsg.lock));
|
||||
|
||||
|
@ -277,7 +277,7 @@ struct vcpu {
|
||||
|
||||
/* External Interfaces */
|
||||
struct vcpu* get_ever_run_vcpu(uint16_t pcpu_id);
|
||||
int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
|
||||
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
|
||||
int start_vcpu(struct vcpu *vcpu);
|
||||
int shutdown_vcpu(struct vcpu *vcpu);
|
||||
void destroy_vcpu(struct vcpu *vcpu);
|
||||
|
@ -105,7 +105,7 @@ int exception_vmexit_handler(struct vcpu *vcpu);
|
||||
int interrupt_window_vmexit_handler(struct vcpu *vcpu);
|
||||
int external_interrupt_vmexit_handler(struct vcpu *vcpu);
|
||||
int acrn_handle_pending_request(struct vcpu *vcpu);
|
||||
int interrupt_init(uint32_t logical_id);
|
||||
int interrupt_init(uint16_t pcpu_id);
|
||||
|
||||
void cancel_event_injection(struct vcpu *vcpu);
|
||||
|
||||
|
@ -14,7 +14,7 @@ struct intr_excp_ctx;
|
||||
#define DUMP_STACK_SIZE 0x200U
|
||||
|
||||
void dump_intr_excp_frame(struct intr_excp_ctx *ctx);
|
||||
void dump_exception(struct intr_excp_ctx *ctx, uint32_t cpu_id);
|
||||
void dump_exception(struct intr_excp_ctx *ctx, uint16_t pcpu_id);
|
||||
|
||||
#else
|
||||
static inline void dump_intr_excp_frame(__unused struct intr_excp_ctx *ctx)
|
||||
@ -22,7 +22,7 @@ static inline void dump_intr_excp_frame(__unused struct intr_excp_ctx *ctx)
|
||||
}
|
||||
|
||||
static inline void dump_exception(__unused struct intr_excp_ctx *ctx,
|
||||
__unused uint32_t cpu_id)
|
||||
__unused uint16_t pcpu_id)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
extern uint32_t console_loglevel;
|
||||
extern uint32_t mem_loglevel;
|
||||
void init_logmsg(uint32_t mem_size, uint32_t flags);
|
||||
void print_logmsg_buffer(uint32_t cpu_id);
|
||||
void print_logmsg_buffer(uint16_t pcpu_id);
|
||||
void do_logmsg(uint32_t severity, const char *fmt, ...);
|
||||
|
||||
#else /* HV_DEBUG */
|
||||
@ -45,7 +45,7 @@ static inline void do_logmsg(__unused uint32_t severity,
|
||||
{
|
||||
}
|
||||
|
||||
static inline void print_logmsg_buffer(__unused uint32_t cpu_id)
|
||||
static inline void print_logmsg_buffer(__unused uint16_t pcpu_id)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user