[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v1 10/10] module: add priority to module_init
From: |
Claudio Fontana |
Subject: |
[RFC v1 10/10] module: add priority to module_init |
Date: |
Mon, 9 Nov 2020 18:27:55 +0100 |
add a new version of module_init that also takes a priority argument,
and use it to be able to run a constructor last for INIT_ACCEL_CPU,
and thus avoid the manual work of keeping track how to conditionalize
the generic x86 cpu models registration.
Signed-off-by: Claudio Fontana <cfontana@suse.de>
---
include/qemu/module.h | 17 ++++++++++++++++-
target/i386/cpu.c | 16 ++++++++++++----
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/include/qemu/module.h b/include/qemu/module.h
index 485eda986a..1f4fac6791 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -30,6 +30,13 @@ static void __attribute__((constructor)) do_qemu_init_ ##
function(void) \
{ \
register_dso_module_init(function, type); \
}
+
+#define module_init_prio(function, type, prio)
\
+static void __attribute__((constructor(prio))) do_qemu_init_ ## function(void)
\
+{
\
+ register_dso_module_init(function, type);
\
+}
+
#else
/* This should not be used directly. Use block_init etc. instead. */
#define module_init(function, type) \
@@ -37,6 +44,11 @@ static void __attribute__((constructor)) do_qemu_init_ ##
function(void) \
{ \
register_module_init(function, type); \
}
+#define module_init_prio(function, type, prio)
\
+static void __attribute__((constructor(prio))) do_qemu_init_ ## function(void)
\
+{
\
+ register_module_init(function, type);
\
+}
#endif
typedef enum {
@@ -55,7 +67,10 @@ typedef enum {
#define block_init(function) module_init(function, MODULE_INIT_BLOCK)
#define opts_init(function) module_init(function, MODULE_INIT_OPTS)
#define type_init(function) module_init(function, MODULE_INIT_QOM)
-#define accel_cpu_init(function) module_init(function, MODULE_INIT_ACCEL_CPU)
+#define accel_cpu_init(function) \
+ module_init_prio(function, MODULE_INIT_ACCEL_CPU, 101)
+#define accel_cpu_init_last(function) \
+ module_init_prio(function, MODULE_INIT_ACCEL_CPU, 65535)
#define trace_init(function) module_init(function, MODULE_INIT_TRACE)
#define xen_backend_init(function) module_init(function, \
MODULE_INIT_XEN_BACKEND)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b547c9d39d..aeaebfde02 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7050,8 +7050,16 @@ static TypeInfo x86_base_cpu_type_info = {
*/
void x86_cpu_register_cpu_models(const char *parent_type)
{
+ static bool x86_cpu_models_registered;
int i;
+ if (x86_cpu_models_registered) {
+ /*
+ * already registered by an accelerator-specific specialization
+ * of x86_cpu
+ */
+ return;
+ }
for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
x86_register_cpudef(&builtin_x86_defs[i], parent_type);
}
@@ -7060,6 +7068,8 @@ void x86_cpu_register_cpu_models(const char *parent_type)
x86_base_cpu_type_info.parent = parent_type;
type_register(&x86_base_cpu_type_info);
+
+ x86_cpu_models_registered = true;
}
static void x86_cpu_register_base_type(void)
@@ -7077,9 +7087,7 @@ static void x86_cpu_type_init(void)
/*
* I would like something better than this check.
*/
- if (!tcg_enabled() && !kvm_enabled() && !hvf_enabled()) {
- x86_cpu_register_cpu_models(TYPE_X86_CPU);
- }
+ x86_cpu_register_cpu_models(TYPE_X86_CPU);
}
-accel_cpu_init(x86_cpu_type_init);
+accel_cpu_init_last(x86_cpu_type_init);
--
2.26.2
Re: [RFC v1 09/10] i386: split cpu.c and defer x86 models registration, Eduardo Habkost, 2020/11/09
[RFC v1 10/10] module: add priority to module_init,
Claudio Fontana <=
Re: [RFC v1 00/10] i386 cleanup, no-reply, 2020/11/09