All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapper
Date: Tue, 03 Apr 2012 13:33:28 +0200	[thread overview]
Message-ID: <4F7AE008.1040008@redhat.com> (raw)
In-Reply-To: <1333442297-18932-10-git-send-email-laijs@cn.fujitsu.com>

Il 03/04/2012 10:38, Lai Jiangshan ha scritto:
> Wrapper for qemu_coroutine_create()+qemu_coroutine_enter()
> 
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
>  block.c             |   28 +++++++---------------------
>  hw/9pfs/virtio-9p.c |    4 +---
>  nbd.c               |    2 +-
>  qemu-coroutine.h    |   12 ++++++++++++
>  qemu-io.c           |    4 +---
>  5 files changed, 22 insertions(+), 28 deletions(-)
> 
> diff --git a/block.c b/block.c
> index b88ee90..adf2010 100644
> --- a/block.c
> +++ b/block.c
> @@ -1451,7 +1451,6 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
>          .iov_base = (void *)buf,
>          .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
>      };
> -    Coroutine *co;
>      RwCo rwco = {
>          .bs = bs,
>          .sector_num = sector_num,
> @@ -1467,8 +1466,7 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
>          /* Fast-path if already in coroutine context */
>          bdrv_rw_co_entry(&rwco);
>      } else {
> -        co = qemu_coroutine_create(bdrv_rw_co_entry);
> -        qemu_coroutine_enter(co, &rwco);
> +        qemu_coroutine_run(bdrv_rw_co_entry, &rwco);
>          while (rwco.ret == NOT_DONE) {
>              qemu_aio_wait();
>          }
> @@ -2414,7 +2412,6 @@ static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque)
>  int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
>                        int *pnum)
>  {
> -    Coroutine *co;
>      BdrvCoIsAllocatedData data = {
>          .bs = bs,
>          .sector_num = sector_num,
> @@ -2423,8 +2420,7 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
>          .done = false,
>      };
>  
> -    co = qemu_coroutine_create(bdrv_is_allocated_co_entry);
> -    qemu_coroutine_enter(co, &data);
> +    qemu_coroutine_run(bdrv_is_allocated_co_entry, &data);
>      while (!data.done) {
>          qemu_aio_wait();
>      }
> @@ -3348,7 +3344,6 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
>                                                 void *opaque,
>                                                 bool is_write)
>  {
> -    Coroutine *co;
>      BlockDriverAIOCBCoroutine *acb;
>  
>      acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
> @@ -3357,8 +3352,7 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
>      acb->req.qiov = qiov;
>      acb->is_write = is_write;
>  
> -    co = qemu_coroutine_create(bdrv_co_do_rw);
> -    qemu_coroutine_enter(co, acb);
> +    qemu_coroutine_run(bdrv_co_do_rw, acb);
>  
>      return &acb->common;
>  }
> @@ -3378,12 +3372,10 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
>  {
>      trace_bdrv_aio_flush(bs, opaque);
>  
> -    Coroutine *co;
>      BlockDriverAIOCBCoroutine *acb;
>  
>      acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
> -    co = qemu_coroutine_create(bdrv_aio_flush_co_entry);
> -    qemu_coroutine_enter(co, acb);
> +    qemu_coroutine_run(bdrv_aio_flush_co_entry, acb);
>  
>      return &acb->common;
>  }
> @@ -3402,7 +3394,6 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
>          int64_t sector_num, int nb_sectors,
>          BlockDriverCompletionFunc *cb, void *opaque)
>  {
> -    Coroutine *co;
>      BlockDriverAIOCBCoroutine *acb;
>  
>      trace_bdrv_aio_discard(bs, sector_num, nb_sectors, opaque);
> @@ -3410,8 +3401,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
>      acb = qemu_aio_get(&bdrv_em_co_aio_pool, bs, cb, opaque);
>      acb->req.sector = sector_num;
>      acb->req.nb_sectors = nb_sectors;
> -    co = qemu_coroutine_create(bdrv_aio_discard_co_entry);
> -    qemu_coroutine_enter(co, acb);
> +    qemu_coroutine_run(bdrv_aio_discard_co_entry, acb);
>  
>      return &acb->common;
>  }
> @@ -3586,7 +3576,6 @@ void bdrv_invalidate_cache_all(void)
>  
>  int bdrv_flush(BlockDriverState *bs)
>  {
> -    Coroutine *co;
>      RwCo rwco = {
>          .bs = bs,
>          .ret = NOT_DONE,
> @@ -3596,8 +3585,7 @@ int bdrv_flush(BlockDriverState *bs)
>          /* Fast-path if already in coroutine context */
>          bdrv_flush_co_entry(&rwco);
>      } else {
> -        co = qemu_coroutine_create(bdrv_flush_co_entry);
> -        qemu_coroutine_enter(co, &rwco);
> +        qemu_coroutine_run(bdrv_flush_co_entry, &rwco);
>          while (rwco.ret == NOT_DONE) {
>              qemu_aio_wait();
>          }
> @@ -3645,7 +3633,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
>  
>  int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
>  {
> -    Coroutine *co;
>      RwCo rwco = {
>          .bs = bs,
>          .sector_num = sector_num,
> @@ -3657,8 +3644,7 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
>          /* Fast-path if already in coroutine context */
>          bdrv_discard_co_entry(&rwco);
>      } else {
> -        co = qemu_coroutine_create(bdrv_discard_co_entry);
> -        qemu_coroutine_enter(co, &rwco);
> +        qemu_coroutine_run(bdrv_discard_co_entry, &rwco);
>          while (rwco.ret == NOT_DONE) {
>              qemu_aio_wait();
>          }
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index c633fb9..e2f384e 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -3230,7 +3230,6 @@ static inline bool is_read_only_op(V9fsPDU *pdu)
>  
>  static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
>  {
> -    Coroutine *co;
>      CoroutineEntry *handler;
>  
>      if (pdu->id >= ARRAY_SIZE(pdu_co_handlers) ||
> @@ -3243,8 +3242,7 @@ static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
>      if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) {
>          handler = v9fs_fs_ro;
>      }
> -    co = qemu_coroutine_create(handler);
> -    qemu_coroutine_enter(co, pdu);
> +    qemu_coroutine_run(handler, pdu);
>  }
>  
>  void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
> diff --git a/nbd.c b/nbd.c
> index 567e94e..14ede03 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -926,7 +926,7 @@ static void nbd_read(void *opaque)
>      if (client->recv_coroutine) {
>          qemu_coroutine_enter(client->recv_coroutine, NULL);
>      } else {
> -        qemu_coroutine_enter(qemu_coroutine_create(nbd_trip), client);
> +        qemu_coroutine_run(nbd_trip, client);
>      }
>  }
>  
> diff --git a/qemu-coroutine.h b/qemu-coroutine.h
> index 82a7e5c..572013a 100644
> --- a/qemu-coroutine.h
> +++ b/qemu-coroutine.h
> @@ -74,6 +74,18 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry);
>  void qemu_coroutine_enter(Coroutine *coroutine, void *opaque);
>  
>  /**
> + * Create a new coroutine and transfer control to it
> + *
> + * Wrapper for qemu_coroutine_create()+qemu_coroutine_enter()
> + */
> +static inline void qemu_coroutine_run(CoroutineEntry *entry, void *opaque)
> +{
> +    Coroutine *co = qemu_coroutine_create(entry);
> +
> +    qemu_coroutine_enter(co, opaque);
> +}
> +
> +/**
>   * Transfer control back to a coroutine's caller
>   *
>   * This function does not return until the coroutine is re-entered using
> diff --git a/qemu-io.c b/qemu-io.c
> index 3189530..75e9ac5 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -243,7 +243,6 @@ static void coroutine_fn co_write_zeroes_entry(void *opaque)
>  
>  static int do_co_write_zeroes(int64_t offset, int count, int *total)
>  {
> -    Coroutine *co;
>      CoWriteZeroes data = {
>          .offset = offset,
>          .count  = count,
> @@ -251,8 +250,7 @@ static int do_co_write_zeroes(int64_t offset, int count, int *total)
>          .done   = false,
>      };
>  
> -    co = qemu_coroutine_create(co_write_zeroes_entry);
> -    qemu_coroutine_enter(co, &data);
> +    qemu_coroutine_run(co_write_zeroes_entry, &data);
>      while (!data.done) {
>          qemu_aio_wait();
>      }

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

  reply	other threads:[~2012-04-03 11:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-03  8:38 [Qemu-devel] [PATCH 01/10] coroutine: use qemu_coroutine_switch() directly Lai Jiangshan
2012-04-03  8:38 ` [Qemu-devel] [PATCH 02/10] coroutine: rename unlock_bh_queue to co_runnable_queue Lai Jiangshan
2012-04-03 11:30   ` Paolo Bonzini
2012-04-03  8:38 ` [Qemu-devel] [PATCH 03/10] coroutine: rename qemu_co_queue_next_bh() to qemu_co_process_runnable() Lai Jiangshan
2012-04-03 11:31   ` Paolo Bonzini
2012-04-03 11:43   ` Kevin Wolf
2012-04-03  8:38 ` [Qemu-devel] [PATCH 04/10] coroutine: init co_runnable_bh during boot Lai Jiangshan
2012-04-03 11:31   ` Paolo Bonzini
2012-04-03  8:38 ` [Qemu-devel] [PATCH 05/10] coroutine: add qemu_co_runnable_schedule() Lai Jiangshan
2012-04-03 11:31   ` Paolo Bonzini
2012-04-03  8:38 ` [Qemu-devel] [PATCH 06/10] coroutine: move runnale coroutine code to qemu-coroutine.c Lai Jiangshan
2012-04-03 11:32   ` Paolo Bonzini
2012-04-03  8:38 ` [Qemu-devel] [PATCH 07/10] coroutine: split qemu-coroutine-lock.c Lai Jiangshan
2012-04-03 11:32   ` Paolo Bonzini
2012-04-03 11:47   ` Kevin Wolf
2012-04-03  8:38 ` [Qemu-devel] [PATCH 08/10] coroutine: process the coroutines woken by child when child yield Lai Jiangshan
2012-04-05 12:43   ` Kevin Wolf
2012-04-03  8:38 ` [Qemu-devel] [PATCH 09/10] coroutine: schedule timeout coroutine instead process it directly Lai Jiangshan
2012-04-03 11:26   ` Paolo Bonzini
2012-04-03  8:38 ` [Qemu-devel] [PATCH 10/10] coroutine: add qemu_coroutine_run() wrapper Lai Jiangshan
2012-04-03 11:33   ` Paolo Bonzini [this message]
2012-04-03 11:30 ` [Qemu-devel] [PATCH 01/10] coroutine: use qemu_coroutine_switch() directly 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=4F7AE008.1040008@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.