From: Arun R Bharadwaj <arun@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH 2/6] Move paio_cancel() to new infrastructure.
Date: Thu, 18 Nov 2010 23:36:55 +0530 [thread overview]
Message-ID: <20101118180655.4434.23045.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20101118180547.4434.95904.stgit@localhost6.localdomain6>
Move paio_cancel() to new infrastructure and introduce
the necessary APIs for this.
Signed-off-by: Arun R Bharadwaj <arun@linux.vnet.ibm.com>
---
posix-aio-compat.c | 92 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index 7b862b5..eb1e2db 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -27,9 +27,31 @@
#include "qemu-common.h"
#include "trace.h"
#include "block_int.h"
+#include "qemu-thread.h"
#include "block/raw-posix-aio.h"
+static QemuMutex aiocb_mutex;
+static QemuCond aiocb_completion;
+
+typedef struct ThreadletQueue
+{
+ QemuMutex lock;
+ QemuCond cond;
+ int max_threads;
+ int min_threads;
+ int cur_threads;
+ int idle_threads;
+ QTAILQ_HEAD(, ThreadletWork) request_list;
+} ThreadletQueue;
+
+typedef struct ThreadletWork
+{
+ QTAILQ_ENTRY(ThreadletWork) node;
+ void (*func)(struct ThreadletWork *work);
+} ThreadletWork;
+
+static ThreadletQueue globalqueue;
struct qemu_paiocb {
BlockDriverAIOCB common;
@@ -51,6 +73,7 @@ struct qemu_paiocb {
struct qemu_paiocb *next;
int async_context_id;
+ ThreadletWork work;
};
typedef struct PosixAioState {
@@ -58,6 +81,45 @@ typedef struct PosixAioState {
struct qemu_paiocb *first_aio;
} PosixAioState;
+/**
+ * dequeue_work_on_queue: Cancel a task queued on a Queue.
+ * @queue: The queue containing the task to be cancelled.
+ * @work: Contains the information of the task that needs to be cancelled.
+ *
+ * Returns: 0 if the task is successfully cancelled.
+ * 1 otherwise.
+ */
+
+static int dequeue_work_on_queue(ThreadletQueue *queue, ThreadletWork *work)
+{
+ ThreadletWork *ret_work;
+ int ret = 1;
+
+ qemu_mutex_lock(&queue->lock);
+ QTAILQ_FOREACH(ret_work, &(queue->request_list), node) {
+ if (ret_work == work) {
+ QTAILQ_REMOVE(&queue->request_list, ret_work, node);
+ ret = 0;
+ break;
+ }
+ }
+ qemu_mutex_unlock(&queue->lock);
+
+ return ret;
+}
+
+/**
+ * dequeue_work: Cancel a task queued on the global queue.
+ * @work: Contains the information of the task that needs to be cancelled.
+ *
+ * Returns: 0 if the task is successfully cancelled.
+ * 1 otherwise.
+ */
+
+static int dequeue_work(ThreadletWork *work)
+{
+ return dequeue_work_on_queue(&globalqueue, work);
+}
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
@@ -397,9 +459,9 @@ static ssize_t qemu_paio_return(struct qemu_paiocb *aiocb)
{
ssize_t ret;
- mutex_lock(&lock);
+ qemu_mutex_lock(&aiocb_mutex);
ret = aiocb->ret;
- mutex_unlock(&lock);
+ qemu_mutex_unlock(&aiocb_mutex);
return ret;
}
@@ -534,22 +596,13 @@ static void paio_remove(struct qemu_paiocb *acb)
static void paio_cancel(BlockDriverAIOCB *blockacb)
{
struct qemu_paiocb *acb = (struct qemu_paiocb *)blockacb;
- int active = 0;
-
- mutex_lock(&lock);
- if (!acb->active) {
- QTAILQ_REMOVE(&request_list, acb, node);
- acb->ret = -ECANCELED;
- } else if (acb->ret == -EINPROGRESS) {
- active = 1;
- }
- mutex_unlock(&lock);
-
- if (active) {
- /* fail safe: if the aio could not be canceled, we wait for
- it */
- while (qemu_paio_error(acb) == EINPROGRESS)
- ;
+ if (dequeue_work(&acb->work) != 0) {
+ /* Wait for running work item to complete */
+ qemu_mutex_lock(&aiocb_mutex);
+ while (acb->ret == -EINPROGRESS) {
+ qemu_cond_wait(&aiocb_completion, &aiocb_mutex);
+ }
+ qemu_mutex_unlock(&aiocb_mutex);
}
paio_remove(acb);
@@ -623,6 +676,9 @@ int paio_init(void)
if (posix_aio_state)
return 0;
+ qemu_mutex_init(&aiocb_mutex);
+ qemu_cond_init(&aiocb_completion);
+
s = qemu_malloc(sizeof(PosixAioState));
sigfillset(&act.sa_mask);
next prev parent reply other threads:[~2010-11-18 18:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 18:06 [Qemu-devel] [PATCH 0/6] v12: Threadlets: A generic task offloading framework Arun R Bharadwaj
2010-11-18 18:06 ` [Qemu-devel] [PATCH 1/6] Make the necessary changes in Makefile and configure file Arun R Bharadwaj
2010-11-19 9:55 ` Stefan Hajnoczi
2010-11-18 18:06 ` Arun R Bharadwaj [this message]
2010-11-19 10:07 ` [Qemu-devel] [PATCH 2/6] Move paio_cancel() to new infrastructure Stefan Hajnoczi
2010-11-30 23:20 ` Venkateswararao Jujjuri (JV)
2010-11-18 18:07 ` [Qemu-devel] [PATCH 3/6] Move qemu_paio_submit() to the " Arun R Bharadwaj
2010-11-30 23:22 ` Venkateswararao Jujjuri (JV)
2010-11-18 18:07 ` [Qemu-devel] [PATCH 4/6] Cleanup posix-aio.compat.c off all the old code Arun R Bharadwaj
2010-11-30 23:23 ` Venkateswararao Jujjuri (JV)
2010-11-18 18:07 ` [Qemu-devel] [PATCH 5/6] Move threadlets infrastructure to qemu-threadlets.c Arun R Bharadwaj
2010-11-30 23:18 ` Venkateswararao Jujjuri (JV)
2010-11-18 18:07 ` [Qemu-devel] [PATCH 6/6] Add helper functions to enable virtio-9p make use of the threadlets Arun R Bharadwaj
2010-11-19 10:17 ` Stefan Hajnoczi
2010-11-30 23:17 ` Venkateswararao Jujjuri (JV)
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=20101118180655.4434.23045.stgit@localhost6.localdomain6 \
--to=arun@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).