From: Philippe Mathieu-Daudé <philmd@linaro.org>
Endianness access is constant between device resets.
Use the field instead of calling the same function.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@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);
@@ -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);
@@ -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 df2887e7296..f08e94843ea 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.47.3
On 2/3/26 12:56 PM, Pierrick Bouvier wrote: > From: Philippe Mathieu-Daudé <philmd@linaro.org> > > Endianness access is constant between device resets. > Use the field instead of calling the same function. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> > --- > include/hw/virtio/virtio-access.h | 24 ++++++++++++------------ > hw/virtio/virtio.c | 4 ++-- > 2 files changed, 14 insertions(+), 14 deletions(-) > Oops, seems like it's not correct, I found some failing tests bisecting to this patch. I'll dig into it to see what is happening. Regards, Pierrick
On 3/2/26 21:56, Pierrick Bouvier wrote: > From: Philippe Mathieu-Daudé <philmd@linaro.org> > > Endianness access is constant between device resets. > Use the field instead of calling the same function. Maybe we should justify here, simply adding from your v3 comment: When doing automated benchmark with fio (see instructions in [*]) this resulted in a +1.4% speedup vs existing code. [*] https://lore.kernel.org/qemu-devel/20260202185233.GC405548@fedora/ > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> > --- > include/hw/virtio/virtio-access.h | 24 ++++++++++++------------ > hw/virtio/virtio.c | 4 ++-- > 2 files changed, 14 insertions(+), 14 deletions(-)
On Tue, 3 Feb 2026, Philippe Mathieu-Daudé wrote: > On 3/2/26 21:56, Pierrick Bouvier wrote: >> From: Philippe Mathieu-Daudé <philmd@linaro.org> >> >> Endianness access is constant between device resets. >> Use the field instead of calling the same function. > > Maybe we should justify here, simply adding from your v3 comment: > > When doing automated benchmark with fio (see instructions > in [*]) this resulted in a +1.4% speedup vs existing code. > > [*] https://lore.kernel.org/qemu-devel/20260202185233.GC405548@fedora/ What does existing code refer to here? According to cover letter it's within 0.003% of existing speed so not actually faster but only a tiny bit slower. The speed up above maybe from previous version of the series without this patch so maybe clarify that more if you include this in the commit message. Regards, BALATON Zoltan >> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> >> --- >> include/hw/virtio/virtio-access.h | 24 ++++++++++++------------ >> hw/virtio/virtio.c | 4 ++-- >> 2 files changed, 14 insertions(+), 14 deletions(-) > > >
On 2/3/26 2:38 PM, BALATON Zoltan wrote: > On Tue, 3 Feb 2026, Philippe Mathieu-Daudé wrote: >> On 3/2/26 21:56, Pierrick Bouvier wrote: >>> From: Philippe Mathieu-Daudé <philmd@linaro.org> >>> >>> Endianness access is constant between device resets. >>> Use the field instead of calling the same function. >> >> Maybe we should justify here, simply adding from your v3 comment: >> >> When doing automated benchmark with fio (see instructions >> in [*]) this resulted in a +1.4% speedup vs existing code. >> >> [*] https://lore.kernel.org/qemu-devel/20260202185233.GC405548@fedora/ > > What does existing code refer to here? According to cover letter it's > within 0.003% of existing speed so not actually faster but only a tiny bit > slower. The speed up above maybe from previous version of the series > without this patch so maybe clarify that more if you include this in the > commit message. > Existing is upstream/master. +1.4% is with this patch. End result is -0.3% with the full series applied. > Regards, > BALATON Zoltan > >>> >>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> >>> --- >>> include/hw/virtio/virtio-access.h | 24 ++++++++++++------------ >>> hw/virtio/virtio.c | 4 ++-- >>> 2 files changed, 14 insertions(+), 14 deletions(-) >> >> >>
© 2016 - 2026 Red Hat, Inc.