mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
iothread: release AioContext around aio_poll
This is the first step towards having fine-grained critical sections in
dataplane threads, which will resolve lock ordering problems between
address_space_* functions (which need the BQL when doing MMIO, even
after we complete RCU-based dispatch) and the AioContext.
Because AioContext does not use contention callbacks anymore, the
unit test has to be changed.
Previously applied as a0710f7995
and
then reverted.
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1477565348-5458-19-git-send-email-pbonzini@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
parent
c9d1a56174
commit
65c1b5b622
5 changed files with 41 additions and 55 deletions
|
@ -100,6 +100,7 @@ static void event_ready_cb(EventNotifier *e)
|
|||
|
||||
typedef struct {
|
||||
QemuMutex start_lock;
|
||||
EventNotifier notifier;
|
||||
bool thread_acquired;
|
||||
} AcquireTestData;
|
||||
|
||||
|
@ -111,6 +112,11 @@ static void *test_acquire_thread(void *opaque)
|
|||
qemu_mutex_lock(&data->start_lock);
|
||||
qemu_mutex_unlock(&data->start_lock);
|
||||
|
||||
/* event_notifier_set might be called either before or after
|
||||
* the main thread's call to poll(). The test case's outcome
|
||||
* should be the same in either case.
|
||||
*/
|
||||
event_notifier_set(&data->notifier);
|
||||
aio_context_acquire(ctx);
|
||||
aio_context_release(ctx);
|
||||
|
||||
|
@ -125,20 +131,19 @@ static void set_event_notifier(AioContext *ctx, EventNotifier *notifier,
|
|||
aio_set_event_notifier(ctx, notifier, false, handler);
|
||||
}
|
||||
|
||||
static void dummy_notifier_read(EventNotifier *unused)
|
||||
static void dummy_notifier_read(EventNotifier *n)
|
||||
{
|
||||
g_assert(false); /* should never be invoked */
|
||||
event_notifier_test_and_clear(n);
|
||||
}
|
||||
|
||||
static void test_acquire(void)
|
||||
{
|
||||
QemuThread thread;
|
||||
EventNotifier notifier;
|
||||
AcquireTestData data;
|
||||
|
||||
/* Dummy event notifier ensures aio_poll() will block */
|
||||
event_notifier_init(¬ifier, false);
|
||||
set_event_notifier(ctx, ¬ifier, dummy_notifier_read);
|
||||
event_notifier_init(&data.notifier, false);
|
||||
set_event_notifier(ctx, &data.notifier, dummy_notifier_read);
|
||||
g_assert(!aio_poll(ctx, false)); /* consume aio_notify() */
|
||||
|
||||
qemu_mutex_init(&data.start_lock);
|
||||
|
@ -152,12 +157,13 @@ static void test_acquire(void)
|
|||
/* Block in aio_poll(), let other thread kick us and acquire context */
|
||||
aio_context_acquire(ctx);
|
||||
qemu_mutex_unlock(&data.start_lock); /* let the thread run */
|
||||
g_assert(!aio_poll(ctx, true));
|
||||
g_assert(aio_poll(ctx, true));
|
||||
g_assert(!data.thread_acquired);
|
||||
aio_context_release(ctx);
|
||||
|
||||
qemu_thread_join(&thread);
|
||||
set_event_notifier(ctx, ¬ifier, NULL);
|
||||
event_notifier_cleanup(¬ifier);
|
||||
set_event_notifier(ctx, &data.notifier, NULL);
|
||||
event_notifier_cleanup(&data.notifier);
|
||||
|
||||
g_assert(data.thread_acquired);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue