There is no need to init timers if we're not even sure that our extensions are valid. Execute riscv_cpu_validate_set_extensions() before riscv_timer_init().
Signed-off-by: Daniel Henrique Barboza <dbarb...@ventanamicro.com> Reviewed-by: LIU Zhiwei <zhiwei_...@linux.alibaba.com> Reviewed-by: Weiwei Li <liwei...@iscas.ac.cn> --- target/riscv/cpu.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e8045840bd..331272c8a0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1196,13 +1196,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) return; } - -#ifndef CONFIG_USER_ONLY - if (cpu->cfg.ext_sstc) { - riscv_timer_init(cpu); - } -#endif /* CONFIG_USER_ONLY */ - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -1210,6 +1203,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } #ifndef CONFIG_USER_ONLY + if (cpu->cfg.ext_sstc) { + riscv_timer_init(cpu); + } + if (cpu->cfg.pmu_num) { if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpmf) { cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, -- 2.39.2