osdep: Cache getpagesize() call in qemu_real_host_page_size()
cover osdep: Cache getpagesize() call in qemu_real_host_page_size()
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(-)
Signature · 1 line
2.51.0
PATCH 1/2 osdep: Un-inline qemu_real_host_page_size()
--- include/qemu/osdep.h | 6 +----- util/osdep.c | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-)
include/qemu/osdep.h +1 -5
@@ -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 ();
util/osdep.c +5 -0
@@ -613,3 +613,8 @@ int qemu_fdatasync(int fd)return fsync (fd);#endif } + +uintptr_t qemu_real_host_page_size (void ) +{ +return getpagesize (); +}
Signature · 1 line
2.51.0
PATCH 2/2 osdep: Cache getpagesize() call in qemu_real_host_page_size()
In reply to 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.
--- util/osdep.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
util/osdep.c +7 -1
@@ -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; }
Signature · 1 line
2.51.0
Quoted 7 lines · Philippe Mathieu-Daudé
Cache
getpagesize()call once, so we don't have to worry how often we can callqemu_real_host_page_size()andqemu_real_host_page_mask().Philippe Mathieu-Daudé (2):
osdep: Un-inlineqemu_real_host_page_size()
osdep: Cachegetpagesize()call inqemu_real_host_page_size()
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~