From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Harsh Prateek Bora <harshpb@linux.ibm.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Pierrick Bouvier <pierrick.bouvier@linaro.org>,
Nicholas Piggin <npiggin@gmail.com>,
qemu-ppc@nongnu.org
Subject: Re: [PATCH v3 04/11] hw/virtio: Use VirtIODevice::access_is_big_endian field
Date: Mon, 2 Feb 2026 02:45:53 -0500 [thread overview]
Message-ID: <20260202024316-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260201232924.93399-5-philmd@linaro.org>
On Mon, Feb 02, 2026 at 12:29:16AM +0100, Philippe Mathieu-Daudé wrote:
> Endianness access is constant between device resets.
> Use the field instead of calling the same function.
yes but the function was inlined and often a NOP. worth mentioning.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> include/hw/virtio/virtio-access.h | 24 ++++++++++++------------
> hw/virtio/virtio.c | 4 ++--
> 2 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h
> index cd17d0c87eb..f3b4d0075b5 100644
> --- a/include/hw/virtio/virtio-access.h
> +++ b/include/hw/virtio/virtio-access.h
> @@ -42,7 +42,7 @@ static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)
>
> static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> stw_be_p(ptr, v);
> } else {
> stw_le_p(ptr, v);
So this is the main extra cost: on an LE host, we now have this branch on every
access where previously it was all optimized out.
Is it measureable? It is worth testing.
> @@ -51,7 +51,7 @@ static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)
>
> static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> stl_be_p(ptr, v);
> } else {
> stl_le_p(ptr, v);
> @@ -60,7 +60,7 @@ static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)
>
> static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> stq_be_p(ptr, v);
> } else {
> stq_le_p(ptr, v);
> @@ -69,7 +69,7 @@ static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
>
> static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> return lduw_be_p(ptr);
> } else {
> return lduw_le_p(ptr);
and this one.
> @@ -78,7 +78,7 @@ static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
>
> static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> return ldl_be_p(ptr);
> } else {
> return ldl_le_p(ptr);
> @@ -87,7 +87,7 @@ static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
>
> static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> return ldq_be_p(ptr);
> } else {
> return ldq_le_p(ptr);
> @@ -97,9 +97,9 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
> static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
> {
> #if HOST_BIG_ENDIAN
> - return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
> + return vdev->access_is_big_endian ? s : bswap16(s);
> #else
> - return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
> + return vdev->access_is_big_endian ? bswap16(s) : s;
> #endif
> }
>
> @@ -111,9 +111,9 @@ static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s)
> static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s)
> {
> #if HOST_BIG_ENDIAN
> - return virtio_access_is_big_endian(vdev) ? s : bswap32(s);
> + return vdev->access_is_big_endian ? s : bswap32(s);
> #else
> - return virtio_access_is_big_endian(vdev) ? bswap32(s) : s;
> + return vdev->access_is_big_endian ? bswap32(s) : s;
> #endif
> }
>
> @@ -125,9 +125,9 @@ static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s)
> static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s)
> {
> #if HOST_BIG_ENDIAN
> - return virtio_access_is_big_endian(vdev) ? s : bswap64(s);
> + return vdev->access_is_big_endian ? s : bswap64(s);
> #else
> - return virtio_access_is_big_endian(vdev) ? bswap64(s) : s;
> + return vdev->access_is_big_endian ? bswap64(s) : s;
> #endif
> }
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 242c207a591..1dc60d37cb4 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -220,7 +220,7 @@ static inline uint16_t virtio_lduw_phys_cached(VirtIODevice *vdev,
> MemoryRegionCache *cache,
> hwaddr pa)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> return lduw_be_phys_cached(cache, pa);
> }
> return lduw_le_phys_cached(cache, pa);
> @@ -230,7 +230,7 @@ static inline void virtio_stw_phys_cached(VirtIODevice *vdev,
> MemoryRegionCache *cache,
> hwaddr pa, uint16_t value)
> {
> - if (virtio_access_is_big_endian(vdev)) {
> + if (vdev->access_is_big_endian) {
> stw_be_phys_cached(cache, pa, value);
> } else {
> stw_le_phys_cached(cache, pa, value);
> --
> 2.52.0
next prev parent reply other threads:[~2026-02-02 7:46 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-01 23:29 [PATCH v3 00/11] single-binary: hw/virtio Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 01/11] target-info: add target_base_ppc, target_ppc and target_ppc64 Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 02/11] hw/virtio: Constify virtio_is_big_endian() argument Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 03/11] hw/virtio: Introduce VirtIODevice::access_is_big_endian boolean field Philippe Mathieu-Daudé
2026-02-01 23:50 ` Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 04/11] hw/virtio: Use VirtIODevice::access_is_big_endian field Philippe Mathieu-Daudé
2026-02-02 7:45 ` Michael S. Tsirkin [this message]
2026-02-02 13:08 ` Alex Bennée
2026-02-02 16:04 ` Michael S. Tsirkin
2026-02-02 18:52 ` Stefan Hajnoczi
2026-02-02 19:25 ` Pierrick Bouvier
2026-02-03 3:22 ` Pierrick Bouvier
2026-02-03 11:07 ` Michael S. Tsirkin
2026-02-03 17:31 ` Pierrick Bouvier
2026-02-03 19:06 ` Michael S. Tsirkin
2026-02-03 19:10 ` Pierrick Bouvier
2026-02-03 19:37 ` Pierrick Bouvier
2026-02-03 10:44 ` Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 05/11] hw/virtio: Reduce virtio_access_is_big_endian() scope Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 06/11] hw/virtio: Check target supports legacy bi-endianness at runtime Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 07/11] hw/virtio: Replace TARGET_BIG_ENDIAN -> target_big_endian() Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 08/11] hw/ppc/spapr: extract SPAPR_MAX_RAM_SLOTS in a new header Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 09/11] hw/virtio/vhost-user: make compilation unit common Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 10/11] hw/virtio/virtio-qmp: " Philippe Mathieu-Daudé
2026-02-01 23:29 ` [PATCH v3 11/11] hw/virtio: make all compilation units common Philippe Mathieu-Daudé
2026-02-02 7:47 ` [PATCH v3 00/11] single-binary: hw/virtio Michael S. Tsirkin
2026-02-02 11:16 ` Philippe Mathieu-Daudé
2026-02-02 18:13 ` 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=20260202024316-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=harshpb@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sgarzare@redhat.com \
/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.