replay: push replay_mutex_lock up the call tree

Now instead of using the replay_lock to guard the output of the log we
now use it to protect the whole execution section. This replaces what
the BQL used to do when it was held during TCG execution.

We also introduce some rules for locking order - mainly that you
cannot take the replay_mutex while holding the BQL. This leads to some
slight sophistry during start-up and extending the
replay_mutex_destroy function to unlock the mutex without checking
for the BQL condition so it can be cleanly dropped in the non-replay
case.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Tested-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20180227095248.1060.40374.stgit@pasha-VirtualBox>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
This commit is contained in:
Alex Bennée 2018-02-27 12:52:48 +03:00 committed by Paolo Bonzini
parent 1a423896fa
commit d759c951f3
10 changed files with 109 additions and 76 deletions

View file

@ -79,16 +79,14 @@ bool replay_has_events(void)
void replay_flush_events(void)
{
replay_mutex_lock();
g_assert(replay_mutex_locked());
while (!QTAILQ_EMPTY(&events_list)) {
Event *event = QTAILQ_FIRST(&events_list);
replay_mutex_unlock();
replay_run_event(event);
replay_mutex_lock();
QTAILQ_REMOVE(&events_list, event, events);
g_free(event);
}
replay_mutex_unlock();
}
void replay_disable_events(void)
@ -102,14 +100,14 @@ void replay_disable_events(void)
void replay_clear_events(void)
{
replay_mutex_lock();
g_assert(replay_mutex_locked());
while (!QTAILQ_EMPTY(&events_list)) {
Event *event = QTAILQ_FIRST(&events_list);
QTAILQ_REMOVE(&events_list, event, events);
g_free(event);
}
replay_mutex_unlock();
}
/*! Adds specified async event to the queue */
@ -136,9 +134,8 @@ void replay_add_event(ReplayAsyncEventKind event_kind,
event->opaque2 = opaque2;
event->id = id;
replay_mutex_lock();
g_assert(replay_mutex_locked());
QTAILQ_INSERT_TAIL(&events_list, event, events);
replay_mutex_unlock();
}
void replay_bh_schedule_event(QEMUBH *bh)
@ -207,13 +204,11 @@ static void replay_save_event(Event *event, int checkpoint)
/* Called with replay mutex locked */
void replay_save_events(int checkpoint)
{
g_assert(replay_mutex_locked());
while (!QTAILQ_EMPTY(&events_list)) {
Event *event = QTAILQ_FIRST(&events_list);
replay_save_event(event, checkpoint);
replay_mutex_unlock();
replay_run_event(event);
replay_mutex_lock();
QTAILQ_REMOVE(&events_list, event, events);
g_free(event);
}
@ -292,6 +287,7 @@ static Event *replay_read_event(int checkpoint)
/* Called with replay mutex locked */
void replay_read_events(int checkpoint)
{
g_assert(replay_mutex_locked());
while (replay_state.data_kind == EVENT_ASYNC) {
Event *event = replay_read_event(checkpoint);
if (!event) {
@ -299,9 +295,7 @@ void replay_read_events(int checkpoint)
}
replay_finish_event();
read_event_kind = -1;
replay_mutex_unlock();
replay_run_event(event);
replay_mutex_lock();
g_free(event);
}