qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size()
@ 2025-11-03 10:51 Philippe Mathieu-Daudé
  2025-11-03 10:51 ` [PATCH 1/2] osdep: Un-inline qemu_real_host_page_size() Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-03 10:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Pierrick Bouvier, Philippe Mathieu-Daudé

Cache getpagesize() call once, so we don't have to worry
how often we can call qemu_real_host_page_size() and
qemu_real_host_page_mask().

Philippe Mathieu-Daudé (2):
  osdep: Un-inline qemu_real_host_page_size()
  osdep: Cache getpagesize() call in qemu_real_host_page_size()

 include/qemu/osdep.h |  6 +-----
 util/osdep.c         | 11 +++++++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

-- 
2.51.0



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

* [PATCH 1/2] osdep: Un-inline qemu_real_host_page_size()
  2025-11-03 10:51 [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
@ 2025-11-03 10:51 ` Philippe Mathieu-Daudé
  2025-11-03 10:51 ` [PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
  2025-11-06 10:53 ` [PATCH 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-03 10:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Pierrick Bouvier, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/osdep.h | 6 +-----
 util/osdep.c         | 5 +++++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index cf8d7cf7e61..fd714014eaf 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -763,14 +763,10 @@ bool qemu_finish_async_prealloc_mem(Error **errp);
  */
 char *qemu_get_pid_name(pid_t pid);
 
+uintptr_t qemu_real_host_page_size(void);
 /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
  * when intptr_t is 32-bit and we are aligning a long long.
  */
-static inline uintptr_t qemu_real_host_page_size(void)
-{
-    return getpagesize();
-}
-
 static inline intptr_t qemu_real_host_page_mask(void)
 {
     return -(intptr_t)qemu_real_host_page_size();
diff --git a/util/osdep.c b/util/osdep.c
index 770369831bc..44fad13dcc7 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -613,3 +613,8 @@ int qemu_fdatasync(int fd)
     return fsync(fd);
 #endif
 }
+
+uintptr_t qemu_real_host_page_size(void)
+{
+    return getpagesize();
+}
-- 
2.51.0



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

* [PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size()
  2025-11-03 10:51 [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
  2025-11-03 10:51 ` [PATCH 1/2] osdep: Un-inline qemu_real_host_page_size() Philippe Mathieu-Daudé
@ 2025-11-03 10:51 ` Philippe Mathieu-Daudé
  2025-11-06 10:53 ` [PATCH 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-03 10:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Pierrick Bouvier, Philippe Mathieu-Daudé

Since we can not know whether a libc implementation of
getpagesize() calls syscalls -- potentially slow --, but
we know the host page size won't change during runtime,
we can cache its value.

Reported-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 util/osdep.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/util/osdep.c b/util/osdep.c
index 44fad13dcc7..9b50d00dbda 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -616,5 +616,11 @@ int qemu_fdatasync(int fd)
 
 uintptr_t qemu_real_host_page_size(void)
 {
-    return getpagesize();
+    static uintptr_t real_host_page_size;
+
+    if (!real_host_page_size) {
+        real_host_page_size = getpagesize();
+    }
+
+    return real_host_page_size;
 }
-- 
2.51.0



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

* Re: [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size()
  2025-11-03 10:51 [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
  2025-11-03 10:51 ` [PATCH 1/2] osdep: Un-inline qemu_real_host_page_size() Philippe Mathieu-Daudé
  2025-11-03 10:51 ` [PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
@ 2025-11-06 10:53 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2025-11-06 10:53 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Pierrick Bouvier

On 11/3/25 11:51, Philippe Mathieu-Daudé wrote:
> Cache getpagesize() call once, so we don't have to worry
> how often we can call qemu_real_host_page_size() and
> qemu_real_host_page_mask().
> 
> Philippe Mathieu-Daudé (2):
>    osdep: Un-inline qemu_real_host_page_size()
>    osdep: Cache getpagesize() call in qemu_real_host_page_size()

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

That's a step up, certainly.  I had been thinking of making it a faux const variable, akin 
to how we manage page-vary-common.c, and a high priority constructor.

With less efford you could mark the function __attribute__((const)), so that the compiler 
will CSE calls.


r~


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

end of thread, other threads:[~2025-11-06 10:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 10:51 [PATCH 0/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
2025-11-03 10:51 ` [PATCH 1/2] osdep: Un-inline qemu_real_host_page_size() Philippe Mathieu-Daudé
2025-11-03 10:51 ` [PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size() Philippe Mathieu-Daudé
2025-11-06 10:53 ` [PATCH 0/2] " Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).