Commit 74c0b816 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

replay: pass raw icount value to replay_save_clock



This avoids lock recursion when REPLAY_CLOCK is called inside the
timers spinlock.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 0c2ed83f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -509,7 +509,7 @@ static void icount_warp_rt(void)
    seqlock_write_lock(&timers_state.vm_clock_seqlock,
                       &timers_state.vm_clock_lock);
    if (runstate_is_running()) {
        int64_t clock = REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT,
        int64_t clock = REPLAY_CLOCK_LOCKED(REPLAY_CLOCK_VIRTUAL_RT,
                                            cpu_get_clock_locked());
        int64_t warp_delta;

+8 −2
Original line number Diff line number Diff line
@@ -100,14 +100,20 @@ bool replay_has_interrupt(void);
/* Processing clocks and other time sources */

/*! Save the specified clock */
int64_t replay_save_clock(ReplayClockKind kind, int64_t clock);
int64_t replay_save_clock(ReplayClockKind kind, int64_t clock,
                          int64_t raw_icount);
/*! Read the specified clock from the log or return cached data */
int64_t replay_read_clock(ReplayClockKind kind);
/*! Saves or reads the clock depending on the current replay mode. */
#define REPLAY_CLOCK(clock, value)                                      \
    (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))       \
        : replay_mode == REPLAY_MODE_RECORD                             \
            ? replay_save_clock((clock), (value))                       \
            ? replay_save_clock((clock), (value), cpu_get_icount_raw()) \
        : (value))
#define REPLAY_CLOCK_LOCKED(clock, value)                               \
    (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))       \
        : replay_mode == REPLAY_MODE_RECORD                             \
            ? replay_save_clock((clock), (value), cpu_get_icount_raw_locked()) \
        : (value))

/* Events */
+15 −10
Original line number Diff line number Diff line
@@ -217,11 +217,8 @@ void replay_mutex_unlock(void)
    }
}

/*! Saves cached instructions. */
void replay_save_instructions(void)
void replay_advance_current_step(uint64_t current_step)
{
    if (replay_file && replay_mode == REPLAY_MODE_RECORD) {
        g_assert(replay_mutex_locked());
    int diff = (int)(replay_get_current_step() - replay_state.current_step);

    /* Time can only go forward */
@@ -233,4 +230,12 @@ void replay_save_instructions(void)
        replay_state.current_step += diff;
    }
}

/*! Saves cached instructions. */
void replay_save_instructions(void)
{
    if (replay_file && replay_mode == REPLAY_MODE_RECORD) {
        g_assert(replay_mutex_locked());
        replay_advance_current_step(replay_get_current_step());
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -122,6 +122,8 @@ void replay_finish_event(void);
    data_kind variable. */
void replay_fetch_data_kind(void);

/*! Advance replay_state.current_step to the specified value. */
void replay_advance_current_step(uint64_t current_step);
/*! Saves queued events (like instructions and sound). */
void replay_save_instructions(void);

+5 −3
Original line number Diff line number Diff line
@@ -15,13 +15,15 @@
#include "replay-internal.h"
#include "qemu/error-report.h"

int64_t replay_save_clock(ReplayClockKind kind, int64_t clock)
int64_t replay_save_clock(ReplayClockKind kind, int64_t clock, int64_t raw_icount)
{

    if (replay_file) {
        g_assert(replay_mutex_locked());

        replay_save_instructions();
        /* Due to the caller's locking requirements we get the icount from it
         * instead of using replay_save_instructions().
         */
        replay_advance_current_step(raw_icount);
        replay_put_event(EVENT_CLOCK + kind);
        replay_put_qword(clock);
    }
Loading