From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViOKm-0008U5-12 for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:53:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ViOKe-00067d-Q7 for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:53:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViOKe-00067K-Ht for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:53:36 -0500 Message-ID: <528A0DC6.9050401@redhat.com> Date: Mon, 18 Nov 2013 14:53:26 +0200 From: Alon Levy MIME-Version: 1.0 References: <1384777531-14635-1-git-send-email-marcandre.lureau@gmail.com> <1384777531-14635-21-git-send-email-marcandre.lureau@gmail.com> In-Reply-To: <1384777531-14635-21-git-send-email-marcandre.lureau@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [Spice-devel] [PATCH 20/21] spice-core: allow an interface to be in AIO context List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, spice-devel@freedesktop.org On 11/18/2013 02:25 PM, Marc-Andr=C3=A9 Lureau wrote: > The Spice block driver must be able complete operations within a AIO > context only. >=20 > Spice is currently only running within the main loop, and doesn't allow > the block driver to complete operations, such as flush during migration. >=20 > This patch allows a Spice interface to be associated with a different > context. Currently, the interface user_data is simply used to > differentiate main loop from AIO, but could later be used to associate > an interface with a particular thread. >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > include/ui/qemu-spice.h | 2 +- > qemu-char.c | 2 +- > spice-qemu-char.c | 9 +++---- > ui/spice-core.c | 62 +++++++++++++++++++++++++++++++++++++++++= ++------ > 4 files changed, 62 insertions(+), 13 deletions(-) >=20 > diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h > index a93b4b2..d5ba702 100644 > --- a/include/ui/qemu-spice.h > +++ b/include/ui/qemu-spice.h > @@ -48,7 +48,7 @@ int qemu_spice_migrate_info(const char *hostname, int= port, int tls_port, > void do_info_spice_print(Monitor *mon, const QObject *data); > void do_info_spice(Monitor *mon, QObject **ret_data); > =20 > -CharDriverState *qemu_chr_open_spice_vmc(const char *type); > +CharDriverState *qemu_chr_open_spice_vmc(const char *type, bool aio); > #if SPICE_SERVER_VERSION >=3D 0x000c02 > CharDriverState *qemu_chr_open_spice_port(const char *name); > void qemu_spice_register_ports(void); > diff --git a/qemu-char.c b/qemu-char.c > index 418dc69..bfac7bf 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -3747,7 +3747,7 @@ ChardevReturn *qmp_chardev_add(const char *id, Ch= ardevBackend *backend, > #endif > #ifdef CONFIG_SPICE > case CHARDEV_BACKEND_KIND_SPICEVMC: > - chr =3D qemu_chr_open_spice_vmc(backend->spicevmc->type); > + chr =3D qemu_chr_open_spice_vmc(backend->spicevmc->type, false= ); > break; > case CHARDEV_BACKEND_KIND_SPICEPORT: > chr =3D qemu_chr_open_spice_port(backend->spiceport->fqdn); > diff --git a/spice-qemu-char.c b/spice-qemu-char.c > index 16439c5..421f7de 100644 > --- a/spice-qemu-char.c > +++ b/spice-qemu-char.c > @@ -248,7 +248,7 @@ static void print_allowed_subtypes(void) > fprintf(stderr, "\n"); > } > =20 > -static CharDriverState *chr_open(const char *subtype) > +static CharDriverState *chr_open(const char *subtype, bool aio) > { > CharDriverState *chr; > SpiceCharDriver *s; > @@ -257,6 +257,7 @@ static CharDriverState *chr_open(const char *subtyp= e) > s =3D g_malloc0(sizeof(SpiceCharDriver)); > s->chr =3D chr; > s->active =3D false; > + s->sin.base.user_data =3D (void*)aio; > s->sin.subtype =3D g_strdup(subtype); > chr->opaque =3D s; > chr->chr_write =3D spice_chr_write; > @@ -271,7 +272,7 @@ static CharDriverState *chr_open(const char *subtyp= e) > return chr; > } > =20 > -CharDriverState *qemu_chr_open_spice_vmc(const char *type) > +CharDriverState *qemu_chr_open_spice_vmc(const char *type, bool aio) > { > const char **psubtype =3D spice_server_char_device_recognized_subt= ypes(); > =20 > @@ -291,7 +292,7 @@ CharDriverState *qemu_chr_open_spice_vmc(const char= *type) > return NULL; > } > =20 > - return chr_open(type); > + return chr_open(type, aio); > } > =20 > #if SPICE_SERVER_VERSION >=3D 0x000c02 > @@ -305,7 +306,7 @@ CharDriverState *qemu_chr_open_spice_port(const cha= r *name) > return NULL; > } > =20 > - chr =3D chr_open("port"); > + chr =3D chr_open("port", false); > s =3D chr->opaque; > s->sin.portname =3D g_strdup(name); > =20 > diff --git a/ui/spice-core.c b/ui/spice-core.c > index e4d533d..0f69630 100644 > --- a/ui/spice-core.c > +++ b/ui/spice-core.c > @@ -53,34 +53,64 @@ static QemuThread me; > =20 > struct SpiceTimer { > QEMUTimer *timer; > + QEMUBH *bh; > QTAILQ_ENTRY(SpiceTimer) next; > }; > static QTAILQ_HEAD(, SpiceTimer) timers =3D QTAILQ_HEAD_INITIALIZER(ti= mers); > =20 > +#if SPICE_INTERFACE_CORE_MAJOR >=3D 2 > +static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque, SpiceB= aseInstance *sin) > +#else > static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque) > +#endif > { > SpiceTimer *timer; > =20 > timer =3D g_malloc0(sizeof(*timer)); > - timer->timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, func, opaque); > + > +#if SPICE_INTERFACE_CORE_MAJOR >=3D 2 > + bool aio =3D sin ? !!sin->user_data : false; Shouldn't there be a cast there: (bool)sin->user_data ? > + if (aio) { > + fprintf(stderr, "AIO doesn't have timers yet, using BH\n"); > + timer->bh =3D qemu_bh_new(func, opaque); > + } else > +#endif > + { > + timer->timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, func, opaqu= e); > + } > + > QTAILQ_INSERT_TAIL(&timers, timer, next); > + > return timer; > } > =20 > static void timer_start(SpiceTimer *timer, uint32_t ms) > { > - timer_mod(timer->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + m= s); > + if (timer->bh) { > + qemu_bh_schedule_idle(timer->bh); /* at least every 10ms, see = async.c */ > + } else { > + timer_mod(timer->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)= + ms); > + } > } > =20 > static void timer_cancel(SpiceTimer *timer) > { > - timer_del(timer->timer); > + if (timer->bh) { > + qemu_bh_cancel(timer->bh); > + } else { > + timer_del(timer->timer); > + } > } > =20 > static void timer_remove(SpiceTimer *timer) > { > - timer_del(timer->timer); > - timer_free(timer->timer); > + if (timer->bh) { > + qemu_bh_delete(timer->bh); > + } else { > + timer_del(timer->timer); > + timer_free(timer->timer); > + } > + > QTAILQ_REMOVE(&timers, timer, next); > g_free(timer); > } > @@ -89,6 +119,7 @@ struct SpiceWatch { > int fd; > int event_mask; > SpiceWatchFunc func; > + bool aio; > void *opaque; > QTAILQ_ENTRY(SpiceWatch) next; > }; > @@ -118,10 +149,19 @@ static void watch_update_mask(SpiceWatch *watch, = int event_mask) > if (watch->event_mask & SPICE_WATCH_EVENT_WRITE) { > on_write =3D watch_write; > } > - qemu_set_fd_handler(watch->fd, on_read, on_write, watch); > + > + if (watch->aio) { > + qemu_aio_set_fd_handler(watch->fd, on_read, on_write, watch); > + } else { > + qemu_set_fd_handler(watch->fd, on_read, on_write, watch); > + } > } > =20 > +#if SPICE_INTERFACE_CORE_MAJOR >=3D 2 > +static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc fu= nc, void *opaque, SpiceBaseInstance *sin) > +#else > static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc fu= nc, void *opaque) > +#endif > { > SpiceWatch *watch; > =20 > @@ -129,6 +169,10 @@ static SpiceWatch *watch_add(int fd, int event_mas= k, SpiceWatchFunc func, void * > watch->fd =3D fd; > watch->func =3D func; > watch->opaque =3D opaque; > +#if SPICE_INTERFACE_CORE_MAJOR >=3D 2 > + watch->aio =3D sin ? !!sin->user_data : false; > +#endif > + > QTAILQ_INSERT_TAIL(&watches, watch, next); > =20 > watch_update_mask(watch, event_mask); > @@ -137,7 +181,11 @@ static SpiceWatch *watch_add(int fd, int event_mas= k, SpiceWatchFunc func, void * > =20 > static void watch_remove(SpiceWatch *watch) > { > - qemu_set_fd_handler(watch->fd, NULL, NULL, NULL); > + if (watch->aio) { > + qemu_aio_set_fd_handler(watch->fd, NULL, NULL, NULL); > + } else { > + qemu_set_fd_handler(watch->fd, NULL, NULL, NULL); > + } > QTAILQ_REMOVE(&watches, watch, next); > g_free(watch); > } >=20