Skip to content

Commit

Permalink
feat: Allow icount mode import checkpoints created w/o icount
Browse files Browse the repository at this point in the history
  • Loading branch information
xusine committed Sep 25, 2024
1 parent 5b04cb7 commit 2a7b41a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion accel/tcg/icount-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static int64_t icount_get_locked(void)
{
int64_t icount = icount_get_raw_locked();
return qatomic_read_i64(&timers_state.qemu_icount_bias) +
icount_to_ns(icount);
icount_to_ns(icount) + timers_state.virtual_clock_snapshot;
}

int64_t icount_get_raw(void)
Expand Down
3 changes: 3 additions & 0 deletions include/sysemu/cpu-timers-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ typedef struct TimersState {
int64_t vm_clock_warp_start;
int64_t cpu_clock_offset;

/* Add by Cyan. the vm_clock from the recent snapshot */
int64_t virtual_clock_snapshot;

/* Only written by TCG thread */
int64_t qemu_icount;

Expand Down
22 changes: 20 additions & 2 deletions system/cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ void cpu_enable_ticks(void)
seqlock_write_lock(&timers_state.vm_clock_seqlock,
&timers_state.vm_clock_lock);
if (!timers_state.cpu_ticks_enabled) {
timers_state.virtual_clock_snapshot = timers_state.cpu_clock_offset;

if (icount_enabled()) {
// well, we have adjust the virtual_clock_snapshot time, so we should clean the current icount.
// by assigning offset, we cancel the value of the current icount.
timers_state.qemu_icount_bias = - icount_to_ns(timers_state.qemu_icount);
}

timers_state.cpu_ticks_offset -= cpu_get_host_ticks();
timers_state.cpu_clock_offset -= get_clock();
timers_state.cpu_ticks_enabled = 1;
Expand All @@ -128,7 +136,16 @@ void cpu_disable_ticks(void)
&timers_state.vm_clock_lock);
if (timers_state.cpu_ticks_enabled) {
timers_state.cpu_ticks_offset += cpu_get_host_ticks();
timers_state.cpu_clock_offset = cpu_get_clock_locked();

if (icount_enabled()) {
// record the current time calculated with icount.
int64_t current_system_time = icount_to_ns(timers_state.qemu_icount) + timers_state.qemu_icount_bias + timers_state.virtual_clock_snapshot;
timers_state.cpu_clock_offset = current_system_time; // record it to the snapshot.
} else {
// record the CPU time.
timers_state.cpu_clock_offset = cpu_get_clock_locked();
}

timers_state.cpu_ticks_enabled = 0;
}
seqlock_write_unlock(&timers_state.vm_clock_seqlock,
Expand All @@ -137,7 +154,8 @@ void cpu_disable_ticks(void)

static bool icount_state_needed(void *opaque)
{
return icount_enabled();
// return icount_enabled();
return false;
}

static bool warp_timer_state_needed(void *opaque)
Expand Down
3 changes: 2 additions & 1 deletion target/arm/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ static int64_t cycles_ns_per(uint64_t cycles)

static bool instructions_supported(CPUARMState *env)
{
return icount_enabled() == 1; /* Precise instruction counting */
// return icount_enabled() == 1; /* Precise instruction counting */
return false;
}

static uint64_t instructions_get_count(CPUARMState *env)
Expand Down

0 comments on commit 2a7b41a

Please sign in to comment.