diff mbox series

[01/11] cpus: Cache CPUClass early in instance_init() handler

Message ID 20250121114056.53949-2-philmd@linaro.org
State New
Headers show
Series cpus: Prefer cached CpuClass over CPU_GET_CLASS() macro | expand

Commit Message

Philippe Mathieu-Daudé Jan. 21, 2025, 11:40 a.m. UTC
Cache CPUClass as early as possible, when the instance
is initialized.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 cpu-target.c         | 3 ---
 hw/core/cpu-common.c | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Richard Henderson Jan. 21, 2025, 3:54 p.m. UTC | #1
On 1/21/25 03:40, Philippe Mathieu-Daudé wrote:
> Cache CPUClass as early as possible, when the instance
> is initialized.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   cpu-target.c         | 3 ---
>   hw/core/cpu-common.c | 3 +++
>   2 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> diff --git a/cpu-target.c b/cpu-target.c
> index 667688332c9..89874496a41 100644
> --- a/cpu-target.c
> +++ b/cpu-target.c
> @@ -134,9 +134,6 @@ const VMStateDescription vmstate_cpu_common = {
>   
>   bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
>   {
> -    /* cache the cpu class for the hotpath */
> -    cpu->cc = CPU_GET_CLASS(cpu);
> -
>       if (!accel_cpu_common_realize(cpu, errp)) {
>           return false;
>       }
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index cb79566cc51..ff605059c15 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -238,6 +238,9 @@ static void cpu_common_initfn(Object *obj)
>   {
>       CPUState *cpu = CPU(obj);
>   
> +    /* cache the cpu class for the hotpath */
> +    cpu->cc = CPU_GET_CLASS(cpu);
> +
>       gdb_init_cpu(cpu);
>       cpu->cpu_index = UNASSIGNED_CPU_INDEX;
>       cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX;
diff mbox series

Patch

diff --git a/cpu-target.c b/cpu-target.c
index 667688332c9..89874496a41 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -134,9 +134,6 @@  const VMStateDescription vmstate_cpu_common = {
 
 bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
 {
-    /* cache the cpu class for the hotpath */
-    cpu->cc = CPU_GET_CLASS(cpu);
-
     if (!accel_cpu_common_realize(cpu, errp)) {
         return false;
     }
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index cb79566cc51..ff605059c15 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -238,6 +238,9 @@  static void cpu_common_initfn(Object *obj)
 {
     CPUState *cpu = CPU(obj);
 
+    /* cache the cpu class for the hotpath */
+    cpu->cc = CPU_GET_CLASS(cpu);
+
     gdb_init_cpu(cpu);
     cpu->cpu_index = UNASSIGNED_CPU_INDEX;
     cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX;