Commit 3fe71223 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Fam Zheng
Browse files

aio: convert from RFifoLock to QemuRecMutex



It is simpler and a bit faster, and QEMU does not need the contention
callbacks (and thus the fairness) anymore.

Reviewed-by: default avatarFam Zheng <famz@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Message-Id: <1477565348-5458-21-git-send-email-pbonzini@redhat.com>
Signed-off-by: default avatarFam Zheng <famz@redhat.com>
parent feadec63
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ aio_ctx_finalize(GSource *source)

    aio_set_event_notifier(ctx, &ctx->notifier, false, NULL);
    event_notifier_cleanup(&ctx->notifier);
    rfifolock_destroy(&ctx->lock);
    qemu_rec_mutex_destroy(&ctx->lock);
    qemu_mutex_destroy(&ctx->bh_lock);
    timerlistgroup_deinit(&ctx->tlg);
}
@@ -372,7 +372,7 @@ AioContext *aio_context_new(Error **errp)
#endif
    ctx->thread_pool = NULL;
    qemu_mutex_init(&ctx->bh_lock);
    rfifolock_init(&ctx->lock, NULL, NULL);
    qemu_rec_mutex_init(&ctx->lock);
    timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);

    return ctx;
@@ -393,10 +393,10 @@ void aio_context_unref(AioContext *ctx)

void aio_context_acquire(AioContext *ctx)
{
    rfifolock_lock(&ctx->lock);
    qemu_rec_mutex_lock(&ctx->lock);
}

void aio_context_release(AioContext *ctx)
{
    rfifolock_unlock(&ctx->lock);
    qemu_rec_mutex_unlock(&ctx->lock);
}
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
#include "qemu/queue.h"
#include "qemu/event_notifier.h"
#include "qemu/thread.h"
#include "qemu/rfifolock.h"
#include "qemu/timer.h"

typedef struct BlockAIOCB BlockAIOCB;
@@ -54,7 +53,7 @@ struct AioContext {
    GSource source;

    /* Protects all fields from multi-threaded access */
    RFifoLock lock;
    QemuRecMutex lock;

    /* The list of registered AIO handlers */
    QLIST_HEAD(, AioHandler) aio_handlers;

include/qemu/rfifolock.h

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
/*
 * Recursive FIFO lock
 *
 * Copyright Red Hat, Inc. 2013
 *
 * Authors:
 *  Stefan Hajnoczi   <stefanha@redhat.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 *
 */

#ifndef QEMU_RFIFOLOCK_H
#define QEMU_RFIFOLOCK_H

#include "qemu/thread.h"

/* Recursive FIFO lock
 *
 * This lock provides more features than a plain mutex:
 *
 * 1. Fairness - enforces FIFO order.
 * 2. Nesting - can be taken recursively.
 * 3. Contention callback - optional, called when thread must wait.
 *
 * The recursive FIFO lock is heavyweight so prefer other synchronization
 * primitives if you do not need its features.
 */
typedef struct {
    QemuMutex lock;             /* protects all fields */

    /* FIFO order */
    unsigned int head;          /* active ticket number */
    unsigned int tail;          /* waiting ticket number */
    QemuCond cond;              /* used to wait for our ticket number */

    /* Nesting */
    QemuThread owner_thread;    /* thread that currently has ownership */
    unsigned int nesting;       /* amount of nesting levels */

    /* Contention callback */
    void (*cb)(void *);         /* called when thread must wait, with ->lock
                                 * held so it may not recursively lock/unlock
                                 */
    void *cb_opaque;
} RFifoLock;

void rfifolock_init(RFifoLock *r, void (*cb)(void *), void *opaque);
void rfifolock_destroy(RFifoLock *r);
void rfifolock_lock(RFifoLock *r);
void rfifolock_unlock(RFifoLock *r);

#endif /* QEMU_RFIFOLOCK_H */
+0 −1
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ test-qmp-marshal.c
test-qobject-output-visitor
test-rcu-list
test-replication
test-rfifolock
test-string-input-visitor
test-string-output-visitor
test-thread-pool
+0 −2
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ check-unit-y += tests/test-visitor-serialization$(EXESUF)
check-unit-y += tests/test-iov$(EXESUF)
gcov-files-test-iov-y = util/iov.c
check-unit-y += tests/test-aio$(EXESUF)
check-unit-$(CONFIG_POSIX) += tests/test-rfifolock$(EXESUF)
check-unit-y += tests/test-throttle$(EXESUF)
gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c
gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c
@@ -490,7 +489,6 @@ tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y)
tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y)
tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y)
tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y)
tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o $(test-util-obj-y)
tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-util-obj-y)
tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y)
Loading