From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNRTG-0000m3-Lh for qemu-devel@nongnu.org; Tue, 11 Mar 2014 14:32:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNRT8-0005Rg-F6 for qemu-devel@nongnu.org; Tue, 11 Mar 2014 14:32:10 -0400 Received: from cantor2.suse.de ([195.135.220.15]:51998 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNRT8-0005Ra-5l for qemu-devel@nongnu.org; Tue, 11 Mar 2014 14:32:02 -0400 Message-ID: <531F56A1.9000109@suse.de> Date: Tue, 11 Mar 2014 19:32:01 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1393842608-17795-1-git-send-email-stefanha@redhat.com> <1393842608-17795-5-git-send-email-stefanha@redhat.com> In-Reply-To: <1393842608-17795-5-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v6 4/7] iothread: add I/O thread object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , "Shergill, Gurinder" , Michael Roth , Paolo Bonzini , "Vinod, Chegu" Am 03.03.2014 11:30, schrieb Stefan Hajnoczi: > This is a stand-in for Michael Roth's QContext. I expect this to be > replaced once QContext is completed. >=20 > The IOThread object is an AioContext event loop thread. This patch add= s > the concept of multiple event loop threads, allowing users to define > them. >=20 > When SMP guests run on SMP hosts it makes sense to instantiate multiple > IOThreads. This spreads event loop processing across multiple cores. > Note that additional patches are required to actually bind a device to > an IOThread. >=20 > Signed-off-by: Stefan Hajnoczi > --- > Makefile.objs | 1 + > include/sysemu/iothread.h | 30 ++++++++++++ > iothread.c | 119 ++++++++++++++++++++++++++++++++++++++= ++++++++ > 3 files changed, 150 insertions(+) > create mode 100644 include/sysemu/iothread.h > create mode 100644 iothread.c >=20 > diff --git a/Makefile.objs b/Makefile.objs > index 4a62913..846ed66 100644 > --- a/Makefile.objs > +++ b/Makefile.objs > @@ -44,6 +44,7 @@ libcacard-y +=3D libcacard/vcardt.o > =20 > ifeq ($(CONFIG_SOFTMMU),y) > common-obj-y =3D blockdev.o blockdev-nbd.o block/ > +common-obj-y +=3D iothread.o > common-obj-y +=3D net/ > common-obj-y +=3D qdev-monitor.o device-hotplug.o > common-obj-$(CONFIG_WIN32) +=3D os-win32.o > diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h > new file mode 100644 > index 0000000..a32214a > --- /dev/null > +++ b/include/sysemu/iothread.h > @@ -0,0 +1,30 @@ > +/* > + * Event loop thread > + * > + * Copyright Red Hat Inc., 2013 > + * > + * Authors: > + * Stefan Hajnoczi > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or = later. > + * See the COPYING file in the top-level directory. > + * > + */ > + > +#ifndef IOTHREAD_H > +#define IOTHREAD_H > + > +#include "block/aio.h" > + > +#define TYPE_IOTHREAD "iothread" > + > +typedef struct IOThread IOThread; > + > +#define IOTHREAD(obj) \ > + OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) > + > +IOThread *iothread_find(const char *id); > +char *iothread_get_id(IOThread *iothread); > +AioContext *iothread_get_aio_context(IOThread *iothread); > + > +#endif /* IOTHREAD_H */ > diff --git a/iothread.c b/iothread.c > new file mode 100644 > index 0000000..231ce6c > --- /dev/null > +++ b/iothread.c > @@ -0,0 +1,119 @@ > +/* > + * Event loop thread > + * > + * Copyright Red Hat Inc., 2013 > + * > + * Authors: > + * Stefan Hajnoczi > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or = later. > + * See the COPYING file in the top-level directory. > + * > + */ > + > +#include "qom/object.h" > +#include "qom/object_interfaces.h" > +#include "qemu/module.h" > +#include "qemu/thread.h" > +#include "block/aio.h" > +#include "sysemu/iothread.h" > + > +#define IOTHREADS_PATH "/objects" > + > +typedef ObjectClass IOThreadClass; > +struct IOThread { > + Object parent; Can you rename to parent_obj in your tree please and leave a while line after? Thanks, Andreas > + QemuThread thread; > + AioContext *ctx; > + bool stopping; > +}; > + > +#define IOTHREAD_GET_CLASS(obj) \ > + OBJECT_GET_CLASS(IOThreadClass, obj, TYPE_IOTHREAD) > +#define IOTHREAD_CLASS(klass) \ > + OBJECT_CLASS_CHECK(IOThreadClass, klass, TYPE_IOTHREAD) > + > +static void *iothread_run(void *opaque) > +{ > + IOThread *iothread =3D opaque; > + > + while (!iothread->stopping) { > + aio_context_acquire(iothread->ctx); > + while (!iothread->stopping && aio_poll(iothread->ctx, true)) { > + /* Progress was made, keep going */ > + } > + aio_context_release(iothread->ctx); > + } > + return NULL; > +} > + > +static void iothread_instance_finalize(Object *obj) > +{ > + IOThread *iothread =3D IOTHREAD(obj); > + > + iothread->stopping =3D true; > + aio_notify(iothread->ctx); > + qemu_thread_join(&iothread->thread); > + aio_context_unref(iothread->ctx); > +} > + > +static void iothread_complete(UserCreatable *obj, Error **errp) > +{ > + IOThread *iothread =3D IOTHREAD(obj); > + > + iothread->stopping =3D false; > + iothread->ctx =3D aio_context_new(); > + > + /* This assumes we are called from a thread with useful CPU affini= ty for us > + * to inherit. > + */ > + qemu_thread_create(&iothread->thread, iothread_run, > + iothread, QEMU_THREAD_JOINABLE); > +} > + > +static void iothread_class_init(ObjectClass *klass, void *class_data) > +{ > + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); > + ucc->complete =3D iothread_complete; > +} > + > +static const TypeInfo iothread_info =3D { > + .name =3D TYPE_IOTHREAD, > + .parent =3D TYPE_OBJECT, > + .class_init =3D iothread_class_init, > + .instance_size =3D sizeof(IOThread), > + .instance_finalize =3D iothread_instance_finalize, > + .interfaces =3D (InterfaceInfo[]) { > + {TYPE_USER_CREATABLE}, > + {} > + }, > +}; > + > +static void iothread_register_types(void) > +{ > + type_register_static(&iothread_info); > +} > + > +type_init(iothread_register_types) > + > +IOThread *iothread_find(const char *id) > +{ > + Object *container =3D container_get(object_get_root(), IOTHREADS_P= ATH); > + Object *child; > + > + child =3D object_property_get_link(container, id, NULL); > + if (!child) { > + return NULL; > + } > + return (IOThread *)object_dynamic_cast(child, TYPE_IOTHREAD); > +} > + > +char *iothread_get_id(IOThread *iothread) > +{ > + return object_get_canonical_path_component(OBJECT(iothread)); > +} > + > +AioContext *iothread_get_aio_context(IOThread *iothread) > +{ > + return iothread->ctx; > +} >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg