qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 13/21] hw/core: Use a callback for target specific query-cpus-fast information
Date: Mon, 15 May 2023 15:02:25 +0200	[thread overview]
Message-ID: <20230515130233.418183-14-thuth@redhat.com> (raw)
In-Reply-To: <20230515130233.418183-1-thuth@redhat.com>

For being able to create a universal QEMU binary one day, core
files like machine-qmp-cmds.c must not contain any "#ifdef TARGET_..."
parts. Thus let's provide the target specific function via a
function pointer in CPUClass instead, as a first step towards
making this file target independent.

Message-Id: <20230424160434.331175-2-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/hw/core/cpu.h      |  4 ++++
 include/qemu/typedefs.h    |  1 +
 hw/core/machine-qmp-cmds.c | 16 ++--------------
 target/s390x/cpu.c         |  8 ++++++++
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 397fd3ac68..5a019a27bc 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -106,6 +106,9 @@ struct SysemuCPUOps;
  * @has_work: Callback for checking if there is work to do.
  * @memory_rw_debug: Callback for GDB memory access.
  * @dump_state: Callback for dumping state.
+ * @query_cpu_fast:
+ *       Fill in target specific information for the "query-cpus-fast"
+ *       QAPI call.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  * @set_pc: Callback for setting the Program Counter register. This
  *       should have the semantics used by the target architecture when
@@ -151,6 +154,7 @@ struct CPUClass {
     int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
                            uint8_t *buf, int len, bool is_write);
     void (*dump_state)(CPUState *cpu, FILE *, int flags);
+    void (*query_cpu_fast)(CPUState *cpu, CpuInfoFast *value);
     int64_t (*get_arch_id)(CPUState *cpu);
     void (*set_pc)(CPUState *cpu, vaddr value);
     vaddr (*get_pc)(CPUState *cpu);
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index df4b55ac65..8e9ef252f5 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -41,6 +41,7 @@ typedef struct CompatProperty CompatProperty;
 typedef struct ConfidentialGuestSupport ConfidentialGuestSupport;
 typedef struct CPUAddressSpace CPUAddressSpace;
 typedef struct CPUArchState CPUArchState;
+typedef struct CpuInfoFast CpuInfoFast;
 typedef struct CPUJumpCache CPUJumpCache;
 typedef struct CPUState CPUState;
 typedef struct CPUTLBEntryFull CPUTLBEntryFull;
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index b98ff15089..c158c02aa3 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -28,18 +28,6 @@
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 
-static void cpustate_to_cpuinfo_s390(CpuInfoS390 *info, const CPUState *cpu)
-{
-#ifdef TARGET_S390X
-    S390CPU *s390_cpu = S390_CPU(cpu);
-    CPUS390XState *env = &s390_cpu->env;
-
-    info->cpu_state = env->cpu_state;
-#else
-    abort();
-#endif
-}
-
 /*
  * fast means: we NEVER interrupt vCPU threads to retrieve
  * information from KVM.
@@ -68,8 +56,8 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
         }
 
         value->target = target;
-        if (target == SYS_EMU_TARGET_S390X) {
-            cpustate_to_cpuinfo_s390(&value->u.s390x, cpu);
+        if (cpu->cc->query_cpu_fast) {
+            cpu->cc->query_cpu_fast(cpu, value);
         }
 
         QAPI_LIST_APPEND(tail, value);
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 40fdeaa905..df167493c3 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -140,6 +140,13 @@ static bool s390_cpu_has_work(CPUState *cs)
     return s390_cpu_has_int(cpu);
 }
 
+static void s390_query_cpu_fast(CPUState *cpu, CpuInfoFast *value)
+{
+    S390CPU *s390_cpu = S390_CPU(cpu);
+
+    value->u.s390x.cpu_state = s390_cpu->env.cpu_state;
+}
+
 /* S390CPUClass::reset() */
 static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
 {
@@ -332,6 +339,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = s390_cpu_class_by_name,
     cc->has_work = s390_cpu_has_work;
     cc->dump_state = s390_cpu_dump_state;
+    cc->query_cpu_fast = s390_query_cpu_fast;
     cc->set_pc = s390_cpu_set_pc;
     cc->get_pc = s390_cpu_get_pc;
     cc->gdb_read_register = s390_cpu_gdb_read_register;
-- 
2.31.1



  parent reply	other threads:[~2023-05-15 13:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 13:02 [PULL 00/21] Tests, docs, s390x and misc patches Thomas Huth
2023-05-15 13:02 ` [PULL 01/21] tests/avocado/virtio-gpu: Fix the URLs of the test_virtio_vga_virgl test Thomas Huth
2023-05-15 13:02 ` [PULL 02/21] sysemu/kvm: Remove unused headers Thomas Huth
2023-05-15 13:02 ` [PULL 03/21] net: stream: test reconnect option with an unix socket Thomas Huth
2023-05-15 13:02 ` [PULL 04/21] tests/qtest: replace qmp_discard_response with qtest_qmp_assert_success Thomas Huth
2023-05-15 13:02 ` [PULL 05/21] hw/pci-bridge: Fix release ordering by embedding PCIBridgeWindows within PCIBridge Thomas Huth
2023-05-15 13:02 ` [PULL 06/21] Add information how to fix common build error on Windows in symlink-install-tree Thomas Huth
2023-05-15 13:02 ` [PULL 07/21] tests: libvirt-ci: Update to commit 'c8971e90ac' to pull in mformat and xorriso Thomas Huth
2023-05-15 13:02 ` [PULL 08/21] tests/lcitool: Add mtools and xorriso and remove genisoimage as dependencies Thomas Huth
2023-05-15 13:02 ` [PULL 09/21] util/async-teardown: wire up query-command-line-options Thomas Huth
2023-05-15 13:02 ` [PULL 10/21] s390x/pv: Fix spurious warning with asynchronous teardown Thomas Huth
2023-05-15 13:02 ` [PULL 11/21] docs/devel: remind developers to run CI container pipeline when updating images Thomas Huth
2023-05-15 13:02 ` [PULL 12/21] docs/about/emulation: fix typo Thomas Huth
2023-05-15 13:02 ` Thomas Huth [this message]
2023-05-15 13:02 ` [PULL 14/21] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
2023-05-15 13:02 ` [PULL 15/21] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
2023-05-15 13:02 ` [PULL 16/21] hw/net: Move xilinx_ethlite.c to the target-independent " Thomas Huth
2023-05-15 13:02 ` [PULL 17/21] s390x/tcg: Fix LDER instruction format Thomas Huth
2023-05-15 13:02 ` [PULL 18/21] tests/tcg/multiarch: Make the system memory test work on big-endian Thomas Huth
2023-05-15 13:02 ` [PULL 19/21] tests/tcg/s390x: Enable the multiarch system tests Thomas Huth
2023-05-15 13:02 ` [PULL 20/21] target/s390x: Fix EXECUTE of relative branches Thomas Huth
2023-05-15 13:02 ` [PULL 21/21] tests/tcg/s390x: Test " Thomas Huth
2023-05-15 20:53 ` [PULL 00/21] Tests, docs, s390x and misc patches Richard Henderson
2023-05-16  7:11   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515130233.418183-14-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).