From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=57740 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdM4T-0007cM-7q for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdM4R-0001g5-SV for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:29 -0500 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:48837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdM4R-0001fH-BQ for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:27 -0500 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp08.au.ibm.com (8.14.4/8.13.1) with ESMTP id p0DCEcLJ004681 for ; Thu, 13 Jan 2011 23:14:38 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0DCEPOZ1519764 for ; Thu, 13 Jan 2011 23:14:25 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0DCEPuV003448 for ; Thu, 13 Jan 2011 23:14:25 +1100 From: Arun R Bharadwaj Date: Thu, 13 Jan 2011 17:44:23 +0530 Message-ID: <20110113121423.4487.40990.stgit@localhost6.localdomain6> In-Reply-To: <20110113120837.4487.95784.stgit@localhost6.localdomain6> References: <20110113120837.4487.95784.stgit@localhost6.localdomain6> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 02/12] Introduce work concept in posix-aio-compat.c List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@linux.vnet.ibm.com, jvrao@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com This patch introduces work concept by introducing the ThreadletWork structure. Signed-off-by: Arun R Bharadwaj --- posix-aio-compat.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-) diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 82862ec..ddf42f5 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -33,6 +33,10 @@ static QemuMutex aiocb_mutex; static QemuCond aiocb_completion; +typedef struct ThreadletWork +{ + QTAILQ_ENTRY(ThreadletWork) node; +} ThreadletWork; struct qemu_paiocb { BlockDriverAIOCB common; @@ -47,13 +51,13 @@ struct qemu_paiocb { int ev_signo; off_t aio_offset; - QTAILQ_ENTRY(qemu_paiocb) node; int aio_type; ssize_t ret; int active; struct qemu_paiocb *next; int async_context_id; + ThreadletWork work; }; typedef struct PosixAioState { @@ -69,7 +73,7 @@ static pthread_attr_t attr; static int max_threads = 64; static int cur_threads = 0; static int idle_threads = 0; -static QTAILQ_HEAD(, qemu_paiocb) request_list; +static QTAILQ_HEAD(, ThreadletWork) request_list; #ifdef CONFIG_PREADV static int preadv_present = 1; @@ -307,6 +311,7 @@ static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb) static void *aio_thread(void *unused) { pid_t pid; + ThreadletWork *work; pid = getpid(); @@ -330,8 +335,11 @@ static void *aio_thread(void *unused) if (QTAILQ_EMPTY(&request_list)) break; - aiocb = QTAILQ_FIRST(&request_list); - QTAILQ_REMOVE(&request_list, aiocb, node); + work = QTAILQ_FIRST(&request_list); + QTAILQ_REMOVE(&request_list, work, node); + + aiocb = container_of(work, struct qemu_paiocb, work); + aiocb->active = 1; idle_threads--; mutex_unlock(&lock); @@ -398,7 +406,7 @@ static void qemu_paio_submit(struct qemu_paiocb *aiocb) mutex_lock(&lock); if (idle_threads == 0 && cur_threads < max_threads) spawn_thread(); - QTAILQ_INSERT_TAIL(&request_list, aiocb, node); + QTAILQ_INSERT_TAIL(&request_list, &aiocb->work, node); mutex_unlock(&lock); cond_signal(&cond); } @@ -548,7 +556,7 @@ static void paio_cancel(BlockDriverAIOCB *blockacb) qemu_mutex_lock(&aiocb_mutex); if (!acb->active) { - QTAILQ_REMOVE(&request_list, acb, node); + QTAILQ_REMOVE(&request_list, &acb->work, node); acb->ret = -ECANCELED; } else if (acb->ret == -EINPROGRESS) { active = 1;