Skip to content

Commit d3bb5d0

Browse files
calmisibonzini
authored andcommitted
i386/cpu: Extract a common fucntion to setup value of MSR_CORE_THREAD_COUNT
There are duplicated code to setup the value of MSR_CORE_THREAD_COUNT. Extract a common function for it. Signed-off-by: Xiaoyao Li <[email protected]> Reviewed-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d662b66 commit d3bb5d0

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

target/i386/cpu-system.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,14 @@ void x86_cpu_get_crash_info_qom(Object *obj, Visitor *v,
309309
errp);
310310
qapi_free_GuestPanicInformation(panic_info);
311311
}
312+
313+
uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu)
314+
{
315+
CPUState *cs = CPU(cpu);
316+
uint64_t val;
317+
318+
val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
319+
val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
320+
321+
return val;
322+
}

target/i386/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,8 @@ static inline void cpu_x86_load_seg_cache_sipi(X86CPU *cpu,
24132413
cs->halted = 0;
24142414
}
24152415

2416+
uint64_t cpu_x86_get_msr_core_thread_count(X86CPU *cpu);
2417+
24162418
int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
24172419
target_ulong *base, unsigned int *limit,
24182420
unsigned int *flags);

target/i386/hvf/x86_emu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,7 @@ void simulate_rdmsr(CPUX86State *env)
765765
val = env->mtrr_deftype;
766766
break;
767767
case MSR_CORE_THREAD_COUNT:
768-
val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
769-
val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
768+
val = cpu_x86_get_msr_core_thread_count(cpu);
770769
break;
771770
default:
772771
/* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */

target/i386/kvm/kvm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,10 +2614,7 @@ static bool kvm_rdmsr_core_thread_count(X86CPU *cpu,
26142614
uint32_t msr,
26152615
uint64_t *val)
26162616
{
2617-
CPUState *cs = CPU(cpu);
2618-
2619-
*val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
2620-
*val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
2617+
*val = cpu_x86_get_msr_core_thread_count(cpu);
26212618

26222619
return true;
26232620
}

target/i386/tcg/system/misc_helper.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ void helper_rdmsr(CPUX86State *env)
468468
val = x86_cpu->ucode_rev;
469469
break;
470470
case MSR_CORE_THREAD_COUNT: {
471-
CPUState *cs = CPU(x86_cpu);
472-
val = (cs->nr_threads * cs->nr_cores) | (cs->nr_cores << 16);
471+
val = cpu_x86_get_msr_core_thread_count(x86_cpu);
473472
break;
474473
}
475474
case MSR_APIC_START ... MSR_APIC_END: {

0 commit comments

Comments
 (0)