diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2018-11-29 12:37:04 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-03-07 17:28:07 +0100 |
commit | eb5937bad691ed18a401079a0604aa11fea0ecdd (patch) | |
tree | a26310ca140c15230c51cceeebc538f7f55b7888 /tests/libqos/malloc.c | |
parent | 143e6db6fa4ecd2a85de740cc3754aeb86d1e802 (diff) |
tests/libqos: embed allocators instead of malloc-ing them separately
qgraph will embed these objects instead of allocating them in a separate
object. Expose a new API "generic_alloc_init" and "generic_alloc_destroy"
for that, and rename the existing API with s/init/new/ and s/uninit/free/.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/libqos/malloc.c')
-rw-r--r-- | tests/libqos/malloc.c | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c index f7bae47a08..615422a5c4 100644 --- a/tests/libqos/malloc.c +++ b/tests/libqos/malloc.c @@ -15,24 +15,12 @@ #include "qemu-common.h" #include "qemu/host-utils.h" -typedef QTAILQ_HEAD(MemList, MemBlock) MemList; - typedef struct MemBlock { QTAILQ_ENTRY(MemBlock) MLIST_ENTNAME; uint64_t size; uint64_t addr; } MemBlock; -struct QGuestAllocator { - QAllocOpts opts; - uint64_t start; - uint64_t end; - uint32_t page_size; - - MemList *used; - MemList *free; -}; - #define DEFAULT_PAGE_SIZE 4096 static void mlist_delete(MemList *list, MemBlock *node) @@ -225,7 +213,7 @@ static void mlist_free(QGuestAllocator *s, uint64_t addr) * Mostly for valgrind happiness, but it does offer * a chokepoint for debugging guest memory leaks, too. */ -void alloc_uninit(QGuestAllocator *allocator) +void alloc_destroy(QGuestAllocator *allocator) { MemBlock *node; MemBlock *tmp; @@ -261,7 +249,6 @@ void alloc_uninit(QGuestAllocator *allocator) g_free(allocator->used); g_free(allocator->free); - g_free(allocator); } uint64_t guest_alloc(QGuestAllocator *allocator, size_t size) @@ -297,11 +284,13 @@ void guest_free(QGuestAllocator *allocator, uint64_t addr) } } -QGuestAllocator *alloc_init(uint64_t start, uint64_t end) +void alloc_init(QGuestAllocator *s, QAllocOpts opts, + uint64_t start, uint64_t end, + size_t page_size) { - QGuestAllocator *s = g_malloc0(sizeof(*s)); MemBlock *node; + s->opts = opts; s->start = start; s->end = end; @@ -313,26 +302,7 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end) node = mlist_new(s->start, s->end - s->start); QTAILQ_INSERT_HEAD(s->free, node, MLIST_ENTNAME); - s->page_size = DEFAULT_PAGE_SIZE; - - return s; -} - -QGuestAllocator *alloc_init_flags(QAllocOpts opts, - uint64_t start, uint64_t end) -{ - QGuestAllocator *s = alloc_init(start, end); - s->opts = opts; - return s; -} - -void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size) -{ - /* Can't alter the page_size for an allocator in-use */ - g_assert(QTAILQ_EMPTY(allocator->used)); - - g_assert(is_power_of_2(page_size)); - allocator->page_size = page_size; + s->page_size = page_size; } void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts) |