static int64_t qemu_icount_delta(void) { if (use_icount == 1) { /* When not using an adaptive execution frequency we tend to get badly out of sync with real time, so just delay for a reasonable amount of time. */ return 0; } else { return cpu_get_icount() - cpu_get_clock(); } }
int64_t qemu_get_clock_ns(QEMUClock *clock) { switch(clock->type) { case QEMU_CLOCK_REALTIME: return get_clock(); default: case QEMU_CLOCK_VIRTUAL: if (use_icount) { return cpu_get_icount(); } else { return cpu_get_clock(); } case QEMU_CLOCK_HOST: return get_clock_realtime(); } }
/* return the host CPU cycle counter and handle stop/restart */ int64_t cpu_get_ticks(void) { if (use_icount) { return cpu_get_icount(); } if (!timers_state.cpu_ticks_enabled) { return timers_state.cpu_ticks_offset; } else { int64_t ticks; ticks = cpu_get_real_ticks(); if (timers_state.cpu_ticks_prev > ticks) { /* Note: non increasing ticks may happen if the host uses software suspend */ timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - ticks; } timers_state.cpu_ticks_prev = ticks; return ticks + timers_state.cpu_ticks_offset; } }
int64_t qemu_get_clock(QEMUClock *clock) { switch(clock->type) { case QEMU_CLOCK_REALTIME: return get_clock() / 1000000; default: case QEMU_CLOCK_VIRTUAL: #ifdef MARSS_QEMU if (in_simulation) { return cpu_get_sim_clock(); } #endif if (use_icount) { return cpu_get_icount(); } else { return cpu_get_clock(); } case QEMU_CLOCK_HOST: return get_clock_realtime(); } }
int64_t qemu_get_clock_ns(QEMUClock *clock) { int64_t now, last; switch(clock->type) { case QEMU_CLOCK_REALTIME: return get_clock(); default: case QEMU_CLOCK_VIRTUAL: if (use_icount) { return cpu_get_icount(); } else { return cpu_get_clock(); } case QEMU_CLOCK_HOST: now = get_clock_realtime(); last = clock->last; clock->last = now; if (now < last) { notifier_list_notify(&clock->reset_notifiers, &now); } return now; } }
/* return the host CPU cycle counter and handle stop/restart */ int64_t cpu_get_ticks(void) { #ifdef MARSS_QEMU if(in_simulation) { return timers_state.cpu_sim_ticks_offset + sim_cycle; } #endif if (use_icount) { return cpu_get_icount(); } if (!timers_state.cpu_ticks_enabled) { return timers_state.cpu_ticks_offset; } else { int64_t ticks; ticks = cpu_get_real_ticks(); if (timers_state.cpu_ticks_prev > ticks) { /* Note: non increasing ticks may happen if the host uses software suspend */ timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - ticks; } timers_state.cpu_ticks_prev = ticks; return ticks + timers_state.cpu_ticks_offset; } }