Skip to contentSkip to conversation

QEMU cpus.c refactoring

RFC Superseded Claudio Fontana 4 participants 18 messages May 25, 2020 – May 27, 2020

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover QEMU cpus.c refactoring

Motivation and higher level steps:

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

--------

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

*** BLURB HERE ***

Claudio Fontana (4):
softmmu: move softmmu only files from root
cpu-throttle: new module, extracted from cpus.c cpu-timers, icount: new modules
cpus: extract out accel-specific code to each accel

 MAINTAINERS                                  |   14 +-
 Makefile.target                              |    7 +-
 accel/kvm/Makefile.objs                      |    2 +
 accel/kvm/kvm-all.c                          |   15 +-
 accel/kvm/kvm-cpus-interface.c               |   94 ++
 accel/kvm/kvm-cpus-interface.h               |    8 +
 accel/qtest.c                                |   88 +-
 accel/stubs/kvm-stub.c                       |    3 +-
 accel/tcg/Makefile.objs                      |    1 +
 accel/tcg/cpu-exec.c                         |   43 +-
 accel/tcg/tcg-all.c                          |   19 +-
 accel/tcg/tcg-cpus-interface.c               |  523 ++++++
 accel/tcg/tcg-cpus-interface.h               |    8 +
 accel/tcg/translate-all.c                    |    3 +-
 cpus.c                                       | 2290 --------------------------
 docs/replay.txt                              |    6 +-
 exec.c                                       |    4 -
 hw/core/cpu.c                                |    1 +
 hw/core/ptimer.c                             |    6 +-
 hw/i386/x86.c                                |    1 +
 include/exec/cpu-all.h                       |    4 +
 include/exec/exec-all.h                      |    4 +-
 include/hw/core/cpu.h                        |   37 -
 include/qemu/main-loop.h                     |    5 +
 include/qemu/timer.h                         |   22 +-
 include/sysemu/cpu-throttle.h                |   50 +
 include/sysemu/cpu-timers.h                  |   72 +
 include/sysemu/cpus.h                        |   44 +-
 include/sysemu/hvf.h                         |    1 -
 include/sysemu/hw_accel.h                    |   57 +-
 include/sysemu/kvm.h                         |    2 +-
 include/sysemu/qtest.h                       |    2 +
 include/sysemu/replay.h                      |    4 +-
 migration/migration.c                        |    1 +
 migration/ram.c                              |    1 +
 replay/replay.c                              |    6 +-
 softmmu/Makefile.objs                        |   13 +
 arch_init.c => softmmu/arch_init.c           |    0
 balloon.c => softmmu/balloon.c               |    0
 softmmu/cpu-throttle.c                       |  122 ++
 softmmu/cpu-timers.c                         |  267 +++
 softmmu/cpus.c                               |  741 +++++++++
 softmmu/icount.c                             |  496 ++++++
 ioport.c => softmmu/ioport.c                 |    0
 memory.c => softmmu/memory.c                 |    0
 memory_mapping.c => softmmu/memory_mapping.c |    0
 qtest.c => softmmu/qtest.c                   |   34 +-
 softmmu/timers-state.h                       |   45 +
 softmmu/vl.c                                 |    8 +-
 stubs/Makefile.objs                          |    4 +-
 stubs/clock-warp.c                           |    4 +-
 stubs/cpu-get-clock.c                        |    3 +-
 stubs/cpu-get-icount.c                       |   21 -
 stubs/cpu-synchronize-state.c                |   15 +
 stubs/icount.c                               |   22 +
 stubs/qemu-timer-notify-cb.c                 |    8 +
 stubs/qtest.c                                |    5 +
 target/alpha/translate.c                     |    3 +-
 target/arm/helper.c                          |    7 +-
 target/i386/Makefile.objs                    |    7 +-
 target/i386/hax-all.c                        |    6 +-
 target/i386/hax-cpus-interface.c             |   85 +
 target/i386/hax-cpus-interface.h             |    8 +
 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-interface.c         |   92 ++
 target/i386/hvf/hvf-cpus-interface.h         |    8 +
 target/i386/hvf/hvf.c                        |    5 +-
 target/i386/whpx-all.c                       |    3 +
 target/i386/whpx-cpus-interface.c            |   96 ++
 target/i386/whpx-cpus-interface.h            |    8 +
 target/riscv/csr.c                           |    8 +-
 tests/ptimer-test-stubs.c                    |    7 +-
 tests/test-timed-average.c                   |    2 +-
 util/main-loop.c                             |    4 +-
 util/qemu-timer.c                            |   12 +-
 78 files changed, 3136 insertions(+), 2517 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 delete mode 100644 cpus.c
 create mode 100644 include/sysemu/cpu-throttle.h
 create mode 100644 include/sysemu/cpu-timers.h
 rename arch_init.c => softmmu/arch_init.c (100%)
 rename balloon.c => softmmu/balloon.c (100%)
 create mode 100644 softmmu/cpu-throttle.c
 create mode 100644 softmmu/cpu-timers.c
 create mode 100644 softmmu/cpus.c
 create mode 100644 softmmu/icount.c
 rename ioport.c => softmmu/ioport.c (100%)
 rename memory.c => softmmu/memory.c (100%)
 rename memory_mapping.c => softmmu/memory_mapping.c (100%)
 rename qtest.c => softmmu/qtest.c (95%)
 create mode 100644 softmmu/timers-state.h
 delete mode 100644 stubs/cpu-get-icount.c
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 stubs/icount.c
 create mode 100644 stubs/qemu-timer-notify-cb.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h
Signature · 1 line
2.16.4
#1 lore raw

RFC v3 1/4 softmmu: move softmmu only files from root

move arch_init, balloon, cpus, ioport, memory, memory_mapping, qtest.

They are all specific to CONFIG_SOFTMMU.

---
 MAINTAINERS                                  | 12 ++++++------
 Makefile.target                              |  7 ++-----
 softmmu/Makefile.objs                        | 10 ++++++++++
 arch_init.c => softmmu/arch_init.c           |  0
 balloon.c => softmmu/balloon.c               |  0
 cpus.c => softmmu/cpus.c                     |  0
 ioport.c => softmmu/ioport.c                 |  0
 memory.c => softmmu/memory.c                 |  0
 memory_mapping.c => softmmu/memory_mapping.c |  0
 qtest.c => softmmu/qtest.c                   |  0
 10 files changed, 18 insertions(+), 11 deletions(-)
 rename arch_init.c => softmmu/arch_init.c (100%)
 rename balloon.c => softmmu/balloon.c (100%)
 rename cpus.c => softmmu/cpus.c (100%)
 rename ioport.c => softmmu/ioport.c (100%)
 rename memory.c => softmmu/memory.c (100%)
 rename memory_mapping.c => softmmu/memory_mapping.c (100%)
 rename qtest.c => softmmu/qtest.c (100%)
MAINTAINERS +6 -6
index 3690f313c3..0288ffbc50 100644
@@ -114,7 +114,7 @@ Overall TCG CPUs
 M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
-F: cpus.c
+F: softmmu/cpus.c
 F: cpus-common.c
 F: exec.c
 F: accel/tcg/
@@ -1668,7 +1668,7 @@ M: David Hildenbrand <[email protected]>
 S: Maintained
 F: hw/virtio/virtio-balloon*.c
 F: include/hw/virtio/virtio-balloon.h
-F: balloon.c
+F: softmmu/balloon.c
 F: include/sysemu/balloon.h
 
 virtio-9p
@@ -2110,12 +2110,12 @@ Memory API
 M: Paolo Bonzini <[email protected]>
 S: Supported
 F: include/exec/ioport.h
-F: ioport.c
 F: include/exec/memop.h
 F: include/exec/memory.h
 F: include/exec/ram_addr.h
 F: include/exec/ramblock.h
-F: memory.c
+F: softmmu/ioport.c
+F: softmmu/memory.c
 F: include/exec/memory-internal.h
 F: exec.c
 F: scripts/coccinelle/memory-region-housekeeping.cocci
@@ -2147,7 +2147,7 @@ F: ui/cocoa.m
 Main loop
 M: Paolo Bonzini <[email protected]>
 S: Maintained
-F: cpus.c
+F: softmmu/cpus.c
 F: include/qemu/main-loop.h
 F: include/sysemu/runstate.h
 F: util/main-loop.c
@@ -2306,7 +2306,7 @@ M: Thomas Huth <[email protected]>
 M: Laurent Vivier <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
-F: qtest.c
+F: softmmu/qtest.c
 F: accel/qtest.c
 F: tests/qtest/
 
Makefile.target +2 -5
index 8ed1eba95b..7fbf5d8b92 100644
@@ -152,16 +152,13 @@ endif #CONFIG_BSD_USER
 #########################################################
 # System emulator target
 ifdef CONFIG_SOFTMMU
-obj-y += arch_init.o cpus.o gdbstub.o balloon.o ioport.o
-obj-y += qtest.o
+obj-y += softmmu/
+obj-y += gdbstub.o
 obj-y += dump/
 obj-y += hw/
 obj-y += monitor/
 obj-y += qapi/
-obj-y += memory.o
-obj-y += memory_mapping.o
 obj-y += migration/ram.o
-obj-y += softmmu/
 LIBS := $(libs_softmmu) $(LIBS)
 
 # Hardware support
softmmu/Makefile.objs +10 -0
index dd15c24346..a4bd9f2f52 100644
@@ -1,3 +1,13 @@
 softmmu-main-y = softmmu/main.o
+
+obj-y += arch_init.o
+obj-y += cpus.o
+obj-y += balloon.o
+obj-y += ioport.o
+obj-y += memory.o
+obj-y += memory_mapping.o
+
+obj-y += qtest.o
+
 obj-y += vl.o
 vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS)
softmmu/arch_init.c renamed from arch_init.c +0 -0
similarity index 100%
rename from arch_init.c
rename to softmmu/arch_init.c
softmmu/balloon.c renamed from balloon.c +0 -0
similarity index 100%
rename from balloon.c
rename to softmmu/balloon.c
softmmu/cpus.c renamed from cpus.c +0 -0
similarity index 100%
rename from cpus.c
rename to softmmu/cpus.c
softmmu/ioport.c renamed from ioport.c +0 -0
similarity index 100%
rename from ioport.c
rename to softmmu/ioport.c
softmmu/memory.c renamed from memory.c +0 -0
similarity index 100%
rename from memory.c
rename to softmmu/memory.c
softmmu/memory_mapping.c renamed from memory_mapping.c +0 -0
similarity index 100%
rename from memory_mapping.c
rename to softmmu/memory_mapping.c
softmmu/qtest.c renamed from qtest.c +0 -0
similarity index 100%
rename from qtest.c
rename to softmmu/qtest.c
Signature · 1 line
2.16.4
#2 lore raw

Re: [RFC v3 1/4] softmmu: move softmmu only files from root

Quoted 10 lines · Claudio Fontana

move arch_init, balloon, cpus, ioport, memory, memory_mapping, qtest.

They are all specific to CONFIG_SOFTMMU.

---
 MAINTAINERS                                  | 12 ++++++------
 Makefile.target                              |  7 ++-----
 softmmu/Makefile.objs                        | 10 ++++++++++
 arch_init.c => softmmu/arch_init.c           |  0

OK.

Quoted 1 line
 balloon.c => softmmu/balloon.c               |  0

OK

Quoted 1 line
 cpus.c => softmmu/cpus.c                     |  0

I'm still not 100% convinced.

Quoted 1 line
 ioport.c => softmmu/ioport.c                 |  0

OK

Quoted 1 line
 memory.c => softmmu/memory.c                 |  0

OK

Quoted 1 line
 memory_mapping.c => softmmu/memory_mapping.c |  0

I am not sure (yet).

Quoted 1 line
 qtest.c => softmmu/qtest.c                   |  0

This one seems to belong to accel/

Quoted 8 lines
 10 files changed, 18 insertions(+), 11 deletions(-)
 rename arch_init.c => softmmu/arch_init.c (100%)
 rename balloon.c => softmmu/balloon.c (100%)
 rename cpus.c => softmmu/cpus.c (100%)
 rename ioport.c => softmmu/ioport.c (100%)
 rename memory.c => softmmu/memory.c (100%)
 rename memory_mapping.c => softmmu/memory_mapping.c (100%)
 rename qtest.c => softmmu/qtest.c (100%)

What about the corresponding headers?

[...]

#3 lore raw

Re: [RFC v3 1/4] softmmu: move softmmu only files from root

Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Claudio Fontana

move arch_init, balloon, cpus, ioport, memory, memory_mapping, qtest.

They are all specific to CONFIG_SOFTMMU.

---
 MAINTAINERS                                  | 12 ++++++------
 Makefile.target                              |  7 ++-----
 softmmu/Makefile.objs                        | 10 ++++++++++
 arch_init.c => softmmu/arch_init.c           |  0

OK.

Quoted 7 lines
Quoted 1 line
 balloon.c => softmmu/balloon.c               |  0

OK

Quoted 1 line
 cpus.c => softmmu/cpus.c                     |  0

I'm still not 100% convinced.

Hi Philippe, do you see a reason to keep cpus.c in the top_srcdir?

The way I see it, it belongs in softmmu/,

we have a separate cpu-common.c that is target-indep and in common between user and softmmu, while cpus.c is softmmu-only right?

Quoted 5 lines
Quoted 2 lines
 ioport.c => softmmu/ioport.c                 |  0

OK

Quoted 7 lines
Quoted 1 line
 memory.c => softmmu/memory.c                 |  0

OK

Quoted 1 line
 memory_mapping.c => softmmu/memory_mapping.c |  0

I am not sure (yet).

headers are already in sysemu (sysemu/memory_mapping.h)

Quoted 4 lines
Quoted 2 lines
 qtest.c => softmmu/qtest.c                   |  0

This one seems to belong to accel/

We already have accel/qtest.c , that is the qtest AccelClass.

Here we are talking about qtest.c from the top_srcdir, which it the qtest server and is built with softmmu code, with header in sysemu/qtest.h

Thomas?

Quoted 10 lines
Quoted 8 lines
 10 files changed, 18 insertions(+), 11 deletions(-)
 rename arch_init.c => softmmu/arch_init.c (100%)
 rename balloon.c => softmmu/balloon.c (100%)
 rename cpus.c => softmmu/cpus.c (100%)
 rename ioport.c => softmmu/ioport.c (100%)
 rename memory.c => softmmu/memory.c (100%)
 rename memory_mapping.c => softmmu/memory_mapping.c (100%)
 rename qtest.c => softmmu/qtest.c (100%)

What about the corresponding headers?

headers already in sysemu/ :

sysemu/arch_init.h
sysemu/balloon.h
sysemu/cpus.h
sysemu/qtest.h - (again, for the qtest server)
sysemu/memory_mapping.h

headers currently in exec/ :

exec/memory.h
exec/ioport.h

Paolo?

Quoted 3 lines

[...]

#4 lore raw

Re: [RFC v3 1/4] softmmu: move softmmu only files from root

Quoted 21 lines · Claudio Fontana
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Claudio Fontana

move arch_init, balloon, cpus, ioport, memory, memory_mapping, qtest.

They are all specific to CONFIG_SOFTMMU.

---
 MAINTAINERS                                  | 12 ++++++------
 Makefile.target                              |  7 ++-----
 softmmu/Makefile.objs                        | 10 ++++++++++
 arch_init.c => softmmu/arch_init.c           |  0

OK.

Quoted 1 line
 balloon.c => softmmu/balloon.c               |  0

OK

Quoted 1 line
 cpus.c => softmmu/cpus.c                     |  0
Quoted 8 lines
Quoted 1 line

I'm still not 100% convinced.

Hi Philippe, do you see a reason to keep cpus.c in the top_srcdir?

The way I see it, it belongs in softmmu/,

we have a separate cpu-common.c that is target-indep and in common between user and softmmu, while cpus.c is softmmu-only right?

Sorry, I meant to say I need to look more in details at this file uses and will do a second review pass on your series.

Quoted 18 lines
Quoted 7 lines
Quoted 4 lines


 ioport.c => softmmu/ioport.c                 |  0

OK

Quoted 7 lines
Quoted 1 line
 memory.c => softmmu/memory.c                 |  0

OK

Quoted 1 line
 memory_mapping.c => softmmu/memory_mapping.c |  0

I am not sure (yet).

headers are already in sysemu (sysemu/memory_mapping.h)

Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
 qtest.c => softmmu/qtest.c                   |  0

This one seems to belong to accel/

We already have accel/qtest.c , that is the qtest AccelClass.

Here we are talking about qtest.c from the top_srcdir, which it the qtest server and is built with softmmu code, with header in sysemu/qtest.h

I haven't looked at it in detail but will.

Quoted 22 lines

Thomas?

Quoted 10 lines
Quoted 8 lines
 10 files changed, 18 insertions(+), 11 deletions(-)
 rename arch_init.c => softmmu/arch_init.c (100%)
 rename balloon.c => softmmu/balloon.c (100%)
 rename cpus.c => softmmu/cpus.c (100%)
 rename ioport.c => softmmu/ioport.c (100%)
 rename memory.c => softmmu/memory.c (100%)
 rename memory_mapping.c => softmmu/memory_mapping.c (100%)
 rename qtest.c => softmmu/qtest.c (100%)

What about the corresponding headers?

headers already in sysemu/ :

sysemu/arch_init.h
sysemu/balloon.h
sysemu/cpus.h
sysemu/qtest.h - (again, for the qtest server)
sysemu/memory_mapping.h

Quoted 4 lines

headers currently in exec/ :

exec/memory.h
exec/ioport.h

Yes, if you want a clean separation, I'd rather restrict include/softmmu/ to softmmu builds. user-mode and tools builds shouldn't access these headers.

Quoted 7 lines

Paolo?

Quoted 3 lines

[...]

#5 lore raw

RFC v3 2/4 cpu-throttle: new module, extracted from cpus.c

In reply to Claudio Fontana

move the vcpu throttling functionality into its own module.

This functionality is not specific to any accelerator,
and it is used currently by migration to slow down guests to try to have migrations converge, and by the cocoa MacOS UI to throttle speed.

cpu-throttle contains the controls to adjust and inspect throttle settings, start (set) and stop vcpu throttling, and the throttling function itself that is run periodically on vcpus to make them take a nap.

Execution of the throttling function on all vcpus is triggered by a timer, registered at module initialization.

No functionality change.

---
 MAINTAINERS                   |   3 +-
 include/hw/core/cpu.h         |  37 -------------
 include/qemu/main-loop.h      |   5 ++
 include/sysemu/cpu-throttle.h |  50 +++++++++++++++++
 migration/migration.c         |   1 +
 migration/ram.c               |   1 +
 softmmu/Makefile.objs         |   1 +
 softmmu/cpu-throttle.c        | 122 ++++++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c                |  95 +++-----------------------------
 9 files changed, 190 insertions(+), 125 deletions(-)
 create mode 100644 include/sysemu/cpu-throttle.h
 create mode 100644 softmmu/cpu-throttle.c
MAINTAINERS +2 -1
index 0288ffbc50..708768f120 100644
@@ -2147,13 +2147,14 @@ F: ui/cocoa.m
 Main loop
 M: Paolo Bonzini <[email protected]>
 S: Maintained
-F: softmmu/cpus.c
 F: include/qemu/main-loop.h
 F: include/sysemu/runstate.h
 F: util/main-loop.c
 F: util/qemu-timer.c
 F: softmmu/vl.c
 F: softmmu/main.c
+F: softmmu/cpus.c
+F: softmmu/cpu-throttle.c
 F: qapi/run-state.json
 
 Human Monitor (HMP)
include/hw/core/cpu.h +0 -37
index 07f7698155..e6b75d456c 100644
@@ -817,43 +817,6 @@ bool cpu_exists(int64_t id);
  */
 CPUState *cpu_by_arch_id(int64_t id);
 
-/**
- * cpu_throttle_set:
- * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
- *
- * Throttles all vcpus by forcing them to sleep for the given percentage of
- * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
- * (example: 10ms sleep for every 30ms awake).
- *
- * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
- * Once the throttling starts, it will remain in effect until cpu_throttle_stop
- * is called.
- */
-void cpu_throttle_set(int new_throttle_pct);
-
-/**
- * cpu_throttle_stop:
- *
- * Stops the vcpu throttling started by cpu_throttle_set.
- */
-void cpu_throttle_stop(void);
-
-/**
- * cpu_throttle_active:
- *
- * Returns: %true if the vcpus are currently being throttled, %false otherwise.
- */
-bool cpu_throttle_active(void);
-
-/**
- * cpu_throttle_get_percentage:
- *
- * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
- *
- * Returns: The throttle percentage in range 1 to 99.
- */
-int cpu_throttle_get_percentage(void);
-
 #ifndef CONFIG_USER_ONLY
 
 typedef void (*CPUInterruptHandler)(CPUState *, int);
include/qemu/main-loop.h +5 -0
index a6d20b0719..8e98613656 100644
@@ -303,6 +303,11 @@ void qemu_mutex_unlock_iothread(void);
  */
 void qemu_cond_wait_iothread(QemuCond *cond);
 
+/*
+ * qemu_cond_timedwait_iothread: like the previous, but with timeout
+ */
+void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
+
 /* internal interfaces */
 
 void qemu_fd_register(int fd);
include/sysemu/cpu-throttle.h new file +50 -0

50 lines not on this page · raw message

migration/migration.c +1 -0
index 0bb042a0f7..dd18323f32 100644
@@ -23,6 +23,7 @@
 #include "socket.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/cpu-throttle.h"
 #include "rdma.h"
 #include "ram.h"
 #include "migration/global_state.h"
migration/ram.c +1 -0
index 859f835f1a..527f0c7316 100644
@@ -52,6 +52,7 @@
 #include "migration/colo.h"
 #include "block.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/cpu-throttle.h"
 #include "savevm.h"
 #include "qemu/iov.h"
 #include "multifd.h"
softmmu/Makefile.objs +1 -0
index a4bd9f2f52..a414a74c50 100644
@@ -2,6 +2,7 @@ softmmu-main-y = softmmu/main.o
 
 obj-y += arch_init.o
 obj-y += cpus.o
+obj-y += cpu-throttle.o
 obj-y += balloon.o
 obj-y += ioport.o
 obj-y += memory.o
softmmu/cpu-throttle.c new file +122 -0

122 lines not on this page · raw message

softmmu/cpus.c +8 -87

124 lines not on this page · raw message

Signature · 1 line
2.16.4
#6 lore raw

Re: [RFC v3 2/4] cpu-throttle: new module, extracted from cpus.c

Quoted 36 lines · Claudio Fontana

move the vcpu throttling functionality into its own module.

This functionality is not specific to any accelerator,
and it is used currently by migration to slow down guests to try to have migrations converge, and by the cocoa MacOS UI to throttle speed.

cpu-throttle contains the controls to adjust and inspect throttle settings, start (set) and stop vcpu throttling, and the throttling function itself that is run periodically on vcpus to make them take a nap.

Execution of the throttling function on all vcpus is triggered by a timer, registered at module initialization.

No functionality change.

---
 MAINTAINERS                   |   3 +-
 include/hw/core/cpu.h         |  37 -------------
 include/qemu/main-loop.h      |   5 ++
 include/sysemu/cpu-throttle.h |  50 +++++++++++++++++
 migration/migration.c         |   1 +
 migration/ram.c               |   1 +
 softmmu/Makefile.objs         |   1 +
 softmmu/cpu-throttle.c        | 122 ++++++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c                |  95 +++-----------------------------
 9 files changed, 190 insertions(+), 125 deletions(-)
 create mode 100644 include/sysemu/cpu-throttle.h
 create mode 100644 softmmu/cpu-throttle.c
MAINTAINERS +0 -0
index 0288ffbc50..708768f120 100644
@@ -2147,13 +2147,14 @@ F: ui/cocoa.m
 Main loop

MAINTAINERS F: ui/cocoa.m · line 2156

Quoted 10 lines
MAINTAINERS +1 -1
 M: Paolo Bonzini <[email protected]>
 S: Maintained
-F: softmmu/cpus.c
 F: include/qemu/main-loop.h
 F: include/sysemu/runstate.h
 F: util/main-loop.c
 F: util/qemu-timer.c
 F: softmmu/vl.c
 F: softmmu/main.c
+F: softmmu/cpus.c

This line belong the the previous patch (#1).

MAINTAINERS F: ui/cocoa.m · line 2158

Quoted 2 lines
MAINTAINERS +1 -0
+F: softmmu/cpu-throttle.c
 F: qapi/run-state.json

Can you reorder patches #1/#2 to avoid moving cpu-throttle code twice?

Otherwise this patch looks good.

[...]

#7 lore raw

Re: [RFC v3 2/4] cpu-throttle: new module, extracted from cpus.c

Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Claudio Fontana

move the vcpu throttling functionality into its own module.

This functionality is not specific to any accelerator,
and it is used currently by migration to slow down guests to try to have migrations converge, and by the cocoa MacOS UI to throttle speed.

cpu-throttle contains the controls to adjust and inspect throttle settings, start (set) and stop vcpu throttling, and the throttling function itself that is run periodically on vcpus to make them take a nap.

Execution of the throttling function on all vcpus is triggered by a timer, registered at module initialization.

No functionality change.

---
 MAINTAINERS                   |   3 +-
 include/hw/core/cpu.h         |  37 -------------
 include/qemu/main-loop.h      |   5 ++
 include/sysemu/cpu-throttle.h |  50 +++++++++++++++++
 migration/migration.c         |   1 +
 migration/ram.c               |   1 +
 softmmu/Makefile.objs         |   1 +
 softmmu/cpu-throttle.c        | 122 ++++++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c                |  95 +++-----------------------------
 9 files changed, 190 insertions(+), 125 deletions(-)
 create mode 100644 include/sysemu/cpu-throttle.h
 create mode 100644 softmmu/cpu-throttle.c
MAINTAINERS +0 -1
index 0288ffbc50..708768f120 100644
@@ -2147,13 +2147,14 @@ F: ui/cocoa.m
 Main loop
 M: Paolo Bonzini <[email protected]>
 S: Maintained
-F: softmmu/cpus.c
 F: include/qemu/main-loop.h
Quoted 8 lines

MAINTAINERS F: ui/cocoa.m · line 2156

Quoted 6 lines
MAINTAINERS +1 -0
 F: include/sysemu/runstate.h
 F: util/main-loop.c
 F: util/qemu-timer.c
 F: softmmu/vl.c
 F: softmmu/main.c
+F: softmmu/cpus.c

This line belong the the previous patch (#1).

right

Quoted 5 lines

MAINTAINERS F: ui/cocoa.m · line 2158

Quoted 3 lines
MAINTAINERS +1 -0
+F: softmmu/cpu-throttle.c
 F: qapi/run-state.json

Can you reorder patches #1/#2 to avoid moving cpu-throttle code twice?

I have no preference, will wait for more comments then, as you suggested elsewhere.

Quoted 6 lines

Otherwise this patch looks good.

[...]

#8 lore raw

RFC v3 3/4 cpu-timers, icount: new modules

In reply to Claudio Fontana

refactoring of cpus.c continues with cpu timer state extraction.

cpu-timers: responsible for the cpu timers state, and for access to 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 misuses icount to warp time (qtest_clock_warp). In order to solve this problem, detach instead qtest from icount, and use a trivial separate counter for it.

This requires fixing assumptions scattered in the code that qtest_enabled() implies icount_enabled().

No functionality change.

---
 accel/qtest.c                |   6 +-
 accel/tcg/cpu-exec.c         |  43 ++-
 accel/tcg/tcg-all.c          |   7 +-
 accel/tcg/translate-all.c    |   3 +-
 docs/replay.txt              |   6 +-
 exec.c                       |   4 -
 hw/core/ptimer.c             |   6 +-
 hw/i386/x86.c                |   1 +
 include/exec/cpu-all.h       |   4 +
 include/exec/exec-all.h      |   4 +-
 include/qemu/timer.h         |  22 +-
 include/sysemu/cpu-timers.h  |  72 +++++
 include/sysemu/cpus.h        |  12 +-
 include/sysemu/qtest.h       |   2 +
 include/sysemu/replay.h      |   4 +-
 replay/replay.c              |   6 +-
 softmmu/Makefile.objs        |   2 +
 softmmu/cpu-timers.c         | 267 ++++++++++++++++
 softmmu/cpus.c               | 731 +------------------------------------------
 softmmu/icount.c             | 496 +++++++++++++++++++++++++++++
 softmmu/qtest.c              |  34 +-
 softmmu/timers-state.h       |  45 +++
 softmmu/vl.c                 |   8 +-
 stubs/Makefile.objs          |   3 +-
 stubs/clock-warp.c           |   4 +-
 stubs/cpu-get-clock.c        |   3 +-
 stubs/cpu-get-icount.c       |  21 --
 stubs/icount.c               |  22 ++
 stubs/qemu-timer-notify-cb.c |   8 +
 stubs/qtest.c                |   5 +
 target/alpha/translate.c     |   3 +-
 target/arm/helper.c          |   7 +-
 target/riscv/csr.c           |   8 +-
 tests/ptimer-test-stubs.c    |   7 +-
 tests/test-timed-average.c   |   2 +-
 util/main-loop.c             |   4 +-
 util/qemu-timer.c            |  12 +-
 37 files changed, 1062 insertions(+), 832 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/cpu-get-icount.c
 create mode 100644 stubs/icount.c
 create mode 100644 stubs/qemu-timer-notify-cb.c
accel/qtest.c +1 -5
index 5b88f55921..119d0f16a4 100644
@@ -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 +36 -7

90 lines not on this page · raw message

accel/tcg/tcg-all.c +4 -3
index 3b4fda5640..e27385d051 100644
@@ -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
index 42ce1dfcff..479edeb2ea 100644
@@ -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;
docs/replay.txt +3 -3
index 70c27edb36..8952e6d852 100644
@@ -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
 -------------
exec.c +0 -4
index 5162f0d12f..db9a90469b 100644
@@ -104,10 +104,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 +3 -3
index b5a54e2536..149c8e06a5 100644
@@ -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,7 @@ 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 +217,7 @@ 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
index 7a3bc7ab66..002b3cabc2 100644
@@ -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
index d14374bdd4..49eedd714d 100644
@@ -409,8 +409,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 */
 
 int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
include/exec/exec-all.h +2 -2
index 8792bea07a..c1f51e37af 100644
@@ -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
@@ -489,7 +489,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 +1 -21
index 6a8b48b5a9..5336c756d5 100644
@@ -166,7 +166,7 @@ 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
+ * 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 +72 -0

72 lines not on this page · raw message

include/sysemu/cpus.h +1 -11
index 3c1da6a018..149de000a0 100644
@@ -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
index eedd3664f0..91acc98ac4 100644
@@ -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_clock(void);
+
 #endif
include/sysemu/replay.h +2 -2
index 5471bb514d..a140d69a73 100644
@@ -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 +3 -3
index 706c7b4f4b..9896a3b6f5 100644
@@ -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"
@@ -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)
@@ -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/Makefile.objs +2 -0
index a414a74c50..9c0125f37b 100644
@@ -7,6 +7,8 @@ obj-y += balloon.o
 obj-y += ioport.o
 obj-y += memory.o
 obj-y += memory_mapping.o
+obj-y += cpu-timers.o
+obj-$(CONFIG_TCG) += icount.o
 
 obj-y += qtest.o
 
softmmu/cpu-timers.c new file +267 -0

267 lines not on this page · raw message

softmmu/cpus.c +10 -721

812 lines not on this page · raw message

softmmu/icount.c new file +496 -0

496 lines not on this page · raw message

softmmu/qtest.c +33 -1
index 5672b75c35..d79b3f3db1 100644
@@ -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_clock(void)
+{
+    return atomic_read_i64(&qtest_clock_counter);
+}
+
+static void qtest_set_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_clock(qtest_get_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 +45 -0

45 lines not on this page · raw message

softmmu/vl.c +5 -3
index ae5451bc23..ed53cd1b62 100644
@@ -73,6 +73,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"
@@ -2675,7 +2676,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;
 }
 
@@ -2785,7 +2786,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() || qtest_enabled())) {
         error_report("-icount is not allowed with hardware virtualization");
         exit(1);
     }
@@ -4233,7 +4234,8 @@ void qemu_init(int argc, char **argv, char **envp)
     /* spice needs the timers to be initialized by this point */
     qemu_spice_init();
 
-    cpu_ticks_init();
+    /* initialize cpu timers and VCPU throttle modules */
+    cpu_timers_init();
 
     if (default_net) {
         QemuOptsList *net = qemu_find_opts("net");
stubs/Makefile.objs +2 -1
index 6a9e3135e8..238d6f8e9f 100644
@@ -4,7 +4,8 @@ stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
 stub-obj-y += clock-warp.o
 stub-obj-y += cpu-get-clock.o
-stub-obj-y += cpu-get-icount.o
+stub-obj-y += qemu-timer-notify-cb.o
+stub-obj-y += icount.o
 stub-obj-y += dump.o
 stub-obj-y += error-printf.o
 stub-obj-y += fdset.o
stubs/clock-warp.c +2 -2
index b53e5dd94c..304da5091c 100644
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
-#include "qemu/timer.h"
+#include "sysemu/cpu-timers.h"
 
-void qemu_start_warp_timer(void)
+void icount_start_warp_timer(void)
 {
 }
 
stubs/cpu-get-clock.c +2 -1
index 5a92810e87..9e92404816 100644
@@ -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
deleted file mode 100644
index b35f844638..0000000000
@@ -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 +22 -0
new file mode 100644
index 0000000000..9054724e92
@@ -0,0 +1,22 @@
+#include "qemu/osdep.h"
+#include "sysemu/cpu-timers.h"
+
+int64_t icount_get(void)
+{
+    abort();
+}
+
+int64_t icount_get_raw(void)
+{
+    abort();
+}
+
+void icount_configure(QemuOpts *opts, Error **errp)
+{
+    abort();
+}
+
+int icount_enabled(void)
+{
+    return 0;
+}
stubs/qemu-timer-notify-cb.c new file +8 -0
new file mode 100644
index 0000000000..845e46f8e0
@@ -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
index 891eb954fb..fe775a622c 100644
@@ -18,3 +18,8 @@ bool qtest_driver(void)
 {
     return false;
 }
+
+int64_t qtest_get_clock(void)
+{
+    return 0;
+}
target/alpha/translate.c +2 -1
index 8870284f57..36be602179 100644
@@ -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 +4 -3
index a92ae55672..c9f99f7952 100644
@@ -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"
@@ -1205,17 +1206,17 @@ 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)
 {
-    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 +4 -4
index 11d184cd16..6093f73e3a 100644
@@ -194,8 +194,8 @@ static int write_fcsr(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) {
-        *val = cpu_get_icount();
+    if (icount_enabled()) {
+        *val = icount_get();
     } else {
         *val = cpu_get_host_ticks();
     }
@@ -209,8 +209,8 @@ 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) {
-        *val = cpu_get_icount() >> 32;
+    if (icount_enabled()) {
+        *val = icount_get() >> 32;
     } else {
         *val = cpu_get_host_ticks() >> 32;
     }
tests/ptimer-test-stubs.c +5 -2
index ed393d9082..b4447a3e44 100644
@@ -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,10 @@ QEMUTimerListGroup main_loop_tlg;
 
 int64_t ptimer_test_time_ns;
 
-/* Do not artificially limit period - see hw/core/ptimer.c.  */
-int use_icount = 1;
+int icount_enabled(void)
+{
+    return 0;
+}
 bool qtest_allowed;
 
 void timer_init_full(QEMUTimer *ts,
tests/test-timed-average.c +1 -1
index e2bcf5fe13..82c92500df 100644
@@ -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 +2 -2
index eda63fe4e0..f1af697572 100644
@@ -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"
@@ -521,7 +521,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 +8 -4
index b6575a2cd5..12d89fc01e 100644
@@ -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_cb
 
 bool 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)
@@ -417,7 +419,7 @@ static void timerlist_rearm(QEMUTimerList *timer_list)
 {
     /* Interrupt execution to force deadline recalculation.  */
     if (timer_list->clock->type == QEMU_CLOCK_VIRTUAL) {
-        qemu_start_warp_timer();
+        icount_start_warp_timer();
     }
     timerlist_notify(timer_list);
 }
@@ -647,8 +649,10 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
         return get_clock();
     default:
     case QEMU_CLOCK_VIRTUAL:
-        if (use_icount) {
-            return cpu_get_icount();
+        if (icount_enabled()) {
+            return icount_get();
+        } else if (qtest_enabled()) { /* for qtest_clock_warp */
+            return qtest_get_clock();
         } else {
             return cpu_get_clock();
         }
Signature · 1 line
2.16.4
#9 lore raw

Re: [RFC v3 3/4] cpu-timers, icount: new modules

Quoted 56 lines · Claudio Fontana

refactoring of cpus.c continues with cpu timer state extraction.

cpu-timers: responsible for the cpu timers state, and for access to 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 misuses icount to warp time (qtest_clock_warp). In order to solve this problem, detach instead qtest from icount, and use a trivial separate counter for it.

This requires fixing assumptions scattered in the code that qtest_enabled() implies icount_enabled().

No functionality change.

---
 accel/qtest.c                |   6 +-
 accel/tcg/cpu-exec.c         |  43 ++-
 accel/tcg/tcg-all.c          |   7 +-
 accel/tcg/translate-all.c    |   3 +-
 docs/replay.txt              |   6 +-
 exec.c                       |   4 -
 hw/core/ptimer.c             |   6 +-
 hw/i386/x86.c                |   1 +
 include/exec/cpu-all.h       |   4 +
 include/exec/exec-all.h      |   4 +-
 include/qemu/timer.h         |  22 +-
 include/sysemu/cpu-timers.h  |  72 +++++
 include/sysemu/cpus.h        |  12 +-
 include/sysemu/qtest.h       |   2 +
 include/sysemu/replay.h      |   4 +-
 replay/replay.c              |   6 +-
 softmmu/Makefile.objs        |   2 +
 softmmu/cpu-timers.c         | 267 ++++++++++++++++
 softmmu/cpus.c               | 731 +------------------------------------------
 softmmu/icount.c             | 496 +++++++++++++++++++++++++++++
 softmmu/qtest.c              |  34 +-
 softmmu/timers-state.h       |  45 +++
 softmmu/vl.c                 |   8 +-
 stubs/Makefile.objs          |   3 +-
 stubs/clock-warp.c           |   4 +-
 stubs/cpu-get-clock.c        |   3 +-
 stubs/cpu-get-icount.c       |  21 --
 stubs/icount.c               |  22 ++
 stubs/qemu-timer-notify-cb.c |   8 +
 stubs/qtest.c                |   5 +
 target/alpha/translate.c     |   3 +-
 target/arm/helper.c          |   7 +-
 target/riscv/csr.c           |   8 +-
 tests/ptimer-test-stubs.c    |   7 +-
 tests/test-timed-average.c   |   2 +-
 util/main-loop.c             |   4 +-
 util/qemu-timer.c            |  12 +-
Quoted 8 lines
 37 files changed, 1062 insertions(+), 832 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/cpu-get-icount.c
 create mode 100644 stubs/icount.c
 create mode 100644 stubs/qemu-timer-notify-cb.c

Similarly I'd rather see this patch comes before your current #1 "move softmmu only files from root". Anyway wait for other reviewers before spending time to reorder the series.

#10 lore raw

Re: [RFC v3 3/4] cpu-timers, icount: new modules

Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 56 lines · Claudio Fontana

refactoring of cpus.c continues with cpu timer state extraction.

cpu-timers: responsible for the cpu timers state, and for access to 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 misuses icount to warp time (qtest_clock_warp). In order to solve this problem, detach instead qtest from icount, and use a trivial separate counter for it.

This requires fixing assumptions scattered in the code that qtest_enabled() implies icount_enabled().

No functionality change.

---
 accel/qtest.c                |   6 +-
 accel/tcg/cpu-exec.c         |  43 ++-
 accel/tcg/tcg-all.c          |   7 +-
 accel/tcg/translate-all.c    |   3 +-
 docs/replay.txt              |   6 +-
 exec.c                       |   4 -
 hw/core/ptimer.c             |   6 +-
 hw/i386/x86.c                |   1 +
 include/exec/cpu-all.h       |   4 +
 include/exec/exec-all.h      |   4 +-
 include/qemu/timer.h         |  22 +-
 include/sysemu/cpu-timers.h  |  72 +++++
 include/sysemu/cpus.h        |  12 +-
 include/sysemu/qtest.h       |   2 +
 include/sysemu/replay.h      |   4 +-
 replay/replay.c              |   6 +-
 softmmu/Makefile.objs        |   2 +
 softmmu/cpu-timers.c         | 267 ++++++++++++++++
 softmmu/cpus.c               | 731 +------------------------------------------
 softmmu/icount.c             | 496 +++++++++++++++++++++++++++++
 softmmu/qtest.c              |  34 +-
 softmmu/timers-state.h       |  45 +++
 softmmu/vl.c                 |   8 +-
 stubs/Makefile.objs          |   3 +-
 stubs/clock-warp.c           |   4 +-
 stubs/cpu-get-clock.c        |   3 +-
 stubs/cpu-get-icount.c       |  21 --
 stubs/icount.c               |  22 ++
 stubs/qemu-timer-notify-cb.c |   8 +
 stubs/qtest.c                |   5 +
 target/alpha/translate.c     |   3 +-
 target/arm/helper.c          |   7 +-
 target/riscv/csr.c           |   8 +-
 tests/ptimer-test-stubs.c    |   7 +-
 tests/test-timed-average.c   |   2 +-
 util/main-loop.c             |   4 +-
 util/qemu-timer.c            |  12 +-
Quoted 8 lines
 37 files changed, 1062 insertions(+), 832 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/cpu-get-icount.c
 create mode 100644 stubs/icount.c
 create mode 100644 stubs/qemu-timer-notify-cb.c
Quoted 5 lines

Similarly I'd rather see this patch comes before your current #1 "move softmmu only files from root". Anyway wait for other reviewers before spending time to reorder the series.

I understand the desire to avoid moving cpus code back and forth, will then wait for other comments as you suggest.

Ciao and thanks,

Claudio

#11 lore raw

RFC v3 4/4 cpus: extract out accel-specific code to each accel

In reply to Claudio Fontana

each accelerator registers a new "CpusAccelInterface" on initialization, providing functions for starting a vcpu, kicking a vcpu, and sychronizing state.

This way the code in cpus.cc is now all general softmmu code, nothing (or almost nothing) accelerator-specific anymore.

---
 MAINTAINERS                          |   1 +
 accel/kvm/Makefile.objs              |   2 +
 accel/kvm/kvm-all.c                  |  15 +-
 accel/kvm/kvm-cpus-interface.c       |  94 ++++
 accel/kvm/kvm-cpus-interface.h       |   8 +
 accel/qtest.c                        |  82 ++++
 accel/stubs/kvm-stub.c               |   3 +-
 accel/tcg/Makefile.objs              |   1 +
 accel/tcg/tcg-all.c                  |  12 +-
 accel/tcg/tcg-cpus-interface.c       | 523 ++++++++++++++++++++
 accel/tcg/tcg-cpus-interface.h       |   8 +
 hw/core/cpu.c                        |   1 +
 include/sysemu/cpus.h                |  32 ++
 include/sysemu/hvf.h                 |   1 -
 include/sysemu/hw_accel.h            |  57 +--
 include/sysemu/kvm.h                 |   2 +-
 softmmu/cpus.c                       | 911 +++--------------------------------
 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-interface.c     |  85 ++++
 target/i386/hax-cpus-interface.h     |   8 +
 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-interface.c |  92 ++++
 target/i386/hvf/hvf-cpus-interface.h |   8 +
 target/i386/hvf/hvf.c                |   5 +-
 target/i386/whpx-all.c               |   3 +
 target/i386/whpx-cpus-interface.c    |  96 ++++
 target/i386/whpx-cpus-interface.h    |   8 +
 33 files changed, 1220 insertions(+), 903 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h
MAINTAINERS +1 -0
index 708768f120..ac993348fe 100644
@@ -426,6 +426,7 @@ WHPX CPUs
 M: Sunil Muthuswamy <[email protected]>
 S: Supported
 F: target/i386/whpx-all.c
+F: target/i386/whpx-cpus-interface.c
 F: target/i386/whp-dispatch.h
 F: accel/stubs/whpx-stub.c
 F: include/sysemu/whpx.h
accel/kvm/Makefile.objs +2 -0
index fdfa481578..4babbf7796 100644
@@ -1,2 +1,4 @@
 obj-y += kvm-all.o
+obj-y += kvm-cpus-interface.o
+
 obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o
accel/kvm/kvm-all.c +14 -1
index d06cc04079..c9cbbb1184 100644
@@ -45,6 +45,10 @@
 #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-interface.h"
 
 #include "hw/boards.h"
 
@@ -329,7 +333,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;
@@ -363,6 +367,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;
@@ -2146,6 +2158,7 @@ static int kvm_init(MachineState *ms)
         qemu_balloon_inhibit(true);
     }
 
+    cpus_register_accel_interface(&kvm_cpus_interface);
     return 0;
 
 err:
accel/kvm/kvm-cpus-interface.c new file +94 -0

94 lines not on this page · raw message

accel/kvm/kvm-cpus-interface.h new file +8 -0
new file mode 100644
index 0000000000..5531a4a4ad
@@ -0,0 +1,8 @@
+#ifndef KVM_CPUS_INTERFACE_H
+#define KVM_CPUS_INTERFACE_H
+
+#include "sysemu/cpus.h"
+
+extern CpusAccelInterface kvm_cpus_interface;
+
+#endif /* KVM_CPUS_INTERFACE */
accel/qtest.c +82 -0

97 lines not on this page · raw message

accel/stubs/kvm-stub.c +1 -2
index 82f118d2df..69f8a842da 100644
@@ -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)
accel/tcg/Makefile.objs +1 -0
index a92f2c454b..ddc57acae2 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_SOFTMMU) += tcg-all.o
 obj-$(CONFIG_SOFTMMU) += cputlb.o
+obj-$(CONFIG_SOFTMMU) += tcg-cpus-interface.o
 obj-y += tcg-runtime.o tcg-runtime-gvec.o
 obj-y += cpu-exec.o cpu-exec-common.o translate-all.o
 obj-y += translator.o
accel/tcg/tcg-all.c +7 -5
index e27385d051..9e332585d3 100644
@@ -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-interface.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_interface(&tcg_cpus_interface);
+
     return 0;
 }
 
accel/tcg/tcg-cpus-interface.c new file +523 -0

523 lines not on this page · raw message

accel/tcg/tcg-cpus-interface.h new file +8 -0
new file mode 100644
index 0000000000..c6e96b2af4
@@ -0,0 +1,8 @@
+#ifndef TCG_CPUS_INTERFACE_H
+#define TCG_CPUS_INTERFACE_H
+
+#include "sysemu/cpus.h"
+
+extern CpusAccelInterface tcg_cpus_interface;
+
+#endif /* TCG_CPUS_INTERFACE */
hw/core/cpu.c +1 -0
index 5284d384fb..b601654a10 100644
@@ -33,6 +33,7 @@
 #include "hw/qdev-properties.h"
 #include "trace-root.h"
 #include "qemu/plugin.h"
+#include "sysemu/hw_accel.h"
 
 CPUInterruptHandler cpu_interrupt_handler;
 
include/sysemu/cpus.h +32 -0
index 149de000a0..cae22afe4d 100644
@@ -4,7 +4,39 @@
 #include "qemu/timer.h"
 
 /* cpus.c */
+
+/* CPU execution threads */
+
+typedef struct CpusAccelInterface {
+    void (*create_vcpu_thread)(CPUState *cpu);
+    void (*kick_vcpu_thread)(CPUState *cpu);
+
+    void (*cpu_synchronize_post_reset)(CPUState *cpu);
+    void (*cpu_synchronize_post_init)(CPUState *cpu);
+    void (*cpu_synchronize_state)(CPUState *cpu);
+    void (*cpu_synchronize_pre_loadvm)(CPUState *cpu);
+} CpusAccelInterface;
+
+/* register accel-specific interface */
+void cpus_register_accel_interface(CpusAccelInterface *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_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/hvf.h +0 -1
index d211e808e9..cdd4172b24 100644
@@ -86,7 +86,6 @@ int hvf_smp_cpu_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_post_init(CPUState *, run_on_cpu_data);
 
 void hvf_vcpu_destroy(CPUState *);
 void hvf_raise_event(CPUState *);
include/sysemu/hw_accel.h +5 -52

66 lines not on this page · raw message

include/sysemu/kvm.h +1 -1
index 3b2250471c..3d84c940db 100644
@@ -218,7 +218,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 +76 -835

1,054 lines not on this page · raw message

stubs/Makefile.objs +1 -0
index 238d6f8e9f..0256c8cdcd 100644
@@ -45,4 +45,5 @@ stub-obj-y += pci-host-piix.o
 stub-obj-y += ram-block.o
 stub-obj-y += ramfb.o
 stub-obj-y += fw_cfg.o
+stub-obj-y += cpu-synchronize-state.o
 stub-obj-$(CONFIG_SOFTMMU) += semihost.o
stubs/cpu-synchronize-state.c new file +15 -0
new file mode 100644
index 0000000000..3112fe439d
@@ -0,0 +1,15 @@
+#include "qemu/osdep.h"
+#include "sysemu/hw_accel.h"
+
+void cpu_synchronize_state(CPUState *cpu)
+{
+}
+void cpu_synchronize_post_reset(CPUState *cpu)
+{
+}
+void cpu_synchronize_post_init(CPUState *cpu)
+{
+}
+void cpu_synchronize_pre_loadvm(CPUState *cpu)
+{
+}
target/i386/Makefile.objs +4 -3
index 48e0c28434..a847064e68 100644
@@ -9,14 +9,15 @@ obj-y += machine.o arch_memory_mapping.o arch_dump.o monitor.o
 obj-$(CONFIG_KVM) += kvm.o
 obj-$(CONFIG_HYPERV) += hyperv.o
 obj-$(call lnot,$(CONFIG_HYPERV)) += hyperv-stub.o
+obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-cpus-interface.o
 ifeq ($(CONFIG_WIN32),y)
-obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-windows.o
+obj-$(CONFIG_HAX) += hax-windows.o
 endif
 ifeq ($(CONFIG_POSIX),y)
-obj-$(CONFIG_HAX) += hax-all.o hax-mem.o hax-posix.o
+obj-$(CONFIG_HAX) += hax-posix.o
 endif
 obj-$(CONFIG_HVF) += hvf/
-obj-$(CONFIG_WHPX) += whpx-all.o
+obj-$(CONFIG_WHPX) += whpx-all.o whpx-cpus-interface.o
 endif
 obj-$(CONFIG_SEV) += sev.o
 obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o
target/i386/hax-all.c +5 -1
index f9c83fff25..56c99bffd2 100644
@@ -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-interface.h"
+
 #define DEBUG_HAX 0
 
 #define DPRINTF(fmt, ...) \
@@ -361,6 +362,9 @@ static int hax_accel_init(MachineState *ms)
                 !ret ? "working" : "not working",
                 !ret ? "fast virt" : "emulation");
     }
+    if (ret == 0) {
+        cpus_register_accel_interface(&hax_cpus_interface);
+    }
     return ret;
 }
 
target/i386/hax-cpus-interface.c new file +85 -0

85 lines not on this page · raw message

target/i386/hax-cpus-interface.h new file +8 -0
new file mode 100644
index 0000000000..a06f3df752
@@ -0,0 +1,8 @@
+#ifndef HAX_CPUS_INTERFACE_H
+#define HAX_CPUS_INTERFACE_H
+
+#include "sysemu/cpus.h"
+
+extern CpusAccelInterface hax_cpus_interface;
+
+#endif /* HAX_CPUS_INTERFACE */
target/i386/hax-i386.h +2 -0
index 54e9d8b057..667139c7af 100644
@@ -61,6 +61,8 @@ int hax_inject_interrupt(CPUArchState *env, int vector);
 struct hax_vm *hax_vm_create(struct hax_state *hax);
 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
index 3bad89f133..ea956ddfc1 100644
@@ -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
index 863c2bcc19..469b48e608 100644
@@ -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/hvf/Makefile.objs +1 -1
index 927b86bc67..bdbc2c0227 100644
@@ -1,2 +1,2 @@
-obj-y += hvf.o
+obj-y += hvf.o hvf-cpus-interface.o
 obj-y += x86.o x86_cpuid.o x86_decode.o x86_descr.o x86_emu.o x86_flags.o x86_mmu.o x86hvf.o x86_task.o
target/i386/hvf/hvf-cpus-interface.c new file +92 -0

92 lines not on this page · raw message

target/i386/hvf/hvf-cpus-interface.h new file +8 -0
new file mode 100644
index 0000000000..6ea38742e5
@@ -0,0 +1,8 @@
+#ifndef HVF_CPUS_INTERFACE_H
+#define HVF_CPUS_INTERFACE_H
+
+#include "sysemu/cpus.h"
+
+extern CpusAccelInterface hvf_cpus_interface;
+
+#endif /* HVF_CPUS_INTERFACE */
target/i386/hvf/hvf.c +4 -1
index d72543dc31..75cdf88cec 100644
@@ -72,6 +72,8 @@
 #include "sysemu/accel.h"
 #include "target/i386/cpu.h"
 
+#include "hvf-cpus-interface.h"
+
 HVFState *hvf_state;
 
 static void assert_hvf_ok(hv_return_t ret)
@@ -312,7 +314,7 @@ void hvf_cpu_synchronize_post_reset(CPUState *cpu_state)
     run_on_cpu(cpu_state, do_hvf_cpu_synchronize_post_reset, RUN_ON_CPU_NULL);
 }
 
-void _hvf_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
+static void _hvf_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
 {
     CPUState *cpu_state = cpu;
     hvf_put_registers(cpu_state);
@@ -979,6 +981,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_interface(&hvf_cpus_interface);
     return 0;
 }
 
target/i386/whpx-all.c +3 -0
index c78baac6df..daac9858ae 100644
@@ -24,6 +24,8 @@
 #include "migration/blocker.h"
 #include "whp-dispatch.h"
 
+#include "whpx-cpus-interface.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_interface(&whpx_cpus_interface);
 
     printf("Windows Hypervisor Platform accelerator is operational\n");
     return 0;
target/i386/whpx-cpus-interface.c new file +96 -0

96 lines not on this page · raw message

target/i386/whpx-cpus-interface.h new file +8 -0
new file mode 100644
index 0000000000..084e8b15b8
@@ -0,0 +1,8 @@
+#ifndef WHPX_CPUS_INTERFACE_H
+#define WHPX_CPUS_INTERFACE_H
+
+#include "sysemu/cpus.h"
+
+extern CpusAccelInterface whpx_cpus_interface;
+
+#endif /* WHPX_CPUS_INTERFACE */
Signature · 1 line
2.16.4
#12 lore raw

Re: [RFC v3 4/4] cpus: extract out accel-specific code to each accel

Quoted 46 lines · Claudio Fontana

each accelerator registers a new "CpusAccelInterface" on initialization, providing functions for starting a vcpu, kicking a vcpu, and sychronizing state.

This way the code in cpus.cc is now all general softmmu code, nothing (or almost nothing) accelerator-specific anymore.

---
 MAINTAINERS                          |   1 +
 accel/kvm/Makefile.objs              |   2 +
 accel/kvm/kvm-all.c                  |  15 +-
 accel/kvm/kvm-cpus-interface.c       |  94 ++++
 accel/kvm/kvm-cpus-interface.h       |   8 +
 accel/qtest.c                        |  82 ++++
 accel/stubs/kvm-stub.c               |   3 +-
 accel/tcg/Makefile.objs              |   1 +
 accel/tcg/tcg-all.c                  |  12 +-
 accel/tcg/tcg-cpus-interface.c       | 523 ++++++++++++++++++++
 accel/tcg/tcg-cpus-interface.h       |   8 +
 hw/core/cpu.c                        |   1 +
 include/sysemu/cpus.h                |  32 ++
 include/sysemu/hvf.h                 |   1 -
 include/sysemu/hw_accel.h            |  57 +--
 include/sysemu/kvm.h                 |   2 +-
 softmmu/cpus.c                       | 911 +++--------------------------------
 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-interface.c     |  85 ++++
 target/i386/hax-cpus-interface.h     |   8 +
 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-interface.c |  92 ++++
 target/i386/hvf/hvf-cpus-interface.h |   8 +
 target/i386/hvf/hvf.c                |   5 +-
 target/i386/whpx-all.c               |   3 +
 target/i386/whpx-cpus-interface.c    |  96 ++++
 target/i386/whpx-cpus-interface.h    |   8 +
 33 files changed, 1220 insertions(+), 903 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
Quoted 8 lines
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h

Patch looks good, but remember to add proper license headers to all new files when removing the RFC tag.

#13 lore raw

Re: [RFC v3 4/4] cpus: extract out accel-specific code to each accel

Quoted 56 lines · Philippe Mathieu-Daudé
Quoted 46 lines · Claudio Fontana

each accelerator registers a new "CpusAccelInterface" on initialization, providing functions for starting a vcpu, kicking a vcpu, and sychronizing state.

This way the code in cpus.cc is now all general softmmu code, nothing (or almost nothing) accelerator-specific anymore.

---
 MAINTAINERS                          |   1 +
 accel/kvm/Makefile.objs              |   2 +
 accel/kvm/kvm-all.c                  |  15 +-
 accel/kvm/kvm-cpus-interface.c       |  94 ++++
 accel/kvm/kvm-cpus-interface.h       |   8 +
 accel/qtest.c                        |  82 ++++
 accel/stubs/kvm-stub.c               |   3 +-
 accel/tcg/Makefile.objs              |   1 +
 accel/tcg/tcg-all.c                  |  12 +-
 accel/tcg/tcg-cpus-interface.c       | 523 ++++++++++++++++++++
 accel/tcg/tcg-cpus-interface.h       |   8 +
 hw/core/cpu.c                        |   1 +
 include/sysemu/cpus.h                |  32 ++
 include/sysemu/hvf.h                 |   1 -
 include/sysemu/hw_accel.h            |  57 +--
 include/sysemu/kvm.h                 |   2 +-
 softmmu/cpus.c                       | 911 +++--------------------------------
 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-interface.c     |  85 ++++
 target/i386/hax-cpus-interface.h     |   8 +
 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-interface.c |  92 ++++
 target/i386/hvf/hvf-cpus-interface.h |   8 +
 target/i386/hvf/hvf.c                |   5 +-
 target/i386/whpx-all.c               |   3 +
 target/i386/whpx-cpus-interface.c    |  96 ++++
 target/i386/whpx-cpus-interface.h    |   8 +
 33 files changed, 1220 insertions(+), 903 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
Quoted 8 lines
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h
Quoted 3 lines

Patch looks good, but remember to add proper license headers to all new files when removing the RFC tag.

Will do, thanks!

Ciao,

Claudio

#14 lore raw

Re: [RFC v3 4/4] cpus: extract out accel-specific code to each accel

In reply to Claudio Fontana
Quoted 46 lines · Claudio Fontana

each accelerator registers a new "CpusAccelInterface" on initialization, providing functions for starting a vcpu, kicking a vcpu, and sychronizing state.

This way the code in cpus.cc is now all general softmmu code, nothing (or almost nothing) accelerator-specific anymore.

---
 MAINTAINERS                          |   1 +
 accel/kvm/Makefile.objs              |   2 +
 accel/kvm/kvm-all.c                  |  15 +-
 accel/kvm/kvm-cpus-interface.c       |  94 ++++
 accel/kvm/kvm-cpus-interface.h       |   8 +
 accel/qtest.c                        |  82 ++++
 accel/stubs/kvm-stub.c               |   3 +-
 accel/tcg/Makefile.objs              |   1 +
 accel/tcg/tcg-all.c                  |  12 +-
 accel/tcg/tcg-cpus-interface.c       | 523 ++++++++++++++++++++
 accel/tcg/tcg-cpus-interface.h       |   8 +
 hw/core/cpu.c                        |   1 +
 include/sysemu/cpus.h                |  32 ++
 include/sysemu/hvf.h                 |   1 -
 include/sysemu/hw_accel.h            |  57 +--
 include/sysemu/kvm.h                 |   2 +-
 softmmu/cpus.c                       | 911 +++--------------------------------
 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-interface.c     |  85 ++++
 target/i386/hax-cpus-interface.h     |   8 +
 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-interface.c |  92 ++++
 target/i386/hvf/hvf-cpus-interface.h |   8 +
 target/i386/hvf/hvf.c                |   5 +-
 target/i386/whpx-all.c               |   3 +
 target/i386/whpx-cpus-interface.c    |  96 ++++
 target/i386/whpx-cpus-interface.h    |   8 +
 33 files changed, 1220 insertions(+), 903 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
Quoted 8 lines
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h

Hi Claudio,

Overall it looks good.

I wonder if the new structure should get singular form, i.e. softmmu/cpu.c instead of softmmu/cpus.c

Perhaps cpus.c had plural form because it was related to implementation of multiple CPUs/accels. After the split, each accel got it's own implementation of accel interface.

"<accel>-cpus-interface.c" contains implementation rather than interface it's a bit confusing. Perhaps it should be called: "<accel>-cpu.c" or even "<accel>-accel.c".

By the way, If we use registration for each accel, does it mean that include/sysemu/<accel>.h and accel stubs are no longer needed in shared location?

There's an AccelClass in accel/accel.c, I wonder if it should be re-used for accel CPU registration? I don't know but may be generic the leftover of cpus.c also belongs to accel/ rather than softmmu/?

Quoted 11 lines
include/sysemu/cpus.h +2 -0
index 149de000a0..cae22afe4d 100644
@@ -4,7 +4,39 @@
 #include "qemu/timer.h"
 
 /* cpus.c */
+
+/* CPU execution threads */

include/sysemu/cpus.h line 18

Quoted 10 lines
include/sysemu/cpus.h +10 -0
+
+typedef struct CpusAccelInterface {
+    void (*create_vcpu_thread)(CPUState *cpu);
+    void (*kick_vcpu_thread)(CPUState *cpu);
+
+    void (*cpu_synchronize_post_reset)(CPUState *cpu);
+    void (*cpu_synchronize_post_init)(CPUState *cpu);
+    void (*cpu_synchronize_state)(CPUState *cpu);
+    void (*cpu_synchronize_pre_loadvm)(CPUState *cpu);
+} CpusAccelInterface;

I think plural name may be replaced to singular. Interface suffix doesn't seem to be used in QEMU.

cpu_ and _vcpu are sort meaning the same and may be replaced to generic cpu_ prefix. There's a CPUState, CPU<Arch>State, and IMO shorter CPUAccel seems to match the naming. I also don't know if cpu_ prefix should be kept.

So here's how I see the interface:

typedef struct CPUAccel {
    void (*create_thread)(CPUState *cpu);
    void (*kick_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);
} CPUAccel;

include/sysemu/cpus.h line 28

Quoted 10 lines
include/sysemu/cpus.h +10 -0
+
+/* register accel-specific interface */
+void cpus_register_accel_interface(CpusAccelInterface *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);

If it's addressing a single CPU should it be singular too, i.e. cpu_kick_thread?

Quoted 75 lines
include/sysemu/cpus.h +10 -0
+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);
target/i386/hvf/Makefile.objs +1 -1
index 927b86bc67..bdbc2c0227 100644
@@ -1,2 +1,2 @@
-obj-y += hvf.o
+obj-y += hvf.o hvf-cpus-interface.o
 obj-y += x86.o x86_cpuid.o x86_decode.o x86_descr.o x86_emu.o x86_flags.o x86_mmu.o x86hvf.o x86_task.o
target/i386/hvf/hvf-cpus-interface.c new file +47 -0
new file mode 100644
index 0000000000..54bfe307c1
@@ -0,0 +1,92 @@
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "sysemu/hvf.h"
+#include "sysemu/runstate.h"
+#include "sysemu/cpus.h"
+#include "qemu/guest-random.h"
+
+#include "hvf-cpus-interface.h"
+
+/*
+ * The HVF-specific vCPU thread function. This one should only run when the host
+ * CPU supports the VMX "unrestricted guest" feature.
+ */
+static void *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));
+

target/i386/hvf/hvf-cpus-interface.c line 57

Quoted 10 lines
target/i386/hvf/hvf-cpus-interface.c new file +10 -0
+    hvf_vcpu_destroy(cpu);
+    cpu_thread_signal_destroyed(cpu);
+    qemu_mutex_unlock_iothread();
+    rcu_unregister_thread();
+    return NULL;
+}
+
+static void hvf_kick_vcpu_thread(CPUState *cpu)
+{
+    cpus_kick_thread(cpu);

I think we should leave it empty since it's not really implemented for HVF. Here's a WIP implementation I'm yet to send:

https://github.com/roolebo/qemu/commit/4437a4b8af31b0adaa58375f09e0b8547507f64f#diff-5e6ad1baa140ca4a1743b5a2f1a664b5R970

Quoted 18 lines
target/i386/hvf/hvf-cpus-interface.c new file +18 -0
+}
+
+static void hvf_cpu_synchronize_noop(CPUState *cpu)
+{
+}
+
+static void hvf_start_vcpu_thread(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));

target/i386/hvf/hvf-cpus-interface.c line 85

Quoted 10 lines
target/i386/hvf/hvf-cpus-interface.c new file +10 -0
+    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, hvf_cpu_thread_fn,
+                       cpu, QEMU_THREAD_JOINABLE);
+}
+
+CpusAccelInterface hvf_cpus_interface = {
+    .create_vcpu_thread = hvf_start_vcpu_thread,

I think it was meant as hvf_create_vcpu_thread.

target/i386/hvf/hvf-cpus-interface.c line 91

Quoted 6 lines
target/i386/hvf/hvf-cpus-interface.c new file +6 -0
+    .kick_vcpu_thread = hvf_kick_vcpu_thread,
+
+    .cpu_synchronize_post_reset = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_post_init = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_state = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_pre_loadvm = hvf_cpu_synchronize_noop,

I have tested the RFC with hvf accel and it seems to work although I expected it fail. The noop functions are the reason of the behaviour. In some sense it's not equivalent to what it was before but to be fair it's not possible to use existing hvf_cpu_synchronize_* functions in target/i386/hvf/hvf.c without breaking hvf.

Here's how it fails. hvf_cpu_synchronize_state() sets dirty flag to mark that emulator registers in CPUX86State are going to be out of sync with accel registers. If we bind .cpu_synchronize_state to hvf_synchronize_state it'd be called from vapic_write() on I/O writes (from kvmvapic.bin option ROM) to KVM vAPIC page (I/O port 0x7e).

But HVF uses two emulator states CPUX86State and HVFX86EmulatorState and they may become out-of-sync. That's exactly what happens when an I/O write to KVM vAPIC is made. The I/O write triggers cpu state synchronization, so VMCS registers are fetched into CPUX86State and the vcpu_dirty flag is set. Emulation code then advances RIP in the macvm_set_rip() by modifying VMCS directly. On the next round of vcpu run loop it checks if the cpu is dirty (it is) and pushes CPUX86State into the VMCS, effectively overwriting what was set by macvm_set_rip().

If the RFC isn't expected to be merged for a couple of weeks I can prepare a series that drops HVFX86EmulatorState. I need the change for single-stepping support in HVF anyway.

Thanks,
Roman

#15 lore raw

Re: [RFC v3 4/4] cpus: extract out accel-specific code to each accel

Ciao Roman,

thanks for looking at this and trying it out,

Quoted 56 lines · Roman Bolshakov
Quoted 46 lines · Claudio Fontana

each accelerator registers a new "CpusAccelInterface" on initialization, providing functions for starting a vcpu, kicking a vcpu, and sychronizing state.

This way the code in cpus.cc is now all general softmmu code, nothing (or almost nothing) accelerator-specific anymore.

---
 MAINTAINERS                          |   1 +
 accel/kvm/Makefile.objs              |   2 +
 accel/kvm/kvm-all.c                  |  15 +-
 accel/kvm/kvm-cpus-interface.c       |  94 ++++
 accel/kvm/kvm-cpus-interface.h       |   8 +
 accel/qtest.c                        |  82 ++++
 accel/stubs/kvm-stub.c               |   3 +-
 accel/tcg/Makefile.objs              |   1 +
 accel/tcg/tcg-all.c                  |  12 +-
 accel/tcg/tcg-cpus-interface.c       | 523 ++++++++++++++++++++
 accel/tcg/tcg-cpus-interface.h       |   8 +
 hw/core/cpu.c                        |   1 +
 include/sysemu/cpus.h                |  32 ++
 include/sysemu/hvf.h                 |   1 -
 include/sysemu/hw_accel.h            |  57 +--
 include/sysemu/kvm.h                 |   2 +-
 softmmu/cpus.c                       | 911 +++--------------------------------
 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-interface.c     |  85 ++++
 target/i386/hax-cpus-interface.h     |   8 +
 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-interface.c |  92 ++++
 target/i386/hvf/hvf-cpus-interface.h |   8 +
 target/i386/hvf/hvf.c                |   5 +-
 target/i386/whpx-all.c               |   3 +
 target/i386/whpx-cpus-interface.c    |  96 ++++
 target/i386/whpx-cpus-interface.h    |   8 +
 33 files changed, 1220 insertions(+), 903 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus-interface.c
 create mode 100644 accel/kvm/kvm-cpus-interface.h
 create mode 100644 accel/tcg/tcg-cpus-interface.c
Quoted 8 lines
 create mode 100644 accel/tcg/tcg-cpus-interface.h
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 target/i386/hax-cpus-interface.c
 create mode 100644 target/i386/hax-cpus-interface.h
 create mode 100644 target/i386/hvf/hvf-cpus-interface.c
 create mode 100644 target/i386/hvf/hvf-cpus-interface.h
 create mode 100644 target/i386/whpx-cpus-interface.c
 create mode 100644 target/i386/whpx-cpus-interface.h
Quoted 6 lines

Hi Claudio,

Overall it looks good.

I wonder if the new structure should get singular form, i.e. softmmu/cpu.c instead of softmmu/cpus.c

One problem we have in the codebase I think is just an overabundance of cpu.c, cpu.h, and functions called cpu_some_thing(), so it is hard to understand what is what.

"cpus" is at least different, and (if you know of course) it points you to a specific module.

We could look for another module name to match more what is inside, however I did keep it on purpose, considering that cpus.h, cpus.c offers functionality to run on _all_ cpus, fe:

list_cpus,
cpu_synchronize_all_states,
cpu_synchronize_all_post_reset,
cpu_synchronize_all_post_init,
cpu_synchronize_all_pre_loadvm,
pause_all_vcpus,
resume_all_vcpus,
vm_prepare_start,
vm_start,
vm_shutdown

I agree with the sentiment that the current situation of modules, names, functions they contain and headers is confusing, however here I would stay with the (imperfect) cpus.c module name, but maybe there are other opinions we can collect on a possible alternative.

Quoted 4 lines

Perhaps cpus.c had plural form because it was related to implementation of multiple CPUs/accels. After the split, each accel got it's own implementation of accel interface.

Perhaps, I don't really know.

Quoted 4 lines

"<accel>-cpus-interface.c" contains implementation rather than interface it's a bit confusing. Perhaps it should be called: "<accel>-cpu.c" or even "<accel>-accel.c".

What I would like to convey here clearly is that the file contains the implementation for kvm of the cpus accel interface.

I guess kvm-cpus-interface-impl.c would be more "correct"?

Maybe just kvm-cpus.c or kvm-[whatever name we replace the name "cpus.c" with]?

Quoted 4 lines

By the way, If we use registration for each accel, does it mean that include/sysemu/<accel>.h and accel stubs are no longer needed in shared location?

Does it? It seems to me AccelClass and AccelState is used a bit all over the place.

Quoted 3 lines

There's an AccelClass in accel/accel.c, I wonder if it should be re-used for accel CPU registration? I don't know but may be generic the leftover

I had a comment in the RFCv2 thread about this, since it's the first thing I tried:

"
NB: here I _really_ wanted to make AccelClass more useful and add methods to it.

In practice though, accessing the methods becomes clunky and expensive with lots of indirections from cpus.c

(current_accel() call, -> accelerator, ACCEL_GET_CLASS(), -> AccelCpusInterface -> method);

In my first attempt I ended up with a cache of the interface in cpus.c ,
and at that point the usefulness of having the methods at all in AccelClass becomes nil, so that resulted in the cpus accel interface being disjointed from AccelClass. "

However I guess the question is, are we ok to increase substantially the cost of each vcpu kick and sync state for all archs?

I would prefer to err on the side of caution and reduce the overhead increase, although making more use of AccelClass would be "nicer", maybe there are more opinions to collect here as well, or some experience on the hotness of the kick and sync_state code paths for all archs?

Quoted 1 line

of cpus.c also belongs to accel/ rather than softmmu/?

cpus.c does not seem to belong to accel/

Quoted 34 lines
Quoted 12 lines
include/sysemu/cpus.h +2 -0
index 149de000a0..cae22afe4d 100644
@@ -4,7 +4,39 @@
 #include "qemu/timer.h"
 
 /* cpus.c */
+
+/* CPU execution threads */

include/sysemu/cpus.h line 18

Quoted 10 lines
include/sysemu/cpus.h +10 -0
+
+typedef struct CpusAccelInterface {
+    void (*create_vcpu_thread)(CPUState *cpu);
+    void (*kick_vcpu_thread)(CPUState *cpu);
+
+    void (*cpu_synchronize_post_reset)(CPUState *cpu);
+    void (*cpu_synchronize_post_init)(CPUState *cpu);
+    void (*cpu_synchronize_state)(CPUState *cpu);
+    void (*cpu_synchronize_pre_loadvm)(CPUState *cpu);
+} CpusAccelInterface;

I think plural name may be replaced to singular. Interface suffix doesn't seem to be used in QEMU.

cpu_ and _vcpu are sort meaning the same and may be replaced to generic cpu_ prefix. There's a CPUState, CPU<Arch>State, and IMO shorter CPUAccel seems to match the naming. I also don't know if cpu_ prefix should be kept.

So here's how I see the interface:

Quoted 11 lines
typedef struct CPUAccel {
    void (*create_thread)(CPUState *cpu);
    void (*kick_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);
} CPUAccel;

It is fine too, for the "CPUAccel" name, I think it would depend on a couple of other things pending resolution above (but I think it is fine in principle).

Quoted 5 lines
Quoted 5 lines
include/sysemu/cpus.h +5 -0
+
+/* register accel-specific interface */
+void cpus_register_accel_interface(CpusAccelInterface *i);
+
+/* interface available for cpus accelerator threads */
Quoted 8 lines

include/sysemu/cpus.h line 28

Quoted 5 lines
include/sysemu/cpus.h +5 -0
+
+/* For temporary buffers for forming a name */
+#define VCPU_THREAD_NAME_SIZE 16
+
+void cpus_kick_thread(CPUState *cpu);

If it's addressing a single CPU should it be singular too, i.e. cpu_kick_thread?

here the problem is again that there are a lot of functions called kick_cpu_something, kick_vcpu_something or various permutations.

Having modulename_function would help in this case I think.

There is precedent in qemu, and would actually like to see more of it, as it makes things way easier to understand and disambiguate, but maybe it's just my thing?

I could push for even more consistency in this regard in cpus.c and elsewhere (I have balanced this desire with the need to also not change too much, too quickly).

Quoted 91 lines
Quoted 76 lines
include/sysemu/cpus.h +10 -0
+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);
target/i386/hvf/Makefile.objs +1 -1
index 927b86bc67..bdbc2c0227 100644
@@ -1,2 +1,2 @@
-obj-y += hvf.o
+obj-y += hvf.o hvf-cpus-interface.o
 obj-y += x86.o x86_cpuid.o x86_decode.o x86_descr.o x86_emu.o x86_flags.o x86_mmu.o x86hvf.o x86_task.o
target/i386/hvf/hvf-cpus-interface.c new file +47 -0
new file mode 100644
index 0000000000..54bfe307c1
@@ -0,0 +1,92 @@
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "sysemu/hvf.h"
+#include "sysemu/runstate.h"
+#include "sysemu/cpus.h"
+#include "qemu/guest-random.h"
+
+#include "hvf-cpus-interface.h"
+
+/*
+ * The HVF-specific vCPU thread function. This one should only run when the host
+ * CPU supports the VMX "unrestricted guest" feature.
+ */
+static void *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));
+

target/i386/hvf/hvf-cpus-interface.c line 57

Quoted 10 lines
target/i386/hvf/hvf-cpus-interface.c new file +10 -0
+    hvf_vcpu_destroy(cpu);
+    cpu_thread_signal_destroyed(cpu);
+    qemu_mutex_unlock_iothread();
+    rcu_unregister_thread();
+    return NULL;
+}
+
+static void hvf_kick_vcpu_thread(CPUState *cpu)
+{
+    cpus_kick_thread(cpu);

I think we should leave it empty since it's not really implemented for HVF. Here's a WIP implementation I'm yet to send:

Quoted 1 line

https://github.com/roolebo/qemu/commit/4437a4b8af31b0adaa58375f09e0b8547507f64f#diff-5e6ad1baa140ca4a1743b5a2f1a664b5R970

Just let me know what the best course of action is, I thought I reproduced here the existing behavior?

(remember that the code that cpus_kick_thread now consists of _was_ executed before for hvf, in the form of qemu_cpu_kick_thread)

If we need some changes to the existing behavior, should we do it after this so we don't mix refactoring with functional change?

Quoted 23 lines
Quoted 23 lines
target/i386/hvf/hvf-cpus-interface.c new file +22 -0
+}
+
+static void hvf_cpu_synchronize_noop(CPUState *cpu)
+{
+}
+
+static void hvf_start_vcpu_thread(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);
Quoted 8 lines

target/i386/hvf/hvf-cpus-interface.c line 85

Quoted 6 lines
target/i386/hvf/hvf-cpus-interface.c new file +6 -0
+    qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn,
+                       cpu, QEMU_THREAD_JOINABLE);
+}
+
+CpusAccelInterface hvf_cpus_interface = {
+    .create_vcpu_thread = hvf_start_vcpu_thread,

I think it was meant as hvf_create_vcpu_thread.

throughout the code it is "start" for all accelerators, that is probably why "start" was used here as well. The only exception being TCG, which had "init".

Quoted 10 lines

target/i386/hvf/hvf-cpus-interface.c line 91

Quoted 7 lines
target/i386/hvf/hvf-cpus-interface.c new file +6 -0
+    .kick_vcpu_thread = hvf_kick_vcpu_thread,
+
+    .cpu_synchronize_post_reset = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_post_init = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_state = hvf_cpu_synchronize_noop,
+    .cpu_synchronize_pre_loadvm = hvf_cpu_synchronize_noop,

I have tested the RFC with hvf accel and it seems to work although I expected it fail.

So it works?

Quoted 6 lines

The noop functions are the reason of the behaviour. In
some sense it's not equivalent to what it was before but to be fair it's not possible to use existing hvf_cpu_synchronize_* functions in target/i386/hvf/hvf.c without breaking hvf.

Here's how it fails.

Sorry I don't follow, you mentioned before that it seems to work, but now that it fails?

Quoted 15 lines

hvf_cpu_synchronize_state() sets dirty flag to mark
that emulator registers in CPUX86State are going to be out of sync with accel registers. If we bind .cpu_synchronize_state to hvf_synchronize_state it'd be called from vapic_write() on I/O writes (from kvmvapic.bin option ROM) to KVM vAPIC page (I/O port 0x7e).

But HVF uses two emulator states CPUX86State and HVFX86EmulatorState and they may become out-of-sync. That's exactly what happens when an I/O write to KVM vAPIC is made. The I/O write triggers cpu state synchronization, so VMCS registers are fetched into CPUX86State and the vcpu_dirty flag is set. Emulation code then advances RIP in the macvm_set_rip() by modifying VMCS directly. On the next round of vcpu run loop it checks if the cpu is dirty (it is) and pushes CPUX86State into the VMCS, effectively overwriting what was set by macvm_set_rip().

Quoted 3 lines

If the RFC isn't expected to be merged for a couple of weeks I can prepare a series that drops HVFX86EmulatorState. I need the change for single-stepping support in HVF anyway.

Does this have anything to do with the TODO in the current code in cpus.c:

void cpu_synchronize_all_states(void)

{
    CPUState *cpu;

    CPU_FOREACH(cpu) {
        cpu_synchronize_state(cpu);
        /* TODO: move to cpu_synchronize_state() */
        if (hvf_enabled()) {
            hvf_cpu_synchronize_state(cpu);
        }
    }
}

?

Ciao and thanks for the comments, really appreciated!

Claudio

#16 lore raw
In reply to Claudio Fontana
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [RFC v3 0/4] QEMU cpus.c refactoring
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
0f5db0e cpus: extract out accel-specific code to each accel 1b135cf cpu-timers, icount: new modules
cb5c834 cpu-throttle: new module, extracted from cpus.c 3d5a04d softmmu: move softmmu only files from root

=== OUTPUT BEGIN ===
1/4 Checking commit 3d5a04d99492 (softmmu: move softmmu only files from root)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #112:
rename from arch_init.c

total: 0 errors, 1 warnings, 77 lines checked

Patch 1/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/4 Checking commit cb5c834770dd (cpu-throttle: new module, extracted from cpus.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #110:
new file mode 100644

total: 0 errors, 1 warnings, 386 lines checked

Patch 2/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
3/4 Checking commit 1b135cfa40c8 (cpu-timers, icount: new modules)
WARNING: line over 80 characters
#94: FILE: accel/tcg/cpu-exec.c:107:
+ qemu_printf("Warning: The guest is now late by %.1f to %.1f seconds\n",

ERROR: line over 90 characters
#265: FILE: hw/core/ptimer.c:137:
+ if (s->enabled == 1 && (delta * period < 10000) && !icount_enabled() && !qtest_enabled()) {

ERROR: line over 90 characters
#274: FILE: hw/core/ptimer.c:220:
+ if (!oneshot && (s->delta * period < 10000) && !icount_enabled() && !qtest_enabled()) {

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #384:
new file mode 100644

total: 2 errors, 2 warnings, 2331 lines checked

Patch 3/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/4 Checking commit 0f5db0e76127 (cpus: extract out accel-specific code to each accel)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #86:
new file mode 100644

total: 0 errors, 1 warnings, 2463 lines checked

Patch 4/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#17 lore raw

Some comments on patchew output:

Quoted 31 lines · On 5/26/20 12:58 AM, [email protected] wrote:

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [RFC v3 0/4] QEMU cpus.c refactoring
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
0f5db0e cpus: extract out accel-specific code to each accel 1b135cf cpu-timers, icount: new modules
cb5c834 cpu-throttle: new module, extracted from cpus.c 3d5a04d softmmu: move softmmu only files from root

Quoted 7 lines

=== OUTPUT BEGIN ===
1/4 Checking commit 3d5a04d99492 (softmmu: move softmmu only files from root)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #112:
rename from arch_init.c

total: 0 errors, 1 warnings, 77 lines checked

I am not sure who the maintainer of arch_init would be.

get_maintainer.pl: No maintainers found, printing recent contributors.

Quoted 10 lines

Patch 1/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/4 Checking commit cb5c834770dd (cpu-throttle: new module, extracted from cpus.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #110:
new file mode 100644

total: 0 errors, 1 warnings, 386 lines checked

I assumed this would be Paolo, since he maintains related components (and the cpus.c it came from)

Quoted 8 lines

Patch 2/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
3/4 Checking commit 1b135cfa40c8 (cpu-timers, icount: new modules)
WARNING: line over 80 characters
#94: FILE: accel/tcg/cpu-exec.c:107:
+ qemu_printf("Warning: The guest is now late by %.1f to %.1f seconds\n",

Here I would ignore the warning for the benefit of readability of the printf string.

Quoted 4 lines

ERROR: line over 90 characters
#265: FILE: hw/core/ptimer.c:137:
+ if (s->enabled == 1 && (delta * period < 10000) && !icount_enabled() && !qtest_enabled()) {

this I should fix

Quoted 5 lines

ERROR: line over 90 characters
#274: FILE: hw/core/ptimer.c:220:
+ if (!oneshot && (s->delta * period < 10000) && !icount_enabled() && !qtest_enabled()) {

this I should fix

Quoted 15 lines

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #384:
new file mode 100644

total: 2 errors, 2 warnings, 2331 lines checked

Patch 3/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/4 Checking commit 0f5db0e76127 (cpus: extract out accel-specific code to each accel)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #86:
new file mode 100644

Quoted 6 lines

total: 0 errors, 1 warnings, 2463 lines checked

Patch 4/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

I am adding the new accelerator interfaces to the respective accelerator maintainers.

Quoted 10 lines

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]