Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LkjPw-0004Cl-PP for qemu-devel@nongnu.org; Fri, 20 Mar 2009 14:26:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LkjPu-0004CZ-8C for qemu-devel@nongnu.org; Fri, 20 Mar 2009 14:26:03 -0400 Received: from [199.232.76.173] (port=49231 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkjPu-0004CW-11 for qemu-devel@nongnu.org; Fri, 20 Mar 2009 14:26:02 -0400 Received: from savannah.gnu.org ([199.232.41.3]:41820 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LkjPt-0003Pb-LI for qemu-devel@nongnu.org; Fri, 20 Mar 2009 14:26:01 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LkjPs-0000p0-V1 for qemu-devel@nongnu.org; Fri, 20 Mar 2009 18:26:01 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LkjPs-0000os-EB for qemu-devel@nongnu.org; Fri, 20 Mar 2009 18:26:00 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Fri, 20 Mar 2009 18:26:00 +0000 Subject: [Qemu-devel] [6870] Refactor aio callback allocation to use an aiocb pool (Avi Kivity) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6870 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6870 Author: aliguori Date: 2009-03-20 18:25:59 +0000 (Fri, 20 Mar 2009) Log Message: ----------- Refactor aio callback allocation to use an aiocb pool (Avi Kivity) Move the AIOCB allocation code to use a dedicate structure, AIOPool. AIOCB specific information, such as the AIOCB size and cancellation routine, is moved into the pool. At present, there is exactly one pool per block format driver, maintaining the status quo. Signed-off-by: Avi Kivity Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block.c trunk/block_int.h Modified: trunk/block.c =================================================================== --- trunk/block.c 2009-03-20 16:22:31 UTC (rev 6869) +++ trunk/block.c 2009-03-20 18:25:59 UTC (rev 6870) @@ -147,6 +147,7 @@ bdrv->bdrv_read = bdrv_read_em; bdrv->bdrv_write = bdrv_write_em; } + aio_pool_init(&bdrv->aio_pool, bdrv->aiocb_size, bdrv->bdrv_aio_cancel); bdrv->next = first_drv; first_drv = bdrv; } @@ -1371,14 +1372,12 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) { - BlockDriver *drv = acb->bs->drv; - if (acb->cb == bdrv_aio_rw_vector_cb) { VectorTranslationState *s = acb->opaque; acb = s->aiocb; } - drv->bdrv_aio_cancel(acb); + acb->pool->cancel(acb); } @@ -1496,18 +1495,25 @@ bdrv_register(&bdrv_nbd); } -void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, - void *opaque) +void aio_pool_init(AIOPool *pool, int aiocb_size, + void (*cancel)(BlockDriverAIOCB *acb)) { - BlockDriver *drv; + pool->aiocb_size = aiocb_size; + pool->cancel = cancel; + pool->free_aiocb = NULL; +} + +void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque) +{ BlockDriverAIOCB *acb; - drv = bs->drv; - if (drv->free_aiocb) { - acb = drv->free_aiocb; - drv->free_aiocb = acb->next; + if (pool->free_aiocb) { + acb = pool->free_aiocb; + pool->free_aiocb = acb->next; } else { - acb = qemu_mallocz(drv->aiocb_size); + acb = qemu_mallocz(pool->aiocb_size); + acb->pool = pool; } acb->bs = bs; acb->cb = cb; @@ -1515,12 +1521,18 @@ return acb; } +void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, + void *opaque) +{ + return qemu_aio_get_pool(&bs->drv->aio_pool, bs, cb, opaque); +} + void qemu_aio_release(void *p) { - BlockDriverAIOCB *acb = p; - BlockDriver *drv = acb->bs->drv; - acb->next = drv->free_aiocb; - drv->free_aiocb = acb; + BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p; + AIOPool *pool = acb->pool; + acb->next = pool->free_aiocb; + pool->free_aiocb = acb; } /**************************************************************/ Modified: trunk/block_int.h =================================================================== --- trunk/block_int.h 2009-03-20 16:22:31 UTC (rev 6869) +++ trunk/block_int.h 2009-03-20 18:25:59 UTC (rev 6870) @@ -30,6 +30,12 @@ #define BLOCK_FLAG_COMPRESS 2 #define BLOCK_FLAG_COMPAT6 4 +typedef struct AIOPool { + void (*cancel)(BlockDriverAIOCB *acb); + int aiocb_size; + BlockDriverAIOCB *free_aiocb; +} AIOPool; + struct BlockDriver { const char *format_name; int instance_size; @@ -91,7 +97,7 @@ BlockDriverCompletionFunc *cb, void *opaque); - BlockDriverAIOCB *free_aiocb; + AIOPool aio_pool; struct BlockDriver *next; }; @@ -141,6 +147,7 @@ }; struct BlockDriverAIOCB { + AIOPool *pool; BlockDriverState *bs; BlockDriverCompletionFunc *cb; void *opaque; @@ -149,8 +156,13 @@ void get_tmp_filename(char *filename, int size); +void aio_pool_init(AIOPool *pool, int aiocb_size, + void (*cancel)(BlockDriverAIOCB *acb)); + void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); +void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque); void qemu_aio_release(void *p); extern BlockDriverState *bdrv_first;