Skip to contentSkip to conversation

libqos: Convert malloc-pc allocator to a generic allocator

PATCH Applied Marc Marí 3 participants 3 messages Oct 23, 2014 – Jan 6, 2015

lore
Share & tools
lore

Marc Marí

author
#0 lore raw

PATCH v2 1/1 libqos: Convert malloc-pc allocator to a generic allocator

The allocator in malloc-pc has been extracted, so it can be used in every arch. This operation showed that both the alloc and free functions can be also generic.
Because of this, the QGuestAllocator has been removed from is function to wrap the alloc and free function, and now just contains the allocator parameters. As a result, only the allocator initalizer and unitializer are arch dependent.

---
 tests/Makefile           |    2 +-
 tests/libqos/malloc-pc.c |  280 +---------------------------------------------
 tests/libqos/malloc-pc.h |   11 +-
 tests/libqos/malloc.c    |  270 ++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/malloc.h    |   45 +++++---
 5 files changed, 309 insertions(+), 299 deletions(-)
 create mode 100644 tests/libqos/malloc.c
tests/Makefile +1 -1
index 834279c..15bc670 100644
@@ -296,7 +296,7 @@ tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) l
 tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
 tests/test-bitops$(EXESUF): tests/test-bitops.o libqemuutil.a
 
-libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o
+libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o
 libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
 libqos-pc-obj-y += tests/libqos/malloc-pc.o
tests/libqos/malloc-pc.c +6 -274

312 lines not on this page · raw message

tests/libqos/malloc-pc.h +2 -9
index 9f525e3..86ab9f0 100644
@@ -15,15 +15,8 @@
 
 #include "libqos/malloc.h"
 
-typedef enum {
-    PC_ALLOC_NO_FLAGS    = 0x00,
-    PC_ALLOC_LEAK_WARN   = 0x01,
-    PC_ALLOC_LEAK_ASSERT = 0x02,
-    PC_ALLOC_PARANOID    = 0x04
-} PCAllocOpts;
-
 QGuestAllocator *pc_alloc_init(void);
-QGuestAllocator *pc_alloc_init_flags(PCAllocOpts flags);
-void             pc_alloc_uninit(QGuestAllocator *allocator);
+QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags);
+void pc_alloc_uninit(QGuestAllocator *allocator);
 
 #endif
tests/libqos/malloc.c new file +270 -0

270 lines not on this page · raw message

tests/libqos/malloc.h +30 -15

54 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Marc Marí

The allocator in malloc-pc has been extracted, so it can be used in every arch. This operation showed that both the alloc and free functions can be also generic.
Because of this, the QGuestAllocator has been removed from is function to wrap the alloc and free function, and now just contains the allocator parameters. As a result, only the allocator initalizer and unitializer are arch dependent.

Quoted 9 lines
---
  tests/Makefile           |    2 +-
  tests/libqos/malloc-pc.c |  280 +---------------------------------------------
  tests/libqos/malloc-pc.h |   11 +-
  tests/libqos/malloc.c    |  270 ++++++++++++++++++++++++++++++++++++++++++++
  tests/libqos/malloc.h    |   45 +++++---
  5 files changed, 309 insertions(+), 299 deletions(-)

create mode 100644 tests/libqos/malloc.c

[snip]

I previously acknowledged V1 mistakenly instead of V2 here, and have seen no activity since -- so here's another Reviewed-by in case someone has a script waiting for this explicit reply.

I'll also add that I pulled the patch into my testing tree and ran it through Valgrind and my AHCI test suite and it behaves perfectly well.

#2 lore raw
In reply to Marc Marí
Quoted 9 lines · Marc Marí

The allocator in malloc-pc has been extracted, so it can be used in every arch. This operation showed that both the alloc and free functions can be also generic.
Because of this, the QGuestAllocator has been removed from is function to wrap the alloc and free function, and now just contains the allocator parameters. As a result, only the allocator initalizer and unitializer are arch dependent.

Quoted 8 lines
---
 tests/Makefile           |    2 +-
 tests/libqos/malloc-pc.c |  280 +---------------------------------------------
 tests/libqos/malloc-pc.h |   11 +-
 tests/libqos/malloc.c    |  270 ++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/malloc.h    |   45 +++++---
 5 files changed, 309 insertions(+), 299 deletions(-)
 create mode 100644 tests/libqos/malloc.c

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan