From: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
alex.bennee@linaro.org, mark.burton@greensocs.com,
real@ispras.ru, batuzovk@ispras.ru,
maria.klimushenkova@ispras.ru, pavel.dovgaluk@ispras.ru,
pbonzini@redhat.com, afaerber@suse.de, fred.konrad@greensocs.com
Subject: [Qemu-devel] [RFC PATCH v9 15/23] aio: replace stack of bottom halves with queue
Date: Wed, 18 Feb 2015 14:57:10 +0300 [thread overview]
Message-ID: <20150218115710.4176.28907.stgit@PASHA-ISP> (raw)
In-Reply-To: <20150218115534.4176.12578.stgit@PASHA-ISP>
Bottom halves in AIO context are stored and removes
in LIFO order. It makes their execution non-deterministic.
This patch replaces the stack with queue to preserve the
order of bottom halves processing.
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
async.c | 25 +++++++++----------------
include/block/aio.h | 4 ++--
include/qemu/queue.h | 7 +++++++
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/async.c b/async.c
index 2be88cc..a84f122 100644
--- a/async.c
+++ b/async.c
@@ -35,7 +35,7 @@ struct QEMUBH {
AioContext *ctx;
QEMUBHFunc *cb;
void *opaque;
- QEMUBH *next;
+ QSIMPLEQ_ENTRY(QEMUBH) next;
bool scheduled;
bool idle;
bool deleted;
@@ -51,10 +51,7 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
.opaque = opaque,
};
qemu_mutex_lock(&ctx->bh_lock);
- bh->next = ctx->first_bh;
- /* Make sure that the members are ready before putting bh into list */
- smp_wmb();
- ctx->first_bh = bh;
+ QSIMPLEQ_INSERT_TAIL_RCU(&ctx->bh_queue, bh, next);
qemu_mutex_unlock(&ctx->bh_lock);
return bh;
}
@@ -62,16 +59,15 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
int aio_bh_poll(AioContext *ctx)
{
- QEMUBH *bh, **bhp, *next;
+ QEMUBH *bh, *next;
int ret;
ctx->walking_bh++;
ret = 0;
- for (bh = ctx->first_bh; bh; bh = next) {
+ QSIMPLEQ_FOREACH(bh, &ctx->bh_queue, next) {
/* Make sure that fetching bh happens before accessing its members */
smp_read_barrier_depends();
- next = bh->next;
if (!bh->deleted && bh->scheduled) {
bh->scheduled = 0;
/* Paired with write barrier in bh schedule to ensure reading for
@@ -90,14 +86,10 @@ int aio_bh_poll(AioContext *ctx)
/* remove deleted bhs */
if (!ctx->walking_bh) {
qemu_mutex_lock(&ctx->bh_lock);
- bhp = &ctx->first_bh;
- while (*bhp) {
- bh = *bhp;
+ QSIMPLEQ_FOREACH_SAFE(bh, &ctx->bh_queue, next, next) {
if (bh->deleted) {
- *bhp = bh->next;
+ QSIMPLEQ_REMOVE(&ctx->bh_queue, bh, QEMUBH, next);
g_free(bh);
- } else {
- bhp = &bh->next;
}
}
qemu_mutex_unlock(&ctx->bh_lock);
@@ -161,7 +153,7 @@ aio_compute_timeout(AioContext *ctx)
int timeout = -1;
QEMUBH *bh;
- for (bh = ctx->first_bh; bh; bh = bh->next) {
+ QSIMPLEQ_FOREACH(bh, &ctx->bh_queue, next) {
if (!bh->deleted && bh->scheduled) {
if (bh->idle) {
/* idle bottom halves will be polled at least
@@ -204,7 +196,7 @@ aio_ctx_check(GSource *source)
AioContext *ctx = (AioContext *) source;
QEMUBH *bh;
- for (bh = ctx->first_bh; bh; bh = bh->next) {
+ QSIMPLEQ_FOREACH(bh, &ctx->bh_queue, next) {
if (!bh->deleted && bh->scheduled) {
return true;
}
@@ -311,6 +303,7 @@ AioContext *aio_context_new(Error **errp)
qemu_mutex_init(&ctx->bh_lock);
rfifolock_init(&ctx->lock, aio_rfifolock_cb, ctx);
timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);
+ QSIMPLEQ_INIT(&ctx->bh_queue);
return ctx;
}
diff --git a/include/block/aio.h b/include/block/aio.h
index 7d1e26b..82cdf78 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -71,8 +71,8 @@ struct AioContext {
/* lock to protect between bh's adders and deleter */
QemuMutex bh_lock;
- /* Anchor of the list of Bottom Halves belonging to the context */
- struct QEMUBH *first_bh;
+ /* List of Bottom Halves belonging to the context */
+ QSIMPLEQ_HEAD(, QEMUBH) bh_queue;
/* A simple lock used to protect the first_bh list, and ensure that
* no callbacks are removed while we're walking and dispatching callbacks.
diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index c602797..810056d 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -281,6 +281,13 @@ struct { \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
+#define QSIMPLEQ_INSERT_TAIL_RCU(head, elm, field) do { \
+ (elm)->field.sqe_next = NULL; \
+ *(head)->sqh_last = (elm); \
+ smp_wmb(); \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (/*CONSTCOND*/0)
+
#define QSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
next prev parent reply other threads:[~2015-02-18 11:57 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-18 11:55 [Qemu-devel] [RFC PATCH v9 00/23] Deterministic replay core Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 01/23] i386: partial revert of interrupt poll fix Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 02/23] replay: global variables and function stubs Pavel Dovgalyuk
2015-02-18 11:55 ` [Qemu-devel] [RFC PATCH v9 03/23] sysemu: system functions for replay Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 04/23] replay: internal functions for replay log Pavel Dovgalyuk
2015-02-18 12:43 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 05/23] replay: introduce mutex to protect the " Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 06/23] replay: introduce icount event Pavel Dovgalyuk
2015-02-18 13:49 ` Paolo Bonzini
2015-02-18 14:14 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 07/23] cpu-exec: allow temporary disabling icount Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 08/23] cpu: replay instructions sequence Pavel Dovgalyuk
2015-02-18 12:50 ` Paolo Bonzini
2015-02-18 13:48 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 09/23] replay: interrupts and exceptions Pavel Dovgalyuk
2015-02-18 13:54 ` Paolo Bonzini
2015-02-18 14:14 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 10/23] replay: asynchronous events infrastructure Pavel Dovgalyuk
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 11/23] replay: recording and replaying clock ticks Pavel Dovgalyuk
2015-02-18 14:13 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 12/23] timer: replace time() with QEMU_CLOCK_HOST Pavel Dovgalyuk
2015-02-18 13:04 ` Paolo Bonzini
2015-02-18 11:56 ` [Qemu-devel] [RFC PATCH v9 13/23] replay: shutdown event Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 14/23] replay: checkpoints Pavel Dovgalyuk
2015-02-18 14:14 ` Paolo Bonzini
2015-02-18 11:57 ` Pavel Dovgalyuk [this message]
2015-02-18 13:06 ` [Qemu-devel] [RFC PATCH v9 15/23] aio: replace stack of bottom halves with queue Paolo Bonzini
2015-02-18 13:10 ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 16/23] replay: bottom halves Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 17/23] replay: replay aio requests Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 18/23] replay: thread pool Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 19/23] typedef: add typedef for QemuOpts Pavel Dovgalyuk
2015-02-18 13:11 ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 20/23] replay: initialization and deinitialization Pavel Dovgalyuk
2015-02-18 13:14 ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 21/23] replay: replay blockers for devices Pavel Dovgalyuk
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 22/23] replay: command line options Pavel Dovgalyuk
2015-02-18 13:18 ` Paolo Bonzini
2015-02-20 8:02 ` Pavel Dovgaluk
[not found] ` <23594.561199616$1424419399@news.gmane.org>
2015-02-20 10:28 ` Paolo Bonzini
2015-02-18 11:57 ` [Qemu-devel] [RFC PATCH v9 23/23] replay: recording of the user input Pavel Dovgalyuk
2015-02-18 14:19 ` [Qemu-devel] [RFC PATCH v9 00/23] Deterministic replay core Paolo Bonzini
2015-02-27 9:23 ` Pavel Dovgaluk
2015-02-27 13:07 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150218115710.4176.28907.stgit@PASHA-ISP \
--to=pavel.dovgaluk@ispras.ru \
--cc=afaerber@suse.de \
--cc=alex.bennee@linaro.org \
--cc=batuzovk@ispras.ru \
--cc=fred.konrad@greensocs.com \
--cc=maria.klimushenkova@ispras.ru \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=real@ispras.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).