[PATCH v6 0/3] util/thread-pool: Expose minimun and maximum size

Nicolas Saenz Julienne posted 3 patches 2 years ago
event-loop-base.c                | 140 +++++++++++++++++++++++++++++++
include/block/aio.h              |  10 +++
include/block/thread-pool.h      |   3 +
include/qemu/main-loop.h         |  10 +++
include/sysemu/event-loop-base.h |  41 +++++++++
include/sysemu/iothread.h        |   6 +-
iothread.c                       |  68 +++++----------
meson.build                      |  26 +++---
qapi/qom.json                    |  43 ++++++++--
util/aio-posix.c                 |   1 +
util/async.c                     |  20 +++++
util/main-loop.c                 |  65 ++++++++++++++
util/thread-pool.c               |  55 +++++++++++-
13 files changed, 419 insertions(+), 69 deletions(-)
create mode 100644 event-loop-base.c
create mode 100644 include/sysemu/event-loop-base.h
[PATCH v6 0/3] util/thread-pool: Expose minimun and maximum size
Posted by Nicolas Saenz Julienne 2 years ago
As discussed on the previous RFC[1] the thread-pool's dynamic thread
management doesn't play well with real-time and latency sensitive
systems. This series introduces a set of controls that'll permit
achieving more deterministic behaviours, for example by fixing the
pool's size.

We first introduce a new common interface to event loop configuration by
moving iothread's already available properties into an abstract class
called 'EventLooopBackend' and have both 'IOThread' and the newly
created 'MainLoop' inherit the properties from that class.

With this new configuration interface in place it's relatively simple to
introduce new options to fix the even loop's thread pool sizes. The
resulting QAPI looks like this:

    -object main-loop,id=main-loop,thread-pool-min=1,thread-pool-max=1

Note that all patches are bisect friendly and pass all the tests.

[1] https://patchwork.ozlabs.org/project/qemu-devel/patch/20220202175234.656711-1-nsaenzju@redhat.com/
---

Changes since v5:
 - Add 'Since' versioning to MainLoopProperties

Changes since v4:
 - Address Markus' comments WRT qom.json

Changes since v3:
 - Avoid duplication in qom.json by creating EventLoopBaseProperties.
 - Fix failures on first compilation due to race between
   event-loop-base.o and qapi header generation.

Changes since v2:
 - Get rid of wrong locking/waiting
 - Fix qapi versioning
 - Better commit messages

Changes since v1:
 - Address all Stefan's comments
 - Introduce new fix

Nicolas Saenz Julienne (3):
  Introduce event-loop-base abstract class
  util/main-loop: Introduce the main loop into QOM
  util/event-loop-base: Introduce options to set the thread pool size

 event-loop-base.c                | 140 +++++++++++++++++++++++++++++++
 include/block/aio.h              |  10 +++
 include/block/thread-pool.h      |   3 +
 include/qemu/main-loop.h         |  10 +++
 include/sysemu/event-loop-base.h |  41 +++++++++
 include/sysemu/iothread.h        |   6 +-
 iothread.c                       |  68 +++++----------
 meson.build                      |  26 +++---
 qapi/qom.json                    |  43 ++++++++--
 util/aio-posix.c                 |   1 +
 util/async.c                     |  20 +++++
 util/main-loop.c                 |  65 ++++++++++++++
 util/thread-pool.c               |  55 +++++++++++-
 13 files changed, 419 insertions(+), 69 deletions(-)
 create mode 100644 event-loop-base.c
 create mode 100644 include/sysemu/event-loop-base.h

-- 
2.35.1
Re: [PATCH v6 0/3] util/thread-pool: Expose minimun and maximum size
Posted by Stefan Hajnoczi 2 years ago
On Mon, Apr 25, 2022 at 09:57:20AM +0200, Nicolas Saenz Julienne wrote:
> As discussed on the previous RFC[1] the thread-pool's dynamic thread
> management doesn't play well with real-time and latency sensitive
> systems. This series introduces a set of controls that'll permit
> achieving more deterministic behaviours, for example by fixing the
> pool's size.
> 
> We first introduce a new common interface to event loop configuration by
> moving iothread's already available properties into an abstract class
> called 'EventLooopBackend' and have both 'IOThread' and the newly
> created 'MainLoop' inherit the properties from that class.
> 
> With this new configuration interface in place it's relatively simple to
> introduce new options to fix the even loop's thread pool sizes. The
> resulting QAPI looks like this:
> 
>     -object main-loop,id=main-loop,thread-pool-min=1,thread-pool-max=1
> 
> Note that all patches are bisect friendly and pass all the tests.
> 
> [1] https://patchwork.ozlabs.org/project/qemu-devel/patch/20220202175234.656711-1-nsaenzju@redhat.com/
> ---
> 
> Changes since v5:
>  - Add 'Since' versioning to MainLoopProperties
> 
> Changes since v4:
>  - Address Markus' comments WRT qom.json
> 
> Changes since v3:
>  - Avoid duplication in qom.json by creating EventLoopBaseProperties.
>  - Fix failures on first compilation due to race between
>    event-loop-base.o and qapi header generation.
> 
> Changes since v2:
>  - Get rid of wrong locking/waiting
>  - Fix qapi versioning
>  - Better commit messages
> 
> Changes since v1:
>  - Address all Stefan's comments
>  - Introduce new fix
> 
> Nicolas Saenz Julienne (3):
>   Introduce event-loop-base abstract class
>   util/main-loop: Introduce the main loop into QOM
>   util/event-loop-base: Introduce options to set the thread pool size
> 
>  event-loop-base.c                | 140 +++++++++++++++++++++++++++++++
>  include/block/aio.h              |  10 +++
>  include/block/thread-pool.h      |   3 +
>  include/qemu/main-loop.h         |  10 +++
>  include/sysemu/event-loop-base.h |  41 +++++++++
>  include/sysemu/iothread.h        |   6 +-
>  iothread.c                       |  68 +++++----------
>  meson.build                      |  26 +++---
>  qapi/qom.json                    |  43 ++++++++--
>  util/aio-posix.c                 |   1 +
>  util/async.c                     |  20 +++++
>  util/main-loop.c                 |  65 ++++++++++++++
>  util/thread-pool.c               |  55 +++++++++++-
>  13 files changed, 419 insertions(+), 69 deletions(-)
>  create mode 100644 event-loop-base.c
>  create mode 100644 include/sysemu/event-loop-base.h
> 
> -- 
> 2.35.1
> 

Thanks, applied to my block-next tree! If there are more comments I can
drop it again.

https://gitlab.com/stefanha/qemu/commits/block-next

Stefan