[PATCH v2 0/6] Implement icount=auto using TCG Plugins

Pierrick Bouvier posted 6 patches 5 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240530174939.749163-1-pierrick.bouvier@linaro.org
Maintainers: Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Richard Henderson <richard.henderson@linaro.org>
There is a newer version of this series
include/qemu/qemu-plugin.h                    |  23 ++
include/qemu/timer.h                          |  15 ++
include/sysemu/accel-ops.h                    |  18 +-
include/sysemu/cpu-timers.h                   |   3 +-
include/sysemu/qtest.h                        |   2 -
accel/qtest/qtest.c                           |  13 +
contrib/plugins/ips.c                         | 239 ++++++++++++++++++
plugins/api.c                                 |  31 +++
...t-virtual-clock.c => cpus-virtual-clock.c} |   5 +
system/cpus.c                                 |  11 +
system/qtest.c                                |  37 +--
util/qemu-timer.c                             |  26 ++
contrib/plugins/Makefile                      |   1 +
plugins/qemu-plugins.symbols                  |   2 +
stubs/meson.build                             |   2 +-
15 files changed, 389 insertions(+), 39 deletions(-)
create mode 100644 contrib/plugins/ips.c
rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%)
[PATCH v2 0/6] Implement icount=auto using TCG Plugins
Posted by Pierrick Bouvier 5 months, 4 weeks ago
The goal here is to be able to scale temporally execution of qemu-user/system,
using a given number of instructions per second.

We define a virtual clock, that can be late or in advance compared to real time.
When we are in advance, we slow execution (by sleeping) until catching real
time.

Finally, we should be able to cleanup icount=auto mode completely, and keep
icount usage for determistic purposes only.

It is built upon new TCG Plugins inline ops (store + conditional callbacks), now
merged on master.

Example in user-mode:

- Retrieve number of instructions to execute /bin/true
$ ./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true
cpu 0 insns: 120546
total insns: 120546
- Slow execution to match 5 seconds
$ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips,ips=$((120546/5)) /bin/true
real    0m4.985s

v2
--

- Added missing personal Signed-off-by for commits from Alex
- Fix bad rebase in stubs/meson.build
- move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c
- A race condition was identified for plugins init/idle/resume, but is not
  related to this series, and will be fixed in another one:
  https://lore.kernel.org/qemu-devel/20240529152219.825680-1-alex.bennee@linaro.org/

Alex Bennée (4):
  sysemu: add set_virtual_time to accel ops
  qtest: use cpu interface in qtest_clock_warp
  sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time
  plugins: add time control API

Pierrick Bouvier (2):
  qtest: move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c
  contrib/plugins: add ips plugin example for cost modeling

 include/qemu/qemu-plugin.h                    |  23 ++
 include/qemu/timer.h                          |  15 ++
 include/sysemu/accel-ops.h                    |  18 +-
 include/sysemu/cpu-timers.h                   |   3 +-
 include/sysemu/qtest.h                        |   2 -
 accel/qtest/qtest.c                           |  13 +
 contrib/plugins/ips.c                         | 239 ++++++++++++++++++
 plugins/api.c                                 |  31 +++
 ...t-virtual-clock.c => cpus-virtual-clock.c} |   5 +
 system/cpus.c                                 |  11 +
 system/qtest.c                                |  37 +--
 util/qemu-timer.c                             |  26 ++
 contrib/plugins/Makefile                      |   1 +
 plugins/qemu-plugins.symbols                  |   2 +
 stubs/meson.build                             |   2 +-
 15 files changed, 389 insertions(+), 39 deletions(-)
 create mode 100644 contrib/plugins/ips.c
 rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%)

-- 
2.39.2


Re: [PATCH v2 0/6] Implement icount=auto using TCG Plugins
Posted by Pierrick Bouvier 5 months, 4 weeks ago
A v3 was just sent, with a fix to the algorithm used.

On 5/30/24 10:49, Pierrick Bouvier wrote:
> The goal here is to be able to scale temporally execution of qemu-user/system,
> using a given number of instructions per second.
> 
> We define a virtual clock, that can be late or in advance compared to real time.
> When we are in advance, we slow execution (by sleeping) until catching real
> time.
> 
> Finally, we should be able to cleanup icount=auto mode completely, and keep
> icount usage for determistic purposes only.
> 
> It is built upon new TCG Plugins inline ops (store + conditional callbacks), now
> merged on master.
> 
> Example in user-mode:
> 
> - Retrieve number of instructions to execute /bin/true
> $ ./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true
> cpu 0 insns: 120546
> total insns: 120546
> - Slow execution to match 5 seconds
> $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips,ips=$((120546/5)) /bin/true
> real    0m4.985s
> 
> v2
> --
> 
> - Added missing personal Signed-off-by for commits from Alex
> - Fix bad rebase in stubs/meson.build
> - move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c
> - A race condition was identified for plugins init/idle/resume, but is not
>    related to this series, and will be fixed in another one:
>    https://lore.kernel.org/qemu-devel/20240529152219.825680-1-alex.bennee@linaro.org/
> 
> Alex Bennée (4):
>    sysemu: add set_virtual_time to accel ops
>    qtest: use cpu interface in qtest_clock_warp
>    sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time
>    plugins: add time control API
> 
> Pierrick Bouvier (2):
>    qtest: move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c
>    contrib/plugins: add ips plugin example for cost modeling
> 
>   include/qemu/qemu-plugin.h                    |  23 ++
>   include/qemu/timer.h                          |  15 ++
>   include/sysemu/accel-ops.h                    |  18 +-
>   include/sysemu/cpu-timers.h                   |   3 +-
>   include/sysemu/qtest.h                        |   2 -
>   accel/qtest/qtest.c                           |  13 +
>   contrib/plugins/ips.c                         | 239 ++++++++++++++++++
>   plugins/api.c                                 |  31 +++
>   ...t-virtual-clock.c => cpus-virtual-clock.c} |   5 +
>   system/cpus.c                                 |  11 +
>   system/qtest.c                                |  37 +--
>   util/qemu-timer.c                             |  26 ++
>   contrib/plugins/Makefile                      |   1 +
>   plugins/qemu-plugins.symbols                  |   2 +
>   stubs/meson.build                             |   2 +-
>   15 files changed, 389 insertions(+), 39 deletions(-)
>   create mode 100644 contrib/plugins/ips.c
>   rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%)
>