[RFC 0/1] QEMU cpus.c refactoring part2

Claudio Fontana posted 1 patch 1 week ago
Failed in applying to current master (apply log)
MAINTAINERS                   |   1 +
accel/Makefile.objs           |   2 +-
accel/kvm/Makefile.objs       |   2 +
accel/kvm/kvm-all.c           |  15 +-
accel/kvm/kvm-cpus.c          |  94 +++++
accel/kvm/kvm-cpus.h          |  17 +
accel/qtest/Makefile.objs     |   2 +
accel/qtest/qtest-cpus.c      | 105 +++++
accel/qtest/qtest-cpus.h      |  17 +
accel/{ => qtest}/qtest.c     |   7 +
accel/stubs/kvm-stub.c        |   3 +-
accel/tcg/Makefile.objs       |   1 +
accel/tcg/tcg-all.c           |  12 +-
accel/tcg/tcg-cpus.c          | 532 +++++++++++++++++++++++++
accel/tcg/tcg-cpus.h          |  17 +
hw/core/cpu.c                 |   1 +
include/sysemu/cpus.h         |  33 ++
include/sysemu/hw_accel.h     |  57 +--
include/sysemu/kvm.h          |   2 +-
softmmu/cpus.c                | 908 +++---------------------------------------
stubs/Makefile.objs           |   1 +
stubs/cpu-synchronize-state.c |  15 +
target/i386/Makefile.objs     |   7 +-
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/hvf/Makefile.objs |   2 +-
target/i386/hvf/hvf-cpus.c    | 141 +++++++
target/i386/hvf/hvf-cpus.h    |  17 +
target/i386/hvf/hvf.c         |   3 +
target/i386/whpx-all.c        |   3 +
target/i386/whpx-cpus.c       |  96 +++++
target/i386/whpx-cpus.h       |  17 +
36 files changed, 1357 insertions(+), 915 deletions(-)
create mode 100644 accel/kvm/kvm-cpus.c
create mode 100644 accel/kvm/kvm-cpus.h
create mode 100644 accel/qtest/Makefile.objs
create mode 100644 accel/qtest/qtest-cpus.c
create mode 100644 accel/qtest/qtest-cpus.h
rename accel/{ => qtest}/qtest.c (86%)
create mode 100644 accel/tcg/tcg-cpus.c
create mode 100644 accel/tcg/tcg-cpus.h
create mode 100644 stubs/cpu-synchronize-state.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

[RFC 0/1] QEMU cpus.c refactoring part2

Posted by Claudio Fontana 1 week ago
Motivation and higher level steps:

https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html

This is based on and requires "QEMU cpus.c refactoring part1":

https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg09401.html

OPEN ITEMS:

* needs review
* requires HVF patches before this can be committed (Roman).
* investigate splitting into multiple patches

----

* 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 (1):
  cpus: extract out accel-specific code to each accel

 MAINTAINERS                   |   1 +
 accel/Makefile.objs           |   2 +-
 accel/kvm/Makefile.objs       |   2 +
 accel/kvm/kvm-all.c           |  15 +-
 accel/kvm/kvm-cpus.c          |  94 +++++
 accel/kvm/kvm-cpus.h          |  17 +
 accel/qtest/Makefile.objs     |   2 +
 accel/qtest/qtest-cpus.c      | 105 +++++
 accel/qtest/qtest-cpus.h      |  17 +
 accel/{ => qtest}/qtest.c     |   7 +
 accel/stubs/kvm-stub.c        |   3 +-
 accel/tcg/Makefile.objs       |   1 +
 accel/tcg/tcg-all.c           |  12 +-
 accel/tcg/tcg-cpus.c          | 532 +++++++++++++++++++++++++
 accel/tcg/tcg-cpus.h          |  17 +
 hw/core/cpu.c                 |   1 +
 include/sysemu/cpus.h         |  33 ++
 include/sysemu/hw_accel.h     |  57 +--
 include/sysemu/kvm.h          |   2 +-
 softmmu/cpus.c                | 908 +++---------------------------------------
 stubs/Makefile.objs           |   1 +
 stubs/cpu-synchronize-state.c |  15 +
 target/i386/Makefile.objs     |   7 +-
 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/hvf/Makefile.objs |   2 +-
 target/i386/hvf/hvf-cpus.c    | 141 +++++++
 target/i386/hvf/hvf-cpus.h    |  17 +
 target/i386/hvf/hvf.c         |   3 +
 target/i386/whpx-all.c        |   3 +
 target/i386/whpx-cpus.c       |  96 +++++
 target/i386/whpx-cpus.h       |  17 +
 36 files changed, 1357 insertions(+), 915 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus.c
 create mode 100644 accel/kvm/kvm-cpus.h
 create mode 100644 accel/qtest/Makefile.objs
 create mode 100644 accel/qtest/qtest-cpus.c
 create mode 100644 accel/qtest/qtest-cpus.h
 rename accel/{ => qtest}/qtest.c (86%)
 create mode 100644 accel/tcg/tcg-cpus.c
 create mode 100644 accel/tcg/tcg-cpus.h
 create mode 100644 stubs/cpu-synchronize-state.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

-- 
2.16.4