Skip to contentSkip to conversation

target: Use env_archcpu() instead of ARCH_CPU(env_cpu(env))

PATCH In review Philippe Mathieu-Daudé 8 participants 27 messages Oct 9, 2023 – Oct 20, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

cover target: Use env_archcpu() instead of ARCH_CPU(env_cpu(env))

When we have a CPUArchState* pointer we can directly get the corresponding ArchCPU* pointer with env_archcpu(). No need to use QOM cast which is slower due when building with --enable-qom-cast-debug.

This series replace ARCH_CPU(env_cpu(env)) by env_archcpu(env) when possible.

Philippe Mathieu-Daudé (6):
target/ppc: Use env_archcpu() in helper_book3s_msgsndp() target/riscv: Use env_archcpu() in [check_]nanbox() target/s390x: Use env_archcpu() in handle_diag_308() target/xtensa: Use env_archcpu() in update_c[compare|count]() target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]() target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

 target/i386/hvf/x86_emu.h |  4 ++--
 target/riscv/internals.h  |  8 ++++----
 target/i386/hvf/hvf.c     |  4 ++--
 target/i386/hvf/x86_emu.c | 25 ++++++++++++-------------
 target/ppc/excp_helper.c  |  2 +-
 target/s390x/diag.c       |  2 +-
 target/xtensa/op_helper.c |  4 ++--
 7 files changed, 24 insertions(+), 25 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/6 target/ppc: Use env_archcpu() in helper_book3s_msgsndp()

When CPUArchState* is available (here CPUPPCState*), we can use the fast env_archcpu() macro to get ArchCPU* (here PowerPCCPU*). The QOM cast POWERPC_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
 target/ppc/excp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +1 -1
index 7926114d5c..a42743a3e0 100644
@@ -3136,7 +3136,7 @@ void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb)
 void helper_book3s_msgsndp(CPUPPCState *env, target_ulong rb)
 {
     CPUState *cs = env_cpu(env);
-    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    PowerPCCPU *cpu = env_archcpu(env);
     CPUState *ccs;
     uint32_t nr_threads = cs->nr_threads;
     int ttir = rb & PPC_BITMASK(57, 63);
Signature · 1 line
2.41.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] target/ppc: Use env_archcpu() in helper_book3s_msgsndp()

Quoted 15 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUPPCState*), we can use the fast env_archcpu() macro to get ArchCPU* (here PowerPCCPU*). The QOM cast POWERPC_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
  target/ppc/excp_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +0 -0
index 7926114d5c..a42743a3e0 100644

target/ppc/excp_helper.c void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb) · line 3139

Quoted 5 lines
target/ppc/excp_helper.c +1 -1
@@ -3136,7 +3136,7 @@ void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb)
  void helper_book3s_msgsndp(CPUPPCState *env, target_ulong rb)
  {
      CPUState *cs = env_cpu(env);
-    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    PowerPCCPU *cpu = env_archcpu(env);
Quoted 3 lines
target/ppc/excp_helper.c +0 -0
      CPUState *ccs;
      uint32_t nr_threads = cs->nr_threads;
      int ttir = rb & PPC_BITMASK(57, 63);
Acked-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] target/ppc: Use env_archcpu() in helper_book3s_msgsndp()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUPPCState*), we can use the fast env_archcpu() macro to get ArchCPU* (here PowerPCCPU*). The QOM cast POWERPC_CPU() macro will be slower when building with --enable-qom-cast-debug.

Alistair

Quoted 21 lines
---
 target/ppc/excp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +1 -2
index 7926114d5c..a42743a3e0 100644
@@ -3136,7 +3136,7 @@ void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb)
 void helper_book3s_msgsndp(CPUPPCState *env, target_ulong rb)
 {
     CPUState *cs = env_cpu(env);
-    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    PowerPCCPU *cpu = env_archcpu(env);
     CPUState *ccs;
     uint32_t nr_threads = cs->nr_threads;
     int ttir = rb & PPC_BITMASK(57, 63);
--

2.41.0

#4 lore raw

PATCH 2/6 target/riscv: Use env_archcpu() in [check_]nanbox()

In reply to Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
 target/riscv/internals.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/internals.h +4 -4
index b5f823c7ec..8239ae83cc 100644
@@ -87,7 +87,7 @@ enum {
 static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int32_t)f;
     } else {
         return f | MAKE_64BIT_MASK(32, 32);
@@ -97,7 +97,7 @@ static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 {
     /* Disable NaN-boxing check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint32_t)f;
     }
 
@@ -113,7 +113,7 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int16_t)f;
     } else {
         return f | MAKE_64BIT_MASK(16, 48);
@@ -123,7 +123,7 @@ static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
 {
     /* Disable nanbox check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint16_t)f;
     }
 
Signature · 1 line
2.41.0
Reviewed-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 8 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

---

Quoted 43 lines
  target/riscv/internals.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/internals.h +4 -4
index b5f823c7ec..8239ae83cc 100644
@@ -87,7 +87,7 @@ enum {
  static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
  {
      /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (int32_t)f;
      } else {
          return f | MAKE_64BIT_MASK(32, 32);
@@ -97,7 +97,7 @@ static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
  static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
  {
      /* Disable NaN-boxing check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (uint32_t)f;
      }
 
@@ -113,7 +113,7 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
  static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
  {
      /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (int16_t)f;
      } else {
          return f | MAKE_64BIT_MASK(16, 48);
@@ -123,7 +123,7 @@ static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
  static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
  {
      /* Disable nanbox check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (uint16_t)f;
      }
 
Reviewed-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

By the way, does the community has the plan to support heterogeneous architecture cpus in one soc? If so, maybe we have to do this qom cast somewhere.

Zhiwei

Quoted 44 lines
---
  target/riscv/internals.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/internals.h +4 -4
index b5f823c7ec..8239ae83cc 100644
@@ -87,7 +87,7 @@ enum {
  static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
  {
      /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (int32_t)f;
      } else {
          return f | MAKE_64BIT_MASK(32, 32);
@@ -97,7 +97,7 @@ static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
  static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
  {
      /* Disable NaN-boxing check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (uint32_t)f;
      }
 
@@ -113,7 +113,7 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
  static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
  {
      /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (int16_t)f;
      } else {
          return f | MAKE_64BIT_MASK(16, 48);
@@ -123,7 +123,7 @@ static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
  static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
  {
      /* Disable nanbox check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
          return (uint16_t)f;
      }
 
#7 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 7 lines · LIU Zhiwei
Quoted 5 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

Quoted 6 lines
Quoted 2 lines

By the way, does the community has the plan to support heterogeneous architecture cpus in one soc?

Yes.

Quoted 1 line

If so, maybe we have to do this qom cast somewhere.

No, I don't think so. Or at least not in these places.

r~

#8 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 8 lines · Richard Henderson
Quoted 7 lines · LIU Zhiwei
Quoted 5 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

By the way, does the community has the plan to support heterogeneous architecture cpus in one soc?

Yes.

Hi Richard,

It's a good news. Thanks.

Quoted 4 lines
Quoted 2 lines

If so, maybe we have to do this qom cast somewhere.

No, I don't think so.  Or at least not in these places.

Yes.  Perhaps, we should remove all RISCV_CPU macros using after the qom objects realized.

Do you think we should remove the RISCV_CPU using in riscv_cpu_exec_interrupt? Although it  is not so hot. I think there is no reason to use it there. Except this, there are many other places in hw/ and target/riscv using the RISCV_CPU macro.

If we know whether we should remove the RISCV_CPU macro use in these places, we can do it in another patch.

Thanks,
Zhiwei

Quoted 3 lines

r~

#9 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 11 lines · LIU Zhiwei
Quoted 7 lines · Richard Henderson
Quoted 6 lines · LIU Zhiwei
Quoted 4 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

If so, maybe we have to do this qom cast somewhere.

No, I don't think so.  Or at least not in these places.

Yes.  Perhaps, we should remove all RISCV_CPU macros using after the qom objects realized.

Do you think we should remove the RISCV_CPU using in riscv_cpu_exec_interrupt? Although it  is not so hot. I think there is no reason to use it there.

I have some note in my TODO to check replacing CPUState by ArchCPU in TCGCPUOps (like the cpu_exec_interrupt handler you mentioned). However I'm running out of time, so feel free to try it.

Using ArchCPU avoids the cast in target code.

Quoted 1 line

Except this, there are many other places in hw/ and target/riscv using the RISCV_CPU macro.

If a method is exposed as API, we need to check the type. After that for internal calls this is pointless.

Quoted 8 lines

If we know whether we should remove the RISCV_CPU macro use in these places, we can do it in another patch.

Thanks,
Zhiwei

Quoted 3 lines

r~

#10 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · LIU Zhiwei
Quoted 11 lines · Richard Henderson
Quoted 9 lines · LIU Zhiwei
Quoted 4 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

If so, maybe we have to do this qom cast somewhere.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

No, I don't think so.  Or at least not in these places.

Yes.  Perhaps, we should remove all RISCV_CPU macros using after the qom objects realized.

Do you think we should remove the RISCV_CPU using in riscv_cpu_exec_interrupt? Although it  is not so hot. I think there is no reason to use it there.

I have some note in my TODO to check replacing CPUState by ArchCPU in TCGCPUOps (like the cpu_exec_interrupt handler you mentioned).

IMHO, this will make it harder for heterogeneous SOC support. ArchCPU is not a target agnostic struct.

I must miss something.

Quoted 2 lines

However
I'm running out of time, so feel free to try it.

I'd like to have a try if it will not block the heterogeneous SOC support.

Quoted 2 lines

Using ArchCPU avoids the cast in target code.

Yes

Quoted 5 lines
Quoted 2 lines

Except this, there are many other places in hw/ and target/riscv using the RISCV_CPU macro.

If a method is exposed as API, we need to check the type. After that for internal calls this is pointless.

Make sense. Thanks.

Zhiwei

Quoted 9 lines
Quoted 9 lines

If we know whether we should remove the RISCV_CPU macro use in these places, we can do it in another patch.

Thanks,
Zhiwei

Quoted 3 lines

r~

#11 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 18 lines · LIU Zhiwei
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · LIU Zhiwei
Quoted 12 lines · Richard Henderson
Quoted 9 lines · LIU Zhiwei
Quoted 4 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

If so, maybe we have to do this qom cast somewhere.

No, I don't think so.  Or at least not in these places.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yes.  Perhaps, we should remove all RISCV_CPU macros using after the qom objects realized.

Do you think we should remove the RISCV_CPU using in riscv_cpu_exec_interrupt? Although it  is not so hot. I think there is no reason to use it there.

I have some note in my TODO to check replacing CPUState by ArchCPU in TCGCPUOps (like the cpu_exec_interrupt handler you mentioned).

IMHO, this will make it harder for heterogeneous SOC support. ArchCPU is not a target agnostic struct.

ArchCPU is a target-agnostic typedef of a structure with no visible definition. C is perfectly happy to manipulate pointers to such structures.

Whether it is worthwhile to adjust interfaces from CPUState to ArchCPU, I don't know.

r~

#12 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

Quoted 23 lines · Richard Henderson
Quoted 22 lines · LIU Zhiwei
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 18 lines · LIU Zhiwei
Quoted 9 lines · Richard Henderson
Quoted 6 lines · LIU Zhiwei
Quoted 4 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

Quoted 3 lines
Quoted 1 line

If so, maybe we have to do this qom cast somewhere.

No, I don't think so.  Or at least not in these places.

Yes.  Perhaps, we should remove all RISCV_CPU macros using after the qom objects realized.

Do you think we should remove the RISCV_CPU using in riscv_cpu_exec_interrupt? Although it  is not so hot. I think there is no reason to use it there.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I have some note in my TODO to check replacing CPUState by ArchCPU in TCGCPUOps (like the cpu_exec_interrupt handler you mentioned).

IMHO, this will make it harder for heterogeneous SOC support. ArchCPU is not a target agnostic struct.

ArchCPU is a target-agnostic typedef of a structure with no visible definition. C is perfectly happy to manipulate pointers to such structures.

Get it. Thanks

Quoted 1 line

Whether it is worthwhile to adjust interfaces from CPUState to ArchCPU, I don't know.

OK. Let's just wait for a good reason to do that.

Zhiwei

Quoted 3 lines

r~

Reviewed-by on v1 2/6
#13 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

In reply to Philippe Mathieu-Daudé
Quoted 43 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
 target/riscv/internals.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/internals.h +3 -3
index b5f823c7ec..8239ae83cc 100644
@@ -87,7 +87,7 @@ enum {
 static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int32_t)f;
     } else {
         return f | MAKE_64BIT_MASK(32, 32);
@@ -97,7 +97,7 @@ static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 {
     /* Disable NaN-boxing check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint32_t)f;
     }
 
@@ -113,7 +113,7 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int16_t)f;
     } else {
         return f | MAKE_64BIT_MASK(16, 48);

target/riscv/internals.h static inline uint64_t nanbox_h(CPURISCVState *env, float16 f) · line 128

Quoted 7 lines
target/riscv/internals.h +1 -1
@@ -123,7 +123,7 @@ static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
 {
     /* Disable nanbox check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint16_t)f;
     }
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
Reviewed-by on v1 2/6
#14 lore raw

Re: [PATCH 2/6] target/riscv: Use env_archcpu() in [check_]nanbox()

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPURISCVState*), we can use the fast env_archcpu() macro to get ArchCPU* (here RISCVCPU*). The QOM cast RISCV_CPU() macro will be slower when building with --enable-qom-cast-debug.

Alistair

Quoted 48 lines
---
 target/riscv/internals.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/internals.h +4 -5
index b5f823c7ec..8239ae83cc 100644
@@ -87,7 +87,7 @@ enum {
 static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int32_t)f;
     } else {
         return f | MAKE_64BIT_MASK(32, 32);
@@ -97,7 +97,7 @@ static inline uint64_t nanbox_s(CPURISCVState *env, float32 f)
 static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 {
     /* Disable NaN-boxing check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint32_t)f;
     }
 
@@ -113,7 +113,7 @@ static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f)
 static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 {
     /* the value is sign-extended instead of NaN-boxing for zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (int16_t)f;
     } else {
         return f | MAKE_64BIT_MASK(16, 48);
@@ -123,7 +123,7 @@ static inline uint64_t nanbox_h(CPURISCVState *env, float16 f)
 static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f)
 {
     /* Disable nanbox check when enable zfinx */
-    if (RISCV_CPU(env_cpu(env))->cfg.ext_zfinx) {
+    if (env_archcpu(env)->cfg.ext_zfinx) {
         return (uint16_t)f;
     }
 
--

2.41.0

#15 lore raw

PATCH 3/6 target/s390x: Use env_archcpu() in handle_diag_308()

In reply to Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUS390XState*), we can use the fast env_archcpu() macro to get ArchCPU* (here S390CPU*). The QOM cast S390_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/diag.c +1 -1
index 8ce18e08f3..27ffd48576 100644
@@ -77,7 +77,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     bool valid;
     CPUState *cs = env_cpu(env);
-    S390CPU *cpu = S390_CPU(cs);
+    S390CPU *cpu = env_archcpu(env);
     uint64_t addr =  env->regs[r1];
     uint64_t subcode = env->regs[r3];
     IplParameterBlock *iplb;
Signature · 1 line
2.41.0
Acked-by on v1 3/6
#16 lore raw

Re: [PATCH 3/6] target/s390x: Use env_archcpu() in handle_diag_308()

Quoted 7 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUS390XState*), we can use the fast env_archcpu() macro to get ArchCPU* (here S390CPU*). The QOM cast S390_CPU() macro will be slower when building with --enable-qom-cast-debug.

Alistair

Quoted 21 lines
---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/diag.c +1 -2
index 8ce18e08f3..27ffd48576 100644
@@ -77,7 +77,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     bool valid;
     CPUState *cs = env_cpu(env);
-    S390CPU *cpu = S390_CPU(cs);
+    S390CPU *cpu = env_archcpu(env);
     uint64_t addr =  env->regs[r1];
     uint64_t subcode = env->regs[r3];
     IplParameterBlock *iplb;
--

2.41.0

#17 lore raw

PATCH 4/6 target/xtensa: Use env_archcpu() in update_c[compare|count]()

In reply to Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUXtensaState*), we can use the fast env_archcpu() macro to get ArchCPU* (here XtensaCPU*). The QOM cast XTENSA_CPU() macro will be slower when building with --enable-qom-cast-debug.

---
 target/xtensa/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/xtensa/op_helper.c +2 -2
index 7bb8cd6726..496754ba57 100644
@@ -37,7 +37,7 @@
 
 void HELPER(update_ccount)(CPUXtensaState *env)
 {
-    XtensaCPU *cpu = XTENSA_CPU(env_cpu(env));
+    XtensaCPU *cpu = env_archcpu(env);
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     env->ccount_time = now;
@@ -58,7 +58,7 @@ void HELPER(wsr_ccount)(CPUXtensaState *env, uint32_t v)
 
 void HELPER(update_ccompare)(CPUXtensaState *env, uint32_t i)
 {
-    XtensaCPU *cpu = XTENSA_CPU(env_cpu(env));
+    XtensaCPU *cpu = env_archcpu(env);
     uint64_t dcc;
 
     qatomic_and(&env->sregs[INTSET],
Signature · 1 line
2.41.0
Acked-by on v1 4/6
#18 lore raw

Re: [PATCH 4/6] target/xtensa: Use env_archcpu() in update_c[compare|count]()

Quoted 7 lines · Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUXtensaState*), we can use the fast env_archcpu() macro to get ArchCPU* (here XtensaCPU*). The QOM cast XTENSA_CPU() macro will be slower when building with --enable-qom-cast-debug.

Alistair

Quoted 30 lines
---
 target/xtensa/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/xtensa/op_helper.c +2 -3
index 7bb8cd6726..496754ba57 100644
@@ -37,7 +37,7 @@
 
 void HELPER(update_ccount)(CPUXtensaState *env)
 {
-    XtensaCPU *cpu = XTENSA_CPU(env_cpu(env));
+    XtensaCPU *cpu = env_archcpu(env);
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     env->ccount_time = now;
@@ -58,7 +58,7 @@ void HELPER(wsr_ccount)(CPUXtensaState *env, uint32_t v)
 
 void HELPER(update_ccompare)(CPUXtensaState *env, uint32_t i)
 {
-    XtensaCPU *cpu = XTENSA_CPU(env_cpu(env));
+    XtensaCPU *cpu = env_archcpu(env);
     uint64_t dcc;
 
     qatomic_and(&env->sregs[INTSET],
--

2.41.0

#19 lore raw

PATCH 5/6 target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]()

In reply to Philippe Mathieu-Daudé

We already have 'x86_cpu = X86_CPU(cpu)'. Use the variable instead of doing another QOM cast with X86_CPU().

---
 target/i386/hvf/x86_emu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/hvf/x86_emu.c +2 -2
index ccda568478..af1f205ecf 100644
@@ -676,7 +676,7 @@ void simulate_rdmsr(struct CPUState *cpu)
         val = rdtscp() + rvmcs(cpu->accel->fd, VMCS_TSC_OFFSET);
         break;
     case MSR_IA32_APICBASE:
-        val = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
+        val = cpu_get_apic_base(x86_cpu->apic_state);
         break;
     case MSR_IA32_UCODE_REV:
         val = x86_cpu->ucode_rev;
@@ -776,7 +776,7 @@ void simulate_wrmsr(struct CPUState *cpu)
     case MSR_IA32_TSC:
         break;
     case MSR_IA32_APICBASE:
-        cpu_set_apic_base(X86_CPU(cpu)->apic_state, data);
+        cpu_set_apic_base(x86_cpu->apic_state, data);
         break;
     case MSR_FSBASE:
         wvmcs(cpu->accel->fd, VMCS_GUEST_FS_BASE, data);
Signature · 1 line
2.41.0
Reviewed-by on v1 5/6
#21 lore raw

Re: [PATCH 5/6] target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]()

In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

Date: Mon, 9 Oct 2023 13:02:38 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 5/6] target/i386/hvf: Use x86_cpu in
simulate_[rdmsr|wrmsr]()
X-Mailer: git-send-email 2.41.0

Quoted 7 lines

We already have 'x86_cpu = X86_CPU(cpu)'. Use the variable instead of doing another QOM cast with X86_CPU().

---
 target/i386/hvf/x86_emu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 28 lines
target/i386/hvf/x86_emu.c +2 -2
index ccda568478..af1f205ecf 100644
@@ -676,7 +676,7 @@ void simulate_rdmsr(struct CPUState *cpu)
         val = rdtscp() + rvmcs(cpu->accel->fd, VMCS_TSC_OFFSET);
         break;
     case MSR_IA32_APICBASE:
-        val = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
+        val = cpu_get_apic_base(x86_cpu->apic_state);
         break;
     case MSR_IA32_UCODE_REV:
         val = x86_cpu->ucode_rev;
@@ -776,7 +776,7 @@ void simulate_wrmsr(struct CPUState *cpu)
     case MSR_IA32_TSC:
         break;
     case MSR_IA32_APICBASE:
-        cpu_set_apic_base(X86_CPU(cpu)->apic_state, data);
+        cpu_set_apic_base(x86_cpu->apic_state, data);
         break;
     case MSR_FSBASE:
         wvmcs(cpu->accel->fd, VMCS_GUEST_FS_BASE, data);
Signature · 1 line
2.41.0
#22 lore raw

PATCH 6/6 target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

In reply to Philippe Mathieu-Daudé

When CPUArchState* is available (here CPUX86State*), we can use the fast env_archcpu() macro to get ArchCPU* (here X86CPU*). The QOM cast X86_CPU() macro will be slower when building with --enable-qom-cast-debug.

Pass CPUX86State* as argument to simulate_rdmsr / simulate_wrmsr instead of a CPUState* to avoid an extra cast.

simulate_rdmsr/simulate_rdmsr(CPUX86State

---
RFC: Not even build-tested.

---
 target/i386/hvf/x86_emu.h |  4 ++--
 target/i386/hvf/hvf.c     |  4 ++--
 target/i386/hvf/x86_emu.c | 21 ++++++++++-----------
 3 files changed, 14 insertions(+), 15 deletions(-)
target/i386/hvf/x86_emu.h +2 -2
index 640da90b30..4b846ba80e 100644
@@ -29,8 +29,8 @@ bool exec_instruction(CPUX86State *env, struct x86_decode *ins);
 void load_regs(struct CPUState *cpu);
 void store_regs(struct CPUState *cpu);
 
-void simulate_rdmsr(struct CPUState *cpu);
-void simulate_wrmsr(struct CPUState *cpu);
+void simulate_rdmsr(CPUX86State *env);
+void simulate_wrmsr(CPUX86State *env);
 
 target_ulong read_reg(CPUX86State *env, int reg, int size);
 void write_reg(CPUX86State *env, int reg, target_ulong val, int size);
target/i386/hvf/hvf.c +2 -2
index cb2cd0b02f..20b9ca3ef5 100644
@@ -591,9 +591,9 @@ int hvf_vcpu_exec(CPUState *cpu)
         {
             load_regs(cpu);
             if (exit_reason == EXIT_REASON_RDMSR) {
-                simulate_rdmsr(cpu);
+                simulate_rdmsr(env);
             } else {
-                simulate_wrmsr(cpu);
+                simulate_wrmsr(env);
             }
             env->eip += ins_len;
             store_regs(cpu);
target/i386/hvf/x86_emu.c +10 -11
index af1f205ecf..b1f8a685d1 100644
@@ -663,11 +663,10 @@ static void exec_lods(CPUX86State *env, struct x86_decode *decode)
     env->eip += decode->len;
 }
 
-void simulate_rdmsr(struct CPUState *cpu)
+void simulate_rdmsr(CPUX86State *env)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
-    CPUX86State *env = &x86_cpu->env;
-    CPUState *cs = env_cpu(env);
+    X86CPU *x86_cpu = env_archcpu(env);
+    CPUState *cpu = env_cpu(env);
     uint32_t msr = ECX(env);
     uint64_t val = 0;
 
@@ -746,8 +745,8 @@ void simulate_rdmsr(struct CPUState *cpu)
         val = env->mtrr_deftype;
         break;
     case MSR_CORE_THREAD_COUNT:
-        val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
-        val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
+        val = cpu->nr_threads * cpu->nr_cores;  /* thread count, bits 15..0 */
+        val |= ((uint32_t)cpu->nr_cores << 16); /* core count, bits 31..16 */
         break;
     default:
         /* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */
@@ -761,14 +760,14 @@ void simulate_rdmsr(struct CPUState *cpu)
 
 static void exec_rdmsr(CPUX86State *env, struct x86_decode *decode)
 {
-    simulate_rdmsr(env_cpu(env));
+    simulate_rdmsr(env);
     env->eip += decode->len;
 }
 
-void simulate_wrmsr(struct CPUState *cpu)
+void simulate_wrmsr(CPUX86State *env)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
-    CPUX86State *env = &x86_cpu->env;
+    X86CPU *x86_cpu = env_archcpu(env);
+    CPUState *cpu = env_cpu(env);
     uint32_t msr = ECX(env);
     uint64_t data = ((uint64_t)EDX(env) << 32) | EAX(env);
 
@@ -856,7 +855,7 @@ void simulate_wrmsr(struct CPUState *cpu)
 
 static void exec_wrmsr(CPUX86State *env, struct x86_decode *decode)
 {
-    simulate_wrmsr(env_cpu(env));
+    simulate_wrmsr(env);
     env->eip += decode->len;
 }
 
Signature · 1 line
2.41.0
Reviewed-by Tested-by on v1 6/6
#23 lore raw

Re: [PATCH 6/6] target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

Quoted 3 lines · Philippe Mathieu-Daudé

simulate_rdmsr/simulate_rdmsr(CPUX86State

Hi Philippe, the above is likely a typo. The subject may also be changed to target/i386/hvf.

Quoted 2 lines

RFC: Not even build-tested.

The patch compiles and works fine. Besides the nits,

Thanks,
Roman

Reviewed-by on v1 6/6
#24 lore raw

Re: [PATCH 6/6] target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

In reply to Philippe Mathieu-Daudé
Quoted 62 lines · Philippe Mathieu-Daudé

Date: Mon, 9 Oct 2023 13:02:39 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 6/6] target/i386: Use env_archcpu() in
simulate_[rdmsr/wrmsr]()
X-Mailer: git-send-email 2.41.0

When CPUArchState* is available (here CPUX86State*), we can use the fast env_archcpu() macro to get ArchCPU* (here X86CPU*). The QOM cast X86_CPU() macro will be slower when building with --enable-qom-cast-debug.

Pass CPUX86State* as argument to simulate_rdmsr / simulate_wrmsr instead of a CPUState* to avoid an extra cast.

simulate_rdmsr/simulate_rdmsr(CPUX86State

---
RFC: Not even build-tested.

---
 target/i386/hvf/x86_emu.h |  4 ++--
 target/i386/hvf/hvf.c     |  4 ++--
 target/i386/hvf/x86_emu.c | 21 ++++++++++-----------
 3 files changed, 14 insertions(+), 15 deletions(-)
target/i386/hvf/x86_emu.h +2 -2
index 640da90b30..4b846ba80e 100644
@@ -29,8 +29,8 @@ bool exec_instruction(CPUX86State *env, struct x86_decode *ins);
 void load_regs(struct CPUState *cpu);
 void store_regs(struct CPUState *cpu);
 
-void simulate_rdmsr(struct CPUState *cpu);
-void simulate_wrmsr(struct CPUState *cpu);
+void simulate_rdmsr(CPUX86State *env);
+void simulate_wrmsr(CPUX86State *env);
 
 target_ulong read_reg(CPUX86State *env, int reg, int size);
 void write_reg(CPUX86State *env, int reg, target_ulong val, int size);
target/i386/hvf/hvf.c +2 -2
index cb2cd0b02f..20b9ca3ef5 100644
@@ -591,9 +591,9 @@ int hvf_vcpu_exec(CPUState *cpu)
         {
             load_regs(cpu);
             if (exit_reason == EXIT_REASON_RDMSR) {
-                simulate_rdmsr(cpu);
+                simulate_rdmsr(env);
             } else {
-                simulate_wrmsr(cpu);
+                simulate_wrmsr(env);
             }
             env->eip += ins_len;
             store_regs(cpu);
target/i386/hvf/x86_emu.c +0 -0
index af1f205ecf..b1f8a685d1 100644
@@ -663,11 +663,10 @@ static void exec_lods(CPUX86State *env, struct x86_decode *decode)
     env->eip += decode->len;

target/i386/hvf/x86_emu.c static void exec_lods(CPUX86State *env, struct x86_decode *decode) · line 669

Quoted 10 lines
target/i386/hvf/x86_emu.c +3 -4
 }
 
-void simulate_rdmsr(struct CPUState *cpu)
+void simulate_rdmsr(CPUX86State *env)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
-    CPUX86State *env = &x86_cpu->env;
-    CPUState *cs = env_cpu(env);
+    X86CPU *x86_cpu = env_archcpu(env);
+    CPUState *cpu = env_cpu(env);

I find these names are confusing since in other i386 file (target/i386/cpu.c), the "X86CPU" is called "cpu", and the "CPUState" is called "cs".

Regarding this naming, it may be worthy of cleanup to unify the naming for i386. ;-)

Quoted 34 lines
target/i386/hvf/x86_emu.c +6 -6
     uint32_t msr = ECX(env);
     uint64_t val = 0;
 
@@ -746,8 +745,8 @@ void simulate_rdmsr(struct CPUState *cpu)
         val = env->mtrr_deftype;
         break;
     case MSR_CORE_THREAD_COUNT:
-        val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
-        val |= ((uint32_t)cs->nr_cores << 16); /* core count, bits 31..16 */
+        val = cpu->nr_threads * cpu->nr_cores;  /* thread count, bits 15..0 */
+        val |= ((uint32_t)cpu->nr_cores << 16); /* core count, bits 31..16 */
         break;
     default:
         /* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */
@@ -761,14 +760,14 @@ void simulate_rdmsr(struct CPUState *cpu)
 
 static void exec_rdmsr(CPUX86State *env, struct x86_decode *decode)
 {
-    simulate_rdmsr(env_cpu(env));
+    simulate_rdmsr(env);
     env->eip += decode->len;
 }
 
-void simulate_wrmsr(struct CPUState *cpu)
+void simulate_wrmsr(CPUX86State *env)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
-    CPUX86State *env = &x86_cpu->env;
+    X86CPU *x86_cpu = env_archcpu(env);
+    CPUState *cpu = env_cpu(env);
     uint32_t msr = ECX(env);
     uint64_t data = ((uint64_t)EDX(env) << 32) | EAX(env);
 

target/i386/hvf/x86_emu.c void simulate_wrmsr(struct CPUState *cpu) · line 860

Quoted 7 lines
target/i386/hvf/x86_emu.c +1 -1
@@ -856,7 +855,7 @@ void simulate_wrmsr(struct CPUState *cpu)
 
 static void exec_wrmsr(CPUX86State *env, struct x86_decode *decode)
 {
-    simulate_wrmsr(env_cpu(env));
+    simulate_wrmsr(env);
     env->eip += decode->len;
 }

-Zhao

Quoted 6 lines
Signature · 2 lines
-- 
2.41.0
Reviewed-by on the v1 series
#25 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

When we have a CPUArchState* pointer we can directly get the corresponding ArchCPU* pointer with env_archcpu(). No need to use QOM cast which is slower due when building with --enable-qom-cast-debug.

This series replace ARCH_CPU(env_cpu(env)) by env_archcpu(env) when possible.

Quoted 7 lines

Philippe Mathieu-Daudé (6):
target/ppc: Use env_archcpu() in helper_book3s_msgsndp() target/riscv: Use env_archcpu() in [check_]nanbox() target/s390x: Use env_archcpu() in handle_diag_308() target/xtensa: Use env_archcpu() in update_c[compare|count]() target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]() target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

r~

#26 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (6):
target/ppc: Use env_archcpu() in helper_book3s_msgsndp() target/riscv: Use env_archcpu() in [check_]nanbox() target/s390x: Use env_archcpu() in handle_diag_308() target/xtensa: Use env_archcpu() in update_c[compare|count]() target/i386/hvf: Use x86_cpu in simulate_[rdmsr|wrmsr]() target/i386: Use env_archcpu() in simulate_[rdmsr/wrmsr]()

Series queued.