* [PATCH 0/3] hw/core: Make machine-qmp-cmds.c target independent
@ 2023-04-24 16:04 Thomas Huth
2023-04-24 16:04 ` [PATCH 1/3] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thomas Huth @ 2023-04-24 16:04 UTC (permalink / raw)
To: qemu-devel, Eduardo Habkost, Marcel Apfelbaum,
Philippe Mathieu-Daudé
Cc: qemu-s390x, Yanan Wang, Richard Henderson, David Hildenbrand,
Ilya Leoshkevich
For being able to create a universal QEMU binary one day, core files
like machine-qmp-cmds.c must not contain any target specifc macros.
This series reworks the related spots in this file, so we can move
it to the common softmmu_ss source set. This has also the advantage
that we only have to compile this file once, and not multiple times
(one time for each target) anymore.
Thomas Huth (3):
hw/core: Use a callback for target specific query-cpus-fast
information
cpu: Introduce a wrapper for being able to use TARGET_NAME in common
code
hw/core: Move machine-qmp-cmds.c into the target independent source
set
include/hw/core/cpu.h | 6 ++++++
include/qemu/typedefs.h | 1 +
cpu.c | 5 +++++
hw/core/machine-qmp-cmds.c | 20 ++++----------------
target/s390x/cpu.c | 8 ++++++++
hw/core/meson.build | 5 +----
6 files changed, 25 insertions(+), 20 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] hw/core: Use a callback for target specific query-cpus-fast information
2023-04-24 16:04 [PATCH 0/3] hw/core: Make machine-qmp-cmds.c target independent Thomas Huth
@ 2023-04-24 16:04 ` Thomas Huth
2023-04-24 16:04 ` [PATCH 2/3] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
2023-04-24 16:04 ` [PATCH 3/3] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-04-24 16:04 UTC (permalink / raw)
To: qemu-devel, Eduardo Habkost, Marcel Apfelbaum,
Philippe Mathieu-Daudé
Cc: qemu-s390x, Yanan Wang, Richard Henderson, David Hildenbrand,
Ilya Leoshkevich
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.
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code
2023-04-24 16:04 [PATCH 0/3] hw/core: Make machine-qmp-cmds.c target independent Thomas Huth
2023-04-24 16:04 ` [PATCH 1/3] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
@ 2023-04-24 16:04 ` Thomas Huth
2023-04-24 16:04 ` [PATCH 3/3] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-04-24 16:04 UTC (permalink / raw)
To: qemu-devel, Eduardo Habkost, Marcel Apfelbaum,
Philippe Mathieu-Daudé
Cc: qemu-s390x, Yanan Wang, Richard Henderson, David Hildenbrand,
Ilya Leoshkevich
In some spots, it would be helpful to be able to use TARGET_NAME
in common (target independent) code, too. Thus introduce a wrapper
that can be called from common code, too, just like we already
have one for target_words_bigendian().
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/hw/core/cpu.h | 2 ++
cpu.c | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 5a019a27bc..39150cf8f8 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1013,6 +1013,8 @@ void cpu_exec_unrealizefn(CPUState *cpu);
*/
bool target_words_bigendian(void);
+const char *target_name(void);
+
void page_size_init(void);
#ifdef NEED_CPU_H
diff --git a/cpu.c b/cpu.c
index 9105c85404..65ebaf8159 100644
--- a/cpu.c
+++ b/cpu.c
@@ -427,6 +427,11 @@ bool target_words_bigendian(void)
#endif
}
+const char *target_name(void)
+{
+ return TARGET_NAME;
+}
+
void page_size_init(void)
{
/* NOTE: we can always suppose that qemu_host_page_size >=
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] hw/core: Move machine-qmp-cmds.c into the target independent source set
2023-04-24 16:04 [PATCH 0/3] hw/core: Make machine-qmp-cmds.c target independent Thomas Huth
2023-04-24 16:04 ` [PATCH 1/3] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
2023-04-24 16:04 ` [PATCH 2/3] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
@ 2023-04-24 16:04 ` Thomas Huth
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-04-24 16:04 UTC (permalink / raw)
To: qemu-devel, Eduardo Habkost, Marcel Apfelbaum,
Philippe Mathieu-Daudé
Cc: qemu-s390x, Yanan Wang, Richard Henderson, David Hildenbrand,
Ilya Leoshkevich
The only target specific code that is left in here are two spots that
use TARGET_NAME. Change them to use the new target_name() wrapper
function instead, so we can move the file into the common softmmu_ss
source set. That way we only have to compile this file once, and not
for each target anymore.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/core/machine-qmp-cmds.c | 4 ++--
hw/core/meson.build | 5 +----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index c158c02aa3..3860a50c3b 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -37,7 +37,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
MachineState *ms = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(ms);
CpuInfoFastList *head = NULL, **tail = &head;
- SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME,
+ SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, target_name(),
-1, &error_abort);
CPUState *cpu;
@@ -117,7 +117,7 @@ TargetInfo *qmp_query_target(Error **errp)
{
TargetInfo *info = g_malloc0(sizeof(*info));
- info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
+ info->arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
&error_abort);
return info;
diff --git a/hw/core/meson.build b/hw/core/meson.build
index ae977c9396..959bc924d4 100644
--- a/hw/core/meson.build
+++ b/hw/core/meson.build
@@ -41,6 +41,7 @@ softmmu_ss.add(files(
'gpio.c',
'loader.c',
'machine-hmp-cmds.c',
+ 'machine-qmp-cmds.c',
'machine.c',
'nmi.c',
'null-machine.c',
@@ -51,7 +52,3 @@ softmmu_ss.add(files(
'vm-change-state-handler.c',
'clock-vmstate.c',
))
-
-specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files(
- 'machine-qmp-cmds.c',
-))
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-04-24 16:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24 16:04 [PATCH 0/3] hw/core: Make machine-qmp-cmds.c target independent Thomas Huth
2023-04-24 16:04 ` [PATCH 1/3] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
2023-04-24 16:04 ` [PATCH 2/3] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
2023-04-24 16:04 ` [PATCH 3/3] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
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).