All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target-info: set target_arch statically
@ 2026-02-03 19:41 Pierrick Bouvier
  2026-02-04  1:36 ` Richard Henderson
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Pierrick Bouvier @ 2026-02-03 19:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Pierrick Bouvier, richard.henderson

target_arch() function will reparse target_name() every time if it was
not set to a proper SYS_EMU_TARGET_* value (when using
target-info-stub.c), which is not efficient.

Since we want to preserve the constness of TargetInfo but C doesn't give
us flexible compile time expressions, we simply set target_arch using a
static constructor once instead.

This was found when doing changes to virtio_access_is_big_endian()
function, having an overhead of 50% after switching to runtime checks.
With this, overhead left is around 3%, due to indirect function
calls.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target-info-stub.c | 11 ++++++++++-
 target-info.c      |  9 +--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/target-info-stub.c b/target-info-stub.c
index 8392d81e8f8..ff86a02247a 100644
--- a/target-info-stub.c
+++ b/target-info-stub.c
@@ -10,13 +10,14 @@
 #include "qemu/target-info.h"
 #include "qemu/target-info-impl.h"
 #include "hw/core/boards.h"
+#include "qapi/error.h"
 #include "cpu.h"
 
 /* Validate correct placement of CPUArchState. */
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
-static const TargetInfo target_info_stub = {
+static TargetInfo target_info_stub = {
     .target_name = TARGET_NAME,
     .target_arch = SYS_EMU_TARGET__MAX,
     .long_bits = TARGET_LONG_BITS,
@@ -29,3 +30,11 @@ const TargetInfo *target_info(void)
 {
     return &target_info_stub;
 }
+
+__attribute__((constructor))
+static void init_target_arch(void)
+{
+    target_info_stub.target_arch = qapi_enum_parse(&SysEmuTarget_lookup,
+                                                   target_name(), -1,
+                                                   &error_abort);
+}
diff --git a/target-info.c b/target-info.c
index 24696ff4111..c3c0856d01a 100644
--- a/target-info.c
+++ b/target-info.c
@@ -10,7 +10,6 @@
 #include "qemu/target-info.h"
 #include "qemu/target-info-qapi.h"
 #include "qemu/target-info-impl.h"
-#include "qapi/error.h"
 
 const char *target_name(void)
 {
@@ -24,13 +23,7 @@ unsigned target_long_bits(void)
 
 SysEmuTarget target_arch(void)
 {
-    SysEmuTarget arch = target_info()->target_arch;
-
-    if (arch == SYS_EMU_TARGET__MAX) {
-        arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
-                               &error_abort);
-    }
-    return arch;
+    return target_info()->target_arch;
 }
 
 const char *target_cpu_type(void)
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-02-06  7:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 19:41 [PATCH] target-info: set target_arch statically Pierrick Bouvier
2026-02-04  1:36 ` Richard Henderson
2026-02-04 16:36   ` Pierrick Bouvier
2026-02-04 22:22     ` Richard Henderson
2026-02-05  9:52       ` Markus Armbruster
2026-02-05 22:36         ` Richard Henderson
2026-02-06  6:58           ` Renaming targets (was: [PATCH] target-info: set target_arch statically) Markus Armbruster
2026-02-06  7:21             ` Renaming targets Pierrick Bouvier
2026-02-06  7:38               ` Markus Armbruster
2026-02-06  7:52                 ` Pierrick Bouvier
2026-02-04  9:10 ` [PATCH] target-info: set target_arch statically Daniel P. Berrangé
2026-02-04 16:38   ` Pierrick Bouvier
2026-02-04 17:06 ` Anton Johansson via qemu development
2026-02-05  9:29 ` Markus Armbruster
2026-02-05 19:02   ` Pierrick Bouvier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.