[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 1/6] cpu: Add new API cpu_type_by_name
From: |
LIU Zhiwei |
Subject: |
[RFC PATCH v2 1/6] cpu: Add new API cpu_type_by_name |
Date: |
Mon, 28 Aug 2023 16:45:31 +0800 |
cpu_type_by_name is used to get the cpu type name from the command
line -cpu.
Currently it is only used by parse_cpu_option. In the next patch, it
will be used by other cpu query functions.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
cpu.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/cpu.c b/cpu.c
index 1c948d1161..e1a9239d0f 100644
--- a/cpu.c
+++ b/cpu.c
@@ -257,28 +257,35 @@ void cpu_exec_initfn(CPUState *cpu)
#endif
}
-const char *parse_cpu_option(const char *cpu_option)
+static const char *cpu_type_by_name(const char *cpu_model)
{
ObjectClass *oc;
- CPUClass *cc;
- gchar **model_pieces;
const char *cpu_type;
- model_pieces = g_strsplit(cpu_option, ",", 2);
- if (!model_pieces[0]) {
- error_report("-cpu option cannot be empty");
- exit(1);
- }
- oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+ oc = cpu_class_by_name(CPU_RESOLVING_TYPE, cpu_model);
if (oc == NULL) {
- error_report("unable to find CPU model '%s'", model_pieces[0]);
- g_strfreev(model_pieces);
+ error_report("unable to find CPU model '%s'", cpu_model);
exit(EXIT_FAILURE);
}
cpu_type = object_class_get_name(oc);
- cc = CPU_CLASS(oc);
+ return cpu_type;
+}
+
+const char *parse_cpu_option(const char *cpu_option)
+{
+ const char *cpu_type;
+ CPUClass *cc;
+ gchar **model_pieces;
+
+ model_pieces = g_strsplit(cpu_option, ",", 2);
+ if (!model_pieces[0]) {
+ error_report("-cpu option cannot be empty");
+ exit(1);
+ }
+ cpu_type = cpu_type_by_name(model_pieces[0]);
+ cc = CPU_CLASS(object_class_by_name(cpu_type));
cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
g_strfreev(model_pieces);
return cpu_type;
--
2.17.1
- [RFC PATCH v2 0/6] Add API for list cpu extensions, LIU Zhiwei, 2023/08/28
- [RFC PATCH v2 1/6] cpu: Add new API cpu_type_by_name,
LIU Zhiwei <=
- [RFC PATCH v2 2/6] target/riscv: Add API list_cpu_props, LIU Zhiwei, 2023/08/28
- [RFC PATCH v2 3/6] softmmu/vl: Add qemu_cpu_opts QemuOptsList, LIU Zhiwei, 2023/08/28
- [RFC PATCH v2 4/6] target/riscv: Add default value for misa property, LIU Zhiwei, 2023/08/28
- [RFC PATCH v2 5/6] target/riscv: Add defalut value for string property, LIU Zhiwei, 2023/08/28
- [RFC PATCH v2 6/6] linux-user: Move qemu_cpu_opts to cpu.c, LIU Zhiwei, 2023/08/28
- Re: [RFC PATCH v2 0/6] Add API for list cpu extensions, Igor Mammedov, 2023/08/28