QEMU cpus.c refactoring part2
Subsystems (2)
v7 cover QEMU cpus.c refactoring part2
Motivation and higher level steps:
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
Current state is all reviewed, I think this is a good base to include at this point.
I had to fix one build issue in patch 1 that went undetected previously due to a meson thing (parallel build).
Further work for future patches include:
* additional improvements to naming consistency in QEMU files. (Claudio, Alex, Roman)
* tcg vcpu start refactoring, providing then multiple structs for mttg, icount, normal. (Claudio, Alex)
* possible removal of NULL check for virtual clock if the qcow2 early call is solved. (Claudio, Paolo, Berto)
PATCH v6 -> PATCH v7:
* in patch "cpu-timers, icount: new modules":
- remove redundant double initialization of spice
- remove lingering calls to icount_get
PATCH v5 -> PATCH v6:
* moved to mason build system
* patch (new): cpus: remove checks for non-NULL cpus_accel (Richard)
This has however a big caveat: in some cases the virtual clock is queried before an accelerator is set or ticks are enabled; this is currently special cased (keeping the NULL check in cpus_get_virtual_clock), but maybe this should not happen at all? (Paolo, Berto)
* in patch "cpu-timers, icount: new modules"
do not change (yet) icount_enabled() to a function. Mimic instead what is done with tcg_enabled(). (Richard)
* split the changes into two separate patches, with name-only changes extracted out into a separate patch (Richard).
Removed existing Reviewed-by because of these changes (Alex)- Alex are you ok with them?
* in patch "cpus: prepare new CpusAccel cpu accelerator interface" remove some unneeded stubs from stubs/cpu-synchronize-state.c Use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out TCG-specific code to accel/tcg" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out qtest-specific code to accel/qtest" use const for the CpusAccel interface;
use g_assert_not_reached (Richard)
* in patch "cpus: extract out kvm-specific code to accel/kvm" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hax-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out whpx-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hvf-specific code to target/i386/hvf/" use const for the CpusAccel interface. (Richard)
RFC v4 -> PATCH v5:
* in patch 2, move comment about cpus_get_elapsed_ticks from patch 3 (Philippe)
* in patch 11-14, do not create separate xxx-int.h files, instead use the xxx-cpus.h files (Philippe)
RFC v3 -> v4:
* added patch 9: cleanup unneeded includes
* added patch 10: add handle_interrupt to the interface (Roman)
* added patch 11-14: remove accelerator specific internal functions from global includes (Roman)
* in patch 2, removed leftover "if hvf_enabled" hunk
* in patch 2, convert if (!tcg_enabled) with more punctual if (hax_enabled) when eating dummy APC
----
RFC v2 -> v3:
* provided defaults for all methods.
Only create_vcpu_thread is now a mandatory field. (Paolo)
* separated new CpusAccel patch from its first user, new patch nr. 2:
"cpus: prepare new CpusAccel cpu accelerator interface"
* new CpusAccel methods: get_virtual_clock and get_elapsed_ticks. (Paolo)
In this series, get_virtual_clock has a separate implementation between TCG/icount and qtest,
while get_elapsed_ticks only returns a virtual counter for icount.
Looking for more comments in this area.
----
RFC v1 -> v2:
* split the cpus.c accelerator refactoring into 6 patches.
* other minor changes to be able to proceed step by step.
----
* Rebased on commit 255ae6e2158c743717bed76c9a2365ee4bcd326e, "replay: notify the main loop when there are no instructions"
[SPLIT into part1 and part2]
----
v6 -> v7:
* rebased changes on top of Pavel Dovgalyuk changes to dma-helpers.c "icount: make dma reads deterministic"
----
v5 -> v6:
* rebased changes on top of Emilio G. Cota changes to cpus.c "cpu: convert queued work to a QSIMPLEQ"
* keep a pointer in cpus.c instead of a copy of CpusAccel (Alex)
----
v4 -> v5: rebase on latest master
* rebased changes on top of roman series to remove one of the extra states for hvf. (Is the result now functional for HVF?)
* rebased changes on top of icount changes and fixes to icount_configure and the new shift vmstate. (Markus)
v3 -> v4:
* overall: added copyright headers to all files that were missing them (used copyright and license of the module the stuff was extracted from). For the new interface files, added SUSE LLC.
* 1/4 (move softmmu only files from root):
MAINTAINERS: moved softmmu/cpus.c to its final location (from patch 2)
* 2/4 (cpu-throttle):
MAINTAINERS (to patch 1),
copyright Fabrice Bellard and license from cpus.c
* 3/4 (cpu-timers, icount):
- MAINTAINERS: add cpu-timers.c and icount.c to Paolo
- break very long lines (patchew)
- add copyright SUSE LLC, GPLv2 to cpu-timers.h
- add copyright Fabrice Bellard and license from cpus.c to timers-state.h as it is lifted from cpus.c
- vl.c: in configure_accelerators bail out if icount_enabled() and !tcg_enabled() as qtest does not enable icount anymore.
* 4/4 (accel stuff to accel):
- add copyright SUSE LLC to files that mostly only consist of the new interface. Add whatever copyright was in the accelerator code if instead they mostly consist of accelerator code.
- change a comment to mention the result of the AccelClass experiment
- moved qtest accelerator into accel/qtest/ , make it like the others.
- rename xxx-cpus-interface to xxx-cpus (remove "interface" from names)
- rename accel_int to cpus_accel
- rename CpusAccel functions from cpu_synchronize_* to synchronize_*
--------
v2 -> v3:
* turned into a 4 patch series, adding a first patch moving softmmu code currently in top_srcdir to softmmu/
* cpu-throttle: moved to softmmu/
* cpu-timers, icount:
- moved to softmmu/
- fixed assumption of qtest_enabled() => icount_enabled() causing the failure of check-qtest-arm goal, in test-arm-mptimer.c
Fix is in hw/core/ptimer.c,
where the artificial timeout rate limit should not be applied under qtest_enabled(), in a similar way to how it is not applied for icount_enabled().
* CpuAccelInterface: no change.
--------
v1 -> v2:
* 1/3 (cpu-throttle): provide a description in the commit message
* 2/3 (cpu-timers, icount): in this v2 separate icount from cpu-timers, as icount is actually TCG-specific. Only build it under CONFIG_TCG.
To do this, qtest had to be detached from icount. To this end, a trivial global counter for qtest has been introduced.
* 3/3 (CpuAccelInterface): provided a description.
This is point 8) in that plan. The idea is to extract the unrelated parts in cpus, and register interfaces from each single accelerator to the main cpus module (cpus.c).
While doing this RFC, I noticed some assumptions about Windows being either TCG or HAX (not considering WHPX) that might need to be revisited. I added a comment there.
The thing builds successfully based on Linux cross-compilations for windows/hax, windows/whpx, and I got a good build on Darwin/hvf.
Tests run successully for tcg and kvm configurations, but did not test on windows or darwin.
Welcome your feedback and help on this,
Claudio
Claudio Fontana (16):
cpu-timers, icount: new modules
icount: rename functions to be consistent with the module name
cpus: prepare new CpusAccel cpu accelerator interface
cpus: extract out TCG-specific code to accel/tcg
cpus: extract out qtest-specific code to accel/qtest
cpus: extract out kvm-specific code to accel/kvm
cpus: extract out hax-specific code to target/i386/
cpus: extract out whpx-specific code to target/i386/
cpus: extract out hvf-specific code to target/i386/hvf/
cpus: cleanup now unneeded includes
cpus: remove checks for non-NULL cpus_accel
cpus: add handle_interrupt to the CpusAccel interface
hvf: remove hvf specific functions from global includes
whpx: remove whpx specific functions from global includes
hax: remove hax specific functions from global includes
kvm: remove kvm specific functions from global includes
MAINTAINERS | 5 +-
accel/kvm/kvm-all.c | 14 +-
accel/kvm/kvm-cpus.c | 88 ++
accel/kvm/kvm-cpus.h | 24 +
accel/kvm/meson.build | 5 +-
accel/meson.build | 2 +-
accel/qtest/meson.build | 7 +
accel/qtest/qtest-cpus.c | 91 ++
accel/qtest/qtest-cpus.h | 17 +
accel/{ => qtest}/qtest.c | 13 +-
accel/stubs/hax-stub.c | 10 -
accel/stubs/hvf-stub.c | 30 -
accel/stubs/kvm-stub.c | 23 -
accel/stubs/meson.build | 2 -
accel/stubs/whpx-stub.c | 47 -
accel/tcg/cpu-exec.c | 43 +-
accel/tcg/meson.build | 2 +-
accel/tcg/tcg-all.c | 43 +-
accel/tcg/tcg-cpus.c | 569 +++++++++++
accel/tcg/tcg-cpus.h | 17 +
accel/tcg/translate-all.c | 3 +-
dma-helpers.c | 4 +-
docs/replay.txt | 6 +-
exec.c | 4 -
hw/core/cpu.c | 14 +-
hw/core/ptimer.c | 8 +-
hw/i386/x86.c | 3 +-
include/exec/cpu-all.h | 4 +
include/exec/exec-all.h | 4 +-
include/hw/core/cpu.h | 14 -
include/qemu/timer.h | 24 +-
include/sysemu/cpu-timers.h | 90 ++
include/sysemu/cpus.h | 50 +-
include/sysemu/hax.h | 17 -
include/sysemu/hvf.h | 8 -
include/sysemu/hw_accel.h | 69 +-
include/sysemu/kvm.h | 7 -
include/sysemu/qtest.h | 2 +
include/sysemu/replay.h | 4 +-
include/sysemu/whpx.h | 19 -
replay/replay.c | 6 +-
softmmu/cpu-timers.c | 279 ++++++
softmmu/cpus.c | 1697 +++-----------------------------
softmmu/icount.c | 492 +++++++++
softmmu/meson.build | 10 +-
softmmu/qtest.c | 34 +-
softmmu/timers-state.h | 69 ++
softmmu/vl.c | 8 +-
stubs/clock-warp.c | 7 -
stubs/cpu-get-clock.c | 3 +-
stubs/cpu-get-icount.c | 21 -
stubs/cpu-synchronize-state.c | 9 +
stubs/cpus-get-virtual-clock.c | 8 +
stubs/icount.c | 45 +
stubs/meson.build | 6 +-
stubs/qemu-timer-notify-cb.c | 8 +
stubs/qtest.c | 5 +
target/alpha/translate.c | 3 +-
target/arm/helper.c | 7 +-
target/i386/hax-all.c | 17 +-
target/i386/hax-cpus.c | 84 ++
target/i386/hax-cpus.h | 33 +
target/i386/hax-i386.h | 2 +
target/i386/hax-mem.c | 2 +-
target/i386/hax-posix.c | 13 +-
target/i386/hax-windows.c | 22 +-
target/i386/hax-windows.h | 2 +
target/i386/hvf/hvf-cpus.c | 131 +++
target/i386/hvf/hvf-cpus.h | 25 +
target/i386/hvf/hvf.c | 12 +-
target/i386/hvf/meson.build | 1 +
target/i386/hvf/x86hvf.c | 2 +
target/i386/hvf/x86hvf.h | 1 -
target/i386/meson.build | 14 +-
target/i386/whpx-all.c | 13 +-
target/i386/whpx-cpus.c | 96 ++
target/i386/whpx-cpus.h | 34 +
target/riscv/csr.c | 8 +-
tests/ptimer-test-stubs.c | 5 +-
tests/test-timed-average.c | 2 +-
util/main-loop.c | 12 +-
util/qemu-timer.c | 14 +-
82 files changed, 2637 insertions(+), 2031 deletions(-)
create mode 100644 accel/kvm/kvm-cpus.c
create mode 100644 accel/kvm/kvm-cpus.h
create mode 100644 accel/qtest/meson.build
create mode 100644 accel/qtest/qtest-cpus.c
create mode 100644 accel/qtest/qtest-cpus.h
rename accel/{ => qtest}/qtest.c (81%)
delete mode 100644 accel/stubs/hvf-stub.c
delete mode 100644 accel/stubs/whpx-stub.c
create mode 100644 accel/tcg/tcg-cpus.c
create mode 100644 accel/tcg/tcg-cpus.h
create mode 100644 include/sysemu/cpu-timers.h
create mode 100644 softmmu/cpu-timers.c
create mode 100644 softmmu/icount.c
create mode 100644 softmmu/timers-state.h
delete mode 100644 stubs/clock-warp.c
delete mode 100644 stubs/cpu-get-icount.c
create mode 100644 stubs/cpu-synchronize-state.c
create mode 100644 stubs/cpus-get-virtual-clock.c
create mode 100644 stubs/icount.c
create mode 100644 stubs/qemu-timer-notify-cb.c
create mode 100644 target/i386/hax-cpus.c
create mode 100644 target/i386/hax-cpus.h
create mode 100644 target/i386/hvf/hvf-cpus.c
create mode 100644 target/i386/hvf/hvf-cpus.h
create mode 100644 target/i386/whpx-cpus.c
create mode 100644 target/i386/whpx-cpus.hSignature · 1 line
2.26.2
PATCH v7 1/16 cpu-timers, icount: new modules
refactoring of cpus.c continues with cpu timer state extraction.
cpu-timers: responsible for the softmmu cpu timers state,
including cpu clocks and ticks.
icount: counts the TCG instructions executed. As such it is specific to the TCG accelerator. Therefore, it is built only under CONFIG_TCG.
One complication is due to qtest, which uses an icount field to warp time as part of qtest (qtest_clock_warp).
In order to solve this problem, provide a separate counter for qtest.
This requires fixing assumptions scattered in the code that qtest_enabled() implies icount_enabled(), checking each specific case.
--- MAINTAINERS | 2 + accel/qtest.c | 6 +- accel/tcg/cpu-exec.c | 39 +- accel/tcg/tcg-all.c | 7 +- accel/tcg/translate-all.c | 3 +- dma-helpers.c | 4 +- exec.c | 4 - hw/core/ptimer.c | 8 +- hw/i386/x86.c | 1 + include/exec/cpu-all.h | 4 + include/exec/exec-all.h | 4 +- include/qemu/timer.h | 24 +- include/sysemu/cpu-timers.h | 87 ++++ include/sysemu/cpus.h | 12 +- include/sysemu/qtest.h | 2 + replay/replay.c | 4 +- softmmu/cpu-timers.c | 284 +++++++++++++ softmmu/cpus.c | 744 +---------------------------------- softmmu/icount.c | 492 +++++++++++++++++++++++ softmmu/meson.build | 10 +- softmmu/qtest.c | 34 +- softmmu/timers-state.h | 69 ++++ softmmu/vl.c | 6 +- stubs/clock-warp.c | 7 - stubs/cpu-get-clock.c | 3 +- stubs/cpu-get-icount.c | 21 - stubs/icount.c | 45 +++ stubs/meson.build | 4 +- stubs/qemu-timer-notify-cb.c | 8 + stubs/qtest.c | 5 + target/alpha/translate.c | 3 +- target/arm/helper.c | 3 +- target/riscv/csr.c | 4 +- tests/ptimer-test-stubs.c | 5 +- tests/test-timed-average.c | 2 +- util/main-loop.c | 12 +- util/qemu-timer.c | 10 +- 37 files changed, 1135 insertions(+), 847 deletions(-) create mode 100644 include/sysemu/cpu-timers.h create mode 100644 softmmu/cpu-timers.c create mode 100644 softmmu/icount.c create mode 100644 softmmu/timers-state.h delete mode 100644 stubs/clock-warp.c delete mode 100644 stubs/cpu-get-icount.c create mode 100644 stubs/icount.c create mode 100644 stubs/qemu-timer-notify-cb.c
MAINTAINERS +2 -0
@@ -2287,6 +2287,8 @@ F: softmmu/vl.c F: softmmu/main.c F: softmmu/cpus.c F: softmmu/cpu-throttle.c +F: softmmu/cpu-timers.c +F: softmmu/icount.c F: qapi/run-state.json Human Monitor (HMP)
accel/qtest.c +1 -5
@@ -19,14 +19,10 @@#include "sysemu/accel.h" #include "sysemu/qtest.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" static int qtest_init_accel (MachineState *ms) { -QemuOpts *opts =qemu_opts_create (qemu_find_opts ("icount" ),NULL ,0 , - &error_abort); -qemu_opt_set (opts,"shift" ,"0" , &error_abort); -configure_icount (opts, &error_abort); -qemu_opts_del (opts);return 0 ; }
accel/tcg/cpu-exec.c +34 -5
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/qemu-print.h" #include "cpu.h" #include "trace.h" #include "disas/disas.h"
@@ -36,6 +37,8 @@#include "hw/i386/apic.h" #endif #include "sysemu/cpus.h" +#include "exec/cpu-all.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" /* -icount align implementation. */
@@ -56,6 +59,9 @@ typedef struct SyncClocks {#define MAX_DELAY_PRINT_RATE 2000000000LL#define MAX_NB_PRINTS 100 +static int64_t max_delay; +static int64_t max_advance; +static void align_clocks (SyncClocks *sc,CPUState *cpu) {int64_t cpu_icount;
@@ -98,9 +104,9 @@ static void print_delay(const SyncClocks *sc) (-sc->diff_clk / (float)1000000000LL < (threshold_delay - THRESHOLD_REDUCE))) { threshold_delay = (-sc->diff_clk /1000000000LL ) +1 ; -printf ("Warning: The guest is now late by %.1f to %.1f seconds\n" , - threshold_delay -1 , - threshold_delay); +qemu_printf ("Warning: The guest is now late by %.1f to %.1f seconds\n" , + threshold_delay -1 , + threshold_delay); nb_prints++; last_realtime_clock = sc->realtime_clock; }
@@ -614,7 +620,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,/* Finally, check if we need to exit to the main loop. */ if (unlikely (atomic_read (&cpu->exit_request)) - || (use_icount + || (icount_enabled () &&cpu_neg (cpu)->icount_decr.u16.low + cpu->icount_extra ==0 )) {atomic_set (&cpu->exit_request,0 );if (cpu->exception_index ==-1 ) {
@@ -655,7 +661,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, }/* Instruction counter expired. */ -assert (use_icount); +assert (icount_enabled ());#ifndef CONFIG_USER_ONLY /* Ensure global icount has gone forward */ cpu_update_icount (cpu);
@@ -758,3 +764,26 @@ int cpu_exec(CPUState *cpu)return ret; } + +#ifndef CONFIG_USER_ONLY + +void dump_drift_info (void ) +{ +if (!icount_enabled ()) { +return ; + } + +qemu_printf ("Host - Guest clock %" PRIi64" ms\n" , + (cpu_get_clock () -cpu_get_icount ()) /SCALE_MS ); +if (icount_align_option) { +qemu_printf ("Max guest delay %" PRIi64" ms\n" , + -max_delay /SCALE_MS ); +qemu_printf ("Max guest advance %" PRIi64" ms\n" , + max_advance /SCALE_MS ); + }else { +qemu_printf ("Max guest delay NA\n" ); +qemu_printf ("Max guest advance NA\n" ); + } +} + +#endif /* !CONFIG_USER_ONLY */
accel/tcg/tcg-all.c +4 -3
@@ -29,6 +29,7 @@#include "qom/object.h" #include "cpu.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "qemu/main-loop.h" #include "tcg/tcg.h" #include "qapi/error.h"
@@ -65,7 +66,7 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask)qemu_cpu_kick (cpu); }else {atomic_set (&cpu_neg (cpu)->icount_decr.u16.high,-1 ); -if (use_icount && +if (icount_enabled () && !cpu->can_do_io && (mask & ~old_mask) !=0 ) {cpu_abort (cpu,"Raised interrupt while not in I/O function" );
@@ -104,7 +105,7 @@ static bool check_tcg_memory_orders_compatible(void)static bool default_mttcg_enabled (void ) { -if (use_icount ||TCG_OVERSIZED_GUEST ) { +if (icount_enabled () ||TCG_OVERSIZED_GUEST ) {return false; }else {#ifdef TARGET_SUPPORTS_MTTCG
@@ -146,7 +147,7 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp)if (strcmp (value,"multi" ) ==0 ) {if (TCG_OVERSIZED_GUEST ) {error_setg (errp,"No MTTCG when guest word size > hosts" ); - }else if (use_icount) { + }else if (icount_enabled ()) {error_setg (errp,"No MTTCG when icount is enabled" ); }else {#ifndef TARGET_SUPPORTS_MTTCG
accel/tcg/translate-all.c +2 -1
@@ -57,6 +57,7 @@#include "qemu/main-loop.h" #include "exec/log.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" /* #define DEBUG_TB_INVALIDATE */
@@ -369,7 +370,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, found:if (reset_icount && (tb_cflags (tb) &CF_USE_ICOUNT )) { -assert (use_icount); +assert (icount_enabled ());/* Reset the cycle counter to the start of the block and shift if to the number of actually executed instructions */ cpu_neg (cpu)->icount_decr.u16.low += num_insns - i;
dma-helpers.c +2 -2
@@ -13,7 +13,7 @@#include "trace/trace-root.h" #include "qemu/thread.h" #include "qemu/main-loop.h" -#include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "qemu/range.h" /* #define DEBUG_IOMMU */
@@ -151,7 +151,7 @@ static void dma_blk_cb(void *opaque, int ret)* from several sectors. This code splits all SGs into several * groups. SGs in every group do not overlap. */ -if (mem && use_icount && dbs->dir ==DMA_DIRECTION_FROM_DEVICE ) { +if (mem &&icount_enabled () && dbs->dir ==DMA_DIRECTION_FROM_DEVICE ) {int i;for (i =0 ; i < dbs->iov.niov ; ++i) { if (ranges_overlap((intptr_t)dbs->iov.iov[i].iov_base,
exec.c +0 -4
@@ -102,10 +102,6 @@ uintptr_t qemu_host_page_size;intptr_t qemu_host_page_mask;#if !defined(CONFIG_USER_ONLY ) -/* 0 = Do not count executed instructions. -1 = Precise instruction counting. -2 = Adaptive rate instruction counting. */ -int use_icount;typedef struct PhysPageEntry PhysPageEntry ;
hw/core/ptimer.c +5 -3
@@ -7,11 +7,11 @@*/ #include "qemu/osdep.h" -#include "qemu/timer.h" #include "hw/ptimer.h" #include "migration/vmstate.h" #include "qemu/host-utils.h" #include "sysemu/replay.h" +#include "sysemu/cpu-timers.h" #include "sysemu/qtest.h" #include "block/aio.h" #include "sysemu/cpus.h"
@@ -134,7 +134,8 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)* on the current generation of host machines. */ -if (s->enabled ==1 && (delta * period <10000 ) && !use_icount) { +if (s->enabled ==1 && (delta * period <10000 ) && + !icount_enabled () && !qtest_enabled ()) { period =10000 / delta; period_frac =0 ; }
@@ -217,7 +218,8 @@ uint64_t ptimer_get_count(ptimer_state *s)uint32_t period_frac = s->period_frac;uint64_t period = s->period; -if (!oneshot && (s->delta * period <10000 ) && !use_icount) { +if (!oneshot && (s->delta * period <10000 ) && + !icount_enabled () && !qtest_enabled ()) { period =10000 / s->delta; period_frac =0 ; }
hw/i386/x86.c +1 -0
@@ -34,6 +34,7 @@#include "sysemu/numa.h" #include "sysemu/replay.h" #include "sysemu/sysemu.h" +#include "sysemu/cpu-timers.h" #include "trace.h" #include "hw/i386/x86.h"
include/exec/cpu-all.h +4 -0
@@ -407,8 +407,12 @@ static inline bool tlb_hit(target_ulong tlb_addr, target_ulong addr) return tlb_hit_page(tlb_addr, addr & TARGET_PAGE_MASK); } +#ifdef CONFIG_TCG +void dump_drift_info (void );void dump_exec_info (void );void dump_opcount_info (void ); +#endif /* CONFIG_TCG */ +#endif /* !CONFIG_USER_ONLY */ /* Returns: 0 on success, -1 on error */
include/exec/exec-all.h +2 -2
@@ -25,7 +25,7 @@#ifdef CONFIG_TCG #include "exec/cpu_ldst.h" #endif -#include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */ #define DEBUG_DISAS
@@ -497,7 +497,7 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb)static inline uint32_t curr_cflags (void ) {return (parallel_cpus ?CF_PARALLEL :0 ) - | (use_icount ?CF_USE_ICOUNT :0 ); + | (icount_enabled () ?CF_USE_ICOUNT :0 ); }/* TranslationBlock invalidate API */
include/qemu/timer.h +2 -22
@@ -166,8 +166,8 @@ bool qemu_clock_expired(QEMUClockType type);* * Determine whether a clock should be used for deadline * calculations. Some clocks, for instance vm_clock with -* use_icount set, do not count in nanoseconds. Such clocks -* are not used for deadline calculations, and are presumed +* icount_enabled() set, do not count in nanoseconds. +* Such clocks are not used for deadline calculations, and are presumed * to interrupt any poll using qemu_notify/aio_notify * etc. *
@@ -224,13 +224,6 @@ void qemu_clock_notify(QEMUClockType type);*/ void qemu_clock_enable (QEMUClockType type,bool enabled); -/** -* qemu_start_warp_timer: -* -* Starts a timer for virtual clock update -*/ -void qemu_start_warp_timer (void ); -/** * qemu_clock_run_timers: * @type: clock on which to operate
@@ -791,12 +784,6 @@ static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2)*/ void init_clocks (QEMUTimerListNotifyCB *notify_cb); -int64_t cpu_get_ticks (void ); -/* Caller must hold BQL */ -void cpu_enable_ticks (void ); -/* Caller must hold BQL */ -void cpu_disable_ticks (void ); -static inline int64_t get_max_clock_jump (void ) {/* This should be small enough to prevent excessive interrupts from being
@@ -850,13 +837,6 @@ static inline int64_t get_clock(void) }#endif -/* icount */ -int64_t cpu_get_icount_raw (void ); -int64_t cpu_get_icount (void ); -int64_t cpu_get_clock (void ); -int64_t cpu_icount_to_ns (int64_t icount); -void cpu_update_icount (CPUState *cpu); -/*******************************************/ /* host CPU ticks (if available) */
include/sysemu/cpu-timers.h new file +87 -0
87 lines not on this page · raw message
include/sysemu/cpus.h +1 -11
@@ -4,33 +4,23 @@#include "qemu/timer.h" /* cpus.c */ +bool all_cpu_threads_idle (void );bool qemu_in_vcpu_thread (void );void qemu_init_cpu_loop (void );void resume_all_vcpus (void );void pause_all_vcpus (void );void cpu_stop_current (void ); -void cpu_ticks_init (void ); -void configure_icount (QemuOpts *opts,Error **errp); -extern int use_icount;extern int icount_align_option; -/* drift information for info jit command */ -extern int64_t max_delay; -extern int64_t max_advance; -void dump_drift_info (void ); -/* Unblock cpu */ void qemu_cpu_kick_self (void ); -void qemu_timer_notify_cb (void *opaque,QEMUClockType type);void cpu_synchronize_all_states (void );void cpu_synchronize_all_post_reset (void );void cpu_synchronize_all_post_init (void );void cpu_synchronize_all_pre_loadvm (void ); -void qtest_clock_warp (int64_t dest); -#ifndef CONFIG_USER_ONLY /* vl.c */ /* *-user doesn't have configurable SMP topology */
include/sysemu/qtest.h +2 -0
@@ -30,4 +30,6 @@ void qtest_server_set_send_handler(void (*send)(void *, const char *), void *opaque);void qtest_server_inproc_recv (void *opaque,const char *buf); +int64_t qtest_get_virtual_clock (void ); +#endif
replay/replay.c +2 -2
@@ -11,10 +11,10 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" #include "sysemu/runstate.h" #include "replay-internal.h" -#include "qemu/timer.h" #include "qemu/main-loop.h" #include "qemu/option.h" #include "sysemu/cpus.h"
@@ -345,7 +345,7 @@ void replay_start(void)error_reportf_err (replay_blockers->data,"Record/replay: " );exit (1 ); } -if (!use_icount) { +if (!icount_enabled ()) {error_report ("Please enable icount to use record/replay" );exit (1 ); }
softmmu/cpu-timers.c new file +284 -0
284 lines not on this page · raw message
softmmu/cpus.c +7 -737
813 lines not on this page · raw message
softmmu/icount.c new file +492 -0
492 lines not on this page · raw message
softmmu/meson.build +8 -2
@@ -1,4 +1,4 @@ -specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( +specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'arch_init.c', 'balloon.c', 'cpus.c',
@@ -7,4 +7,10 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files( 'memory.c', 'memory_mapping.c', 'qtest.c', - 'vl.c')) + 'vl.c', + 'cpu-timers.c', +)]) + +specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files( + 'icount.c' +)])
softmmu/qtest.c +33 -1
@@ -21,7 +21,7 @@#include "exec/memory.h" #include "hw/irq.h" #include "sysemu/accel.h" -#include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/error-report.h"
@@ -273,6 +273,38 @@ static void qtest_irq_handler(void *opaque, int n, int level) } } +static int64_t qtest_clock_counter; + +int64_t qtest_get_virtual_clock (void ) +{ +return atomic_read_i64 (&qtest_clock_counter); +} + +static void qtest_set_virtual_clock (int64_t count) +{ +atomic_set_i64 (&qtest_clock_counter, count); +} + +static void qtest_clock_warp (int64_t dest) +{ +int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +AioContext *aio_context; +assert (qtest_enabled ()); + aio_context =qemu_get_aio_context (); +while (clock < dest) { +int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL , +QEMU_TIMER_ATTR_ALL ); +int64_t warp =qemu_soonest_timeout (dest - clock, deadline); + +qtest_set_virtual_clock (qtest_get_virtual_clock () + warp); + +qemu_clock_run_timers (QEMU_CLOCK_VIRTUAL ); +timerlist_run_timers (aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL ]); + clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + } +qemu_clock_notify (QEMU_CLOCK_VIRTUAL ); +} +static void qtest_process_command (CharBackend *chr,gchar **words) {const gchar *command;
softmmu/timers-state.h new file +69 -0
69 lines not on this page · raw message
softmmu/vl.c +4 -2
@@ -74,6 +74,7 @@#include "hw/audio/soundhw.h" #include "audio/audio.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "migration/colo.h" #include "migration/postcopy-ram.h" #include "sysemu/kvm.h"
@@ -2802,7 +2803,7 @@ static void configure_accelerators(const char *progname)error_report ("falling back to %s" , ac->name); } -if (use_icount && !(tcg_enabled () ||qtest_enabled ())) { +if (icount_enabled () && !tcg_enabled ()) {error_report ("-icount is not allowed with hardware virtualization" );exit (1 ); }
@@ -4237,7 +4238,8 @@ void qemu_init(int argc, char **argv, char **envp)semihosting_arg_fallback (kernel_filename, kernel_cmdline); } -cpu_ticks_init (); +/* initialize cpu timers and VCPU throttle modules */ +cpu_timers_init ();if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );
stubs/clock-warp.c deleted +0 -7
@@ -1,7 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu/timer.h" - -void qemu_start_warp_timer (void ) -{ -} -
stubs/cpu-get-clock.c +2 -1
@@ -1,5 +1,6 @@#include "qemu/osdep.h" -#include "qemu/timer.h" +#include "sysemu/cpu-timers.h" +#include "qemu/main-loop.h" int64_t cpu_get_clock (void ) {
stubs/cpu-get-icount.c deleted +0 -21
@@ -1,21 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu/timer.h" -#include "sysemu/cpus.h" -#include "qemu/main-loop.h" - -int use_icount; - -int64_t cpu_get_icount (void ) -{ -abort (); -} - -int64_t cpu_get_icount_raw (void ) -{ -abort (); -} - -void qemu_timer_notify_cb (void *opaque,QEMUClockType type) -{ -qemu_notify_event (); -}
stubs/icount.c new file +45 -0
45 lines not on this page · raw message
stubs/meson.build +2 -2
@@ -3,10 +3,10 @@ stub_ss.add(files('bdrv-next-monitor-owned.c')) stub_ss.add(files('blk-commit-all.c')) stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) -stub_ss.add(files('clock-warp.c')) stub_ss.add(files('cmos.c')) stub_ss.add(files('cpu-get-clock.c')) -stub_ss.add(files('cpu-get-icount.c')) +stub_ss.add(files('qemu-timer-notify-cb.c')) +stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c')) stub_ss.add(files('error-printf.c')) stub_ss.add(files('fd-register.c'))
stubs/qemu-timer-notify-cb.c new file +8 -0
@@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "sysemu/cpu-timers.h" +#include "qemu/main-loop.h" + +void qemu_timer_notify_cb (void *opaque,QEMUClockType type) +{ +qemu_notify_event (); +}
stubs/qtest.c +5 -0
@@ -18,3 +18,8 @@ bool qtest_driver(void) {return false; } + +int64_t qtest_get_virtual_clock (void ) +{ +return 0 ; +}
target/alpha/translate.c +2 -1
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "disas/disas.h" #include "qemu/host-utils.h" #include "exec/exec-all.h"
@@ -1329,7 +1330,7 @@ static DisasJumpType gen_mfpr(DisasContext *ctx, TCGv va, int regno)case 249 :/* VMTIME */ helper = gen_helper_get_vmtime; do_helper: -if (use_icount) { +if (icount_enabled ()) {gen_io_start ();helper (va);return DISAS_PC_STALE ;
target/arm/helper.c +2 -1
@@ -24,6 +24,7 @@#include "hw/irq.h" #include "hw/semihosting/semihost.h" #include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "sysemu/kvm.h" #include "sysemu/tcg.h" #include "qemu/range.h"
@@ -1206,7 +1207,7 @@ static int64_t cycles_ns_per(uint64_t cycles)static bool instructions_supported (CPUARMState *env) { -return use_icount ==1 /* Precise instruction counting */ ; +return icount_enabled () ==1 ;/* Precise instruction counting */ }static uint64_t instructions_get_count (CPUARMState *env)
target/riscv/csr.c +2 -2
@@ -299,7 +299,7 @@ static int write_vstart(CPURISCVState *env, int csrno, target_ulong val)static int read_instret (CPURISCVState *env,int csrno,target_ulong *val) {#if !defined(CONFIG_USER_ONLY ) -if (use_icount) { +if (icount_enabled ()) { *val =cpu_get_icount (); }else { *val =cpu_get_host_ticks ();
@@ -314,7 +314,7 @@ static int read_instret(CPURISCVState *env, int csrno, target_ulong *val)static int read_instreth (CPURISCVState *env,int csrno,target_ulong *val) {#if !defined(CONFIG_USER_ONLY ) -if (use_icount) { +if (icount_enabled ()) { *val =cpu_get_icount () >>32 ; }else { *val =cpu_get_host_ticks () >>32 ;
tests/ptimer-test-stubs.c +3 -2
@@ -12,6 +12,7 @@#include "qemu/main-loop.h" #include "sysemu/replay.h" #include "migration/vmstate.h" +#include "sysemu/cpu-timers.h" #include "ptimer-test.h"
@@ -30,8 +31,8 @@ QEMUTimerListGroup main_loop_tlg;int64_t ptimer_test_time_ns; -/* Do not artificially limit period - see hw/core/ptimer.c. */ -int use_icount =1 ; +/* under qtest_enabled(), will not artificially limit period - see hw/core/ptimer.c. */ +int use_icount;bool qtest_allowed; void timer_init_full(QEMUTimer *ts,
tests/test-timed-average.c +1 -1
@@ -11,7 +11,7 @@*/ #include "qemu/osdep.h" - +#include "sysemu/cpu-timers.h" #include "qemu/timed-average.h" /* This is the clock for QEMU_CLOCK_VIRTUAL */
util/main-loop.c +8 -4
@@ -27,7 +27,7 @@#include "qemu/cutils.h" #include "qemu/timer.h" #include "sysemu/qtest.h" -#include "sysemu/cpus.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" #include "qemu/main-loop.h" #include "block/aio.h"
@@ -517,9 +517,13 @@ void main_loop_wait(int nonblocking) mlpoll.state = ret <0 ?MAIN_LOOP_POLL_ERR :MAIN_LOOP_POLL_OK ;notifier_list_notify (&main_loop_poll_notifiers, &mlpoll); -/* CPU thread can infinitely wait for event after -missing the warp */ -qemu_start_warp_timer (); +if (icount_enabled ()) { +/* +* CPU thread can infinitely wait for event after +* missing the warp +*/ +qemu_start_warp_timer (); + }qemu_clock_run_all_timers (); }
util/qemu-timer.c +7 -3
@@ -26,8 +26,10 @@#include "qemu/main-loop.h" #include "qemu/timer.h" #include "qemu/lockable.h" +#include "sysemu/cpu-timers.h" #include "sysemu/replay.h" #include "sysemu/cpus.h" +#include "sysemu/qtest.h" #ifdef CONFIG_POSIX #include <pthread.h>
@@ -134,7 +136,7 @@ static void qemu_clock_init(QEMUClockType type, QEMUTimerListNotifyCB *notify_cbbool qemu_clock_use_for_deadline (QEMUClockType type) { -return !(use_icount && (type ==QEMU_CLOCK_VIRTUAL )); +return !(icount_enabled () && (type ==QEMU_CLOCK_VIRTUAL )); }void qemu_clock_notify (QEMUClockType type)
@@ -416,7 +418,7 @@ static bool timer_mod_ns_locked(QEMUTimerList *timer_list,static void timerlist_rearm (QEMUTimerList *timer_list) {/* Interrupt execution to force deadline recalculation. */ -if (timer_list->clock->type ==QEMU_CLOCK_VIRTUAL ) { +if (icount_enabled () && timer_list->clock->type ==QEMU_CLOCK_VIRTUAL ) {qemu_start_warp_timer (); }timerlist_notify (timer_list);
@@ -633,8 +635,10 @@ int64_t qemu_clock_get_ns(QEMUClockType type)return get_clock ();default :case QEMU_CLOCK_VIRTUAL : -if (use_icount) { +if (icount_enabled ()) {return cpu_get_icount (); + }else if (qtest_enabled ()) {/* for qtest_clock_warp */ +return qtest_get_virtual_clock (); }else {return cpu_get_clock (); }
Signature · 1 line
2.26.2
PATCH v7 2/16 icount: rename functions to be consistent with the module name
In reply to Claudio Fontana--- accel/tcg/cpu-exec.c | 6 +++--- docs/replay.txt | 6 +++--- include/sysemu/cpu-timers.h | 16 +++++++------- include/sysemu/replay.h | 4 ++-- replay/replay.c | 2 +- softmmu/cpu-timers.c | 6 +++--- softmmu/cpus.c | 6 +++--- softmmu/icount.c | 42 ++++++++++++++++++------------------- softmmu/vl.c | 2 +- stubs/icount.c | 16 +++++++------- target/arm/helper.c | 4 ++-- target/riscv/csr.c | 4 ++-- util/main-loop.c | 2 +- util/qemu-timer.c | 4 ++-- 14 files changed, 60 insertions(+), 60 deletions(-)
accel/tcg/cpu-exec.c +3 -3
@@ -71,7 +71,7 @@ static void align_clocks(SyncClocks *sc, CPUState *cpu) } cpu_icount = cpu->icount_extra +cpu_neg (cpu)->icount_decr.u16.low; - sc->diff_clk +=cpu_icount_to_ns (sc->last_cpu_icount - cpu_icount); + sc->diff_clk +=icount_to_ns (sc->last_cpu_icount - cpu_icount); sc->last_cpu_icount = cpu_icount;if (sc->diff_clk >VM_CLOCK_ADVANCE ) {
@@ -664,7 +664,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,assert (icount_enabled ());#ifndef CONFIG_USER_ONLY /* Ensure global icount has gone forward */ -cpu_update_icount (cpu); +icount_update (cpu);/* Refill decrementer and continue execution. */ insns_left =MIN (0xffff , cpu->icount_budget);cpu_neg (cpu)->icount_decr.u16.low = insns_left;
@@ -774,7 +774,7 @@ void dump_drift_info(void) }qemu_printf ("Host - Guest clock %" PRIi64" ms\n" , - (cpu_get_clock () -cpu_get_icount ()) /SCALE_MS ); + (cpu_get_clock () -icount_get ()) /SCALE_MS );if (icount_align_option) {qemu_printf ("Max guest delay %" PRIi64" ms\n" , -max_delay /SCALE_MS );
docs/replay.txt +3 -3
@@ -184,11 +184,11 @@ is then incremented (which is called "warping" the virtual clock) as soon as the timer fires or the CPUs need to go out of the idle state. Two functions are used for this purpose; because these actions change virtual machine state and must be deterministic, each of them creates a -checkpoint. qemu_start_warp_timer checks if the CPUs are idle and if so -starts accounting real time to virtual clock. qemu_account_warp_timer +checkpoint. icount_start_warp_timer checks if the CPUs are idle and if so +starts accounting real time to virtual clock. icount_account_warp_timer is called when the CPUs get an interrupt or when the warp timer fires, and it warps the virtual clock by the amount of real time that has passed -since qemu_start_warp_timer. +since icount_start_warp_timer. Bottom halves -------------
include/sysemu/cpu-timers.h +8 -8
@@ -35,30 +35,30 @@ extern int use_icount;* Update the icount with the executed instructions. Called by * cpus-tcg vCPU thread so the main-loop can see time has moved forward. */ -void cpu_update_icount (CPUState *cpu); +void icount_update (CPUState *cpu);/* get raw icount value */ -int64_t cpu_get_icount_raw (void ); +int64_t icount_get_raw (void );/* return the virtual CPU time in ns, based on the instruction counter. */ -int64_t cpu_get_icount (void ); +int64_t icount_get (void );/* * convert an instruction counter value to ns, based on the icount shift. * This shift is set as a fixed value with the icount "shift" option * (precise mode), or it is constantly approximated and corrected at * runtime in adaptive mode. */ -int64_t cpu_icount_to_ns (int64_t icount); +int64_t icount_to_ns (int64_t icount);/* configure the icount options, including "shift" */ -void configure_icount (QemuOpts *opts,Error **errp); +void icount_configure (QemuOpts *opts,Error **errp);/* used by tcg vcpu thread to calc icount budget */ -int64_t qemu_icount_round (int64_t count); +int64_t icount_round (int64_t count);/* if the CPUs are idle, start accounting real time to virtual clock. */ -void qemu_start_warp_timer (void ); -void qemu_account_warp_timer (void ); +void icount_start_warp_timer (void ); +void icount_account_warp_timer (void );/* * CPU Ticks and Clock
include/sysemu/replay.h +2 -2
@@ -109,12 +109,12 @@ int64_t replay_read_clock(ReplayClockKind kind);#define REPLAY_CLOCK (clock, value) \ (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \ : replay_mode == REPLAY_MODE_RECORD \ - ? replay_save_clock((clock), (value), cpu_get_icount_raw()) \ + ? replay_save_clock((clock), (value), icount_get_raw()) \ : (value))#define REPLAY_CLOCK_LOCKED (clock, value) \ (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock)) \ : replay_mode == REPLAY_MODE_RECORD \ - ? replay_save_clock((clock), (value), cpu_get_icount_raw_locked()) \ + ? replay_save_clock((clock), (value), icount_get_raw_locked()) \ : (value))/* Processing data from random generators */
replay/replay.c +1 -1
@@ -64,7 +64,7 @@ bool replay_next_event_is(int event)uint64_t replay_get_current_icount (void ) { -return cpu_get_icount_raw (); +return icount_get_raw (); }int replay_get_instructions (void )
softmmu/cpu-timers.c +3 -3
@@ -70,7 +70,7 @@ int64_t cpu_get_ticks(void)int64_t ticks;if (icount_enabled ()) { -return cpu_get_icount (); +return icount_get (); }qemu_spin_lock (&timers_state.vm_clock_lock);
@@ -160,7 +160,7 @@ static bool adjust_timers_state_needed(void *opaque)return s->icount_rt_timer !=NULL ; } -static bool shift_state_needed (void *opaque) +static bool icount_shift_state_needed (void *opaque) {return icount_enabled () ==2 ; }
@@ -196,7 +196,7 @@ static const VMStateDescription icount_vmstate_shift = { .name = "timer/icount/shift", .version_id = 1, .minimum_version_id = 1, - .needed = shift_state_needed, + .needed = icount_shift_state_needed, .fields = (VMStateField []) {VMSTATE_INT16 (icount_time_shift, TimersState),VMSTATE_END_OF_LIST ()
softmmu/cpus.c +3 -3
@@ -560,7 +560,7 @@ static int64_t tcg_get_icount_limit(void) deadline =INT32_MAX ; } -return qemu_icount_round (deadline); +return icount_round (deadline); }else {return replay_get_instructions (); }
@@ -615,7 +615,7 @@ static void process_icount_data(CPUState *cpu) {if (icount_enabled ()) {/* Account for executed instructions */ -cpu_update_icount (cpu); +icount_update (cpu);/* Reset the counters */ cpu_neg (cpu)->icount_decr.u16.low =0 ;
@@ -716,7 +716,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)replay_mutex_lock ();qemu_mutex_lock_iothread ();/* Account partial waits to QEMU_CLOCK_VIRTUAL. */ -qemu_account_warp_timer (); +icount_account_warp_timer ();/* Run the timers here. This is much more efficient than * waking up the I/O thread and waiting for completion.
softmmu/icount.c +21 -21
142 lines not on this page · raw message
softmmu/vl.c +1 -1
@@ -2693,7 +2693,7 @@ static void user_register_global_props(void)static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) { -configure_icount (opts, errp); +icount_configure (opts, errp);return 0 ; }
stubs/icount.c +8 -8
@@ -6,40 +6,40 @@int use_icount; -void cpu_update_icount (CPUState *cpu) +void icount_update (CPUState *cpu) {abort (); } -void configure_icount (QemuOpts *opts,Error **errp) +void icount_configure (QemuOpts *opts,Error **errp) {/* signal error */ error_setg (errp,"cannot configure icount, TCG support not available" ); } -int64_t cpu_get_icount_raw (void ) +int64_t icount_get_raw (void ) {abort ();return 0 ; } -int64_t cpu_get_icount (void ) +int64_t icount_get (void ) {abort ();return 0 ; } -int64_t cpu_icount_to_ns (int64_t icount) +int64_t icount_to_ns (int64_t icount) {abort ();return 0 ; } -int64_t qemu_icount_round (int64_t count) +int64_t icount_round (int64_t count) {abort ();return 0 ; } -void qemu_start_warp_timer (void ) +void icount_start_warp_timer (void ) {abort (); } -void qemu_account_warp_timer (void ) +void icount_account_warp_timer (void ) {abort (); }
target/arm/helper.c +2 -2
@@ -1212,12 +1212,12 @@ static bool instructions_supported(CPUARMState *env)static uint64_t instructions_get_count (CPUARMState *env) { -return (uint64_t )cpu_get_icount_raw (); +return (uint64_t )icount_get_raw (); }static int64_t instructions_ns_per (uint64_t icount) { -return cpu_icount_to_ns ((int64_t )icount); +return icount_to_ns ((int64_t )icount); }#endif
target/riscv/csr.c +2 -2
@@ -300,7 +300,7 @@ static int read_instret(CPURISCVState *env, int csrno, target_ulong *val) {#if !defined(CONFIG_USER_ONLY )if (icount_enabled ()) { - *val =cpu_get_icount (); + *val =icount_get (); }else { *val =cpu_get_host_ticks (); }
@@ -315,7 +315,7 @@ static int read_instreth(CPURISCVState *env, int csrno, target_ulong *val) {#if !defined(CONFIG_USER_ONLY )if (icount_enabled ()) { - *val =cpu_get_icount () >>32 ; + *val =icount_get () >>32 ; }else { *val =cpu_get_host_ticks () >>32 ; }
util/main-loop.c +1 -1
@@ -522,7 +522,7 @@ void main_loop_wait(int nonblocking)* CPU thread can infinitely wait for event after * missing the warp */ -qemu_start_warp_timer (); +icount_start_warp_timer (); }qemu_clock_run_all_timers (); }
util/qemu-timer.c +2 -2
@@ -419,7 +419,7 @@ static void timerlist_rearm(QEMUTimerList *timer_list) {/* Interrupt execution to force deadline recalculation. */ if (icount_enabled () && timer_list->clock->type ==QEMU_CLOCK_VIRTUAL ) { -qemu_start_warp_timer (); +icount_start_warp_timer (); }timerlist_notify (timer_list); }
@@ -636,7 +636,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)default :case QEMU_CLOCK_VIRTUAL :if (icount_enabled ()) { -return cpu_get_icount (); +return icount_get (); }else if (qtest_enabled ()) {/* for qtest_clock_warp */ return qtest_get_virtual_clock (); }else {
Signature · 1 line
2.26.2
PATCH v7 3/16 cpus: prepare new CpusAccel cpu accelerator interface
In reply to Claudio FontanaThe new interface starts unused, will start being used by the next patches.
It provides methods for each accelerator to start a vcpu, kick a vcpu, synchronize state, get cpu virtual clock and elapsed ticks.
In qemu_wait_io_event, make it clear that APC is used only for HAX on Windows.
--- hw/core/cpu.c | 1 + hw/i386/x86.c | 2 +- include/sysemu/cpu-timers.h | 9 +- include/sysemu/cpus.h | 36 ++++++ include/sysemu/hw_accel.h | 69 +----------- softmmu/cpu-timers.c | 9 +- softmmu/cpus.c | 195 ++++++++++++++++++++++++++------- stubs/cpu-synchronize-state.c | 9 ++ stubs/cpus-get-virtual-clock.c | 8 ++ stubs/meson.build | 2 + util/qemu-timer.c | 8 +- 11 files changed, 225 insertions(+), 123 deletions(-) create mode 100644 stubs/cpu-synchronize-state.c create mode 100644 stubs/cpus-get-virtual-clock.c
hw/core/cpu.c +1 -0
@@ -33,6 +33,7 @@#include "hw/qdev-properties.h" #include "trace/trace-root.h" #include "qemu/plugin.h" +#include "sysemu/hw_accel.h" CPUInterruptHandler cpu_interrupt_handler;
hw/i386/x86.c +1 -1
@@ -240,7 +240,7 @@ static long get_file_size(FILE *f)/* TSC handling */ uint64_t cpu_get_tsc (CPUX86State *env) { -return cpu_get_ticks (); +return cpus_get_elapsed_ticks (); }/* IRQ handling */
include/sysemu/cpu-timers.h +6 -3
@@ -70,9 +70,8 @@ void cpu_enable_ticks(void);void cpu_disable_ticks (void );/* -* return the time elapsed in VM between vm_start and vm_stop. Unless -* icount is active, cpu_get_ticks() uses units of the host CPU cycle -* counter. +* return the time elapsed in VM between vm_start and vm_stop. +* cpu_get_ticks() uses units of the host CPU cycle counter. */ int64_t cpu_get_ticks (void );
@@ -84,4 +83,8 @@ int64_t cpu_get_clock(void);void qemu_timer_notify_cb (void *opaque,QEMUClockType type); +/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface */ +int64_t cpus_get_virtual_clock (void ); +int64_t cpus_get_elapsed_ticks (void ); +#endif /* SYSEMU_CPU_TIMERS_H */
include/sysemu/cpus.h +36 -0
@@ -4,7 +4,43 @@#include "qemu/timer.h" /* cpus.c */ + +/* CPU execution threads */ + +typedef struct CpusAccel { +void (*create_vcpu_thread)(CPUState *cpu);/* MANDATORY */ +void (*kick_vcpu_thread)(CPUState *cpu); + +void (*synchronize_post_reset)(CPUState *cpu); +void (*synchronize_post_init)(CPUState *cpu); +void (*synchronize_state)(CPUState *cpu); +void (*synchronize_pre_loadvm)(CPUState *cpu); + +int64_t (*get_virtual_clock)(void ); +int64_t (*get_elapsed_ticks)(void ); +}CpusAccel ; + +/* register accel-specific cpus interface implementation */ +void cpus_register_accel (const CpusAccel *i); + +/* interface available for cpus accelerator threads */ + +/* For temporary buffers for forming a name */ +#define VCPU_THREAD_NAME_SIZE 16 + +void cpus_kick_thread (CPUState *cpu); +bool cpu_work_list_empty (CPUState *cpu); +bool cpu_thread_is_idle (CPUState *cpu);bool all_cpu_threads_idle (void ); +bool cpu_can_run (CPUState *cpu); +void qemu_wait_io_event_common (CPUState *cpu); +void qemu_wait_io_event (CPUState *cpu); +void cpu_thread_signal_created (CPUState *cpu); +void cpu_thread_signal_destroyed (CPUState *cpu); +void cpu_handle_guest_debug (CPUState *cpu); + +/* end interface for cpus accelerator threads */ +bool qemu_in_vcpu_thread (void );void qemu_init_cpu_loop (void );void resume_all_vcpus (void );
include/sysemu/hw_accel.h +5 -64
78 lines not on this page · raw message
softmmu/cpu-timers.c +2 -7
@@ -61,18 +61,13 @@ static int64_t cpu_get_ticks_locked(void) }/* -* return the time elapsed in VM between vm_start and vm_stop. Unless -* icount is active, cpu_get_ticks() uses units of the host CPU cycle -* counter. +* return the time elapsed in VM between vm_start and vm_stop. +* cpu_get_ticks() uses units of the host CPU cycle counter. */ int64_t cpu_get_ticks (void ) {int64_t ticks; -if (icount_enabled ()) { -return icount_get (); - } -qemu_spin_lock (&timers_state.vm_clock_lock); ticks =cpu_get_ticks_locked ();qemu_spin_unlock (&timers_state.vm_clock_lock);
softmmu/cpus.c +154 -41
373 lines not on this page · raw message
stubs/cpu-synchronize-state.c new file +9 -0
@@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "sysemu/hw_accel.h" + +void cpu_synchronize_state (CPUState *cpu) +{ +} +void cpu_synchronize_post_init (CPUState *cpu) +{ +}
stubs/cpus-get-virtual-clock.c new file +8 -0
@@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "sysemu/cpu-timers.h" +#include "qemu/main-loop.h" + +int64_t cpus_get_virtual_clock (void ) +{ +return cpu_get_clock (); +}
stubs/meson.build +2 -0
@@ -5,6 +5,7 @@ stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('cmos.c')) stub_ss.add(files('cpu-get-clock.c')) +stub_ss.add(files('cpus-get-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c'))
@@ -45,6 +46,7 @@ stub_ss.add(files('vmgenid.c')) stub_ss.add(files('vmstate.c')) stub_ss.add(files('vm-stop.c')) stub_ss.add(files('win32-kbd-hook.c')) +stub_ss.add(files('cpu-synchronize-state.c')) if have_system stub_ss.add(files('semihost.c')) endif
util/qemu-timer.c +1 -7
@@ -635,13 +635,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)return get_clock ();default :case QEMU_CLOCK_VIRTUAL : -if (icount_enabled ()) { -return icount_get (); - }else if (qtest_enabled ()) {/* for qtest_clock_warp */ -return qtest_get_virtual_clock (); - }else { -return cpu_get_clock (); - } +return cpus_get_virtual_clock ();case QEMU_CLOCK_HOST :return REPLAY_CLOCK (REPLAY_CLOCK_HOST ,get_clock_realtime ());case QEMU_CLOCK_VIRTUAL_RT :
Signature · 1 line
2.26.2
PATCH v7 4/16 cpus: extract out TCG-specific code to accel/tcg
In reply to Claudio FontanaTCG is the first accelerator to register a "CpusAccel" interface on initialization, providing functions for starting a vcpu, kicking a vcpu, sychronizing state and getting virtual clock and ticks.
--- accel/tcg/meson.build | 2 +- accel/tcg/tcg-all.c | 12 +- accel/tcg/tcg-cpus.c | 541 ++++++++++++++++++++++++++++++++++++++++++ accel/tcg/tcg-cpus.h | 17 ++ softmmu/cpus.c | 496 +------------------------------------- 5 files changed, 567 insertions(+), 501 deletions(-) create mode 100644 accel/tcg/tcg-cpus.c create mode 100644 accel/tcg/tcg-cpus.h
accel/tcg/meson.build +1 -1
@@ -12,4 +12,4 @@ tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c')) tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: files('plugin-gen.c')) specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) -specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files('tcg-all.c', 'cputlb.c')) +specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files('tcg-all.c', 'cputlb.c', 'tcg-cpus.c'))
accel/tcg/tcg-all.c +7 -5
@@ -24,19 +24,17 @@*/ #include "qemu/osdep.h" -#include "sysemu/accel.h" +#include "qemu-common.h" #include "sysemu/tcg.h" -#include "qom/object.h" -#include "cpu.h" -#include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" -#include "qemu/main-loop.h" #include "tcg/tcg.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "hw/boards.h" #include "qapi/qapi-builtin-visit.h" +#include "tcg-cpus.h" + typedef struct TCGState { AccelState parent_obj;
@@ -123,6 +121,8 @@ static void tcg_accel_instance_init(Object *obj) s->mttcg_enabled =default_mttcg_enabled (); } +bool mttcg_enabled; +static int tcg_init (MachineState *ms) {TCGState *s =TCG_STATE (current_accel ());
@@ -130,6 +130,8 @@ static int tcg_init(MachineState *ms)tcg_exec_init (s->tb_size *1024 *1024 ); cpu_interrupt_handler = tcg_handle_interrupt; mttcg_enabled = s->mttcg_enabled; +cpus_register_accel (&tcg_cpus); +return 0 ; }
accel/tcg/tcg-cpus.c new file +541 -0
541 lines not on this page · raw message
accel/tcg/tcg-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 TCG_CPUS_H +#define TCG_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel tcg_cpus; + +#endif /* TCG_CPUS_H */
softmmu/cpus.c +1 -495
577 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 5/16 cpus: extract out qtest-specific code to accel/qtest
In reply to Claudio Fontanaregister a "CpusAccel" interface for qtest as well.
---
MAINTAINERS | 2 +-
accel/meson.build | 2 +-
accel/qtest/meson.build | 7 +++
accel/qtest/qtest-cpus.c | 91 +++++++++++++++++++++++++++++++++++++++
accel/qtest/qtest-cpus.h | 17 ++++++++
accel/{ => qtest}/qtest.c | 7 +++
softmmu/cpus.c | 64 +--------------------------
7 files changed, 125 insertions(+), 65 deletions(-)
create mode 100644 accel/qtest/meson.build
create mode 100644 accel/qtest/qtest-cpus.c
create mode 100644 accel/qtest/qtest-cpus.h
rename accel/{ => qtest}/qtest.c (86%)MAINTAINERS +1 -1
@@ -2444,7 +2444,7 @@ M: Laurent Vivier <[email protected]> R: Paolo Bonzini <[email protected]> S: Maintained F: softmmu/qtest.c -F: accel/qtest.c +F: accel/qtest/ F: tests/qtest/ X: tests/qtest/bios-tables-test-allowed-diff.h
accel/meson.build +1 -1
@@ -1,6 +1,6 @@ softmmu_ss.add(files('accel.c')) -specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: files('qtest.c')) +subdir('qtest') subdir('kvm') subdir('tcg') subdir('xen')
accel/qtest/meson.build new file +7 -0
@@ -0,0 +1,7 @@ +qtest_ss = ss.source_set() +qtest_ss.add(files( + 'qtest.c', + 'qtest-cpus.c', +)) + +specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: qtest_ss)
accel/qtest/qtest-cpus.c new file +91 -0
91 lines not on this page · raw message
accel/qtest/qtest-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 QTEST_CPUS_H +#define QTEST_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel qtest_cpus; + +#endif /* QTEST_CPUS_H */
accel/qtest/qtest.c renamed from accel/qtest.c +7 -0
@@ -12,6 +12,7 @@*/ #include "qemu/osdep.h" +#include "qemu/rcu.h" #include "qapi/error.h" #include "qemu/module.h" #include "qemu/option.h"
@@ -20,9 +21,15 @@#include "sysemu/qtest.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" +#include "qemu/guest-random.h" +#include "qemu/main-loop.h" +#include "hw/core/cpu.h" + +#include "qtest-cpus.h" static int qtest_init_accel (MachineState *ms) { +cpus_register_accel (&qtest_cpus);return 0 ; }
softmmu/cpus.c +1 -63
94 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 6/16 cpus: extract out kvm-specific code to accel/kvm
In reply to Claudio Fontanaregister a "CpusAccel" interface for KVM as well.
--- accel/kvm/kvm-all.c | 14 ++++++- accel/kvm/kvm-cpus.c | 88 ++++++++++++++++++++++++++++++++++++++++++ accel/kvm/kvm-cpus.h | 17 ++++++++ accel/kvm/meson.build | 5 ++- accel/stubs/kvm-stub.c | 3 +- include/sysemu/kvm.h | 2 +- softmmu/cpus.c | 77 ------------------------------------ 7 files changed, 124 insertions(+), 82 deletions(-) create mode 100644 accel/kvm/kvm-cpus.c create mode 100644 accel/kvm/kvm-cpus.h
accel/kvm/kvm-all.c +13 -1
@@ -44,6 +44,9 @@#include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "sysemu/reset.h" +#include "qemu/guest-random.h" +#include "sysemu/hw_accel.h" +#include "kvm-cpus.h" #include "hw/boards.h"
@@ -378,7 +381,7 @@ err:return ret; } -int kvm_destroy_vcpu (CPUState *cpu) +static int do_kvm_destroy_vcpu (CPUState *cpu) {KVMState *s = kvm_state;long mmap_size;
@@ -412,6 +415,14 @@ err:return ret; } +void kvm_destroy_vcpu (CPUState *cpu) +{ +if (do_kvm_destroy_vcpu (cpu) <0 ) { +error_report ("kvm_destroy_vcpu failed" ); +exit (EXIT_FAILURE ); + } +} +static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) {struct KVMParkedVcpu *cpu;
@@ -2232,6 +2243,7 @@ static int kvm_init(MachineState *ms)assert (!ret); } +cpus_register_accel (&kvm_cpus);return 0 ; err:
accel/kvm/kvm-cpus.c new file +88 -0
88 lines not on this page · raw message
accel/kvm/kvm-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 KVM_CPUS_H +#define KVM_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel kvm_cpus; + +#endif /* KVM_CPUS_H */
accel/kvm/meson.build +4 -1
@@ -1,5 +1,8 @@ kvm_ss = ss.source_set() -kvm_ss.add(files('kvm-all.c')) +kvm_ss.add(files( + 'kvm-all.c', + 'kvm-cpus.c', +)) kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c')) specific_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
accel/stubs/kvm-stub.c +1 -2
@@ -32,9 +32,8 @@ bool kvm_readonly_mem_allowed;bool kvm_ioeventfd_any_length_allowed;bool kvm_msi_use_devid; -int kvm_destroy_vcpu (CPUState *cpu) +void kvm_destroy_vcpu (CPUState *cpu) { -return -ENOSYS ; }int kvm_init_vcpu (CPUState *cpu)
include/sysemu/kvm.h +1 -1
@@ -224,7 +224,7 @@ int kvm_has_intx_set_mask(void);int kvm_init_vcpu (CPUState *cpu);int kvm_cpu_exec (CPUState *cpu); -int kvm_destroy_vcpu (CPUState *cpu); +void kvm_destroy_vcpu (CPUState *cpu);/** * kvm_arm_supports_user_irq
softmmu/cpus.c +0 -77
125 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v7 7/16 cpus: extract out hax-specific code to target/i386/
In reply to Claudio Fontanaregister a "CpusAccel" interface for HAX as well.
--- softmmu/cpus.c | 80 +----------------------------------- target/i386/hax-all.c | 6 ++- target/i386/hax-cpus.c | 85 +++++++++++++++++++++++++++++++++++++++ target/i386/hax-cpus.h | 17 ++++++++ target/i386/hax-i386.h | 2 + target/i386/hax-posix.c | 12 ++++++ target/i386/hax-windows.c | 20 +++++++++ target/i386/meson.build | 9 ++++- 8 files changed, 149 insertions(+), 82 deletions(-) create mode 100644 target/i386/hax-cpus.c create mode 100644 target/i386/hax-cpus.h
softmmu/cpus.c +1 -79
@@ -33,7 +33,6 @@#include "exec/gdbstub.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm.h" -#include "sysemu/hax.h" #include "sysemu/hvf.h" #include "sysemu/whpx.h" #include "exec/exec-all.h"
@@ -179,9 +178,6 @@ void cpu_synchronize_state(CPUState *cpu)if (cpus_accel && cpus_accel->synchronize_state) { cpus_accel->synchronize_state (cpu); } -if (hax_enabled ()) { -hax_cpu_synchronize_state (cpu); - }if (whpx_enabled ()) {whpx_cpu_synchronize_state (cpu); }
@@ -192,9 +188,6 @@ void cpu_synchronize_post_reset(CPUState *cpu)if (cpus_accel && cpus_accel->synchronize_post_reset) { cpus_accel->synchronize_post_reset (cpu); } -if (hax_enabled ()) { -hax_cpu_synchronize_post_reset (cpu); - }if (whpx_enabled ()) {whpx_cpu_synchronize_post_reset (cpu); }
@@ -205,9 +198,6 @@ void cpu_synchronize_post_init(CPUState *cpu)if (cpus_accel && cpus_accel->synchronize_post_init) { cpus_accel->synchronize_post_init (cpu); } -if (hax_enabled ()) { -hax_cpu_synchronize_post_init (cpu); - }if (whpx_enabled ()) {whpx_cpu_synchronize_post_init (cpu); }
@@ -218,9 +208,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)if (cpus_accel && cpus_accel->synchronize_pre_loadvm) { cpus_accel->synchronize_pre_loadvm (cpu); } -if (hax_enabled ()) { -hax_cpu_synchronize_pre_loadvm (cpu); - }if (hvf_enabled ()) {hvf_cpu_synchronize_pre_loadvm (cpu); }
@@ -416,35 +403,6 @@ void qemu_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } -static void *qemu_hax_cpu_thread_fn (void *arg) -{ -CPUState *cpu = arg; -int r; - -rcu_register_thread (); -qemu_mutex_lock_iothread (); -qemu_thread_get_self (cpu->thread); - - cpu->thread_id =qemu_get_thread_id (); - current_cpu = cpu; -hax_init_vcpu (cpu); -cpu_thread_signal_created (cpu); -qemu_guest_random_seed_thread_part2 (cpu->random_seed); - -do { -if (cpu_can_run (cpu)) { - r =hax_smp_cpu_exec (cpu); -if (r ==EXCP_DEBUG ) { -cpu_handle_guest_debug (cpu); - } - } - -qemu_wait_io_event (cpu); - }while (!cpu->unplug ||cpu_can_run (cpu)); -rcu_unregister_thread (); -return NULL ; -} -/* The HVF-specific vCPU thread function. This one should only run when the host * CPU supports the VMX "unrestricted guest" feature. */ static void *qemu_hvf_cpu_thread_fn (void *arg)
@@ -529,12 +487,6 @@ static void *qemu_whpx_cpu_thread_fn(void *arg)return NULL ; } -#ifdef _WIN32 -static void CALLBACK dummy_apc_func(ULONG_PTR unused) -{ -} -#endif -void cpus_kick_thread (CPUState *cpu) {#ifndef _WIN32
@@ -553,10 +505,6 @@ void cpus_kick_thread(CPUState *cpu)if (!qemu_cpu_is_self (cpu)) {if (whpx_enabled ()) {whpx_vcpu_kick (cpu); - }else if (!QueueUserAPC (dummy_apc_func, cpu->hThread,0 )) { -fprintf (stderr,"%s: QueueUserAPC failed with error %lu\n" , - __func__,GetLastError ()); -exit (1 ); } }#endif
@@ -567,14 +515,7 @@ void qemu_cpu_kick(CPUState *cpu)qemu_cond_broadcast (cpu->halt_cond);if (cpus_accel && cpus_accel->kick_vcpu_thread) { cpus_accel->kick_vcpu_thread (cpu); - }else { -if (hax_enabled ()) { -/* -* FIXME: race condition with the exit_request check in -* hax_vcpu_hax_exec -*/ - cpu->exit_request =1 ; - } + }else {/* default */ cpus_kick_thread (cpu); } }
@@ -722,23 +663,6 @@ void cpu_remove_sync(CPUState *cpu)qemu_mutex_lock_iothread (); } -static void qemu_hax_start_vcpu (CPUState *cpu) -{ -char thread_name[VCPU_THREAD_NAME_SIZE ]; - - cpu->thread =g_malloc0 (sizeof (QemuThread)); - cpu->halt_cond =g_malloc0 (sizeof (QemuCond)); -qemu_cond_init (cpu->halt_cond); - -snprintf (thread_name,VCPU_THREAD_NAME_SIZE ,"CPU %d/HAX" , - cpu->cpu_index); -qemu_thread_create (cpu->thread, thread_name, qemu_hax_cpu_thread_fn, - cpu,QEMU_THREAD_JOINABLE ); -#ifdef _WIN32 - cpu->hThread =qemu_thread_get_handle (cpu->thread); -#endif -} -static void qemu_hvf_start_vcpu (CPUState *cpu) {char thread_name[VCPU_THREAD_NAME_SIZE ];
@@ -800,8 +724,6 @@ void qemu_init_vcpu(CPUState *cpu)if (cpus_accel) {/* accelerator already implements the CpusAccel interface */ cpus_accel->create_vcpu_thread (cpu); - }else if (hax_enabled ()) { -qemu_hax_start_vcpu (cpu); }else if (hvf_enabled ()) {qemu_hvf_start_vcpu (cpu); }else if (whpx_enabled ()) {
target/i386/hax-all.c +5 -1
@@ -32,9 +32,10 @@#include "sysemu/accel.h" #include "sysemu/reset.h" #include "sysemu/runstate.h" -#include "qemu/main-loop.h" #include "hw/boards.h" +#include "hax-cpus.h" +#define DEBUG_HAX 0#define DPRINTF (fmt, ...) \
@@ -374,6 +375,9 @@ static int hax_accel_init(MachineState *ms) !ret ?"working" :"not working" , !ret ? "fast virt" : "emulation"); } +if (ret ==0 ) { +cpus_register_accel (&hax_cpus); + }return ret; }
target/i386/hax-cpus.c new file +85 -0
85 lines not on this page · raw message
target/i386/hax-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 HAX_CPUS_H +#define HAX_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel hax_cpus; + +#endif /* HAX_CPUS_H */
target/i386/hax-i386.h +2 -0
@@ -60,6 +60,8 @@ int hax_inject_interrupt(CPUArchState *env, int vector);struct hax_vm *hax_vm_create (struct hax_state *hax,int max_cpus);int hax_vcpu_run (struct hax_vcpu_state *vcpu);int hax_vcpu_create (int id); +void hax_kick_vcpu_thread (CPUState *cpu); +int hax_sync_vcpu_state (CPUArchState *env,struct vcpu_state_t *state,int set);int hax_sync_msr (CPUArchState *env,struct hax_msr_data *msrs,int set);
target/i386/hax-posix.c +12 -0
@@ -16,6 +16,8 @@#include "target/i386/hax-i386.h" +#include "sysemu/cpus.h" +hax_fd hax_mod_open (void ) {int fd =open ("/dev/HAX" ,O_RDWR );
@@ -292,3 +294,13 @@ int hax_inject_interrupt(CPUArchState *env, int vector)return ioctl (fd,HAX_VCPU_IOCTL_INTERRUPT , &vector); } + +void hax_kick_vcpu_thread (CPUState *cpu) +{ +/* +* FIXME: race condition with the exit_request check in +* hax_vcpu_hax_exec +*/ + cpu->exit_request =1 ; +cpus_kick_thread (cpu); +}
target/i386/hax-windows.c +20 -0
@@ -463,3 +463,23 @@ int hax_inject_interrupt(CPUArchState *env, int vector)return 0 ; } } + +static void CALLBACK dummy_apc_func(ULONG_PTR unused) +{ +} + +void hax_kick_vcpu_thread (CPUState *cpu) +{ +/* +* FIXME: race condition with the exit_request check in +* hax_vcpu_hax_exec +*/ + cpu->exit_request =1 ; +if (!qemu_cpu_is_self (cpu)) { +if (!QueueUserAPC (dummy_apc_func, cpu->hThread,0 )) { +fprintf (stderr,"%s: QueueUserAPC failed with error %lu\n" , + __func__,GetLastError ()); +exit (1 ); + } + } +}
target/i386/meson.build +7 -2
@@ -31,8 +31,13 @@ i386_softmmu_ss.add(files( i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c')) i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files('whpx-all.c')) -i386_softmmu_ss.add(when: ['CONFIG_POSIX', 'CONFIG_HAX'], if_true: files('hax-all.c', 'hax-mem.c', 'hax-posix.c')) -i386_softmmu_ss.add(when: ['CONFIG_WIN32', 'CONFIG_HAX'], if_true: files('hax-all.c', 'hax-mem.c', 'hax-windows.c')) +i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files( + 'hax-all.c', + 'hax-mem.c', + 'hax-cpus.c', +)) +i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c')) +i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c')) subdir('hvf')
Signature · 1 line
2.26.2
PATCH v7 8/16 cpus: extract out whpx-specific code to target/i386/
In reply to Claudio Fontanaregister a "CpusAccel" interface for WHPX as well.
--- MAINTAINERS | 1 + softmmu/cpus.c | 79 --------------------------------- target/i386/meson.build | 5 ++- target/i386/whpx-all.c | 3 ++ target/i386/whpx-cpus.c | 96 +++++++++++++++++++++++++++++++++++++++++ target/i386/whpx-cpus.h | 17 ++++++++ 6 files changed, 121 insertions(+), 80 deletions(-) create mode 100644 target/i386/whpx-cpus.c create mode 100644 target/i386/whpx-cpus.h
MAINTAINERS +1 -0
@@ -451,6 +451,7 @@ WHPX CPUs M: Sunil Muthuswamy <[email protected]> S: Supported F: target/i386/whpx-all.c +F: target/i386/whpx-cpus.c F: target/i386/whp-dispatch.h F: accel/stubs/whpx-stub.c F: include/sysemu/whpx.h
softmmu/cpus.c +0 -79
133 lines not on this page · raw message
target/i386/meson.build +4 -1
@@ -30,7 +30,10 @@ i386_softmmu_ss.add(files( )) i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c')) i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) -i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files('whpx-all.c')) +i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files( + 'whpx-all.c', + 'whpx-cpus.c', +)) i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files( 'hax-all.c', 'hax-mem.c',
target/i386/whpx-all.c +3 -0
@@ -24,6 +24,8 @@#include "migration/blocker.h" #include "whp-dispatch.h" +#include "whpx-cpus.h" +#include <WinHvPlatform.h> #include <WinHvEmulation.h>
@@ -1575,6 +1577,7 @@ static int whpx_accel_init(MachineState *ms)whpx_memory_init (); cpu_interrupt_handler = whpx_handle_interrupt; +cpus_register_accel (&whpx_cpus);printf ("Windows Hypervisor Platform accelerator is operational\n" );return 0 ;
target/i386/whpx-cpus.c new file +96 -0
96 lines not on this page · raw message
target/i386/whpx-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 WHPX_CPUS_H +#define WHPX_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel whpx_cpus; + +#endif /* WHPX_CPUS_H */
Signature · 1 line
2.26.2
PATCH v7 9/16 cpus: extract out hvf-specific code to target/i386/hvf/
In reply to Claudio Fontanaregister a "CpusAccel" interface for HVF as well.
--- softmmu/cpus.c | 66 ------------------ target/i386/hvf/hvf-cpus.c | 131 ++++++++++++++++++++++++++++++++++++ target/i386/hvf/hvf-cpus.h | 17 +++++ target/i386/hvf/hvf.c | 3 + target/i386/hvf/meson.build | 1 + 5 files changed, 152 insertions(+), 66 deletions(-) create mode 100644 target/i386/hvf/hvf-cpus.c create mode 100644 target/i386/hvf/hvf-cpus.h
softmmu/cpus.c +0 -66
@@ -33,7 +33,6 @@#include "exec/gdbstub.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm.h" -#include "sysemu/hvf.h" #include "exec/exec-all.h" #include "qemu/thread.h" #include "qemu/plugin.h"
@@ -198,9 +197,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)if (cpus_accel && cpus_accel->synchronize_pre_loadvm) { cpus_accel->synchronize_pre_loadvm (cpu); } -if (hvf_enabled ()) { -hvf_cpu_synchronize_pre_loadvm (cpu); - } }int64_t cpus_get_virtual_clock (void )
@@ -390,48 +386,6 @@ void qemu_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } -/* The HVF-specific vCPU thread function. This one should only run when the host -* CPU supports the VMX "unrestricted guest" feature. */ -static void *qemu_hvf_cpu_thread_fn (void *arg) -{ -CPUState *cpu = arg; - -int r; - -assert (hvf_enabled ()); - -rcu_register_thread (); - -qemu_mutex_lock_iothread (); -qemu_thread_get_self (cpu->thread); - - cpu->thread_id =qemu_get_thread_id (); - cpu->can_do_io =1 ; - current_cpu = cpu; - -hvf_init_vcpu (cpu); - -/* signal CPU creation */ -cpu_thread_signal_created (cpu); -qemu_guest_random_seed_thread_part2 (cpu->random_seed); - -do { -if (cpu_can_run (cpu)) { - r =hvf_vcpu_exec (cpu); -if (r ==EXCP_DEBUG ) { -cpu_handle_guest_debug (cpu); - } - } -qemu_wait_io_event (cpu); - }while (!cpu->unplug ||cpu_can_run (cpu)); - -hvf_vcpu_destroy (cpu); -cpu_thread_signal_destroyed (cpu); -qemu_mutex_unlock_iothread (); -rcu_unregister_thread (); -return NULL ; -} -void cpus_kick_thread (CPUState *cpu) {#ifndef _WIN32
@@ -602,24 +556,6 @@ void cpu_remove_sync(CPUState *cpu)qemu_mutex_lock_iothread (); } -static void qemu_hvf_start_vcpu (CPUState *cpu) -{ -char thread_name[VCPU_THREAD_NAME_SIZE ]; - -/* HVF currently does not support TCG, and only runs in -* unrestricted-guest mode. */ -assert (hvf_enabled ()); - - cpu->thread =g_malloc0 (sizeof (QemuThread)); - cpu->halt_cond =g_malloc0 (sizeof (QemuCond)); -qemu_cond_init (cpu->halt_cond); - -snprintf (thread_name,VCPU_THREAD_NAME_SIZE ,"CPU %d/HVF" , - cpu->cpu_index); -qemu_thread_create (cpu->thread, thread_name, qemu_hvf_cpu_thread_fn, - cpu,QEMU_THREAD_JOINABLE ); -} -void cpus_register_accel (const CpusAccel *ca) {assert (ca !=NULL );
@@ -647,8 +583,6 @@ void qemu_init_vcpu(CPUState *cpu)if (cpus_accel) {/* accelerator already implements the CpusAccel interface */ cpus_accel->create_vcpu_thread (cpu); - }else if (hvf_enabled ()) { -qemu_hvf_start_vcpu (cpu); }else {g_assert_not_reached (); }
target/i386/hvf/hvf-cpus.c new file +131 -0
131 lines not on this page · raw message
target/i386/hvf/hvf-cpus.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Accelerator CPUS Interface +* +* Copyright 2020 SUSE LLC +* +* 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 HVF_CPUS_H +#define HVF_CPUS_H + +#include "sysemu/cpus.h" + +extern const CpusAccel hvf_cpus; + +#endif /* HVF_CPUS_H */
target/i386/hvf/hvf.c +3 -0
@@ -72,6 +72,8 @@#include "sysemu/accel.h" #include "target/i386/cpu.h" +#include "hvf-cpus.h" +HVFState *hvf_state;static void assert_hvf_ok (hv_return_t ret)
@@ -894,6 +896,7 @@ static int hvf_accel_init(MachineState *ms) hvf_state = s; cpu_interrupt_handler = hvf_handle_interrupt;memory_listener_register (&hvf_memory_listener, &address_space_memory); +cpus_register_accel (&hvf_cpus);return 0 ; }
target/i386/hvf/meson.build +1 -0
@@ -1,5 +1,6 @@ i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files( 'hvf.c', + 'hvf-cpus.c', 'x86.c', 'x86_cpuid.c', 'x86_decode.c',
Signature · 1 line
2.26.2
PATCH v7 10/16 cpus: cleanup now unneeded includes
In reply to Claudio Fontana--- softmmu/cpus.c | 7 ------- 1 file changed, 7 deletions(-)
softmmu/cpus.c +0 -7
@@ -29,20 +29,13 @@#include "qapi/qapi-commands-misc.h" #include "qapi/qapi-events-run-state.h" #include "qapi/qmp/qerror.h" -#include "sysemu/tcg.h" #include "exec/gdbstub.h" #include "sysemu/hw_accel.h" -#include "sysemu/kvm.h" #include "exec/exec-all.h" #include "qemu/thread.h" #include "qemu/plugin.h" #include "sysemu/cpus.h" -#include "qemu/main-loop.h" -#include "qemu/option.h" -#include "qemu/bitmap.h" -#include "qemu/seqlock.h" #include "qemu/guest-random.h" -#include "tcg/tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" #include "sysemu/runstate.h"
Signature · 1 line
2.26.2
PATCH v7 11/16 cpus: remove checks for non-NULL cpus_accel
In reply to Claudio Fontananow that all accelerators support the CpusAccel interface, we can remove most checks for non-NULL cpus_accel, we just add a sanity check/assert at vcpu creation.
--- softmmu/cpus.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
softmmu/cpus.c +21 -12
@@ -166,34 +166,46 @@ void cpu_synchronize_all_pre_loadvm(void)void cpu_synchronize_state (CPUState *cpu) { -if (cpus_accel && cpus_accel->synchronize_state) { +if (cpus_accel->synchronize_state) { cpus_accel->synchronize_state (cpu); } }void cpu_synchronize_post_reset (CPUState *cpu) { -if (cpus_accel && cpus_accel->synchronize_post_reset) { +if (cpus_accel->synchronize_post_reset) { cpus_accel->synchronize_post_reset (cpu); } }void cpu_synchronize_post_init (CPUState *cpu) { -if (cpus_accel && cpus_accel->synchronize_post_init) { +if (cpus_accel->synchronize_post_init) { cpus_accel->synchronize_post_init (cpu); } }void cpu_synchronize_pre_loadvm (CPUState *cpu) { -if (cpus_accel && cpus_accel->synchronize_pre_loadvm) { +if (cpus_accel->synchronize_pre_loadvm) { cpus_accel->synchronize_pre_loadvm (cpu); } }int64_t cpus_get_virtual_clock (void ) { +/* +* XXX +* +* need to check that cpus_accel is not NULL, because qcow2 calls +* qemu_get_clock_ns(CLOCK_VIRTUAL) without any accel initialized and +* with ticks disabled in some io-tests: +* 030 040 041 060 099 120 127 140 156 161 172 181 191 192 195 203 229 249 256 267 +* +* is this expected? +* +* XXX +*/ if (cpus_accel && cpus_accel->get_virtual_clock) {return cpus_accel->get_virtual_clock (); }
@@ -207,7 +219,7 @@ int64_t cpus_get_virtual_clock(void)*/ int64_t cpus_get_elapsed_ticks (void ) { -if (cpus_accel && cpus_accel->get_elapsed_ticks) { +if (cpus_accel->get_elapsed_ticks) {return cpus_accel->get_elapsed_ticks (); }return cpu_get_ticks ();
@@ -399,7 +411,7 @@ void cpus_kick_thread(CPUState *cpu)void qemu_cpu_kick (CPUState *cpu) {qemu_cond_broadcast (cpu->halt_cond); -if (cpus_accel && cpus_accel->kick_vcpu_thread) { +if (cpus_accel->kick_vcpu_thread) { cpus_accel->kick_vcpu_thread (cpu); }else {/* default */ cpus_kick_thread (cpu);
@@ -573,12 +585,9 @@ void qemu_init_vcpu(CPUState *cpu)cpu_address_space_init (cpu,0 ,"cpu-memory" , cpu->memory); } -if (cpus_accel) { -/* accelerator already implements the CpusAccel interface */ - cpus_accel->create_vcpu_thread (cpu); - }else { -g_assert_not_reached (); - } +/* accelerators all implement the CpusAccel interface */ +g_assert (cpus_accel !=NULL && cpus_accel->create_vcpu_thread !=NULL ); + cpus_accel->create_vcpu_thread (cpu);while (!cpu->created) {qemu_cond_wait (&qemu_cpu_cond, &qemu_global_mutex);
Signature · 1 line
2.26.2
PATCH v7 12/16 cpus: add handle_interrupt to the CpusAccel interface
In reply to Claudio Fontanakvm: uses the generic handler
qtest: uses the generic handler
whpx: changed to use the generic handler (identical implementation)
hax: changed to use the generic handler (identical implementation)
hvf: changed to use the generic handler (identical implementation)
tcg: adapt tcg-cpus to point to the tcg-specific handler
--- accel/tcg/tcg-all.c | 26 -------------------------- accel/tcg/tcg-cpus.c | 28 ++++++++++++++++++++++++++++ hw/core/cpu.c | 13 ------------- include/hw/core/cpu.h | 14 -------------- include/sysemu/cpus.h | 2 ++ softmmu/cpus.c | 18 ++++++++++++++++++ target/i386/hax-all.c | 10 ---------- target/i386/hvf/hvf.c | 9 --------- target/i386/whpx-all.c | 10 ---------- 9 files changed, 48 insertions(+), 82 deletions(-)
accel/tcg/tcg-all.c +0 -26
@@ -47,31 +47,6 @@ typedef struct TCGState {#define TCG_STATE (obj) \ OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) -/* mask must never be zero, except for A20 change call */ -static void tcg_handle_interrupt (CPUState *cpu,int mask) -{ -int old_mask; -g_assert (qemu_mutex_iothread_locked ()); - - old_mask = cpu->interrupt_request; - cpu->interrupt_request |= mask; - -/* -* If called from iothread context, wake the target cpu in -* case its halted. -*/ -if (!qemu_cpu_is_self (cpu)) { -qemu_cpu_kick (cpu); - }else { -atomic_set (&cpu_neg (cpu)->icount_decr.u16.high,-1 ); -if (icount_enabled () && - !cpu->can_do_io - && (mask & ~old_mask) !=0 ) { -cpu_abort (cpu,"Raised interrupt while not in I/O function" ); - } - } -} -/* * We default to false if we know other options have been enabled * which are currently incompatible with MTTCG. Otherwise when each
@@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)TCGState *s =TCG_STATE (current_accel ());tcg_exec_init (s->tb_size *1024 *1024 ); - cpu_interrupt_handler = tcg_handle_interrupt; mttcg_enabled = s->mttcg_enabled;cpus_register_accel (&tcg_cpus);
accel/tcg/tcg-cpus.c +28 -0
@@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)return cpu_get_ticks (); } +/* mask must never be zero, except for A20 change call */ +static void tcg_handle_interrupt (CPUState *cpu,int mask) +{ +int old_mask; +g_assert (qemu_mutex_iothread_locked ()); + + old_mask = cpu->interrupt_request; + cpu->interrupt_request |= mask; + +/* +* If called from iothread context, wake the target cpu in +* case its halted. +*/ +if (!qemu_cpu_is_self (cpu)) { +qemu_cpu_kick (cpu); + }else { +atomic_set (&cpu_neg (cpu)->icount_decr.u16.high,-1 ); +if (icount_enabled () && + !cpu->can_do_io + && (mask & ~old_mask) !=0 ) { +cpu_abort (cpu,"Raised interrupt while not in I/O function" ); + } + } +} +const CpusAccel tcg_cpus = { .create_vcpu_thread = tcg_start_vcpu_thread, .kick_vcpu_thread = tcg_kick_vcpu_thread, + + .handle_interrupt = tcg_handle_interrupt, + .get_virtual_clock = tcg_get_virtual_clock, .get_elapsed_ticks = tcg_get_elapsed_ticks, };
hw/core/cpu.c +0 -13
@@ -35,8 +35,6 @@#include "qemu/plugin.h" #include "sysemu/hw_accel.h" -CPUInterruptHandler cpu_interrupt_handler; -CPUState *cpu_by_arch_id (int64_t id) {CPUState *cpu;
@@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len)return addr; } -static void generic_handle_interrupt (CPUState *cpu,int mask) -{ - cpu->interrupt_request |= mask; - -if (!qemu_cpu_is_self (cpu)) { -qemu_cpu_kick (cpu); - } -} - -CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt; -static void cpu_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
include/hw/core/cpu.h +0 -14
@@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);*/ CPUState *cpu_by_arch_id (int64_t id); -#ifndef CONFIG_USER_ONLY - -typedef void (*CPUInterruptHandler )(CPUState *,int ); - -extern CPUInterruptHandler cpu_interrupt_handler; -/** * cpu_interrupt: * @cpu: The CPU to set an interrupt on.
@@ -851,17 +845,9 @@ extern CPUInterruptHandler cpu_interrupt_handler;* * Invokes the interrupt handler. */ -static inline void cpu_interrupt (CPUState *cpu,int mask) -{ -cpu_interrupt_handler (cpu, mask); -} - -#else /* USER_ONLY */ void cpu_interrupt (CPUState *cpu,int mask); -#endif /* USER_ONLY */ -#ifdef NEED_CPU_H #ifdef CONFIG_SOFTMMU
include/sysemu/cpus.h +2 -0
@@ -16,6 +16,8 @@ typedef struct CpusAccel {void (*synchronize_state)(CPUState *cpu);void (*synchronize_pre_loadvm)(CPUState *cpu); +void (*handle_interrupt)(CPUState *cpu,int mask); +int64_t (*get_virtual_clock)(void );int64_t (*get_elapsed_ticks)(void ); } CpusAccel;
softmmu/cpus.c +18 -0
@@ -225,6 +225,24 @@ int64_t cpus_get_elapsed_ticks(void)return cpu_get_ticks (); } +static void generic_handle_interrupt (CPUState *cpu,int mask) +{ + cpu->interrupt_request |= mask; + +if (!qemu_cpu_is_self (cpu)) { +qemu_cpu_kick (cpu); + } +} + +void cpu_interrupt (CPUState *cpu,int mask) +{ +if (cpus_accel->handle_interrupt) { + cpus_accel->handle_interrupt (cpu, mask); + }else { +generic_handle_interrupt (cpu, mask); + } +} +static int do_vm_stop (RunState state,bool send_stop) {int ret =0 ;
target/i386/hax-all.c +0 -10
@@ -297,15 +297,6 @@ int hax_vm_destroy(struct hax_vm *vm)return 0 ; } -static void hax_handle_interrupt (CPUState *cpu,int mask) -{ - cpu->interrupt_request |= mask; - -if (!qemu_cpu_is_self (cpu)) { -qemu_cpu_kick (cpu); - } -} -static int hax_init (ram_addr_t ram_size,int max_cpus) {struct hax_state *hax =NULL ;
@@ -350,7 +341,6 @@ static int hax_init(ram_addr_t ram_size, int max_cpus) qversion.cur_version = hax_cur_version; qversion.min_version = hax_min_version;hax_notify_qemu_version (hax->vm->fd, &qversion); - cpu_interrupt_handler = hax_handle_interrupt;return ret; error:
target/i386/hvf/hvf.c +0 -9
@@ -262,14 +262,6 @@ static void update_apic_tpr(CPUState *cpu)#define VECTORING_INFO_VECTOR_MASK 0xff -static void hvf_handle_interrupt (CPUState * cpu,int mask) -{ - cpu->interrupt_request |= mask; -if (!qemu_cpu_is_self (cpu)) { -qemu_cpu_kick (cpu); - } -} -void hvf_handle_io (CPUArchState *env,uint16_t port,void *buffer,int direction,int size,int count) {
@@ -894,7 +886,6 @@ static int hvf_accel_init(MachineState *ms) } hvf_state = s; - cpu_interrupt_handler = hvf_handle_interrupt;memory_listener_register (&hvf_memory_listener, &address_space_memory);cpus_register_accel (&hvf_cpus);return 0 ;
target/i386/whpx-all.c +0 -10
@@ -1413,15 +1413,6 @@ static void whpx_memory_init(void)memory_listener_register (&whpx_memory_listener, &address_space_memory); } -static void whpx_handle_interrupt (CPUState *cpu,int mask) -{ - cpu->interrupt_request |= mask; - -if (!qemu_cpu_is_self (cpu)) { -qemu_cpu_kick (cpu); - } -} -/* * Load the functions from the given library, using the given handle. If a * handle is provided, it is used, otherwise the library is opened. The
@@ -1576,7 +1567,6 @@ static int whpx_accel_init(MachineState *ms)whpx_memory_init (); - cpu_interrupt_handler = whpx_handle_interrupt;cpus_register_accel (&whpx_cpus);printf ("Windows Hypervisor Platform accelerator is operational\n" );
Signature · 1 line
2.26.2
PATCH v7 13/16 hvf: remove hvf specific functions from global includes
In reply to Claudio Fontana--- accel/stubs/hvf-stub.c | 30 ------------------------------ accel/stubs/meson.build | 1 - include/sysemu/hvf.h | 8 -------- target/i386/hvf/hvf-cpus.h | 8 ++++++++ target/i386/hvf/x86hvf.c | 2 ++ target/i386/hvf/x86hvf.h | 1 - 6 files changed, 10 insertions(+), 40 deletions(-) delete mode 100644 accel/stubs/hvf-stub.c
accel/stubs/hvf-stub.c deleted +0 -30
@@ -1,30 +0,0 @@ -/* -* QEMU HVF support -* -* Copyright 2017 Red Hat, Inc. -* -* This software is licensed under the terms of the GNU General Public -* License version 2 or later, as published by the Free Software Foundation, -* and may be copied, distributed, and modified under those terms. -* -* See the COPYING file in the top-level directory. -* -*/ - -#include "qemu/osdep.h" -#include "cpu.h" -#include "sysemu/hvf.h" - -int hvf_init_vcpu (CPUState *cpu) -{ -return -ENOSYS ; -} - -int hvf_vcpu_exec (CPUState *cpu) -{ -return -ENOSYS ; -} - -void hvf_vcpu_destroy (CPUState *cpu) -{ -}
accel/stubs/meson.build +0 -1
@@ -1,6 +1,5 @@ specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c')) specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c')) -specific_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c')) specific_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
include/sysemu/hvf.h +0 -8
@@ -25,14 +25,6 @@ extern bool hvf_allowed;#define hvf_get_supported_cpuid (func, idx, reg) 0#endif /* !CONFIG_HVF */ -int hvf_init_vcpu (CPUState *); -int hvf_vcpu_exec (CPUState *); -void hvf_cpu_synchronize_state (CPUState *); -void hvf_cpu_synchronize_post_reset (CPUState *); -void hvf_cpu_synchronize_post_init (CPUState *); -void hvf_cpu_synchronize_pre_loadvm (CPUState *); -void hvf_vcpu_destroy (CPUState *); -#define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")typedef struct HVFState HVFState ;
target/i386/hvf/hvf-cpus.h +8 -0
@@ -14,4 +14,12 @@extern const CpusAccel hvf_cpus; +int hvf_init_vcpu (CPUState *); +int hvf_vcpu_exec (CPUState *); +void hvf_cpu_synchronize_state (CPUState *); +void hvf_cpu_synchronize_post_reset (CPUState *); +void hvf_cpu_synchronize_post_init (CPUState *); +void hvf_cpu_synchronize_pre_loadvm (CPUState *); +void hvf_vcpu_destroy (CPUState *); +#endif /* HVF_CPUS_H */
target/i386/hvf/x86hvf.c +2 -0
@@ -32,6 +32,8 @@#include <Hypervisor/hv.h> #include <Hypervisor/hv_vmx.h> +#include "hvf-cpus.h" +void hvf_set_segment (struct CPUState *cpu,struct vmx_segment *vmx_seg,SegmentCache *qseg,bool is_tr) {
target/i386/hvf/x86hvf.h +0 -1
@@ -35,5 +35,4 @@ void hvf_get_msrs(CPUState *cpu_state);void vmx_clear_int_window_exiting (CPUState *cpu);void hvf_get_segments (CPUState *cpu_state);void vmx_update_tpr (CPUState *cpu); -void hvf_cpu_synchronize_state (CPUState *cpu_state);#endif
Signature · 1 line
2.26.2
PATCH v7 14/16 whpx: remove whpx specific functions from global includes
In reply to Claudio Fontana--- accel/stubs/meson.build | 1 - accel/stubs/whpx-stub.c | 47 ----------------------------------------- include/sysemu/whpx.h | 19 ----------------- target/i386/whpx-cpus.h | 17 +++++++++++++++ 4 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 accel/stubs/whpx-stub.c
accel/stubs/meson.build +0 -1
@@ -2,4 +2,3 @@ specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c')) specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c')) specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c')) -specific_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
accel/stubs/whpx-stub.c deleted +0 -47
47 lines not on this page · raw message
include/sysemu/whpx.h +0 -19
@@ -13,18 +13,6 @@#ifndef QEMU_WHPX_H #define QEMU_WHPX_H - -int whpx_init_vcpu (CPUState *cpu); -int whpx_vcpu_exec (CPUState *cpu); -void whpx_destroy_vcpu (CPUState *cpu); -void whpx_vcpu_kick (CPUState *cpu); - - -void whpx_cpu_synchronize_state (CPUState *cpu); -void whpx_cpu_synchronize_post_reset (CPUState *cpu); -void whpx_cpu_synchronize_post_init (CPUState *cpu); -void whpx_cpu_synchronize_pre_loadvm (CPUState *cpu); -#ifdef CONFIG_WHPX int whpx_enabled (void );
@@ -35,11 +23,4 @@ int whpx_enabled(void);#endif /* CONFIG_WHPX */ -/* state subset only touched by the VCPU itself during runtime */ -#define WHPX_SET_RUNTIME_STATE 1 -/* state subset modified during VCPU reset */ -#define WHPX_SET_RESET_STATE 2 -/* full state set, modified during initialization or on vmload */ -#define WHPX_SET_FULL_STATE 3 -#endif /* QEMU_WHPX_H */
target/i386/whpx-cpus.h +17 -0
@@ -14,4 +14,21 @@extern const CpusAccel whpx_cpus; +int whpx_init_vcpu (CPUState *cpu); +int whpx_vcpu_exec (CPUState *cpu); +void whpx_destroy_vcpu (CPUState *cpu); +void whpx_vcpu_kick (CPUState *cpu); + +void whpx_cpu_synchronize_state (CPUState *cpu); +void whpx_cpu_synchronize_post_reset (CPUState *cpu); +void whpx_cpu_synchronize_post_init (CPUState *cpu); +void whpx_cpu_synchronize_pre_loadvm (CPUState *cpu); + +/* state subset only touched by the VCPU itself during runtime */ +#define WHPX_SET_RUNTIME_STATE 1 +/* state subset modified during VCPU reset */ +#define WHPX_SET_RESET_STATE 2 +/* full state set, modified during initialization or on vmload */ +#define WHPX_SET_FULL_STATE 3 +#endif /* WHPX_CPUS_H */
Signature · 1 line
2.26.2
PATCH v7 15/16 hax: remove hax specific functions from global includes
In reply to Claudio Fontana--- accel/stubs/hax-stub.c | 10 ---------- include/sysemu/hax.h | 17 ----------------- target/i386/hax-all.c | 1 - target/i386/hax-cpus.c | 1 - target/i386/hax-cpus.h | 16 ++++++++++++++++ target/i386/hax-mem.c | 2 +- target/i386/hax-posix.c | 3 +-- target/i386/hax-windows.c | 2 +- target/i386/hax-windows.h | 2 ++ 9 files changed, 21 insertions(+), 33 deletions(-)
accel/stubs/hax-stub.c +0 -10
@@ -21,13 +21,3 @@ int hax_sync_vcpus(void) {return 0 ; } - -int hax_init_vcpu (CPUState *cpu) -{ -return -ENOSYS ; -} - -int hax_smp_cpu_exec (CPUState *cpu) -{ -return -ENOSYS ; -}
include/sysemu/hax.h +0 -17
@@ -22,29 +22,12 @@#ifndef QEMU_HAX_H #define QEMU_HAX_H -int hax_sync_vcpus (void ); -int hax_init_vcpu (CPUState *cpu); -int hax_smp_cpu_exec (CPUState *cpu); -int hax_populate_ram (uint64_t va,uint64_t size); - -void hax_cpu_synchronize_state (CPUState *cpu); -void hax_cpu_synchronize_post_reset (CPUState *cpu); -void hax_cpu_synchronize_post_init (CPUState *cpu); -void hax_cpu_synchronize_pre_loadvm (CPUState *cpu);#ifdef CONFIG_HAX int hax_enabled (void ); -#include "qemu/bitops.h" -#include "exec/memory.h" -int hax_vcpu_destroy (CPUState *cpu); -void hax_raise_event (CPUState *cpu); -void hax_reset_vcpu_state (void *opaque); -#include "target/i386/hax-interface.h" -#include "target/i386/hax-i386.h" -#else /* CONFIG_HAX */ #define hax_enabled () (0)
target/i386/hax-all.c +0 -1
@@ -28,7 +28,6 @@#include "exec/address-spaces.h" #include "qemu-common.h" -#include "hax-i386.h" #include "sysemu/accel.h" #include "sysemu/reset.h" #include "sysemu/runstate.h"
target/i386/hax-cpus.c +0 -1
@@ -22,7 +22,6 @@#include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" -#include "hax-i386.h" #include "sysemu/runstate.h" #include "sysemu/cpus.h" #include "qemu/guest-random.h"
target/i386/hax-cpus.h +16 -0
@@ -14,4 +14,20 @@extern const CpusAccel hax_cpus; +#include "hax-interface.h" +#include "hax-i386.h" + +int hax_init_vcpu (CPUState *cpu); +int hax_smp_cpu_exec (CPUState *cpu); +int hax_populate_ram (uint64_t va,uint64_t size); + +void hax_cpu_synchronize_state (CPUState *cpu); +void hax_cpu_synchronize_post_reset (CPUState *cpu); +void hax_cpu_synchronize_post_init (CPUState *cpu); +void hax_cpu_synchronize_pre_loadvm (CPUState *cpu); + +int hax_vcpu_destroy (CPUState *cpu); +void hax_raise_event (CPUState *cpu); +void hax_reset_vcpu_state (void *opaque); +#endif /* HAX_CPUS_H */
target/i386/hax-mem.c +1 -1
@@ -13,7 +13,7 @@#include "exec/address-spaces.h" #include "qemu/error-report.h" -#include "target/i386/hax-i386.h" +#include "hax-cpus.h" #include "qemu/queue.h" #define DEBUG_HAX_MEM 0
target/i386/hax-posix.c +1 -2
@@ -14,9 +14,8 @@#include "qemu/osdep.h" #include <sys/ioctl.h> -#include "target/i386/hax-i386.h" -#include "sysemu/cpus.h" +#include "hax-cpus.h" hax_fd hax_mod_open (void ) {
target/i386/hax-windows.c +1 -1
@@ -12,7 +12,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "hax-i386.h" +#include "hax-cpus.h" /* * return 0 when success, -1 when driver not loaded,
target/i386/hax-windows.h +2 -0
@@ -23,6 +23,8 @@#include <winioctl.h> #include <windef.h> +#include "hax-cpus.h" +#define HAX_INVALID_FD INVALID_HANDLE_VALUEstatic inline void hax_mod_close (struct hax_state *hax)
Signature · 1 line
2.26.2
PATCH v7 16/16 kvm: remove kvm specific functions from global includes
In reply to Claudio Fontana--- accel/kvm/kvm-cpus.h | 7 +++++++ accel/stubs/kvm-stub.c | 22 ---------------------- include/sysemu/kvm.h | 7 ------- 3 files changed, 7 insertions(+), 29 deletions(-)
accel/kvm/kvm-cpus.h +7 -0
@@ -14,4 +14,11 @@extern const CpusAccel kvm_cpus; +int kvm_init_vcpu (CPUState *cpu); +int kvm_cpu_exec (CPUState *cpu); +void kvm_destroy_vcpu (CPUState *cpu); +void kvm_cpu_synchronize_post_reset (CPUState *cpu); +void kvm_cpu_synchronize_post_init (CPUState *cpu); +void kvm_cpu_synchronize_pre_loadvm (CPUState *cpu); +#endif /* KVM_CPUS_H */
accel/stubs/kvm-stub.c +0 -22
@@ -32,15 +32,6 @@ bool kvm_readonly_mem_allowed;bool kvm_ioeventfd_any_length_allowed;bool kvm_msi_use_devid; -void kvm_destroy_vcpu (CPUState *cpu) -{ -} - -int kvm_init_vcpu (CPUState *cpu) -{ -return -ENOSYS ; -} -void kvm_flush_coalesced_mmio_buffer (void ) { }
@@ -49,19 +40,6 @@ void kvm_cpu_synchronize_state(CPUState *cpu) { } -void kvm_cpu_synchronize_post_reset (CPUState *cpu) -{ -} - -void kvm_cpu_synchronize_post_init (CPUState *cpu) -{ -} - -int kvm_cpu_exec (CPUState *cpu) -{ -abort (); -} -bool kvm_has_sync_mmu (void ) {return false;
include/sysemu/kvm.h +0 -7
@@ -222,10 +222,6 @@ int kvm_has_many_ioeventfds(void);int kvm_has_gsi_routing (void );int kvm_has_intx_set_mask (void ); -int kvm_init_vcpu (CPUState *cpu); -int kvm_cpu_exec (CPUState *cpu); -void kvm_destroy_vcpu (CPUState *cpu); -/** * kvm_arm_supports_user_irq *
@@ -485,9 +481,6 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,#endif /* NEED_CPU_H */ void kvm_cpu_synchronize_state (CPUState *cpu); -void kvm_cpu_synchronize_post_reset (CPUState *cpu); -void kvm_cpu_synchronize_post_init (CPUState *cpu); -void kvm_cpu_synchronize_pre_loadvm (CPUState *cpu);void kvm_init_cpu_signals (CPUState *cpu);
Signature · 1 line
2.26.2
btw not sure whose queues should these go through?
Thanks,
Claudio
Quoted 386 lines · Claudio Fontana
Motivation and higher level steps:
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
Current state is all reviewed, I think this is a good base to include at this point.
I had to fix one build issue in patch 1 that went undetected previously due to a meson thing (parallel build).Further work for future patches include:
* additional improvements to naming consistency in QEMU files. (Claudio, Alex, Roman)
* tcg vcpu start refactoring, providing then multiple structs for mttg, icount, normal. (Claudio, Alex)
* possible removal of NULL check for virtual clock if the qcow2 early call is solved. (Claudio, Paolo, Berto)
PATCH v6 -> PATCH v7:
* in patch "cpu-timers, icount: new modules":
- remove redundant double initialization of spice
- remove lingering calls toicount_getPATCH v5 -> PATCH v6:
* moved to mason build system
* patch (new): cpus: remove checks for non-NULL
cpus_accel(Richard)This has however a big caveat: in some cases the virtual clock is queried before an accelerator is set or ticks are enabled; this is currently special cased (keeping the NULL check in
cpus_get_virtual_clock), but maybe this should not happen at all? (Paolo, Berto)* in patch "cpu-timers, icount: new modules"
do not change (yet)icount_enabled()to a function. Mimic instead what is done withtcg_enabled(). (Richard)* split the changes into two separate patches, with name-only changes extracted out into a separate patch (Richard).
Removed existing Reviewed-by because of these changes (Alex)- Alex are you ok with them?* in patch "cpus: prepare new CpusAccel cpu accelerator interface" remove some unneeded stubs from
stubs/cpu-synchronize-state.cUse const for the CpusAccel interface. (Richard)* in patch "cpus: extract out TCG-specific code to accel/tcg" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out qtest-specific code to accel/qtest" use const for the CpusAccel interface;
useg_assert_not_reached(Richard)* in patch "cpus: extract out kvm-specific code to accel/kvm" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hax-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out whpx-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hvf-specific code to target/i386/hvf/" use const for the CpusAccel interface. (Richard)
RFC v4 -> PATCH v5:
* in patch 2, move comment about
cpus_get_elapsed_ticksfrom patch 3 (Philippe)* in patch 11-14, do not create separate
xxx-int.hfiles, instead use thexxx-cpus.hfiles (Philippe)RFC v3 -> v4:
* added patch 9: cleanup unneeded includes
* added patch 10: add
handle_interruptto the interface (Roman)* added patch 11-14: remove accelerator specific internal functions from global includes (Roman)
* in patch 2, removed leftover "if
hvf_enabled" hunk* in patch 2, convert if (!tcg_enabled) with more punctual if (
hax_enabled) when eating dummy APC----
RFC v2 -> v3:
* provided defaults for all methods.
Onlycreate_vcpu_threadis now a mandatory field. (Paolo)* separated new CpusAccel patch from its first user, new patch nr. 2:
"cpus: prepare new CpusAccel cpu accelerator interface"* new CpusAccel methods:
get_virtual_clockandget_elapsed_ticks. (Paolo)In this series,
get_virtual_clockhas a separate implementation between TCG/icount and qtest,
whileget_elapsed_ticksonly returns a virtual counter for icount.Looking for more comments in this area.
----
RFC v1 -> v2:
* split the
cpus.caccelerator refactoring into 6 patches.* other minor changes to be able to proceed step by step.
----
* Rebased on commit
255ae6e2158c743717bed76c9a2365ee4bcd326e, "replay: notify the main loop when there are no instructions"[SPLIT into part1 and part2]
----
v6 -> v7:
* rebased changes on top of Pavel Dovgalyuk changes to
dma-helpers.c"icount: make dma reads deterministic"----
v5 -> v6:
* rebased changes on top of Emilio G. Cota changes to
cpus.c"cpu: convert queued work to a QSIMPLEQ"* keep a pointer in
cpus.cinstead of a copy of CpusAccel (Alex)----
v4 -> v5: rebase on latest master
* rebased changes on top of roman series to remove one of the extra states for hvf. (Is the result now functional for HVF?)
* rebased changes on top of icount changes and fixes to
icount_configureand the new shift vmstate. (Markus)v3 -> v4:
* overall: added copyright headers to all files that were missing them (used copyright and license of the module the stuff was extracted from). For the new interface files, added SUSE LLC.
* 1/4 (move softmmu only files from root):
MAINTAINERS: movedsoftmmu/cpus.cto its final location (from patch 2)* 2/4 (cpu-throttle):
MAINTAINERS(to patch 1),
copyright Fabrice Bellard and license fromcpus.c* 3/4 (cpu-timers, icount):
-
MAINTAINERS: addcpu-timers.candicount.cto Paolo- break very long lines (patchew)
- add copyright SUSE LLC, GPLv2 to
cpu-timers.h- add copyright Fabrice Bellard and license from
cpus.ctotimers-state.has it is lifted fromcpus.c-
vl.c: inconfigure_acceleratorsbail out ificount_enabled()and !tcg_enabled() as qtest does not enable icount anymore.* 4/4 (accel stuff to accel):
- add copyright SUSE LLC to files that mostly only consist of the new interface. Add whatever copyright was in the accelerator code if instead they mostly consist of accelerator code.
- change a comment to mention the result of the AccelClass experiment
- moved qtest accelerator into accel/qtest/ , make it like the others.
- rename xxx-cpus-interface to xxx-cpus (remove "interface" from names)
- rename
accel_inttocpus_accel- rename CpusAccel functions from cpu_synchronize_* to synchronize_*
--------
v2 -> v3:
* turned into a 4 patch series, adding a first patch moving softmmu code currently in
top_srcdirto softmmu/* cpu-throttle: moved to softmmu/
* cpu-timers, icount:
- moved to softmmu/
- fixed assumption of
qtest_enabled()=>icount_enabled()causing the failure of check-qtest-arm goal, intest-arm-mptimer.cFix is in
hw/core/ptimer.c,where the artificial timeout rate limit should not be applied under
qtest_enabled(), in a similar way to how it is not applied foricount_enabled().* CpuAccelInterface: no change.
--------
v1 -> v2:
* 1/3 (cpu-throttle): provide a description in the commit message
* 2/3 (cpu-timers, icount): in this v2 separate icount from cpu-timers, as icount is actually TCG-specific. Only build it under
CONFIG_TCG.To do this, qtest had to be detached from icount. To this end, a trivial global counter for qtest has been introduced.
* 3/3 (CpuAccelInterface): provided a description.
This is point 8) in that plan. The idea is to extract the unrelated parts in cpus, and register interfaces from each single accelerator to the main cpus module (
cpus.c).While doing this RFC, I noticed some assumptions about Windows being either TCG or HAX (not considering WHPX) that might need to be revisited. I added a comment there.
The thing builds successfully based on Linux cross-compilations for windows/hax, windows/whpx, and I got a good build on Darwin/hvf.
Tests run successully for tcg and kvm configurations, but did not test on windows or darwin.
Welcome your feedback and help on this,
Claudio
Claudio Fontana (16):
cpu-timers, icount: new modules
icount: rename functions to be consistent with the module name
cpus: prepare new CpusAccel cpu accelerator interface
cpus: extract out TCG-specific code to accel/tcg
cpus: extract out qtest-specific code to accel/qtest
cpus: extract out kvm-specific code to accel/kvm
cpus: extract out hax-specific code to target/i386/
cpus: extract out whpx-specific code to target/i386/
cpus: extract out hvf-specific code to target/i386/hvf/
cpus: cleanup now unneeded includes
cpus: remove checks for non-NULLcpus_accel
cpus: addhandle_interruptto the CpusAccel interface
hvf: remove hvf specific functions from global includes
whpx: remove whpx specific functions from global includes
hax: remove hax specific functions from global includes
kvm: remove kvm specific functions from global includesMAINTAINERS | 5 +- accel/kvm/kvm-all.c | 14 +- accel/kvm/kvm-cpus.c | 88 ++ accel/kvm/kvm-cpus.h | 24 + accel/kvm/meson.build | 5 +- accel/meson.build | 2 +- accel/qtest/meson.build | 7 + accel/qtest/qtest-cpus.c | 91 ++ accel/qtest/qtest-cpus.h | 17 + accel/{ => qtest}/qtest.c | 13 +- accel/stubs/hax-stub.c | 10 - accel/stubs/hvf-stub.c | 30 - accel/stubs/kvm-stub.c | 23 - accel/stubs/meson.build | 2 - accel/stubs/whpx-stub.c | 47 - accel/tcg/cpu-exec.c | 43 +- accel/tcg/meson.build | 2 +- accel/tcg/tcg-all.c | 43 +- accel/tcg/tcg-cpus.c | 569 +++++++++++ accel/tcg/tcg-cpus.h | 17 + accel/tcg/translate-all.c | 3 +- dma-helpers.c | 4 +- docs/replay.txt | 6 +- exec.c | 4 - hw/core/cpu.c | 14 +- hw/core/ptimer.c | 8 +- hw/i386/x86.c | 3 +- include/exec/cpu-all.h | 4 + include/exec/exec-all.h | 4 +- include/hw/core/cpu.h | 14 - include/qemu/timer.h | 24 +- include/sysemu/cpu-timers.h | 90 ++ include/sysemu/cpus.h | 50 +- include/sysemu/hax.h | 17 - include/sysemu/hvf.h | 8 - include/sysemu/hw_accel.h | 69 +- include/sysemu/kvm.h | 7 - include/sysemu/qtest.h | 2 + include/sysemu/replay.h | 4 +- include/sysemu/whpx.h | 19 - replay/replay.c | 6 +- softmmu/cpu-timers.c | 279 ++++++ softmmu/cpus.c | 1697 +++----------------------------- softmmu/icount.c | 492 +++++++++ softmmu/meson.build | 10 +- softmmu/qtest.c | 34 +- softmmu/timers-state.h | 69 ++ softmmu/vl.c | 8 +- stubs/clock-warp.c | 7 - stubs/cpu-get-clock.c | 3 +- stubs/cpu-get-icount.c | 21 - stubs/cpu-synchronize-state.c | 9 + stubs/cpus-get-virtual-clock.c | 8 + stubs/icount.c | 45 + stubs/meson.build | 6 +- stubs/qemu-timer-notify-cb.c | 8 + stubs/qtest.c | 5 + target/alpha/translate.c | 3 +- target/arm/helper.c | 7 +- target/i386/hax-all.c | 17 +- target/i386/hax-cpus.c | 84 ++ target/i386/hax-cpus.h | 33 + target/i386/hax-i386.h | 2 + target/i386/hax-mem.c | 2 +- target/i386/hax-posix.c | 13 +- target/i386/hax-windows.c | 22 +- target/i386/hax-windows.h | 2 + target/i386/hvf/hvf-cpus.c | 131 +++ target/i386/hvf/hvf-cpus.h | 25 + target/i386/hvf/hvf.c | 12 +- target/i386/hvf/meson.build | 1 + target/i386/hvf/x86hvf.c | 2 + target/i386/hvf/x86hvf.h | 1 - target/i386/meson.build | 14 +- target/i386/whpx-all.c | 13 +- target/i386/whpx-cpus.c | 96 ++ target/i386/whpx-cpus.h | 34 + target/riscv/csr.c | 8 +- tests/ptimer-test-stubs.c | 5 +- tests/test-timed-average.c | 2 +- util/main-loop.c | 12 +- util/qemu-timer.c | 14 +- 82 files changed, 2637 insertions(+), 2031 deletions(-) create mode 100644 accel/kvm/kvm-cpus.c create mode 100644 accel/kvm/kvm-cpus.h create mode 100644 accel/qtest/meson.build create mode 100644 accel/qtest/qtest-cpus.c create mode 100644 accel/qtest/qtest-cpus.h rename accel/{ => qtest}/qtest.c (81%) delete mode 100644 accel/stubs/hvf-stub.c delete mode 100644 accel/stubs/whpx-stub.c create mode 100644 accel/tcg/tcg-cpus.c create mode 100644 accel/tcg/tcg-cpus.h create mode 100644 include/sysemu/cpu-timers.h create mode 100644 softmmu/cpu-timers.c create mode 100644 softmmu/icount.c create mode 100644 softmmu/timers-state.h delete mode 100644 stubs/clock-warp.c delete mode 100644 stubs/cpu-get-icount.c create mode 100644 stubs/cpu-synchronize-state.c create mode 100644 stubs/cpus-get-virtual-clock.c create mode 100644 stubs/icount.c create mode 100644 stubs/qemu-timer-notify-cb.c create mode 100644 target/i386/hax-cpus.c create mode 100644 target/i386/hax-cpus.h create mode 100644 target/i386/hvf/hvf-cpus.c create mode 100644 target/i386/hvf/hvf-cpus.h create mode 100644 target/i386/whpx-cpus.c create mode 100644 target/i386/whpx-cpus.h
Il ven 4 set 2020, 18:08 Claudio Fontana <[email protected]> ha scritto:
Quoted 2 lines
btw not sure whose queues should these go through?
I can take this; the dust from the meson merge should settle soon.
Paolo
Quoted 403 lines
Thanks,
Claudio
Quoted 7 lines · Claudio Fontana
Motivation and higher level steps:
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
Current state is all reviewed, I think this is a good base to include at this point.
I had to fix one build issue in patch 1 that went undetected previouslydue to
Quoted 5 lines
a meson thing (parallel build).
Further work for future patches include:
* additional improvements to naming consistency in QEMU files. (Claudio,
Alex, Roman)
Quoted 2 lines
* tcg vcpu start refactoring, providing then multiple structs for mttg,
icount, normal.
Quoted 3 lines
(Claudio, Alex)
* possible removal of NULL check for virtual clock if the qcow2 early
call is solved.
Quoted 10 lines
(Claudio, Paolo, Berto)
PATCH v6 -> PATCH v7:
* in patch "cpu-timers, icount: new modules":
- remove redundant double initialization of spice
- remove lingering calls toicount_getPATCH v5 -> PATCH v6:
Quoted 7 lines
* moved to mason build system
* patch (new): cpus: remove checks for non-NULL
cpus_accel(Richard)This has however a big caveat: in some cases the virtual clock is queried before an accelerator is set or ticks are enabled; this is currently special cased (keeping the NULL check in
cpus_get_virtual_clock),Quoted 47 lines
but maybe this should not happen at all? (Paolo, Berto)
* in patch "cpu-timers, icount: new modules"
do not change (yet)icount_enabled()to a function. Mimic instead what is done withtcg_enabled(). (Richard)* split the changes into two separate patches, with name-only changes extracted out into a separate patch (Richard).
Removed existing Reviewed-by because of these changes (Alex)- Alex are you ok with them?* in patch "cpus: prepare new CpusAccel cpu accelerator interface" remove some unneeded stubs from
stubs/cpu-synchronize-state.cUse const for the CpusAccel interface. (Richard)* in patch "cpus: extract out TCG-specific code to accel/tcg" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out qtest-specific code to accel/qtest" use const for the CpusAccel interface;
useg_assert_not_reached(Richard)* in patch "cpus: extract out kvm-specific code to accel/kvm" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hax-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out whpx-specific code to target/i386/" use const for the CpusAccel interface. (Richard)
* in patch "cpus: extract out hvf-specific code to target/i386/hvf/" use const for the CpusAccel interface. (Richard)
RFC v4 -> PATCH v5:
* in patch 2, move comment about
cpus_get_elapsed_ticksfrom patch 3 (Philippe)* in patch 11-14, do not create separate
xxx-int.hfiles, instead use thexxx-cpus.hfiles (Philippe)RFC v3 -> v4:
* added patch 9: cleanup unneeded includes
Quoted 8 lines
* added patch 10: add
handle_interruptto the interface (Roman)* added patch 11-14: remove accelerator specific internal functions from global includes (Roman)
* in patch 2, removed leftover "if
hvf_enabled" hunk* in patch 2, convert if (!tcg_enabled) with more punctual if
(
hax_enabled)Quoted 53 lines
when eating dummy APC
----
RFC v2 -> v3:
* provided defaults for all methods.
Onlycreate_vcpu_threadis now a mandatory field. (Paolo)* separated new CpusAccel patch from its first user, new patch nr. 2:
"cpus: prepare new CpusAccel cpu accelerator interface"* new CpusAccel methods:
get_virtual_clockandget_elapsed_ticks. (Paolo)In this series,
get_virtual_clockhas a separate implementation between TCG/icount and qtest,
whileget_elapsed_ticksonly returns a virtual counter for icount.Looking for more comments in this area.
----
RFC v1 -> v2:
* split the
cpus.caccelerator refactoring into 6 patches.* other minor changes to be able to proceed step by step.
----
* Rebased on commit
255ae6e2158c743717bed76c9a2365ee4bcd326e, "replay: notify the main loop when there are no instructions"[SPLIT into part1 and part2]
----
v6 -> v7:
* rebased changes on top of Pavel Dovgalyuk changes to
dma-helpers.c"icount: make dma reads deterministic"----
v5 -> v6:
* rebased changes on top of Emilio G. Cota changes to
cpus.c"cpu: convert queued work to a QSIMPLEQ"* keep a pointer in
cpus.cinstead of a copy of CpusAccel (Alex)Quoted 6 lines
----
v4 -> v5: rebase on latest master
* rebased changes on top of roman series to remove one of the extra
states for hvf.
Quoted 3 lines
(Is the result now functional for HVF?)
* rebased changes on top of icount changes and fixes to
icount_configureand
Quoted 6 lines
the new shift vmstate. (Markus)
v3 -> v4:
* overall: added copyright headers to all files that were missing them (used copyright and license of the module the stuff was extracted
from).
Quoted 13 lines
For the new interface files, added SUSE LLC.
* 1/4 (move softmmu only files from root):
MAINTAINERS: movedsoftmmu/cpus.cto its final location (from patch 2)* 2/4 (cpu-throttle):
MAINTAINERS(to patch 1),
copyright Fabrice Bellard and license fromcpus.c* 3/4 (cpu-timers, icount):
Quoted 7 lines
-
MAINTAINERS: addcpu-timers.candicount.cto Paolo- break very long lines (patchew)
- add copyright SUSE LLC, GPLv2 to
cpu-timers.h- add copyright Fabrice Bellard and license from
cpus.cto
timers-state.hQuoted 209 lines
as it is lifted from
cpus.c-
vl.c: inconfigure_acceleratorsbail out ificount_enabled()and !tcg_enabled() as qtest does not enable icount anymore.* 4/4 (accel stuff to accel):
- add copyright SUSE LLC to files that mostly only consist of the new interface. Add whatever copyright was in the accelerator code if instead they mostly consist of accelerator code.
- change a comment to mention the result of the AccelClass experiment
- moved qtest accelerator into accel/qtest/ , make it like the others.
- rename xxx-cpus-interface to xxx-cpus (remove "interface" from names)
- rename
accel_inttocpus_accel- rename CpusAccel functions from cpu_synchronize_* to synchronize_*
--------
v2 -> v3:
* turned into a 4 patch series, adding a first patch moving softmmu code currently in
top_srcdirto softmmu/* cpu-throttle: moved to softmmu/
* cpu-timers, icount:
- moved to softmmu/
- fixed assumption of
qtest_enabled()=>icount_enabled()causing the failure of check-qtest-arm goal, intest-arm-mptimer.cFix is in
hw/core/ptimer.c,where the artificial timeout rate limit should not be applied under
qtest_enabled(), in a similar way to how it is not applied foricount_enabled().* CpuAccelInterface: no change.
--------
v1 -> v2:
* 1/3 (cpu-throttle): provide a description in the commit message
* 2/3 (cpu-timers, icount): in this v2 separate icount from cpu-timers, as icount is actually TCG-specific. Only build it under
CONFIG_TCG.To do this, qtest had to be detached from icount. To this end, a trivial global counter for qtest has been introduced.
* 3/3 (CpuAccelInterface): provided a description.
This is point 8) in that plan. The idea is to extract the unrelated parts in cpus, and register interfaces from each single accelerator to the main cpus module (
cpus.c).While doing this RFC, I noticed some assumptions about Windows being either TCG or HAX (not considering WHPX) that might need to be revisited. I added a comment there.
The thing builds successfully based on Linux cross-compilations for windows/hax, windows/whpx, and I got a good build on Darwin/hvf.
Tests run successully for tcg and kvm configurations, but did not test on windows or darwin.
Welcome your feedback and help on this,
Claudio
Claudio Fontana (16):
cpu-timers, icount: new modules
icount: rename functions to be consistent with the module name
cpus: prepare new CpusAccel cpu accelerator interface
cpus: extract out TCG-specific code to accel/tcg
cpus: extract out qtest-specific code to accel/qtest
cpus: extract out kvm-specific code to accel/kvm
cpus: extract out hax-specific code to target/i386/
cpus: extract out whpx-specific code to target/i386/
cpus: extract out hvf-specific code to target/i386/hvf/
cpus: cleanup now unneeded includes
cpus: remove checks for non-NULLcpus_accel
cpus: addhandle_interruptto the CpusAccel interface
hvf: remove hvf specific functions from global includes
whpx: remove whpx specific functions from global includes
hax: remove hax specific functions from global includes
kvm: remove kvm specific functions from global includesMAINTAINERS | 5 +- accel/kvm/kvm-all.c | 14 +- accel/kvm/kvm-cpus.c | 88 ++ accel/kvm/kvm-cpus.h | 24 + accel/kvm/meson.build | 5 +- accel/meson.build | 2 +- accel/qtest/meson.build | 7 + accel/qtest/qtest-cpus.c | 91 ++ accel/qtest/qtest-cpus.h | 17 + accel/{ => qtest}/qtest.c | 13 +- accel/stubs/hax-stub.c | 10 - accel/stubs/hvf-stub.c | 30 - accel/stubs/kvm-stub.c | 23 - accel/stubs/meson.build | 2 - accel/stubs/whpx-stub.c | 47 - accel/tcg/cpu-exec.c | 43 +- accel/tcg/meson.build | 2 +- accel/tcg/tcg-all.c | 43 +- accel/tcg/tcg-cpus.c | 569 +++++++++++ accel/tcg/tcg-cpus.h | 17 + accel/tcg/translate-all.c | 3 +- dma-helpers.c | 4 +- docs/replay.txt | 6 +- exec.c | 4 - hw/core/cpu.c | 14 +- hw/core/ptimer.c | 8 +- hw/i386/x86.c | 3 +- include/exec/cpu-all.h | 4 + include/exec/exec-all.h | 4 +- include/hw/core/cpu.h | 14 - include/qemu/timer.h | 24 +- include/sysemu/cpu-timers.h | 90 ++ include/sysemu/cpus.h | 50 +- include/sysemu/hax.h | 17 - include/sysemu/hvf.h | 8 - include/sysemu/hw_accel.h | 69 +- include/sysemu/kvm.h | 7 - include/sysemu/qtest.h | 2 + include/sysemu/replay.h | 4 +- include/sysemu/whpx.h | 19 - replay/replay.c | 6 +- softmmu/cpu-timers.c | 279 ++++++ softmmu/cpus.c | 1697 +++----------------------------- softmmu/icount.c | 492 +++++++++ softmmu/meson.build | 10 +- softmmu/qtest.c | 34 +- softmmu/timers-state.h | 69 ++ softmmu/vl.c | 8 +- stubs/clock-warp.c | 7 - stubs/cpu-get-clock.c | 3 +- stubs/cpu-get-icount.c | 21 - stubs/cpu-synchronize-state.c | 9 + stubs/cpus-get-virtual-clock.c | 8 + stubs/icount.c | 45 + stubs/meson.build | 6 +- stubs/qemu-timer-notify-cb.c | 8 + stubs/qtest.c | 5 + target/alpha/translate.c | 3 +- target/arm/helper.c | 7 +- target/i386/hax-all.c | 17 +- target/i386/hax-cpus.c | 84 ++ target/i386/hax-cpus.h | 33 + target/i386/hax-i386.h | 2 + target/i386/hax-mem.c | 2 +- target/i386/hax-posix.c | 13 +- target/i386/hax-windows.c | 22 +- target/i386/hax-windows.h | 2 + target/i386/hvf/hvf-cpus.c | 131 +++ target/i386/hvf/hvf-cpus.h | 25 + target/i386/hvf/hvf.c | 12 +- target/i386/hvf/meson.build | 1 + target/i386/hvf/x86hvf.c | 2 + target/i386/hvf/x86hvf.h | 1 - target/i386/meson.build | 14 +- target/i386/whpx-all.c | 13 +- target/i386/whpx-cpus.c | 96 ++ target/i386/whpx-cpus.h | 34 + target/riscv/csr.c | 8 +- tests/ptimer-test-stubs.c | 5 +- tests/test-timed-average.c | 2 +- util/main-loop.c | 12 +- util/qemu-timer.c | 14 +- 82 files changed, 2637 insertions(+), 2031 deletions(-) create mode 100644 accel/kvm/kvm-cpus.c create mode 100644 accel/kvm/kvm-cpus.h create mode 100644 accel/qtest/meson.build create mode 100644 accel/qtest/qtest-cpus.c create mode 100644 accel/qtest/qtest-cpus.h rename accel/{ => qtest}/qtest.c (81%) delete mode 100644 accel/stubs/hvf-stub.c delete mode 100644 accel/stubs/whpx-stub.c create mode 100644 accel/tcg/tcg-cpus.c create mode 100644 accel/tcg/tcg-cpus.h create mode 100644 include/sysemu/cpu-timers.h create mode 100644 softmmu/cpu-timers.c create mode 100644 softmmu/icount.c create mode 100644 softmmu/timers-state.h delete mode 100644 stubs/clock-warp.c delete mode 100644 stubs/cpu-get-icount.c create mode 100644 stubs/cpu-synchronize-state.c create mode 100644 stubs/cpus-get-virtual-clock.c create mode 100644 stubs/icount.c create mode 100644 stubs/qemu-timer-notify-cb.c create mode 100644 target/i386/hax-cpus.c create mode 100644 target/i386/hax-cpus.h create mode 100644 target/i386/hvf/hvf-cpus.c create mode 100644 target/i386/hvf/hvf-cpus.h create mode 100644 target/i386/whpx-cpus.c create mode 100644 target/i386/whpx-cpus.h
Quoted 10 lines · Paolo Bonzini
Il ven 4 set 2020, 18:08 Claudio Fontana <[email protected] <mailto:[email protected]>> ha scritto:
btw not sure whose queues should these go through?
I can take this; the dust from the meson merge should settle soon.
Paolo
Thanks Paolo,
if it can help I try to keep a rebased functioning version at
https://github.com/hw-claudio/qemu.git "cpus-refactoring"
some of the CI complains about:
check: qemu-img not found
Makefile.mtest:1229: recipe for target 'check-block' failed
Ciao,
Claudio
Quoted 394 lines
Thanks,
Claudio
On 9/3/20 12:55 PM, Claudio Fontana wrote:
> Motivation and higher level steps:
>
> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
>
> Current state is all reviewed, I think this is a good base to
> include at this point.
> I had to fix one build issue in patch 1 that went undetected previously due to > a meson thing (parallel build).
>
> Further work for future patches include:
>
> * additional improvements to naming consistency in QEMU files. (Claudio, Alex, Roman) >
> * tcg vcpu start refactoring, providing then multiple structs for mttg, icount, normal. > (Claudio, Alex)
>
> * possible removal of NULL check for virtual clock if the qcow2 early call is solved. > (Claudio, Paolo, Berto)
>
> PATCH v6 -> PATCH v7:
>
> * in patch "cpu-timers, icount: new modules":
> - remove redundant double initialization of spice
> - remove lingering calls toicount_get
>
> PATCH v5 -> PATCH v6:
>
> * moved to mason build system
>
> * patch (new): cpus: remove checks for non-NULLcpus_accel(Richard)
>
> This has however a big caveat: in some cases the virtual clock is
> queried before an accelerator is set or ticks are enabled; this is
> currently special cased (keeping the NULL check incpus_get_virtual_clock), > but maybe this should not happen at all? (Paolo, Berto)
>
> * in patch "cpu-timers, icount: new modules"
> do not change (yet)icount_enabled()to a function.
> Mimic instead what is done withtcg_enabled(). (Richard)
>
> * split the changes into two separate patches, with name-only changes
> extracted out into a separate patch (Richard).
> Removed existing Reviewed-by because of these changes (Alex)-
> Alex are you ok with them?
>
> * in patch "cpus: prepare new CpusAccel cpu accelerator interface"
> remove some unneeded stubs fromstubs/cpu-synchronize-state.c
> Use const for the CpusAccel interface. (Richard)
>
> * in patch "cpus: extract out TCG-specific code to accel/tcg"
> use const for the CpusAccel interface. (Richard)
>
> * in patch "cpus: extract out qtest-specific code to accel/qtest"
> use const for the CpusAccel interface;
> useg_assert_not_reached(Richard)
>
> * in patch "cpus: extract out kvm-specific code to accel/kvm"
> use const for the CpusAccel interface. (Richard)
>
> * in patch "cpus: extract out hax-specific code to target/i386/"
> use const for the CpusAccel interface. (Richard)
>
> * in patch "cpus: extract out whpx-specific code to target/i386/"
> use const for the CpusAccel interface. (Richard)
>
> * in patch "cpus: extract out hvf-specific code to target/i386/hvf/"
> use const for the CpusAccel interface. (Richard)
>
>
> RFC v4 -> PATCH v5:
>
> * in patch 2, move comment aboutcpus_get_elapsed_ticksfrom patch 3
> (Philippe)
>
> * in patch 11-14, do not create separatexxx-int.hfiles,
> instead use thexxx-cpus.hfiles (Philippe)
>
> RFC v3 -> v4:
>
> * added patch 9: cleanup unneeded includes
>
> * added patch 10: addhandle_interruptto the interface (Roman)
>
> * added patch 11-14: remove accelerator specific internal functions
> from global includes (Roman)
>
> * in patch 2, removed leftover "ifhvf_enabled" hunk
>
> * in patch 2, convert if (!tcg_enabled) with more punctual if (hax_enabled) > when eating dummy APC
>
> ----
>
> RFC v2 -> v3:
>
> * provided defaults for all methods.
> Onlycreate_vcpu_threadis now a mandatory field. (Paolo)
>
> * separated new CpusAccel patch from its first user, new patch nr. 2:
> "cpus: prepare new CpusAccel cpu accelerator interface"
>
> * new CpusAccel methods:get_virtual_clockandget_elapsed_ticks.
> (Paolo)
>
> In this series,get_virtual_clockhas a separate implementation
> between TCG/icount and qtest,
> whileget_elapsed_ticksonly returns a virtual counter for icount.
>
> Looking for more comments in this area.
>
> ----
>
> RFC v1 -> v2:
>
> * split thecpus.caccelerator refactoring into 6 patches.
>
> * other minor changes to be able to proceed step by step.
>
> ----
>
> * Rebased on commit255ae6e2158c743717bed76c9a2365ee4bcd326e,
> "replay: notify the main loop when there are no instructions"
>
> [SPLIT into part1 and part2]
>
> ----
>
> v6 -> v7:
>
> * rebased changes on top of Pavel Dovgalyuk changes todma-helpers.c
> "icount: make dma reads deterministic"
>
> ----
>
> v5 -> v6:
>
> * rebased changes on top of Emilio G. Cota changes tocpus.c
> "cpu: convert queued work to a QSIMPLEQ"
>
> * keep a pointer incpus.cinstead of a copy of CpusAccel
> (Alex)
>
> ----
>
>
> v4 -> v5: rebase on latest master
>
> * rebased changes on top of roman series to remove one of the extra states for hvf. > (Is the result now functional for HVF?)
>
> * rebased changes on top of icount changes and fixes toicount_configureand > the new shift vmstate. (Markus)
>
> v3 -> v4:
>
> * overall: added copyright headers to all files that were missing them
> (used copyright and license of the module the stuff was extracted from). > For the new interface files, added SUSE LLC.
>
> * 1/4 (move softmmu only files from root):
>
> MAINTAINERS: movedsoftmmu/cpus.cto its final location (from patch 2) >
> * 2/4 (cpu-throttle):
>
> MAINTAINERS (to patch 1),
> copyright Fabrice Bellard and license fromcpus.c
>
> * 3/4 (cpu-timers, icount):
>
> -MAINTAINERS: addcpu-timers.candicount.cto Paolo
>
> - break very long lines (patchew)
>
> - add copyright SUSE LLC, GPLv2 tocpu-timers.h
>
> - add copyright Fabrice Bellard and license fromcpus.ctotimers-state.h> as it is lifted fromcpus.c
>
> -vl.c: inconfigure_acceleratorsbail out ificount_enabled()
> and !tcg_enabled() as qtest does not enable icount anymore.
>
> * 4/4 (accel stuff to accel):
>
> - add copyright SUSE LLC to files that mostly only consist of the
> new interface. Add whatever copyright was in the accelerator code
> if instead they mostly consist of accelerator code.
>
> - change a comment to mention the result of the AccelClass experiment >
> - moved qtest accelerator into accel/qtest/ , make it like the others. >
> - rename xxx-cpus-interface to xxx-cpus (remove "interface" from names) >
> - renameaccel_inttocpus_accel
>
> - rename CpusAccel functions from cpu_synchronize_* to synchronize_*
>
>
> --------
>
> v2 -> v3:
>
> * turned into a 4 patch series, adding a first patch moving
> softmmu code currently intop_srcdirto softmmu/
>
> * cpu-throttle: moved to softmmu/
>
> * cpu-timers, icount:
>
> - moved to softmmu/
>
> - fixed assumption ofqtest_enabled()=>icount_enabled()
> causing the failure of check-qtest-arm goal, intest-arm-mptimer.c
>
> Fix is inhw/core/ptimer.c,
>
> where the artificial timeout rate limit should not be applied
> underqtest_enabled(), in a similar way to how it is not applied
> foricount_enabled().
>
> * CpuAccelInterface: no change.
>
>
> --------
>
>
> v1 -> v2:
>
> * 1/3 (cpu-throttle): provide a description in the commit message
>
> * 2/3 (cpu-timers, icount): in this v2 separate icount from cpu-timers, > as icount is actually TCG-specific. Only build it underCONFIG_TCG.
>
> To do this, qtest had to be detached from icount. To this end, a
> trivial global counter for qtest has been introduced.
>
> * 3/3 (CpuAccelInterface): provided a description.
>
> This is point 8) in that plan. The idea is to extract the unrelated parts > in cpus, and register interfaces from each single accelerator to the main > cpus module (cpus.c).
>
> While doing this RFC, I noticed some assumptions about Windows being
> either TCG or HAX (not considering WHPX) that might need to be revisited. > I added a comment there.
>
> The thing builds successfully based on Linux cross-compilations for
> windows/hax, windows/whpx, and I got a good build on Darwin/hvf.
>
> Tests run successully for tcg and kvm configurations, but did not test on > windows or darwin.
>
> Welcome your feedback and help on this,
>
> Claudio
>
>
> Claudio Fontana (16):
> cpu-timers, icount: new modules
> icount: rename functions to be consistent with the module name
> cpus: prepare new CpusAccel cpu accelerator interface
> cpus: extract out TCG-specific code to accel/tcg
> cpus: extract out qtest-specific code to accel/qtest
> cpus: extract out kvm-specific code to accel/kvm
> cpus: extract out hax-specific code to target/i386/
> cpus: extract out whpx-specific code to target/i386/
> cpus: extract out hvf-specific code to target/i386/hvf/
> cpus: cleanup now unneeded includes
> cpus: remove checks for non-NULLcpus_accel
> cpus: addhandle_interruptto the CpusAccel interface
> hvf: remove hvf specific functions from global includes
> whpx: remove whpx specific functions from global includes
> hax: remove hax specific functions from global includes
> kvm: remove kvm specific functions from global includes
>
> MAINTAINERS | 5 +-
> accel/kvm/kvm-all.c | 14 +-
> accel/kvm/kvm-cpus.c | 88 ++
> accel/kvm/kvm-cpus.h | 24 +
> accel/kvm/meson.build | 5 +-
> accel/meson.build | 2 +-
> accel/qtest/meson.build | 7 +
> accel/qtest/qtest-cpus.c | 91 ++
> accel/qtest/qtest-cpus.h | 17 +
> accel/{ => qtest}/qtest.c | 13 +-
> accel/stubs/hax-stub.c | 10 -
> accel/stubs/hvf-stub.c | 30 -
> accel/stubs/kvm-stub.c | 23 -
> accel/stubs/meson.build | 2 -
> accel/stubs/whpx-stub.c | 47 -
> accel/tcg/cpu-exec.c | 43 +-
> accel/tcg/meson.build | 2 +-
> accel/tcg/tcg-all.c | 43 +-
> accel/tcg/tcg-cpus.c | 569 +++++++++++
> accel/tcg/tcg-cpus.h | 17 +
> accel/tcg/translate-all.c | 3 +-
> dma-helpers.c | 4 +-
> docs/replay.txt | 6 +-
> exec.c | 4 -
> hw/core/cpu.c | 14 +-
> hw/core/ptimer.c | 8 +-
> hw/i386/x86.c | 3 +-
> include/exec/cpu-all.h | 4 +
> include/exec/exec-all.h | 4 +-
> include/hw/core/cpu.h | 14 -
> include/qemu/timer.h | 24 +-
> include/sysemu/cpu-timers.h | 90 ++
> include/sysemu/cpus.h | 50 +-
> include/sysemu/hax.h | 17 -
> include/sysemu/hvf.h | 8 -
> include/sysemu/hw_accel.h | 69 +-
> include/sysemu/kvm.h | 7 -
> include/sysemu/qtest.h | 2 +
> include/sysemu/replay.h | 4 +-
> include/sysemu/whpx.h | 19 -
> replay/replay.c | 6 +-
> softmmu/cpu-timers.c | 279 ++++++
> softmmu/cpus.c | 1697 +++----------------------------- > softmmu/icount.c | 492 +++++++++
> softmmu/meson.build | 10 +-
> softmmu/qtest.c | 34 +-
> softmmu/timers-state.h | 69 ++
> softmmu/vl.c | 8 +-
> stubs/clock-warp.c | 7 -
> stubs/cpu-get-clock.c | 3 +-
> stubs/cpu-get-icount.c | 21 -
> stubs/cpu-synchronize-state.c | 9 +
>stubs/cpus-get-virtual-clock.c| 8 +
> stubs/icount.c | 45 +
> stubs/meson.build | 6 +-
> stubs/qemu-timer-notify-cb.c | 8 +
> stubs/qtest.c | 5 +
> target/alpha/translate.c | 3 +-
> target/arm/helper.c | 7 +-
> target/i386/hax-all.c | 17 +-
> target/i386/hax-cpus.c | 84 ++
> target/i386/hax-cpus.h | 33 +
> target/i386/hax-i386.h | 2 +
> target/i386/hax-mem.c | 2 +-
> target/i386/hax-posix.c | 13 +-
> target/i386/hax-windows.c | 22 +-
> target/i386/hax-windows.h | 2 +
> target/i386/hvf/hvf-cpus.c | 131 +++
> target/i386/hvf/hvf-cpus.h | 25 +
> target/i386/hvf/hvf.c | 12 +-
> target/i386/hvf/meson.build | 1 +
> target/i386/hvf/x86hvf.c | 2 +
> target/i386/hvf/x86hvf.h | 1 -
> target/i386/meson.build | 14 +-
> target/i386/whpx-all.c | 13 +-
> target/i386/whpx-cpus.c | 96 ++
> target/i386/whpx-cpus.h | 34 +
> target/riscv/csr.c | 8 +-
> tests/ptimer-test-stubs.c | 5 +-
> tests/test-timed-average.c | 2 +-
> util/main-loop.c | 12 +-
> util/qemu-timer.c | 14 +-
> 82 files changed, 2637 insertions(+), 2031 deletions(-)
> create mode 100644accel/kvm/kvm-cpus.c
> create mode 100644accel/kvm/kvm-cpus.h
> create mode 100644 accel/qtest/meson.build
> create mode 100644accel/qtest/qtest-cpus.c
> create mode 100644accel/qtest/qtest-cpus.h
> rename accel/{ =>qtest}/qtest.c(81%)
> delete mode 100644accel/stubs/hvf-stub.c
> delete mode 100644accel/stubs/whpx-stub.c
> create mode 100644accel/tcg/tcg-cpus.c
> create mode 100644accel/tcg/tcg-cpus.h
> create mode 100644include/sysemu/cpu-timers.h
> create mode 100644softmmu/cpu-timers.c
> create mode 100644softmmu/icount.c
> create mode 100644softmmu/timers-state.h
> delete mode 100644stubs/clock-warp.c
> delete mode 100644stubs/cpu-get-icount.c
> create mode 100644stubs/cpu-synchronize-state.c
> create mode 100644stubs/cpus-get-virtual-clock.c
> create mode 100644stubs/icount.c
> create mode 100644stubs/qemu-timer-notify-cb.c
> create mode 100644target/i386/hax-cpus.c
> create mode 100644target/i386/hax-cpus.h
> create mode 100644target/i386/hvf/hvf-cpus.c
> create mode 100644target/i386/hvf/hvf-cpus.h
> create mode 100644target/i386/whpx-cpus.c
> create mode 100644target/i386/whpx-cpus.h
>
Quoted 10 lines · Claudio Fontana
Thanks Paolo,
if it can help I try to keep a rebased functioning version at
https://github.com/hw-claudio/qemu.git "cpus-refactoring"
some of the CI complains about:
check: qemu-img not found
Makefile.mtest:1229: recipe for target 'check-block' failed
This will be fixed by the next pull request (the issue appears with --enable-system --disable-tools builds).
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Claudio Fontana
Thanks Paolo,
if it can help I try to keep a rebased functioning version at
https://github.com/hw-claudio/qemu.git "cpus-refactoring"
some of the CI complains about:
Quoted 8 lines
Quoted 2 lines
check: qemu-img not found
Makefile.mtest:1229: recipe for target 'check-block' failedThis will be fixed by the next pull request (the issue appears with --enable-system --disable-tools builds).
Paolo
Generating qemu-version.h with a meson_exe.py custom command
make: *** No rule to make target 'check-softfloat'. Stop.
make: *** Waiting for unfinished jobs....
fatal: No names found, cannot describe anything.
Probably an instance of the same problem right?
I got this from travis-ci.org
GCC check-softfloat (user)
Quoted 19 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Claudio Fontana
Thanks Paolo,
if it can help I try to keep a rebased functioning version at
https://github.com/hw-claudio/qemu.git "cpus-refactoring"
some of the CI complains about:
Quoted 8 lines
Quoted 2 lines
check: qemu-img not found
Makefile.mtest:1229: recipe for target 'check-block' failedThis will be fixed by the next pull request (the issue appears with --enable-system --disable-tools builds).
Paolo
Quoted 6 lines
Generating
qemu-version.hwith ameson_exe.pycustom command
make: *** No rule to make target 'check-softfloat'. Stop.
make: *** Waiting for unfinished jobs....
fatal: No names found, cannot describe anything.Probably an instance of the same problem right?
Yes - I treat check-softfloat as a unit test so it's not dependent on the type of build you are actually doing.
Subject: [PATCH v2 00/10] testing and misc updates
Date: Wed, 9 Sep 2020 12:27:31 +0100
Message-Id: <[email protected]>
I think gets all CI back to green.
Quoted 4 lines
I got this from travis-ci.org
GCC check-softfloat (user)
Signature · 1 line
Alex Bennée