All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Cc: qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	richard.henderson@linaro.org
Subject: Re: [PATCH] target-info: set target_arch statically
Date: Thu, 05 Feb 2026 10:29:50 +0100	[thread overview]
Message-ID: <878qd735dd.fsf@pond.sub.org> (raw)
In-Reply-To: <20260203194113.3026757-1-pierrick.bouvier@linaro.org> (Pierrick Bouvier's message of "Tue, 3 Feb 2026 11:41:13 -0800")

Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:

> 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);
> +}

This is slightly unclean.  Constructors run before main().  If
qapi_enum_parse(..., &error_abort) fails here, error_handle() will
report the unexpected error with error_report() before main() calls
error_init().

See also

    From: Markus Armbruster <armbru@redhat.com>
    Subject: Re: [PATCH v3 02/20] monitor: initialize global data from a constructor 
    Date: Thu, 18 Sep 2025 08:30:23 +0200
    Message-ID: <87frck1dds.fsf@pond.sub.org>

Observation, not objection.

> 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)



  parent reply	other threads:[~2026-02-05  9:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-02-05 19:02   ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878qd735dd.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.