From 333d8562f04eea0676139a10cb80a97f107b45b0 Mon Sep 17 00:00:00 2001 From: "Field G. Van Zee" Date: Sun, 11 Nov 2018 14:28:53 -0600 Subject: [PATCH] Added debug output to bli_malloc.c. Details: - Added debug output to bli_malloc.c in order to debug certain kinds of memory behavior in BLIS. The printf() statements are disabled and must be enabled manually. - Whitespace/comment updates in bli_membrk.c. --- frame/base/bli_malloc.c | 31 +++++++++++++++++++++++++++++++ frame/base/bli_membrk.c | 8 ++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/frame/base/bli_malloc.c b/frame/base/bli_malloc.c index 03c87241f..f983e777e 100644 --- a/frame/base/bli_malloc.c +++ b/frame/base/bli_malloc.c @@ -34,6 +34,8 @@ #include "blis.h" +//#define ENABLE_DEBUG + // ----------------------------------------------------------------------------- void* bli_malloc_pool( size_t size ) @@ -41,11 +43,19 @@ void* bli_malloc_pool( size_t size ) const malloc_ft malloc_fp = BLIS_MALLOC_POOL; const size_t align_size = BLIS_POOL_ADDR_ALIGN_SIZE; +#ifdef ENABLE_DEBUG + printf( "bli_malloc_pool(): allocating block (size %ld, align size %ld)\n", + ( long )size, ( long )align_size ); +#endif + return bli_malloc_align( malloc_fp, size, align_size ); } void bli_free_pool( void* p ) { +#ifdef ENABLE_DEBUG + printf( "bli_free_pool(): freeing block\n" ); +#endif bli_free_align( BLIS_FREE_POOL, p ); } @@ -56,11 +66,19 @@ void* bli_malloc_user( size_t size ) const malloc_ft malloc_fp = BLIS_MALLOC_USER; const size_t align_size = BLIS_HEAP_ADDR_ALIGN_SIZE; +#ifdef ENABLE_DEBUG + printf( "bli_malloc_user(): allocating block (size %ld, align size %ld)\n", + ( long )size, ( long )align_size ); +#endif + return bli_malloc_align( malloc_fp, size, align_size ); } void bli_free_user( void* p ) { +#ifdef ENABLE_DEBUG + printf( "bli_free_user(): freeing block\n" ); +#endif bli_free_align( BLIS_FREE_USER, p ); } @@ -70,11 +88,21 @@ void* bli_malloc_intl( size_t size ) { const malloc_ft malloc_fp = BLIS_MALLOC_INTL; +#ifdef ENABLE_DEBUG + printf( "bli_malloc_intl(): allocating block (size %ld)\n", + ( long )size ); +#endif + return bli_malloc_noalign( malloc_fp, size ); } void* bli_calloc_intl( size_t size ) { +#ifdef ENABLE_DEBUG + printf( "bli_calloc_intl(): allocating block (size %ld)\n", + ( long )size ); +#endif + void* p = bli_malloc_intl( size ); memset( p, 0, size ); @@ -84,6 +112,9 @@ void* bli_calloc_intl( size_t size ) void bli_free_intl( void* p ) { +#ifdef ENABLE_DEBUG + printf( "bli_free_intl(): freeing block\n" ); +#endif bli_free_noalign( BLIS_FREE_INTL, p ); } diff --git a/frame/base/bli_membrk.c b/frame/base/bli_membrk.c index 5f450b5ff..1de5a6259 100644 --- a/frame/base/bli_membrk.c +++ b/frame/base/bli_membrk.c @@ -209,8 +209,10 @@ void bli_membrk_release // section.) block_size_prev = bli_mem_size( mem ); - // BEGIN CRITICAL SECTION + // Acquire the mutex associated with the membrk object. bli_membrk_lock( membrk ); + + // BEGIN CRITICAL SECTION { // Query the size of the blocks currently in the pool. @@ -235,8 +237,10 @@ void bli_membrk_release } } - bli_membrk_unlock( membrk ); // END CRITICAL SECTION + + // Release the mutex associated with the membrk object. + bli_membrk_unlock( membrk ); } // Clear the mem_t object so that it appears unallocated. This clears: