Skip to content

Commit b76c92b

Browse files
wuxyintellijinxia
authored andcommitted
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>
1 parent 188210a commit b76c92b

File tree

11 files changed

+73
-73
lines changed

11 files changed

+73
-73
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ struct vcpu *get_ever_run_vcpu(uint16_t pcpu_id)
3131
* for physical CPU 1 : vcpu->pcpu_id = 1, vcpu->vcpu_id = 1, vmid = 1;
3232
*
3333
***********************************************************************/
34-
int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
34+
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
3535
{
3636
struct vcpu *vcpu;
3737

3838
ASSERT(vm != NULL, "");
3939
ASSERT(rtn_vcpu_handle != NULL, "");
4040

41-
pr_info("Creating VCPU %d", cpu_id);
41+
pr_info("Creating VCPU %hu", pcpu_id);
4242

4343
/* Allocate memory for VCPU */
4444
vcpu = calloc(1, sizeof(struct vcpu));
4545
ASSERT(vcpu != NULL, "");
4646

4747
/* Initialize the physical CPU ID for this VCPU */
48-
vcpu->pcpu_id = cpu_id;
49-
per_cpu(ever_run_vcpu, cpu_id) = vcpu;
48+
vcpu->pcpu_id = pcpu_id;
49+
per_cpu(ever_run_vcpu, pcpu_id) = vcpu;
5050

5151
/* Initialize the parent VM reference */
5252
vcpu->vm = vm;
@@ -72,7 +72,7 @@ int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
7272
ASSERT(vcpu->vcpu_id < vm->hw.num_vcpus,
7373
"Allocated vcpu_id is out of range!");
7474

75-
per_cpu(vcpu, cpu_id) = vcpu;
75+
per_cpu(vcpu, pcpu_id) = vcpu;
7676

7777
pr_info("PCPU%d is working as VM%d VCPU%d, Role: %s",
7878
vcpu->pcpu_id, vcpu->vm->attr.id, vcpu->vcpu_id,

hypervisor/arch/x86/irq.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,19 @@ int init_default_irqs(uint16_t cpu_id)
376376

377377
void dispatch_exception(struct intr_excp_ctx *ctx)
378378
{
379-
unsigned int cpu_id = get_cpu_id();
379+
uint16_t pcpu_id = get_cpu_id();
380380

381381
/* Obtain lock to ensure exception dump doesn't get corrupted */
382382
spinlock_obtain(&exception_spinlock);
383383

384384
/* Dump exception context */
385-
dump_exception(ctx, cpu_id);
385+
dump_exception(ctx, pcpu_id);
386386

387387
/* Release lock to let other CPUs handle exception */
388388
spinlock_release(&exception_spinlock);
389389

390390
/* Halt the CPU */
391-
cpu_dead(cpu_id);
391+
cpu_dead(pcpu_id);
392392
}
393393

394394
void handle_spurious_interrupt(uint32_t vector)
@@ -710,19 +710,19 @@ void get_cpu_interrupt_info(char *str, int str_max)
710710
}
711711
#endif /* HV_DEBUG */
712712

713-
int interrupt_init(uint32_t cpu_id)
713+
int interrupt_init(uint16_t pcpu_id)
714714
{
715715
struct host_idt_descriptor *idtd = &HOST_IDTR;
716716
int status;
717717

718718
set_idt(idtd);
719719

720-
status = init_lapic(cpu_id);
720+
status = init_lapic(pcpu_id);
721721
ASSERT(status == 0, "lapic init failed");
722722
if (status != 0)
723723
return -ENODEV;
724724

725-
status = init_default_irqs(cpu_id);
725+
status = init_default_irqs(pcpu_id);
726726
ASSERT(status == 0, "irqs init failed");
727727
if (status != 0)
728728
return -ENODEV;

hypervisor/arch/x86/lapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ int early_init_lapic(void)
211211
return 0;
212212
}
213213

214-
int init_lapic(uint16_t cpu_id)
214+
int init_lapic(uint16_t pcpu_id)
215215
{
216216
/* Set the Logical Destination Register */
217217
write_lapic_reg32(LAPIC_LOGICAL_DESTINATION_REGISTER,
218-
((1U << cpu_id) << 24));
218+
((1U << pcpu_id) << 24U));
219219

220220
/* Set the Destination Format Register */
221221
write_lapic_reg32(LAPIC_DESTINATION_FORMAT_REGISTER, 0xf << 28);

hypervisor/arch/x86/softirq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ void enable_softirq(uint16_t cpu_id)
1818

1919
void init_softirq(void)
2020
{
21-
uint16_t cpu_id;
21+
uint16_t pcpu_id;
2222

23-
for (cpu_id = 0; cpu_id < phys_cpu_num; cpu_id++) {
24-
per_cpu(softirq_pending, cpu_id) = 0;
25-
bitmap_set(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, cpu_id));
23+
for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++) {
24+
per_cpu(softirq_pending, pcpu_id) = 0;
25+
bitmap_set(SOFTIRQ_ATOMIC, &per_cpu(softirq_pending, pcpu_id));
2626
}
2727
}
2828

hypervisor/common/hv_main.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,33 +104,33 @@ static bool is_vm0_bsp(uint16_t pcpu_id)
104104
return pcpu_id == vm0_desc.vm_hw_logical_core_ids[0];
105105
}
106106

107-
int32_t hv_main(uint16_t cpu_id)
107+
int32_t hv_main(uint16_t pcpu_id)
108108
{
109109
int32_t ret;
110110

111-
pr_info("%s, Starting common entry point for CPU %d",
112-
__func__, cpu_id);
111+
pr_info("%s, Starting common entry point for CPU %hu",
112+
__func__, pcpu_id);
113113

114-
if (cpu_id >= phys_cpu_num) {
115-
pr_err("%s, cpu_id %d out of range %d\n",
116-
__func__, cpu_id, phys_cpu_num);
114+
if (pcpu_id >= phys_cpu_num) {
115+
pr_err("%s, cpu_id %hu out of range %d\n",
116+
__func__, pcpu_id, phys_cpu_num);
117117
return -EINVAL;
118118
}
119119

120-
if (cpu_id != get_cpu_id()) {
121-
pr_err("%s, cpu_id %d mismatch\n", __func__, cpu_id);
120+
if (pcpu_id != get_cpu_id()) {
121+
pr_err("%s, cpu_id %hu mismatch\n", __func__, pcpu_id);
122122
return -EINVAL;
123123
}
124124

125125
/* Enable virtualization extensions */
126-
ret = exec_vmxon_instr(cpu_id);
126+
ret = exec_vmxon_instr(pcpu_id);
127127
if (ret != 0)
128128
return ret;
129129

130130
/* X2APIC mode is disabled by default. */
131131
x2apic_enabled = false;
132132

133-
if (is_vm0_bsp(cpu_id)) {
133+
if (is_vm0_bsp(pcpu_id)) {
134134
ret = prepare_vm0();
135135
if (ret != 0)
136136
return ret;

hypervisor/debug/dump.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,25 @@ static void show_guest_call_trace(struct vcpu *vcpu)
167167
printf("\r\n");
168168
}
169169

170-
static void dump_guest_context(uint32_t cpu_id)
170+
static void dump_guest_context(uint16_t pcpu_id)
171171
{
172172
struct vcpu *vcpu;
173173

174-
vcpu = per_cpu(vcpu, cpu_id);
174+
vcpu = per_cpu(vcpu, pcpu_id);
175175
if (vcpu != NULL) {
176176
dump_guest_reg(vcpu);
177177
dump_guest_stack(vcpu);
178178
show_guest_call_trace(vcpu);
179179
}
180180
}
181181

182-
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
182+
static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint16_t pcpu_id)
183183
{
184184
uint32_t i = 0U;
185185
uint32_t cb_hierarchy = 0U;
186186
uint64_t *sp = (uint64_t *)rsp;
187187

188-
printf("\r\nHost Stack: CPU_ID = %d\r\n", cpu_id);
188+
printf("\r\nHost Stack: CPU_ID = %hu\r\n", pcpu_id);
189189
for (i = 0U; i < DUMP_STACK_SIZE/32U; i++) {
190190
printf("addr(0x%llx) 0x%016llx 0x%016llx 0x%016llx "
191191
"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)
195195

196196
printf("Host Call Trace:\r\n");
197197
if (rsp >
198-
(uint64_t)&per_cpu(stack, cpu_id)[CONFIG_STACK_SIZE - 1]
199-
|| rsp < (uint64_t)&per_cpu(stack, cpu_id)[0]) {
198+
(uint64_t)&per_cpu(stack, pcpu_id)[CONFIG_STACK_SIZE - 1]
199+
|| rsp < (uint64_t)&per_cpu(stack, pcpu_id)[0]) {
200200
return;
201201
}
202202

@@ -214,8 +214,8 @@ static void show_host_call_trace(uint64_t rsp, uint64_t rbp, uint32_t cpu_id)
214214
* if the address is invalid, it will cause hv page fault
215215
* then halt system */
216216
while ((rbp <=
217-
(uint64_t)&per_cpu(stack, cpu_id)[CONFIG_STACK_SIZE - 1])
218-
&& (rbp >= (uint64_t)&per_cpu(stack, cpu_id)[0])
217+
(uint64_t)&per_cpu(stack, pcpu_id)[CONFIG_STACK_SIZE - 1])
218+
&& (rbp >= (uint64_t)&per_cpu(stack, pcpu_id)[0])
219219
&& (cb_hierarchy++ < CALL_TRACE_HIERARCHY_MAX)) {
220220
printf("----> 0x%016llx\r\n",
221221
*(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)
230230

231231
void __assert(uint32_t line, const char *file, char *txt)
232232
{
233-
uint32_t cpu_id = get_cpu_id();
233+
uint16_t pcpu_id = get_cpu_id();
234234
uint64_t rsp = cpu_rsp_get();
235235
uint64_t rbp = cpu_rbp_get();
236236

237237
pr_fatal("Assertion failed in file %s,line %u : %s",
238238
file, line, txt);
239-
show_host_call_trace(rsp, rbp, cpu_id);
240-
dump_guest_context(cpu_id);
239+
show_host_call_trace(rsp, rbp, pcpu_id);
240+
dump_guest_context(pcpu_id);
241241
do {
242242
asm volatile ("pause" ::: "memory");
243243
} while (1);
@@ -278,14 +278,14 @@ void dump_intr_excp_frame(struct intr_excp_ctx *ctx)
278278
printf("===========================\n");
279279
}
280280

281-
void dump_exception(struct intr_excp_ctx *ctx, uint32_t cpu_id)
281+
void dump_exception(struct intr_excp_ctx *ctx, uint16_t pcpu_id)
282282
{
283283
/* Dump host context */
284284
dump_intr_excp_frame(ctx);
285285
/* Show host stack */
286-
show_host_call_trace(ctx->rsp, ctx->rbp, cpu_id);
286+
show_host_call_trace(ctx->rsp, ctx->rbp, pcpu_id);
287287
/* Dump guest context */
288-
dump_guest_context(cpu_id);
288+
dump_guest_context(pcpu_id);
289289

290290
/* Save registers*/
291291
crash_ctx = ctx;

hypervisor/debug/logmsg.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ struct logmsg {
2020

2121
static struct logmsg logmsg;
2222

23-
static inline void alloc_earlylog_sbuf(uint32_t cpu_id)
23+
static inline void alloc_earlylog_sbuf(uint16_t pcpu_id)
2424
{
2525
uint32_t ele_size = LOG_ENTRY_SIZE;
2626
uint32_t ele_num = ((HVLOG_BUF_SIZE >> 1) / phys_cpu_num
2727
- SBUF_HEAD_SIZE) / ele_size;
2828

29-
per_cpu(earlylog_sbuf, cpu_id) = sbuf_allocate(ele_num, ele_size);
30-
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
31-
printf("failed to allcate sbuf for hvlog - %d\n", cpu_id);
29+
per_cpu(earlylog_sbuf, pcpu_id) = sbuf_allocate(ele_num, ele_size);
30+
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
31+
printf("failed to allcate sbuf for hvlog - %hu\n", pcpu_id);
3232
}
3333

34-
static inline void free_earlylog_sbuf(uint32_t cpu_id)
34+
static inline void free_earlylog_sbuf(uint16_t pcpu_id)
3535
{
36-
if (per_cpu(earlylog_sbuf, cpu_id) == NULL)
36+
if (per_cpu(earlylog_sbuf, pcpu_id) == NULL)
3737
return;
3838

39-
free(per_cpu(earlylog_sbuf, cpu_id));
40-
per_cpu(earlylog_sbuf, cpu_id) = NULL;
39+
free(per_cpu(earlylog_sbuf, pcpu_id));
40+
per_cpu(earlylog_sbuf, pcpu_id) = NULL;
4141
}
4242

4343
static int do_copy_earlylog(struct shared_buf *dst_sbuf,
@@ -69,21 +69,21 @@ static int do_copy_earlylog(struct shared_buf *dst_sbuf,
6969

7070
void init_logmsg(__unused uint32_t mem_size, uint32_t flags)
7171
{
72-
int32_t idx;
72+
int16_t pcpu_id;
7373

7474
logmsg.flags = flags;
7575
logmsg.seq = 0;
7676

7777
/* allocate sbuf for log before sos booting */
78-
for (idx = 0; idx < phys_cpu_num; idx++)
79-
alloc_earlylog_sbuf(idx);
78+
for (pcpu_id = 0U; pcpu_id < phys_cpu_num; pcpu_id++)
79+
alloc_earlylog_sbuf(pcpu_id);
8080
}
8181

8282
void do_logmsg(uint32_t severity, const char *fmt, ...)
8383
{
8484
va_list args;
8585
uint64_t timestamp;
86-
uint32_t cpu_id;
86+
uint16_t pcpu_id;
8787
bool do_console_log;
8888
bool do_mem_log;
8989
char *buffer;
@@ -104,14 +104,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
104104
timestamp = ticks_to_us(timestamp);
105105

106106
/* Get CPU ID */
107-
cpu_id = get_cpu_id();
108-
buffer = per_cpu(logbuf, cpu_id);
107+
pcpu_id = get_cpu_id();
108+
buffer = per_cpu(logbuf, pcpu_id);
109109

110110
memset(buffer, 0, LOG_MESSAGE_MAX_SIZE);
111111
/* Put time-stamp, CPU ID and severity into buffer */
112112
snprintf(buffer, LOG_MESSAGE_MAX_SIZE,
113-
"[%lluus][cpu=%u][sev=%u][seq=%u]:",
114-
timestamp, cpu_id, severity,
113+
"[%lluus][cpu=%hu][sev=%u][seq=%u]:",
114+
timestamp, pcpu_id, severity,
115115
atomic_inc_return(&logmsg.seq));
116116

117117
/* Put message into remaining portion of local buffer */
@@ -135,14 +135,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
135135
if (do_mem_log) {
136136
int i, msg_len;
137137
struct shared_buf *sbuf = (struct shared_buf *)
138-
per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
139-
struct shared_buf *early_sbuf = per_cpu(earlylog_sbuf, cpu_id);
138+
per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
139+
struct shared_buf *early_sbuf = per_cpu(earlylog_sbuf, pcpu_id);
140140

141141
if (early_sbuf != NULL) {
142142
if (sbuf != NULL) {
143143
/* switch to sbuf from sos */
144144
do_copy_earlylog(sbuf, early_sbuf);
145-
free_earlylog_sbuf(cpu_id);
145+
free_earlylog_sbuf(pcpu_id);
146146
} else
147147
/* use earlylog sbuf if no sbuf from sos */
148148
sbuf = early_sbuf;
@@ -160,28 +160,28 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
160160
}
161161
}
162162

163-
void print_logmsg_buffer(uint32_t cpu_id)
163+
void print_logmsg_buffer(uint16_t pcpu_id)
164164
{
165165
spinlock_rflags;
166166
char buffer[LOG_ENTRY_SIZE + 1];
167167
int read_cnt;
168168
struct shared_buf **sbuf;
169169
int is_earlylog = 0;
170170

171-
if (cpu_id >= (uint32_t)phys_cpu_num)
171+
if (pcpu_id >= phys_cpu_num)
172172
return;
173173

174-
if (per_cpu(earlylog_sbuf, cpu_id) != NULL) {
175-
sbuf = &per_cpu(earlylog_sbuf, cpu_id);
174+
if (per_cpu(earlylog_sbuf, pcpu_id) != NULL) {
175+
sbuf = &per_cpu(earlylog_sbuf, pcpu_id);
176176
is_earlylog = 1;
177177
} else
178178
sbuf = (struct shared_buf **)
179-
&per_cpu(sbuf, cpu_id)[ACRN_HVLOG];
179+
&per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
180180

181181
spinlock_irqsave_obtain(&(logmsg.lock));
182182
if ((*sbuf) != NULL)
183-
printf("CPU%d: head: 0x%x, tail: 0x%x %s\n\r",
184-
cpu_id, (*sbuf)->head, (*sbuf)->tail,
183+
printf("CPU%hu: head: 0x%x, tail: 0x%x %s\n\r",
184+
pcpu_id, (*sbuf)->head, (*sbuf)->tail,
185185
(is_earlylog != 0) ? "[earlylog]" : "");
186186
spinlock_irqrestore_release(&(logmsg.lock));
187187

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct vcpu {
277277

278278
/* External Interfaces */
279279
struct vcpu* get_ever_run_vcpu(uint16_t pcpu_id);
280-
int create_vcpu(uint16_t cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
280+
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
281281
int start_vcpu(struct vcpu *vcpu);
282282
int shutdown_vcpu(struct vcpu *vcpu);
283283
void destroy_vcpu(struct vcpu *vcpu);

hypervisor/include/arch/x86/irq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int exception_vmexit_handler(struct vcpu *vcpu);
105105
int interrupt_window_vmexit_handler(struct vcpu *vcpu);
106106
int external_interrupt_vmexit_handler(struct vcpu *vcpu);
107107
int acrn_handle_pending_request(struct vcpu *vcpu);
108-
int interrupt_init(uint32_t logical_id);
108+
int interrupt_init(uint16_t pcpu_id);
109109

110110
void cancel_event_injection(struct vcpu *vcpu);
111111

0 commit comments

Comments
 (0)