Skip to content

Commit

Permalink
replay: save prior value of the host clock
Browse files Browse the repository at this point in the history
This patch adds saving/restoring of the host clock field 'last'.
It is used in host clock calculation and therefore clock may
become incorrect when using restored vmstate.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20180227095226.1060.50975.stgit@pasha-VirtualBox>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
  • Loading branch information
Dovgalyuk authored and bonzini committed Mar 12, 2018
1 parent bb040e0 commit 4b930d2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/qemu/timer.h
Expand Up @@ -251,6 +251,20 @@ bool qemu_clock_run_timers(QEMUClockType type);
*/
bool qemu_clock_run_all_timers(void);

/**
* qemu_clock_get_last:
*
* Returns last clock query time.
*/
uint64_t qemu_clock_get_last(QEMUClockType type);
/**
* qemu_clock_set_last:
*
* Sets last clock query time.
*/
void qemu_clock_set_last(QEMUClockType type, uint64_t last);


/*
* QEMUTimerList
*/
Expand Down
2 changes: 2 additions & 0 deletions replay/replay-internal.h
Expand Up @@ -78,6 +78,8 @@ typedef struct ReplayState {
This counter is global, because requests from different
block devices should not get overlapping ids. */
uint64_t block_request_id;
/*! Prior value of the host clock */
uint64_t host_clock_last;
} ReplayState;
extern ReplayState replay_state;

Expand Down
3 changes: 3 additions & 0 deletions replay/replay-snapshot.c
Expand Up @@ -25,6 +25,7 @@ static int replay_pre_save(void *opaque)
{
ReplayState *state = opaque;
state->file_offset = ftell(replay_file);
state->host_clock_last = qemu_clock_get_last(QEMU_CLOCK_HOST);

return 0;
}
Expand All @@ -33,6 +34,7 @@ static int replay_post_load(void *opaque, int version_id)
{
ReplayState *state = opaque;
fseek(replay_file, state->file_offset, SEEK_SET);
qemu_clock_set_last(QEMU_CLOCK_HOST, state->host_clock_last);
/* If this was a vmstate, saved in recording mode,
we need to initialize replay data fields. */
replay_fetch_data_kind();
Expand All @@ -54,6 +56,7 @@ static const VMStateDescription vmstate_replay = {
VMSTATE_UINT32(has_unread_data, ReplayState),
VMSTATE_UINT64(file_offset, ReplayState),
VMSTATE_UINT64(block_request_id, ReplayState),
VMSTATE_UINT64(host_clock_last, ReplayState),
VMSTATE_END_OF_LIST()
},
};
Expand Down
12 changes: 12 additions & 0 deletions util/qemu-timer.c
Expand Up @@ -622,6 +622,18 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
}
}

uint64_t qemu_clock_get_last(QEMUClockType type)
{
QEMUClock *clock = qemu_clock_ptr(type);
return clock->last;
}

void qemu_clock_set_last(QEMUClockType type, uint64_t last)
{
QEMUClock *clock = qemu_clock_ptr(type);
clock->last = last;
}

void qemu_clock_register_reset_notifier(QEMUClockType type,
Notifier *notifier)
{
Expand Down

0 comments on commit 4b930d2

Please sign in to comment.