diff mbox series

[v3,1/7] cpus: Introduce CPUClass::list_cpus() callback

Message ID 20250324185837.46506-2-philmd@linaro.org
State New
Headers show
Series cpus: Convert cpu_list definition to CPUClass:list_cpus callback | expand

Commit Message

Philippe Mathieu-Daudé March 24, 2025, 6:58 p.m. UTC
Some targets define cpu_list to a method listing their
CPUs on stdout. In order to make list_cpus() generic,
introduce the CPUClass::list_cpus() callback.
When no callback is registered, list_cpus() defaults
to the cpu_list definition.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/hw/core/cpu.h | 2 ++
 cpu-target.c          | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Zhao Liu March 26, 2025, 7:43 a.m. UTC | #1
On Mon, Mar 24, 2025 at 07:58:31PM +0100, Philippe Mathieu-Daudé wrote:
> Date: Mon, 24 Mar 2025 19:58:31 +0100
> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> Subject: [PATCH v3 1/7] cpus: Introduce CPUClass::list_cpus() callback
> X-Mailer: git-send-email 2.47.1
> 
> Some targets define cpu_list to a method listing their
> CPUs on stdout. In order to make list_cpus() generic,
> introduce the CPUClass::list_cpus() callback.
> When no callback is registered, list_cpus() defaults
> to the cpu_list definition.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/hw/core/cpu.h | 2 ++
>  cpu-target.c          | 8 +++++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
diff mbox series

Patch

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 5d11d26556a..ccfcd3eb3a6 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -102,6 +102,7 @@  struct SysemuCPUOps;
  * CPUClass:
  * @class_by_name: Callback to map -cpu command line model name to an
  *                 instantiatable CPU type.
+ * @list_cpus: list available CPU models and flags.
  * @parse_features: Callback to parse command line arguments.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  * @mmu_index: Callback for choosing softmmu mmu index;
@@ -150,6 +151,7 @@  struct CPUClass {
     /*< public >*/
 
     ObjectClass *(*class_by_name)(const char *cpu_model);
+    void (*list_cpus)(void);
     void (*parse_features)(const char *typename, char *str, Error **errp);
 
     int (*mmu_index)(CPUState *cpu, bool ifetch);
diff --git a/cpu-target.c b/cpu-target.c
index cae77374b38..5947ca31a0a 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -98,7 +98,13 @@  static void cpu_list(void)
 
 void list_cpus(void)
 {
-    cpu_list();
+    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+
+    if (cc->list_cpus) {
+        cc->list_cpus();
+    } else {
+        cpu_list();
+    }
 }
 
 /* enable or disable single step mode. EXCP_DEBUG is returned by the