- Convert existing lam_err (and friends) code to use lam_output()
- Note in several places that we need to implement lam_exit() This commit was SVN r361.
Этот коммит содержится в:
родитель
1140112b9b
Коммит
b1e1a7ea37
@ -4,7 +4,7 @@
|
||||
|
||||
#include "lam_config.h"
|
||||
#include "lam/mem/free_lists.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
#include "lam/util/output.h"
|
||||
#include "lam/os/numa.h"
|
||||
#include "lam/os/lam_system.h"
|
||||
#include "lam/mem/mem_globals.h"
|
||||
@ -179,7 +179,12 @@ int lam_free_lists_init_with(
|
||||
flist->fl_nlists);
|
||||
if ( !flist->fl_free_lists )
|
||||
{
|
||||
lam_exit((-1, "Error: Out of memory\n"));
|
||||
lam_output(0, "Error: Out of memory");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* run constructors */
|
||||
@ -200,8 +205,14 @@ int lam_free_lists_init_with(
|
||||
(lam_seg_list_t *)malloc(sizeof(lam_seg_list_t));
|
||||
}
|
||||
|
||||
if (!flist->fl_free_lists[list])
|
||||
lam_exit((-1, "Error: Out of memory\n"));
|
||||
if (!flist->fl_free_lists[list]) {
|
||||
lam_output(0, "Error: Out of memory");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC_INIT(flist->fl_free_lists[list], &lam_seg_list_cls);
|
||||
|
||||
@ -219,8 +230,14 @@ int lam_free_lists_init_with(
|
||||
{
|
||||
flist->fl_affinity = (affinity_t *)malloc(sizeof(affinity_t) *
|
||||
flist->fl_nlists);
|
||||
if ( !flist->fl_affinity )
|
||||
lam_exit((-1, "Error: Out of memory\n"));
|
||||
if ( !flist->fl_affinity ) {
|
||||
lam_output(0, "Error: Out of memory");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* copy policies in */
|
||||
for ( pool = 0; pool < flist->fl_nlists; pool++ )
|
||||
@ -241,8 +258,13 @@ int lam_free_lists_init_with(
|
||||
{
|
||||
if (lam_free_lists_create_more_elts(flist, pool) != LAM_SUCCESS)
|
||||
{
|
||||
lam_exit((-1, "Error: Setting up initial private "
|
||||
"free list for %s.\n", flist->fl_description));
|
||||
lam_output(0, "Error: Setting up initial private "
|
||||
"free list for %s.\n", flist->fl_description);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,8 +273,13 @@ int lam_free_lists_init_with(
|
||||
else
|
||||
{
|
||||
/* only 1 process should be initializing the list */
|
||||
lam_exit((-1, "Error: Setting up initial private free "
|
||||
"list %d for %s.\n", pool, flist->fl_description));
|
||||
lam_output(0, "Error: Setting up initial private free "
|
||||
"list %d for %s.\n", pool, flist->fl_description);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,8 +353,8 @@ static void *lam_free_lists_get_mem_chunk(lam_free_lists_t *flist, int index, si
|
||||
|
||||
if (index >= flist->fl_nlists)
|
||||
{
|
||||
lam_err(("Error: Array out of bounds\n"));
|
||||
return chunk;
|
||||
lam_output(0, "Error: Array out of bounds");
|
||||
return chunk;
|
||||
}
|
||||
|
||||
if ( lam_sgl_get_max_bytes_pushed(flist->fl_free_lists[index]) != -1 )
|
||||
@ -341,8 +368,8 @@ static void *lam_free_lists_get_mem_chunk(lam_free_lists_t *flist, int index, si
|
||||
lam_sgl_get_max_consec_fail(flist->fl_free_lists[index]) )
|
||||
{
|
||||
*err = LAM_ERR_OUT_OF_RESOURCE;
|
||||
lam_err(("Error: List out of memory in pool for %s\n",
|
||||
flist->fl_description));
|
||||
lam_output(0, "Error: List out of memory in pool for %s",
|
||||
flist->fl_description);
|
||||
return chunk;
|
||||
} else
|
||||
*err = LAM_ERR_TEMP_OUT_OF_RESOURCE;
|
||||
@ -364,8 +391,8 @@ static void *lam_free_lists_get_mem_chunk(lam_free_lists_t *flist, int index, si
|
||||
lam_sgl_get_max_consec_fail(flist->fl_free_lists[index]) )
|
||||
{
|
||||
*err = LAM_ERR_OUT_OF_RESOURCE;
|
||||
lam_err(("Error: List out of memory in pool for %s\n",
|
||||
flist->fl_description));
|
||||
lam_output(0, "Error: List out of memory in pool for %s\n",
|
||||
flist->fl_description);
|
||||
return chunk;
|
||||
} else
|
||||
*err = LAM_ERR_TEMP_OUT_OF_RESOURCE;
|
||||
@ -422,8 +449,8 @@ static int lam_free_lists_create_more_elts(lam_free_lists_t *flist, int pool_idx
|
||||
void *ptr = lam_free_lists_get_mem_chunk(flist, pool_idx, &len_added, &err);
|
||||
|
||||
if (0 == ptr ) {
|
||||
lam_err(("Error: Can't get new elements for %s\n",
|
||||
flist->fl_description));
|
||||
lam_output(0, "Error: Can't get new elements for %s\n",
|
||||
flist->fl_description);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "lam/constants.h"
|
||||
#include "lam/mem/mem_pool.h"
|
||||
#include "lam/mem/sharedmem_util.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
#include "lam/util/output.h"
|
||||
#include "lam/util/malloc.h"
|
||||
#include "lam/os/numa.h"
|
||||
|
||||
@ -87,14 +87,14 @@ int lam_mp_init_with(lam_mem_pool_t *pool, uint64_t pool_size,
|
||||
|
||||
/* round up pool size to multiple of page size */
|
||||
pool_size = ((((pool_size - 1) / chunk_size) + 1) * chunk_size);
|
||||
if (pool_size == 0) {
|
||||
lam_err(("Error: pool_size == 0\n"));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
if (0 == pool_size) {
|
||||
lam_output(0, "Error: pool_size == 0");
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
if (pool_size < chunk_size) {
|
||||
lam_err(("Error: pool_size < chunk_size\n"));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
lam_output(0, "Error: pool_size < chunk_size");
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
/* add red-zone pages */
|
||||
@ -123,22 +123,32 @@ int lam_mp_init_with(lam_mem_pool_t *pool, uint64_t pool_size,
|
||||
pool->mp_num_chunks = ((pool_size - 1) / chunk_size) + 1;
|
||||
if ((pool->mp_num_chunks > pool->mp_max_chunks) && (pool->mp_max_chunks > 0))
|
||||
{
|
||||
lam_err(("Error: NPoolChunks (%ld) > maxNPoolChunks (%ld)\n",
|
||||
pool->mp_num_chunks, pool->mp_max_chunks));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
lam_output(0, "Error: NPoolChunks (%ld) > maxNPoolChunks (%ld)",
|
||||
pool->mp_num_chunks, pool->mp_max_chunks);
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
/* change memory protection for red zones */
|
||||
retval = mprotect(ptr, page_size, PROT_NONE);
|
||||
if (retval != 0)
|
||||
{
|
||||
lam_exit((-1, "Error in red zone 1 mprotect\n"));
|
||||
lam_output(0, "Error in red zone 1 mprotect");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
/* end red zone */
|
||||
retval =
|
||||
mprotect(ptr + page_size + wrk_size, page_size, PROT_NONE);
|
||||
if (retval != 0)
|
||||
{
|
||||
lam_exit((-1, "Error in red zone 2 mprotect\n"));
|
||||
lam_output(0, "Error in red zone 2 mprotect");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* initialize chunk descriptors */
|
||||
@ -146,8 +156,8 @@ int lam_mp_init_with(lam_mem_pool_t *pool, uint64_t pool_size,
|
||||
pool->mp_chunks = lam_alc_alloc(pool->mp_private_alloc, to_alloc);
|
||||
if ( !pool->mp_chunks )
|
||||
{
|
||||
lam_err(("Error: Out of memory\n"));
|
||||
return LAM_ERROR;
|
||||
lam_output(0, "Error: Out of memory");
|
||||
return LAM_ERROR;
|
||||
}
|
||||
|
||||
ptr = (char *) base;
|
||||
@ -196,7 +206,7 @@ void *lam_mp_request_chunk(lam_mem_pool_t *pool, int pool_index)
|
||||
chunk_desc = lam_alc_alloc(pool->mp_private_alloc, to_alloc);
|
||||
if ( !chunk_desc )
|
||||
{
|
||||
lam_err(("Error! Out of memory!\n"));
|
||||
lam_output(0, "Error! Out of memory!");
|
||||
lam_mutex_unlock(&(pool->mp_lock));
|
||||
return 0;
|
||||
}
|
||||
@ -218,9 +228,9 @@ void *lam_mp_request_chunk(lam_mem_pool_t *pool, int pool_index)
|
||||
lam_alc_alloc(pool->mp_dev_alloc, pool->mp_chunk_sz);
|
||||
if ( !pool->mp_chunks[pool->mp_num_chunks].chd_base_ptr )
|
||||
{
|
||||
lam_err(("Error: Out of memory\n"));
|
||||
lam_mutex_unlock(&(pool->mp_lock));
|
||||
return chunk;
|
||||
lam_output(0, "Error: Out of memory");
|
||||
lam_mutex_unlock(&(pool->mp_lock));
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/* reset pool chunk counter */
|
||||
@ -326,19 +336,27 @@ int lam_fmp_init_with(lam_fixed_mpool_t *pool, ssize_t initial_allocation,
|
||||
LAM_MALLOC(sizeof(lam_memseg_t *)*n_pools);
|
||||
if ( !pool->fmp_segments )
|
||||
{
|
||||
lam_exit((-1,
|
||||
"Unable to allocate memory for "
|
||||
"pool->fmp_segments, requested %ld bytes, errno %d\n",
|
||||
sizeof(int) * n_pools, errno));
|
||||
lam_output(0, "Unable to allocate memory for "
|
||||
"pool->fmp_segments, requested %ld bytes, errno %d",
|
||||
sizeof(int) * n_pools, errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
bzero(pool->fmp_segments, sizeof(lam_memseg_t *)*n_pools);
|
||||
|
||||
pool->fmp_n_segs_in_array = (int *) LAM_MALLOC(sizeof(int) * n_pools);
|
||||
if ( !pool->fmp_n_segs_in_array ) {
|
||||
lam_exit((-1,
|
||||
"Unable to allocate memory for "
|
||||
"pool->fmp_n_segs_in_array, requested %ld bytes, errno %d\n",
|
||||
sizeof(int) * n_pools, errno));
|
||||
lam_output(0, "Unable to allocate memory for "
|
||||
"pool->fmp_n_segs_in_array, requested %ld bytes, errno %d",
|
||||
sizeof(int) * n_pools, errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
bzero(pool->fmp_n_segs_in_array, sizeof(int) * n_pools);
|
||||
|
||||
@ -348,17 +366,26 @@ int lam_fmp_init_with(lam_fixed_mpool_t *pool, ssize_t initial_allocation,
|
||||
ptr = lam_zero_alloc(initial_allocation, MMAP_SHARED_PROT,
|
||||
MMAP_SHARED_FLAGS);
|
||||
if ( !ptr ) {
|
||||
lam_exit((-1,
|
||||
"Unable to allocate "
|
||||
"memory pool , requested %ld, errno %d\n",
|
||||
initial_allocation, errno));
|
||||
lam_output(0, "Unable to allocate "
|
||||
"memory pool , requested %ld, errno %d",
|
||||
initial_allocation, errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( apply_mem_affinity )
|
||||
{
|
||||
if (!lam_set_affinity(ptr, initial_allocation, pool_idx))
|
||||
{
|
||||
lam_exit((-1, "Error: setting memory affinity\n"));
|
||||
lam_output(0, "Error: setting memory affinity");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,9 +475,14 @@ void *lam_fmp_get_mem_segment(lam_fixed_mpool_t *pool,
|
||||
(pool->fmp_n_segments[which_pool] +
|
||||
pool->fmp_n_elts_to_add));
|
||||
if ( !tmp_seg ) {
|
||||
lam_exit((-1, "Unable to "
|
||||
"allocate memory for tmp_seg, errno %d\n",
|
||||
errno));
|
||||
lam_output(0, "Unable to "
|
||||
"allocate memory for tmp_seg, errno %d",
|
||||
errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
/* copy old version of pool->fmp_segments to tmp copy */
|
||||
for (seg_idx = 0; seg_idx < pool->fmp_n_segments[which_pool]; seg_idx++)
|
||||
@ -483,14 +515,24 @@ void *lam_fmp_get_mem_segment(lam_fixed_mpool_t *pool,
|
||||
lam_zero_alloc(len_to_alloc, MMAP_SHARED_PROT, MMAP_SHARED_FLAGS);
|
||||
if ( !tmp_ptr )
|
||||
{
|
||||
lam_exit((-1, "Unable to "
|
||||
"allocate memory pool\n"));
|
||||
lam_output(0, "Unable to allocate memory pool");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( pool->fmp_apply_affinity )
|
||||
{
|
||||
if ( !lam_set_affinity(tmp_ptr, len_to_alloc, which_pool) )
|
||||
lam_exit((-1, "Error: setting memory affinity\n"));
|
||||
if ( !lam_set_affinity(tmp_ptr, len_to_alloc, which_pool) ) {
|
||||
lam_output(0, "Error: setting memory affinity");
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* fill in pool->fmp_segments */
|
||||
|
@ -13,7 +13,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lam/mem/sharedmem_util.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
#include "lam/util/output.h"
|
||||
|
||||
|
||||
void *lam_zero_alloc(size_t len, int mem_prot, int mem_flags)
|
||||
{
|
||||
@ -37,7 +38,7 @@ void *lam_zero_alloc(size_t len, int mem_prot, int mem_flags)
|
||||
ptr = mmap(NULL, len, mem_prot, flags, fd, 0);
|
||||
if ( ptr == MAP_FAILED )
|
||||
{
|
||||
lam_err(("Error: mmap failed (%s)\n", strerror(errno)));
|
||||
lam_output(0, "Error: mmap failed (%s)", strerror(errno));
|
||||
close(fd);
|
||||
return (void *)0;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "lam_config.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
|
||||
/*
|
||||
* Set LAM_MALLOC_DEBUG_LEVEL to
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "lam_config.h"
|
||||
#include "lam/util/reactor.h"
|
||||
#include "lam/util/malloc.h"
|
||||
#include "lam/util/output.h"
|
||||
|
||||
|
||||
const int LAM_NOTIFY_RECV = 1;
|
||||
@ -54,9 +55,8 @@ static inline lam_reactor_descriptor_t* lam_reactor_get_descriptor(lam_reactor_t
|
||||
descriptor = (lam_reactor_descriptor_t*)LAM_MALLOC(sizeof(lam_reactor_descriptor_t));
|
||||
lam_reactor_descriptor_init(descriptor);
|
||||
}
|
||||
if(descriptor == 0) {
|
||||
lam_err(("lam_reactor_get_descriptor(): malloc(%d) failed.", sizeof(lam_reactor_descriptor_t)));
|
||||
return 0;
|
||||
if (NULL == descriptor) {
|
||||
return 0;
|
||||
}
|
||||
descriptor->rd = sd;
|
||||
descriptor->rd_flags = 0;
|
||||
@ -103,8 +103,8 @@ bool lam_reactor_insert(lam_reactor_t* r, int sd, lam_reactor_listener_t* listen
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(sd < 0 || sd > LAM_FD_SETSIZE) {
|
||||
lam_err(("Reactor::insertListener(%d) invalid descriptor.\n", sd));
|
||||
return false;
|
||||
lam_output(0, "lam_reactor_insert(%d) invalid descriptor", sd);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -143,17 +143,17 @@ bool lam_reactor_remove(lam_reactor_t* r, int sd, lam_reactor_listener_t* rl, in
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(sd < 0 || sd > LAM_FD_SETSIZE) {
|
||||
lam_err(("lam_reactor_remove(%d) invalid descriptor.\n", sd));
|
||||
return false;
|
||||
lam_output(0, "lam_reactor_remove(%d) invalid descriptor", sd);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
lam_mutex_lock(&r->r_mutex);
|
||||
lam_reactor_descriptor_t* descriptor = (lam_reactor_descriptor_t*)lam_fh_get_value_for_ikey(&r->r_hash, sd);
|
||||
if(descriptor == 0) {
|
||||
lam_err(("lam_reactor_remove(%d): descriptor not registered.\n", sd));
|
||||
lam_mutex_unlock(&r->r_mutex);
|
||||
return false;
|
||||
if (NULL == descriptor) {
|
||||
lam_output(0, "lam_reactor_remove(%d): descriptor not registered", sd);
|
||||
lam_mutex_unlock(&r->r_mutex);
|
||||
return false;
|
||||
}
|
||||
descriptor->rd_flags &= ~flags;
|
||||
if(flags & LAM_NOTIFY_RECV) {
|
||||
@ -261,10 +261,19 @@ void lam_reactor_poll(lam_reactor_t* r)
|
||||
int rc = select(r->r_max+1, (fd_set*)&rset, (fd_set*)&sset, (fd_set*)&eset, &tm);
|
||||
if(rc < 0) {
|
||||
#ifndef WIN32
|
||||
if(errno != EINTR)
|
||||
if(EINTR != errno) {
|
||||
#endif
|
||||
lam_exit((-1, "lam_reactor_poll: select() failed with errno=%d\n", errno));
|
||||
return;
|
||||
lam_output(0, "lam_reactor_poll: select() failed with errno=%d",
|
||||
errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
lam_reactor_dispatch(r, rc, &rset, &sset, &eset);
|
||||
}
|
||||
@ -279,9 +288,18 @@ void lam_reactor_run(lam_reactor_t* r)
|
||||
int rc = select(r->r_max+1, (fd_set*)&rset, (fd_set*)&sset, (fd_set*)&eset, 0);
|
||||
if(rc < 0) {
|
||||
#ifndef WIN32
|
||||
if(errno != EINTR)
|
||||
if (EINTR != errno) {
|
||||
#endif
|
||||
lam_output(0, "lam_reactor_run: select() failed with errno=%d",
|
||||
errno);
|
||||
#if NEED_TO_IMPLEMENT_LAM_EXIT
|
||||
lam_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
}
|
||||
#endif
|
||||
lam_exit((-1, "lam_reactor_run: select() failed with errno=%d\n", errno));
|
||||
continue;
|
||||
}
|
||||
lam_reactor_dispatch(r, rc, &rset, &sset, &eset);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user