Skip to contentSkip to conversation

accel/tcg: Move perf and debuginfo support to tcg

PATCH Superseded Ilya Leoshkevich 2 participants 8 messages Jun 30, 2023 Arm/Amlogic Meson SoC support

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover accel/tcg: Move perf and debuginfo support to tcg

Hi,

This series is a follow-up to discussion in [1]; the goal is to build perf and debuginfo support only one time.

I had to move tb_cflags() and qemu_target_page_mask(), and I'm not sure if my choices there are perfect. Please let me know if there are better locations for them.

Best regards,
Ilya

[1] https://lists.gnu.org/archive/html/qemu-devel/2023-06/msg06510.html

Ilya Leoshkevich (4):
target: Make qemu_softmmu_page_mask() available for *-user
tcg: Make tb_cflags() usable from target-agnostic code accel/tcg: Remove #ifdef TARGET_I386 from perf.c accel/tcg: Move perf and debuginfo support to tcg

 accel/tcg/meson.build            | 2 --
 accel/tcg/translate-all.c        | 2 +-
 hw/core/loader.c                 | 2 +-
 include/exec/exec-all.h          | 6 ------
 include/exec/translation-block.h | 6 ++++++
 linux-user/elfload.c             | 2 +-
 linux-user/exit.c                | 2 +-
 linux-user/main.c                | 2 +-
 softmmu/physmem.c                | 5 -----
 softmmu/vl.c                     | 2 +-
 target/meson.build               | 2 ++
 target/target-common.c           | 9 +++++++++
 {accel/tcg => tcg}/debuginfo.c   | 0
 {accel/tcg => tcg}/debuginfo.h   | 4 ++--
 tcg/meson.build                  | 3 +++
 {accel/tcg => tcg}/perf.c        | 8 ++------
 {accel/tcg => tcg}/perf.h        | 4 ++--
 tcg/tcg.c                        | 2 +-
 18 files changed, 33 insertions(+), 30 deletions(-)
 create mode 100644 target/target-common.c
 rename {accel/tcg => tcg}/debuginfo.c (100%)
 rename {accel/tcg => tcg}/debuginfo.h (96%)
 rename {accel/tcg => tcg}/perf.c (98%)
 rename {accel/tcg => tcg}/perf.h (95%)
Signature · 1 line
2.41.0
#3 lore raw

PATCH 2/4 tcg: Make tb_cflags() usable from target-agnostic code

Currently tb_cflags() is defined in exec-all.h, which is not usable from target-agnostic code. Move it to translation-block.h, which is.

---
 include/exec/exec-all.h          | 6 ------
 include/exec/translation-block.h | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
include/exec/exec-all.h +0 -6
index 200c27eadfe..652fb9dc126 100644
@@ -466,12 +466,6 @@ int probe_access_full(CPUArchState *env, vaddr addr, int size,
                       CPUTLBEntryFull **pfull, uintptr_t retaddr);
 #endif
 
-/* Hide the qatomic_read to make code a little easier on the eyes */
-static inline uint32_t tb_cflags(const TranslationBlock *tb)
-{
-    return qatomic_read(&tb->cflags);
-}
-
 static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb)
 {
 #ifdef CONFIG_USER_ONLY
include/exec/translation-block.h +6 -0
index 5119924927e..7a7190bb30d 100644
@@ -146,4 +146,10 @@ struct TranslationBlock {
 /* The alignment given to TranslationBlock during allocation. */
 #define CODE_GEN_ALIGN  16
 
+/* Hide the qatomic_read to make code a little easier on the eyes */
+static inline uint32_t tb_cflags(const TranslationBlock *tb)
+{
+    return qatomic_read(&tb->cflags);
+}
+
 #endif /* EXEC_TRANSLATION_BLOCK_H */
Signature · 1 line
2.41.0
#5 lore raw

PATCH 3/4 accel/tcg: Remove #ifdef TARGET_I386 from perf.c

In reply to Ilya Leoshkevich

Preparation for moving perf.c to tcg/.

This affects only profiling guest code, which has code in a non-0 based segment, e.g., 16-bit code, which is not particularly important.

---
 accel/tcg/perf.c | 4 ----
 1 file changed, 4 deletions(-)
accel/tcg/perf.c +0 -4
index cd1aa99a7ee..e2813e11806 100644
@@ -336,10 +336,6 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
         q[insn].address = gen_insn_data[insn * start_words + 0];
         if (tb_cflags(tb) & CF_PCREL) {
             q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
-        } else {
-#if defined(TARGET_I386)
-            q[insn].address -= tb->cs_base;
-#endif
         }
         q[insn].flags = DEBUGINFO_SYMBOL | (jitdump ? DEBUGINFO_LINE : 0);
     }
Signature · 1 line
2.41.0
#6 lore raw

PATCH 4/4 accel/tcg: Move perf and debuginfo support to tcg

In reply to Ilya Leoshkevich

tcg/ should not depend on accel/tcg/, but perf and debuginfo support provided by the latter are being used by tcg/tcg.c.

Since that's the only user, move both to tcg/.

---
 accel/tcg/meson.build          | 2 --
 accel/tcg/translate-all.c      | 2 +-
 hw/core/loader.c               | 2 +-
 linux-user/elfload.c           | 2 +-
 linux-user/exit.c              | 2 +-
 linux-user/main.c              | 2 +-
 softmmu/vl.c                   | 2 +-
 {accel/tcg => tcg}/debuginfo.c | 0
 {accel/tcg => tcg}/debuginfo.h | 4 ++--
 tcg/meson.build                | 3 +++
 {accel/tcg => tcg}/perf.c      | 4 ++--
 {accel/tcg => tcg}/perf.h      | 4 ++--
 tcg/tcg.c                      | 2 +-
 13 files changed, 16 insertions(+), 15 deletions(-)
 rename {accel/tcg => tcg}/debuginfo.c (100%)
 rename {accel/tcg => tcg}/debuginfo.h (96%)
 rename {accel/tcg => tcg}/perf.c (98%)
 rename {accel/tcg => tcg}/perf.h (95%)
accel/tcg/meson.build +0 -2
index 166bef173b8..083c9058391 100644
@@ -12,8 +12,6 @@ tcg_ss.add(files(
 tcg_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c'))
 tcg_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_false: files('user-exec-stub.c'))
 tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c')])
-tcg_ss.add(when: libdw, if_true: files('debuginfo.c'))
-tcg_ss.add(when: 'CONFIG_LINUX', if_true: files('perf.c'))
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
 specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files(
accel/tcg/translate-all.c +1 -1
index d3d4fbc1a41..58d9bd5a69e 100644
@@ -62,7 +62,7 @@
 #include "tb-hash.h"
 #include "tb-context.h"
 #include "internal.h"
-#include "perf.h"
+#include "tcg/perf.h"
 #include "tcg/insn-start-words.h"
 
 TBContext tb_ctx;
hw/core/loader.c +1 -1
index 8b7fd9e9e55..ad8d00440a7 100644
@@ -62,7 +62,7 @@
 #include "hw/boards.h"
 #include "qemu/cutils.h"
 #include "sysemu/runstate.h"
-#include "accel/tcg/debuginfo.h"
+#include "tcg/debuginfo.h"
 
 #include <zlib.h>
 
linux-user/elfload.c +1 -1
index 9a2ec568b09..6900974c373 100644
@@ -21,7 +21,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "target_signal.h"
-#include "accel/tcg/debuginfo.h"
+#include "tcg/debuginfo.h"
 
 #ifdef _ARCH_PPC64
 #undef ARCH_DLINFO
linux-user/exit.c +1 -1
index 3017d28a3c3..122b9d904f1 100644
@@ -17,7 +17,7 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include "accel/tcg/perf.h"
+#include "tcg/perf.h"
 #include "gdbstub/syscalls.h"
 #include "qemu.h"
 #include "user-internals.h"
linux-user/main.c +1 -1
index dba67ffa362..3f65ca49db8 100644
@@ -54,7 +54,7 @@
 #include "signal-common.h"
 #include "loader.h"
 #include "user-mmap.h"
-#include "accel/tcg/perf.h"
+#include "tcg/perf.h"
 
 #ifdef CONFIG_SEMIHOSTING
 #include "semihosting/semihost.h"
softmmu/vl.c +1 -1
index b0b96f67fac..92922377210 100644
@@ -97,7 +97,7 @@
 #endif
 #include "sysemu/qtest.h"
 #ifdef CONFIG_TCG
-#include "accel/tcg/perf.h"
+#include "tcg/perf.h"
 #endif
 
 #include "disas/disas.h"
tcg/debuginfo.c renamed from accel/tcg/debuginfo.c +0 -0
similarity index 100%
rename from accel/tcg/debuginfo.c
rename to tcg/debuginfo.c
tcg/debuginfo.h renamed from accel/tcg/debuginfo.h +2 -2
similarity index 96%
rename from accel/tcg/debuginfo.h
rename to tcg/debuginfo.h
index f064e1c144b..858535b5da5 100644
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#ifndef ACCEL_TCG_DEBUGINFO_H
-#define ACCEL_TCG_DEBUGINFO_H
+#ifndef TCG_DEBUGINFO_H
+#define TCG_DEBUGINFO_H
 
 #include "qemu/bitops.h"
 
tcg/meson.build +3 -0
index c0252c41988..0800e1faae8 100644
@@ -22,6 +22,9 @@ if get_option('tcg_interpreter')
   tcg_ss.add(files('tci.c'))
 endif
 
+tcg_ss.add(when: libdw, if_true: files('debuginfo.c'))
+tcg_ss.add(when: 'CONFIG_LINUX', if_true: files('perf.c'))
+
 tcg_ss = tcg_ss.apply(config_host, strict: false)
 
 libtcg_user = static_library('tcg_user',
tcg/perf.c renamed from accel/tcg/perf.c +2 -2
similarity index 98%
rename from accel/tcg/perf.c
rename to tcg/perf.c
index e2813e11806..4a08fd9d259 100644
@@ -10,7 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "elf.h"
-#include "exec/exec-all.h"
+#include "exec/translation-block.h"
 #include "qemu/timer.h"
 #include "tcg/tcg.h"
 
@@ -335,7 +335,7 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
         /* FIXME: This replicates the restore_state_to_opc() logic. */
         q[insn].address = gen_insn_data[insn * start_words + 0];
         if (tb_cflags(tb) & CF_PCREL) {
-            q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
+            q[insn].address |= (guest_pc & qemu_target_page_mask());
         }
         q[insn].flags = DEBUGINFO_SYMBOL | (jitdump ? DEBUGINFO_LINE : 0);
     }
tcg/perf.h renamed from accel/tcg/perf.h +2 -2
similarity index 95%
rename from accel/tcg/perf.h
rename to tcg/perf.h
index f92dd52c699..c96b5920a3f 100644
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#ifndef ACCEL_TCG_PERF_H
-#define ACCEL_TCG_PERF_H
+#ifndef TCG_PERF_H
+#define TCG_PERF_H
 
 #if defined(CONFIG_TCG) && defined(CONFIG_LINUX)
 /* Start writing perf-<pid>.map. */
tcg/tcg.c +1 -1
index a0628fe4249..2afc5f2d0f7 100644
@@ -54,7 +54,7 @@
 #include "tcg/tcg-ldst.h"
 #include "tcg/tcg-temp-internal.h"
 #include "tcg-internal.h"
-#include "accel/tcg/perf.h"
+#include "tcg/perf.h"
 #ifdef CONFIG_USER_ONLY
 #include "exec/user/guest-base.h"
 #endif
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 target: Make qemu_softmmu_page_mask() available for *-user

In reply to Ilya Leoshkevich

Currently qemu_softmmu_page_mask() is usable only from the softmmu code. Make it possible to use it from the *-user code as wel.

---
 softmmu/physmem.c      | 5 -----
 target/meson.build     | 2 ++
 target/target-common.c | 9 +++++++++
 3 files changed, 11 insertions(+), 5 deletions(-)
 create mode 100644 target/target-common.c
softmmu/physmem.c +0 -5
index bda475a719d..6bdd944fe88 100644
@@ -3359,11 +3359,6 @@ size_t qemu_target_page_size(void)
     return TARGET_PAGE_SIZE;
 }
 
-int qemu_target_page_mask(void)
-{
-    return TARGET_PAGE_MASK;
-}
-
 int qemu_target_page_bits(void)
 {
     return TARGET_PAGE_BITS;
target/meson.build +2 -0
index a53a60486fc..dee2ac47e02 100644
@@ -19,3 +19,5 @@ subdir('sh4')
 subdir('sparc')
 subdir('tricore')
 subdir('xtensa')
+
+specific_ss.add(files('target-common.c'))
target/target-common.c new file +9 -0
new file mode 100644
index 00000000000..6868a1f490f
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "qemu/osdep.h"
+
+#include "exec/exec-all.h"
+
+int qemu_target_page_mask(void)
+{
+    return TARGET_PAGE_MASK;
+}
Signature · 1 line
2.41.0
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] tcg: Make tb_cflags() usable from target-agnostic code

In reply to Ilya Leoshkevich
Quoted 8 lines · Ilya Leoshkevich

Currently tb_cflags() is defined in exec-all.h, which is not usable from target-agnostic code. Move it to translation-block.h, which is.

---
  include/exec/exec-all.h          | 6 ------
  include/exec/translation-block.h | 6 ++++++
  2 files changed, 6 insertions(+), 6 deletions(-)
#2 lore raw

Re: [PATCH 1/4] target: Make qemu_softmmu_page_mask() available for *-user

In reply to Ilya Leoshkevich
Quoted 1 line · Ilya Leoshkevich

Currently qemu_softmmu_page_mask() is usable only from the softmmu

s/qemu_softmmu_page_mask/qemu_target_page_mask/?

Quoted 51 lines

code. Make it possible to use it from the *-user code as wel.

---
  softmmu/physmem.c      | 5 -----
  target/meson.build     | 2 ++
  target/target-common.c | 9 +++++++++
  3 files changed, 11 insertions(+), 5 deletions(-)

create mode 100644 target/target-common.c

softmmu/physmem.c +0 -5
index bda475a719d..6bdd944fe88 100644
@@ -3359,11 +3359,6 @@ size_t qemu_target_page_size(void)
      return TARGET_PAGE_SIZE;
  }
 
-int qemu_target_page_mask(void)
-{
-    return TARGET_PAGE_MASK;
-}
-
  int qemu_target_page_bits(void)
  {
      return TARGET_PAGE_BITS;
target/meson.build +2 -0
index a53a60486fc..dee2ac47e02 100644
@@ -19,3 +19,5 @@ subdir('sh4')
  subdir('sparc')
  subdir('tricore')
  subdir('xtensa')
+
+specific_ss.add(files('target-common.c'))
target/target-common.c new file +9 -0
new file mode 100644
index 00000000000..6868a1f490f
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "qemu/osdep.h"
+
+#include "exec/exec-all.h"
+
+int qemu_target_page_mask(void)
+{
+    return TARGET_PAGE_MASK;
+}
#7 lore raw
In reply to Ilya Leoshkevich
Quoted 45 lines · Ilya Leoshkevich

tcg/ should not depend on accel/tcg/, but perf and debuginfo support provided by the latter are being used by tcg/tcg.c.

Since that's the only user, move both to tcg/.

---
  accel/tcg/meson.build          | 2 --
  accel/tcg/translate-all.c      | 2 +-
  hw/core/loader.c               | 2 +-
  linux-user/elfload.c           | 2 +-
  linux-user/exit.c              | 2 +-
  linux-user/main.c              | 2 +-
  softmmu/vl.c                   | 2 +-
  {accel/tcg => tcg}/debuginfo.c | 0
  {accel/tcg => tcg}/debuginfo.h | 4 ++--
  tcg/meson.build                | 3 +++
  {accel/tcg => tcg}/perf.c      | 4 ++--
  {accel/tcg => tcg}/perf.h      | 4 ++--
  tcg/tcg.c                      | 2 +-
  13 files changed, 16 insertions(+), 15 deletions(-)

rename {accel/tcg => tcg}/debuginfo.c (100%)
rename {accel/tcg => tcg}/debuginfo.h (96%)
rename {accel/tcg => tcg}/perf.c (98%)
rename {accel/tcg => tcg}/perf.h (95%)

tcg/perf.c renamed from accel/tcg/perf.c +1 -1
similarity index 98%
rename from accel/tcg/perf.c
rename to tcg/perf.c
index e2813e11806..4a08fd9d259 100644
@@ -10,7 +10,7 @@
 
  #include "qemu/osdep.h"
  #include "elf.h"
-#include "exec/exec-all.h"
+#include "exec/translation-block.h"
  #include "qemu/timer.h"
  #include "tcg/tcg.h"
 

tcg/perf.c void perf_report_code(uint64_t guest_pc, TranslationBlock *tb, · line 341

Quoted 8 lines
tcg/perf.c renamed from accel/tcg/perf.c +1 -1
@@ -335,7 +335,7 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
          /* FIXME: This replicates the restore_state_to_opc() logic. */
          q[insn].address = gen_insn_data[insn * start_words + 0];
          if (tb_cflags(tb) & CF_PCREL) {
-            q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
+            q[insn].address |= (guest_pc & qemu_target_page_mask());
          }
          q[insn].flags = DEBUGINFO_SYMBOL | (jitdump ? DEBUGINFO_LINE : 0);
      }

Could this hunk belong to patch #1?