[ECOS] New memory allocation debug feature
Øyvind Harboe
oyvind.harboe@zylin.com
Thu Jun 17 10:55:00 GMT 2004
Comments?
--
Ãyvind Harboe
http://www.zylin.com
-------------- next part --------------
? memdebug.txt
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/ChangeLog,v
retrieving revision 1.30
diff -w -u -r1.30 ChangeLog
--- ChangeLog 15 Mar 2004 15:42:04 -0000 1.30
+++ ChangeLog 17 Jun 2004 10:43:22 -0000
@@ -1,3 +1,8 @@
+2004-06-17 Oyvind Harboe <oyvind.harboe@zylin.com>
+
+ * Added _OutOfMemory() fn which is invoked before return NULL
+ from failed allocations. Useful breakpoint site.
+
2004-02-15 Jonathan Larmour <jifl@eCosCentric.com>
* include/kapi.h: Add throw specifications throughout.
Index: cdl/memalloc.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/cdl/memalloc.cdl,v
retrieving revision 1.12
diff -w -u -r1.12 memalloc.cdl
--- cdl/memalloc.cdl 6 Oct 2003 16:41:07 -0000 1.12
+++ cdl/memalloc.cdl 17 Jun 2004 10:43:22 -0000
@@ -239,6 +239,14 @@
forces a NULL pointer to be returned."
}
+ cdl_option CYGSEM_MEMALLOC_INVOKE_OUTOFMEMORY {
+ display "invoke user supplied _OutOfMemory() function when running out of memory"
+ default_value 0
+ description "
+ Whenever the system runs out of memory, it invokes this function before either
+ going to sleep(waiting for memory to become available) or returning failure."
+ }
+
cdl_component CYGPKG_MEMALLOC_MALLOC_ALLOCATORS {
display "malloc() and supporting allocators"
flavor bool
Index: include/common.hxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/common.hxx,v
retrieving revision 1.3
diff -w -u -r1.3 common.hxx
--- include/common.hxx 23 May 2002 23:08:43 -0000 1.3
+++ include/common.hxx 17 Jun 2004 10:43:22 -0000
@@ -131,5 +131,15 @@
typedef cyg_uint16 cyg_mempool_status_flag_t;
+#if CYGSEM_MEMALLOC_INVOKE_OUTOFMEMORY
+// breakpoint site for out of memory conditions
+extern "C" void _OutOfMemory();
+#else
+// this will compile away to nothing with optimisations turned on.
+inline void _OutOfMemory()
+{
+}
+#endif
+
#endif /* ifndef CYGONCE_MEMALLOC_COMMON_HXX */
/* EOF common.hxx */
Index: include/memjoin.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/memjoin.inl,v
retrieving revision 1.6
diff -w -u -r1.6 memjoin.inl
--- include/memjoin.inl 5 Feb 2003 01:10:12 -0000 1.6
+++ include/memjoin.inl 17 Jun 2004 10:43:22 -0000
@@ -178,6 +178,11 @@
}
CYG_REPORT_RETVAL( ptr );
+
+ if (ptr==NULL)
+ {
+ _OutOfMemory();
+ }
return ptr;
} // Cyg_Mempool_Joined<T>::try_alloc()
@@ -214,6 +219,7 @@
ret = pool->resize_alloc( alloc_ptr, newsize, oldsize );
CYG_REPORT_RETVAL( ret );
+
return ret;
} // Cyg_Mempool_Joined<T>::resize_alloc()
Index: include/mempolt2.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mempolt2.inl,v
retrieving revision 1.3
diff -w -u -r1.3 mempolt2.inl
--- include/mempolt2.inl 23 May 2002 23:08:43 -0000 1.3
+++ include/mempolt2.inl 17 Jun 2004 10:43:23 -0000
@@ -116,6 +116,8 @@
Mempolt2WaitInfo waitinfo( size );
+ _OutOfMemory();
+
self->set_wait_info( (CYG_ADDRWORD)&waitinfo );
self->set_sleep_reason( Cyg_Thread::WAIT );
self->sleep();
@@ -187,6 +189,9 @@
// straight to unlock.
if( Cyg_Thread::NONE == self->get_wake_reason() ) {
+
+ _OutOfMemory();
+
self->set_wait_info( (CYG_ADDRWORD)&waitinfo );
self->sleep();
queue.enqueue( self );
@@ -251,6 +256,12 @@
// Unlock the scheduler and maybe switch threads
Cyg_Scheduler::unlock();
+
+ if (ret==NULL)
+ {
+ _OutOfMemory();
+ }
+
return ret;
}
@@ -283,6 +294,12 @@
// Unlock the scheduler and maybe switch threads
Cyg_Scheduler::unlock();
+
+ if (ret==NULL)
+ {
+ _OutOfMemory();
+ }
+
return ret;
}
Index: include/mempoolt.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mempoolt.inl,v
retrieving revision 1.3
diff -w -u -r1.3 mempoolt.inl
--- include/mempoolt.inl 23 May 2002 23:08:43 -0000 1.3
+++ include/mempoolt.inl 17 Jun 2004 10:43:23 -0000
@@ -111,6 +111,9 @@
cyg_uint8 *ret;
cyg_bool result = true;
while( result && (NULL == (ret = pool.alloc( size ))) ) {
+
+ _OutOfMemory();
+
self->set_sleep_reason( Cyg_Thread::WAIT );
self->sleep();
queue.enqueue( self );
@@ -182,6 +185,8 @@
result = false;
while( result && (NULL == (ret = pool.alloc( size ))) ) {
+ _OutOfMemory();
+
self->set_sleep_reason( Cyg_Thread::TIMEOUT );
self->sleep();
queue.enqueue( self );
@@ -248,6 +253,11 @@
// Unlock the scheduler and maybe switch threads
Cyg_Scheduler::unlock();
CYG_REPORT_RETVAL( ret );
+
+ if (ret==NULL)
+ {
+ _OutOfMemory();
+ }
return ret;
}
Index: include/mfiximpl.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mfiximpl.inl,v
retrieving revision 1.3
diff -w -u -r1.3 mfiximpl.inl
--- include/mfiximpl.inl 23 May 2002 23:08:44 -0000 1.3
+++ include/mfiximpl.inl 17 Jun 2004 10:43:23 -0000
@@ -123,7 +123,10 @@
// size parameter is not used
CYG_UNUSED_PARAM( cyg_int32, size );
if ( 0 >= freeblocks )
+ {
+ _OutOfMemory();
return NULL;
+ }
cyg_int32 i = firstfree;
cyg_uint8 *p = NULL;
do {
@@ -173,7 +176,10 @@
if (newsize == blocksize)
return alloc_ptr;
else
+ {
+ _OutOfMemory();
return NULL;
+ }
} // resize_alloc()
Index: include/mvarimpl.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mvarimpl.inl,v
retrieving revision 1.5
diff -w -u -r1.5 mvarimpl.inl
--- include/mvarimpl.inl 23 May 2002 23:08:44 -0000 1.5
+++ include/mvarimpl.inl 17 Jun 2004 10:43:23 -0000
@@ -275,6 +275,10 @@
cyg_uint8 *ptr = memdq2alloc( dq );
CYG_ASSERT( ((CYG_ADDRESS)ptr & (alignment-1)) == 0,
"returned memory not aligned" );
+ if (ptr==NULL)
+ {
+ _OutOfMemory();
+ }
return ptr;
}
@@ -358,6 +362,10 @@
ret = alloc_ptr;
}
+ if (ret==NULL)
+ {
+ _OutOfMemory();
+ }
return ret;
} // resize_alloc()
Index: include/sepmetaimpl.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/sepmetaimpl.inl,v
retrieving revision 1.4
diff -w -u -r1.4 sepmetaimpl.inl
--- include/sepmetaimpl.inl 23 May 2002 23:08:44 -0000 1.4
+++ include/sepmetaimpl.inl 17 Jun 2004 10:43:24 -0000
@@ -375,7 +375,10 @@
struct memdq *dq = find_free_dq( size );
if (NULL == dq)
+ {
+ _OutOfMemory();
return NULL;
+ }
cyg_int32 dqsize = dq->memnext->mem - dq->mem;
@@ -400,7 +403,10 @@
// first get a memdq
if ( NULL == freemetahead ) // out of metadata.
+ {
+ _OutOfMemory();
return NULL;
+ }
// FIXME: since we don't search all the way for an exact fit
// first we may be able to find an exact fit later and therefore
@@ -496,7 +502,10 @@
prevmemsize = dq->mem - dq->memprev->mem;
}
if (nextmemsize + prevmemsize + currsize < newsize)
+ {
+ _OutOfMemory();
return NULL; // can't fit it
+ }
// expand forwards
if ( nextmemsize != 0 ) {
@@ -561,7 +570,10 @@
// if its already allocated we need to create a new free list
// entry
if (NULL == freemetahead)
+ {
+ _OutOfMemory();
return NULL; // can't do it
+ }
struct memdq *fdq = freemetahead;
freemetahead = fdq->next;
Index: src/dlmalloc.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/src/dlmalloc.cxx,v
retrieving revision 1.8
diff -w -u -r1.8 dlmalloc.cxx
--- src/dlmalloc.cxx 6 Oct 2003 18:25:57 -0000 1.8
+++ src/dlmalloc.cxx 17 Jun 2004 10:43:25 -0000
@@ -217,6 +217,8 @@
#include <cyg/memalloc/dlmalloc.hxx>
//#include <cyg/infra/diag.h>
+
+
/*
Debugging:
@@ -1273,6 +1275,7 @@
//diag_printf("chunksize(top)=%ld, nb=%d, remainder=%ld\n", chunksize(top),
// nb, remainder_size);
MALLOC_UNLOCK;
+ _OutOfMemory();
return NULL; /* propagate failure */
}
@@ -1558,6 +1561,7 @@
// couldn't resize the allocation any direction, so return failure
MALLOC_UNLOCK;
+ _OutOfMemory();
return NULL;
}
-------------- next part --------------
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list