mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
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>
This commit is contained in:
parent
143e6db6fa
commit
eb5937bad6
21 changed files with 124 additions and 212 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue