util/oslib: qemu_try_memalign() improvements
v5 cover util/oslib: qemu_try_memalign() improvements
- Use _aligned_malloc for qemu_try_memalign on win32
- Assert qemu_try_memalign() alignment is a power of 2
Since v4:
- Drop superfluous assert (Richard)
Philippe Mathieu-Daudé (1):
util/oslib: Assert qemu_try_memalign() alignment is a power of 2
Richard Henderson (1):
util/oslib-win32: Use _aligned_malloc for qemu_try_memalign
util/oslib-posix.c | 2 ++ util/oslib-win32.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.2
PATCH v5 1/2 util/oslib-win32: Use _aligned_malloc for qemu_try_memalign
From: Richard Henderson <[email protected]>
We do not need or want to be allocating page sized quanta.
Message-Id: <[email protected]>
--- util/oslib-win32.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
util/oslib-win32.c +4 -7
@@ -39,6 +39,7 @@#include "trace.h" #include "qemu/sockets.h" #include "qemu/cutils.h" +#include <malloc.h> /* this must come after including "trace.h" */ #include <shlobj.h>
@@ -56,10 +57,8 @@ void *qemu_try_memalign(size_t alignment, size_t size) {void *ptr; -if (!size) { -abort (); - } - ptr =VirtualAlloc (NULL , size,MEM_COMMIT ,PAGE_READWRITE ); +g_assert (size !=0 ); + ptr =_aligned_malloc (alignment, size);trace_qemu_memalign (alignment, size, ptr);return ptr; }
@@ -93,9 +92,7 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared)void qemu_vfree (void *ptr) {trace_qemu_vfree (ptr); -if (ptr) { -VirtualFree (ptr,0 ,MEM_RELEASE ); - } +_aligned_free (ptr); }void qemu_anon_ram_free (void *ptr,size_t size)
Signature · 1 line
2.26.2
PATCH v5 2/2 util/oslib: Assert qemu_try_memalign() alignment is a power of 2
In reply to Philippe Mathieu-Daudéqemu_try_memalign() expects a power of 2 alignment:
- posix_memalign(3):
The address of the allocated memory will be a multiple of alignment, which must be a power of two and a multiple of sizeof(void *).
- _aligned_malloc()
The alignment value, which must be an integer power of 2.
--- util/oslib-posix.c | 2 ++ util/oslib-win32.c | 1 + 2 files changed, 3 insertions(+)
util/oslib-posix.c +2 -0
@@ -200,6 +200,8 @@ void *qemu_try_memalign(size_t alignment, size_t size)if (alignment <sizeof (void *)) { alignment =sizeof (void *); + }else { +g_assert (is_power_of_2 (alignment)); }#if defined(CONFIG_POSIX_MEMALIGN )
util/oslib-win32.c +1 -0
@@ -58,6 +58,7 @@ void *qemu_try_memalign(size_t alignment, size_t size)void *ptr;g_assert (size !=0 ); +g_assert (is_power_of_2 (alignment)); ptr =_aligned_malloc (alignment, size);trace_qemu_memalign (alignment, size, ptr);return ptr;
Signature · 1 line
2.26.2
Quoted 9 lines · Philippe Mathieu-Daudé
- Use
_aligned_mallocforqemu_try_memalignon win32
- Assertqemu_try_memalign()alignment is a power of 2Since v4:
- Drop superfluous assert (Richard)Philippe Mathieu-Daudé (1):
util/oslib: Assertqemu_try_memalign()alignment is a power of 2
Quoted 7 lines
Richard Henderson (1):
util/oslib-win32: Use_aligned_mallocforqemu_try_memalignutil/oslib-posix.c | 2 ++ util/oslib-win32.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
Ping.
r~
Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé
- Use
_aligned_mallocforqemu_try_memalignon win32
- Assertqemu_try_memalign()alignment is a power of 2Since v4:
- Drop superfluous assert (Richard)Philippe Mathieu-Daudé (1):
util/oslib: Assertqemu_try_memalign()alignment is a power of 2Richard Henderson (1):
util/oslib-win32: Use_aligned_mallocforqemu_try_memalign
Quoted 6 lines
Quoted 4 lines
util/oslib-posix.c | 2 ++ util/oslib-win32.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)Ping.
Ping2. Shall I just queue this to tcg-next?
r~
Quoted 14 lines · Richard Henderson
Quoted 13 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé
- Use
_aligned_mallocforqemu_try_memalignon win32
- Assertqemu_try_memalign()alignment is a power of 2Since v4:
- Drop superfluous assert (Richard)Philippe Mathieu-Daudé (1):
util/oslib: Assertqemu_try_memalign()alignment is a power of 2Richard Henderson (1):
util/oslib-win32: Use_aligned_mallocforqemu_try_memalign
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
util/oslib-posix.c | 2 ++ util/oslib-win32.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-)Ping.
Ping2. Shall I just queue this to tcg-next?
Yes, just go ahead. util/ is everybody's land, maintainers are supposed to know what they're doing. :)
Paolo