diff options
author | Alon Levy <alevy@redhat.com> | 2012-05-23 20:54:44 +0300 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2012-06-15 10:34:56 +0300 |
commit | 21c1d576925e561551b91b44b0d286f0bdc689c4 (patch) | |
tree | 4e70d809ba784e686963c38864fb2f126db041a3 /src | |
parent | a313b5ef1b5b6dda1e6c0ab47f458d692a5462f7 (diff) |
qxl_mem: add debug flags, simple accounting and valgrind enabled
adds preprocessor definitions DEBUG_QXL_MEM & DEBUG_QXL_MEM_VERBOSE
Diffstat (limited to 'src')
-rw-r--r-- | src/qxl.h | 6 | ||||
-rw-r--r-- | src/qxl_driver.c | 8 | ||||
-rw-r--r-- | src/qxl_mem.c | 55 |
3 files changed, 68 insertions, 1 deletions
@@ -416,6 +416,12 @@ void * qxl_allocnf (qxl_screen_t *qxl, unsigned long size); int qxl_garbage_collect (qxl_screen_t *qxl); +#ifdef DEBUG_QXL_MEM +void qxl_mem_unverifiable(struct qxl_mem *mem); +#else +static inline void qxl_mem_unverifiable(struct qxl_mem *mem) {} +#endif + /* * I/O port commands */ diff --git a/src/qxl_driver.c b/src/qxl_driver.c index ab44fa0..43d2693 100644 --- a/src/qxl_driver.c +++ b/src/qxl_driver.c @@ -558,6 +558,13 @@ qxl_reset (qxl_screen_t *qxl) #endif } +static void +qxl_mark_mem_unverifiable(qxl_screen_t *qxl) +{ + qxl_mem_unverifiable(qxl->mem); + qxl_mem_unverifiable(qxl->surf_mem); +} + static Bool qxl_close_screen(CLOSE_SCREEN_ARGS_DECL) { @@ -582,6 +589,7 @@ qxl_close_screen(CLOSE_SCREEN_ARGS_DECL) if (pScrn->vtSema) { qxl_restore_state(pScrn); + qxl_mark_mem_unverifiable(qxl); qxl_unmap_memory(qxl); } pScrn->vtSema = FALSE; diff --git a/src/qxl_mem.c b/src/qxl_mem.c index 6e57a94..3d9acfd 100644 --- a/src/qxl_mem.c +++ b/src/qxl_mem.c @@ -27,13 +27,30 @@ #include "qxl.h" #include "mspace.h" +#ifdef DEBUG_QXL_MEM +#include <valgrind/memcheck.h> +#endif + struct qxl_mem { mspace space; void * base; unsigned long n_bytes; +#ifdef DEBUG_QXL_MEM + size_t used_initial; + int unverifiable; + int missing; +#endif }; +#ifdef DEBUG_QXL_MEM +void +qxl_mem_unverifiable(struct qxl_mem *mem) +{ + mem->unverifiable = 1; +} +#endif + struct qxl_mem * qxl_mem_create (void *base, unsigned long n_bytes) @@ -51,6 +68,17 @@ qxl_mem_create (void *base, mem->base = base; mem->n_bytes = n_bytes; +#ifdef DEBUG_QXL_MEM + { + size_t used; + + mspace_malloc_stats_return(mem->space, NULL, NULL, &used); + mem->used_initial = used; + mem->unverifiable = 0; + mem->missing = 0; + } +#endif + out: return mem; @@ -69,7 +97,15 @@ void * qxl_alloc (struct qxl_mem *mem, unsigned long n_bytes) { - return mspace_malloc (mem->space, n_bytes); + void *addr = mspace_malloc (mem->space, n_bytes); + +#ifdef DEBUG_QXL_MEM + VALGRIND_MALLOCLIKE_BLOCK(addr, n_bytes, 0, 0); +#ifdef DEBUG_QXL_MEM_VERBOSE + fprintf(stderr, "alloc %p: %ld\n", addr, n_bytes); +#endif +#endif + return addr; } void @@ -77,11 +113,28 @@ qxl_free (struct qxl_mem *mem, void *d) { mspace_free (mem->space, d); +#ifdef DEBUG_QXL_MEM +#ifdef DEBUG_QXL_MEM_VERBOSE + fprintf(stderr, "free %p\n", d); +#endif + VALGRIND_FREELIKE_BLOCK(d, 0); +#endif } void qxl_mem_free_all (struct qxl_mem *mem) { +#ifdef DEBUG_QXL_MEM + size_t maxfp, fp, used; + + if (mem->space) + { + mspace_malloc_stats_return(mem->space, &maxfp, &fp, &used); + mem->missing = used - mem->used_initial; + ErrorF ("untracked %zd bytes (%s)", used - mem->used_initial, + mem->unverifiable ? "marked unverifiable" : "oops"); + } +#endif mem->space = create_mspace_with_base (mem->base, mem->n_bytes, 0, NULL); } |