qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 06/33] target/arm: Use generic helper to show CPU model na


From: Gavin Shan
Subject: Re: [PATCH v4 06/33] target/arm: Use generic helper to show CPU model names
Date: Thu, 2 Nov 2023 16:15:59 +1000
User-agent: Mozilla Thunderbird

On 11/2/23 14:12, Richard Henderson wrote:
On 11/1/23 17:24, Gavin Shan wrote:
For target/arm, the registered CPU type name is always the combination
of the CPU model name and suffix. Use cpu_model_from_type() to show the
CPU model names. In arm_cpu_list_entry(), @name is renamed to @model
since it points to CPU model name instead of CPU type name.

Signed-off-by: Gavin Shan <gshan@redhat.com>
---
  target/arm/arm-qmp-cmds.c |  6 ++----
  target/arm/helper.c       | 12 +++++-------
  2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c
index b53d5efe13..c8c712a2c6 100644
--- a/target/arm/arm-qmp-cmds.c
+++ b/target/arm/arm-qmp-cmds.c
@@ -233,12 +233,10 @@ static void arm_cpu_add_definition(gpointer data, 
gpointer user_data)
      ObjectClass *oc = data;
      CpuDefinitionInfoList **cpu_list = user_data;
      CpuDefinitionInfo *info;
-    const char *typename;
+    const char *typename = object_class_get_name(oc);
-    typename = object_class_get_name(oc);
      info = g_malloc0(sizeof(*info));
-    info->name = g_strndup(typename,
-                           strlen(typename) - strlen("-" TYPE_ARM_CPU));
+    info->name = cpu_model_from_type(typename);
      info->q_typename = g_strdup(typename);
      QAPI_LIST_PREPEND(*cpu_list, info);
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 5dc0d20a84..baf4b104ef 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -9436,17 +9436,15 @@ static void arm_cpu_list_entry(gpointer data, gpointer 
user_data)
  {
      ObjectClass *oc = data;
      CPUClass *cc = CPU_CLASS(oc);
-    const char *typename;
-    char *name;
+    const char *typename = object_class_get_name(oc);
+    char *model = cpu_model_from_type(typename);
-    typename = object_class_get_name(oc);
-    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_ARM_CPU));
      if (cc->deprecation_note) {
-        qemu_printf("  %s (deprecated)\n", name);
+        qemu_printf("  %s (deprecated)\n", model);
      } else {
-        qemu_printf("  %s\n", name);
+        qemu_printf("  %s\n", model);
      }
-    g_free(name);
+    g_free(model);
  }

Rather than adjust this target by target, I think you can create one single 
cpu_list function out to cpu-common.c using TYPE_CPU, not even 
CPU_RESOLVING_TYPE.  All of the target-specific code could go away.


Actually I thought of this scheme before. Some targets like x86/ppc/s390 don't 
follow
the unified pattern. However, I think it's reasonable to have a common helper 
for other
targets who follow the fixed pattern. The point is to avoid duplicate code. I 
will have
something like below in v5.

--- cpu-target.c ---

#ifndef cpu_list
static void cpu_list_entry(gpointer data, gpointer user_data)
{
    const char *typename = object_class_get_name(OBJECT_CLASS(data));
    g_autofree char *model = cpu_model_from_type(typename);

    if (cc->deprecation_note) {
        qemu_printf("  %s (deprecated)\n", model);
    } else {
        qemu_printf("  %s\n", model);
    }
}

static void cpu_list(void)
{
    GSList *list;

    list = object_class_get_list_sorted(TYPE_CPU, false);
    qemu_printf("Available CPUs:\n");
    g_slist_foreach(list, cpu_list_entry, NULL);
    g_slist_free(list);
}
#endif

void list_cpus(void)
{
    cpu_list();
}

One question is how list_cpus() can be called from bsd-user/main.c where 
cpu_list()
is still used.

Thanks,
Gavin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]