Let's put the default spapr clock value in a SPAPR_CLOCK_FREQ for better readability.
After that, make 'cpufreq' default to SPAPR_CLOCK_FREQ if kvmppc_get_clockfreq() fails to read the clock from the DT. Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com> --- hw/ppc/spapr.c | 12 +++++++++++- include/hw/ppc/spapr.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index f66e3cbe38..80189c78be 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -654,7 +654,7 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, 0xffffffff, 0xffffffff}; uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : SPAPR_TIMEBASE_FREQ; - uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq(NULL) : 1000000000; + uint32_t cpufreq = SPAPR_CLOCK_FREQ; uint32_t page_sizes_prop[64]; size_t page_sizes_prop_size; unsigned int smp_threads = ms->smp.threads; @@ -699,6 +699,16 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset, } _FDT((fdt_setprop_cell(fdt, offset, "timebase-frequency", tbfreq))); + + if (kvm_enabled()) { + Error *local_err = NULL; + + cpufreq = kvmppc_get_clockfreq(&local_err); + if (local_err) { + cpufreq = SPAPR_CLOCK_FREQ; + } + } + _FDT((fdt_setprop_cell(fdt, offset, "clock-frequency", cpufreq))); _FDT((fdt_setprop_cell(fdt, offset, "slb-size", cpu->hash64_opts->slb_size))); _FDT((fdt_setprop_cell(fdt, offset, "ibm,slb-size", cpu->hash64_opts->slb_size))); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 072dda2c72..ed579635ca 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -26,6 +26,7 @@ typedef struct SpaprPendingHpt SpaprPendingHpt; #define SPAPR_ENTRY_POINT 0x100 #define SPAPR_TIMEBASE_FREQ 512000000ULL +#define SPAPR_CLOCK_FREQ 1000000000ULL #define TYPE_SPAPR_RTC "spapr-rtc" -- 2.36.1