@@ -11,6 +11,7 @@
/**
* AccelCPUState: vCPU fields specific to TCG accelerator
* @cflags: Pre-computed cflags for this cpu.
+ * @icount_extra: Instructions until next timer event.
* @plugin_state: per-CPU plugin state
*/
struct AccelCPUState {
@@ -22,6 +23,9 @@ struct AccelCPUState {
#ifdef CONFIG_USER_ONLY
TaskState *ts;
#else
+ int64_t icount_budget;
+ int64_t icount_extra;
+
/* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers;
#endif /* !CONFIG_USER_ONLY */
@@ -409,7 +409,6 @@ struct qemu_work_item;
* @unplug: Indicates a pending CPU unplug request.
* @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
* @singlestep_enabled: Flags for single-stepping.
- * @icount_extra: Instructions until next timer event.
* @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
* AddressSpaces this CPU has)
* @num_ases: number of CPUAddressSpaces in @cpu_ases
@@ -470,8 +469,6 @@ struct CPUState {
/* updates protected by BQL */
uint32_t interrupt_request;
int singlestep_enabled;
- int64_t icount_budget;
- int64_t icount_extra;
uint64_t random_seed;
QemuMutex work_mutex;
@@ -75,7 +75,7 @@ static void align_clocks(SyncClocks *sc, CPUState *cpu)
return;
}
- cpu_icount = cpu->icount_extra + cpu->neg.icount_decr.u16.low;
+ cpu_icount = cpu->accel->icount_extra + cpu->neg.icount_decr.u16.low;
sc->diff_clk += icount_to_ns(sc->last_cpu_icount - cpu_icount);
sc->last_cpu_icount = cpu_icount;
@@ -126,7 +126,7 @@ static void init_delay_params(SyncClocks *sc, CPUState *cpu)
sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - sc->realtime_clock;
sc->last_cpu_icount
- = cpu->icount_extra + cpu->neg.icount_decr.u16.low;
+ = cpu->accel->icount_extra + cpu->neg.icount_decr.u16.low;
if (sc->diff_clk < max_delay) {
max_delay = sc->diff_clk;
}
@@ -719,7 +719,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
if (cpu->exception_index < 0) {
#ifndef CONFIG_USER_ONLY
if (replay_has_exception()
- && cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0) {
+ && cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->accel->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
| CF_NOIRQ | 1;
@@ -790,7 +790,7 @@ static inline bool icount_exit_request(CPUState *cpu)
if (!(cpu->accel->cflags_next_tb == -1 || cpu->accel->cflags_next_tb & CF_USE_ICOUNT)) {
return false;
}
- return cpu->neg.icount_decr.u16.low + cpu->icount_extra == 0;
+ return cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra == 0;
#endif
}
@@ -942,9 +942,9 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
/* Ensure global icount has gone forward */
icount_update(cpu);
/* Refill decrementer and continue execution. */
- int32_t insns_left = MIN(0xffff, cpu->icount_budget);
+ int32_t insns_left = MIN(0xffff, cpu->accel->icount_budget);
cpu->neg.icount_decr.u16.low = insns_left;
- cpu->icount_extra = cpu->icount_budget - insns_left;
+ cpu->accel->icount_extra = cpu->accel->icount_budget - insns_left;
/*
* If the next tb has more instructions than we have left to
@@ -953,7 +953,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
*/
if (insns_left > 0 && insns_left < tb->icount) {
assert(insns_left <= CF_COUNT_MASK);
- assert(cpu->icount_extra == 0);
+ assert(cpu->accel->icount_extra == 0);
cpu->accel->cflags_next_tb = (tb->cflags & ~CF_COUNT_MASK) | insns_left;
}
#endif
@@ -38,6 +38,7 @@
#include "sysemu/cpu-timers.h"
#include "sysemu/cpu-throttle.h"
#include "sysemu/cpu-timers-internal.h"
+#include "accel/tcg/vcpu-state.h"
/*
* ICOUNT: Instruction Counter
@@ -71,8 +72,8 @@ static void icount_enable_adaptive(void)
*/
static int64_t icount_get_executed(CPUState *cpu)
{
- return (cpu->icount_budget -
- (cpu->neg.icount_decr.u16.low + cpu->icount_extra));
+ return (cpu->accel->icount_budget -
+ (cpu->neg.icount_decr.u16.low + cpu->accel->icount_extra));
}
/*
@@ -83,7 +84,7 @@ static int64_t icount_get_executed(CPUState *cpu)
static void icount_update_locked(CPUState *cpu)
{
int64_t executed = icount_get_executed(cpu);
- cpu->icount_budget -= executed;
+ cpu->accel->icount_budget -= executed;
qatomic_set_i64(&timers_state.qemu_icount,
timers_state.qemu_icount + executed);
@@ -112,16 +112,16 @@ void icount_prepare_for_run(CPUState *cpu, int64_t cpu_budget)
* asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
*/
g_assert(cpu->neg.icount_decr.u16.low == 0);
- g_assert(cpu->icount_extra == 0);
+ g_assert(cpu->accel->icount_extra == 0);
replay_mutex_lock();
- cpu->icount_budget = MIN(icount_get_limit(), cpu_budget);
- insns_left = MIN(0xffff, cpu->icount_budget);
+ cpu->accel->icount_budget = MIN(icount_get_limit(), cpu_budget);
+ insns_left = MIN(0xffff, cpu->accel->icount_budget);
cpu->neg.icount_decr.u16.low = insns_left;
- cpu->icount_extra = cpu->icount_budget - insns_left;
+ cpu->accel->icount_extra = cpu->accel->icount_budget - insns_left;
- if (cpu->icount_budget == 0) {
+ if (cpu->accel->icount_budget == 0) {
/*
* We're called without the BQL, so must take it while
* we're calling timer handlers.
@@ -139,8 +139,8 @@ void icount_process_data(CPUState *cpu)
/* Reset the counters */
cpu->neg.icount_decr.u16.low = 0;
- cpu->icount_extra = 0;
- cpu->icount_budget = 0;
+ cpu->accel->icount_extra = 0;
+ cpu->accel->icount_budget = 0;
replay_account_executed_instructions();
@@ -89,6 +89,7 @@ static void tcg_cpu_reset_hold(CPUState *cpu)
qatomic_set(&cpu->neg.icount_decr.u32, 0);
cpu->neg.can_do_io = true;
+ cpu->accel->icount_extra = 0;
cpu->accel->cflags_next_tb = -1;
}
@@ -121,7 +121,6 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
cpu->interrupt_request = 0;
cpu->halted = cpu->start_powered_off;
cpu->mem_io_pc = 0;
- cpu->icount_extra = 0;
cpu->exception_index = -1;
cpu->crash_occurred = false;