1
1

* remove bool from internal interface, since we might not want to include

ompi_config.h in some of the intercept mechanisms.
* Intercept munmap when called directly by the user when we are using
  ptmalloc2 (previously we only covered when the user called free()).
* Don't go through the locking and list traversal logic trying to fire
  callbacks until there is actually a callback to fire.  This is both
  a performance boost and a way to cope with the hook callback being
  triggered before opal_init.

This commit was SVN r6818.
Этот коммит содержится в:
Brian Barrett 2005-08-12 13:35:01 +00:00
родитель c9f5e591b1
Коммит c8865bd5c1
4 изменённых файлов: 33 добавлений и 7 удалений

Просмотреть файл

@ -41,8 +41,8 @@ static OBJ_CLASS_INSTANCE(callback_list_item_t, opal_list_item_t, NULL, NULL);
*/
static opal_list_t callback_list;
static opal_atomic_lock_t callback_lock;
static bool have_free_support = false;
static bool run_callbacks = false;
static int have_free_support = false;
static int run_callbacks = false;
int
@ -51,7 +51,9 @@ opal_mem_free_init(void)
OBJ_CONSTRUCT(&callback_list, opal_list_t);
opal_atomic_init(&callback_lock, OPAL_ATOMIC_UNLOCKED);
run_callbacks = true;
/* delay running callbacks until there is something in the
registration */
run_callbacks = false;
opal_atomic_mb();
return OMPI_SUCCESS;
@ -84,7 +86,7 @@ opal_mem_free_finalize(void)
/* called from memory manager / memory-manager specific hooks */
void
opal_mem_free_set_free_support(bool support)
opal_mem_free_set_free_support(int support)
{
printf("someone set mem_free support to %d\n", (int) support);
have_free_support = support;
@ -116,7 +118,7 @@ opal_mem_free_release_hook(void *buf, size_t length)
bool
opal_mem_free_is_supported(void)
{
return have_free_support;
return (bool) have_free_support;
}
@ -129,6 +131,12 @@ opal_mem_free_register_handler(opal_mem_free_unpin_fn_t *func, void *cbdata)
if (!have_free_support) return OMPI_ERR_NOT_SUPPORTED;
/* we either have or are about to have a registration that needs
calling back. Let the system know it needs to run callbacks
now */
run_callbacks = true;
opal_atomic_mb();
opal_atomic_lock(&callback_lock);
/* make sure the callback isn't already in the list */

Просмотреть файл

@ -17,7 +17,7 @@
#ifndef OPAL_MEMORY_MEMORY_INTERNAL_H
#define OPAL_MEMORY_MEMORY_INTERNAL_H
void opal_mem_free_set_free_support(bool support);
void opal_mem_free_set_free_support(int support);
void opal_mem_free_release_hook(void *buf, size_t length);
#endif /* OPAL_MEMORY_MEMORY_INTERNAL_H */

Просмотреть файл

@ -468,7 +468,7 @@ ptmalloc_init __MALLOC_P((void))
/********************** BEGIN OMPI CHANGES *****************************/
/* don't use __hook for this, as someone might want to use those
features */
opal_mem_free_set_free_support(true);
opal_mem_free_set_free_support(1);
/********************* BEGIN OMPI CHANGES ******************************/
__malloc_initialized = 1;

Просмотреть файл

@ -51,6 +51,24 @@ opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
#define __const const
#endif
/* need to intercept munmap from the user as well as the usual
malloc. munmap is a weak symbol on any platform that I know of that
supports malloc hooks, so we can just intercept it like this... */
int
munmap(void* addr, size_t len) {
{
static int (*realmunmap)(void*, size_t);
/* dispatch about the pending release */
opal_mem_free_release_hook(addr, len);
if (NULL == realmunmap) {
realmunmap = dlsym(RTLD_NEXT, "munmap");
}
return realmunmap(addr, len);
}
/********************* BEGIN OMPI CHANGES ******************************/