Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into topic/dc_fix_vers
Browse files Browse the repository at this point in the history
  • Loading branch information
alinask committed Mar 7, 2018
2 parents 03046ae + 3d179a1 commit b873f3a
Show file tree
Hide file tree
Showing 23 changed files with 352 additions and 323 deletions.
13 changes: 10 additions & 3 deletions config/m4/ib.m4
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,17 @@ AS_IF([test "x$with_ib" == xyes],
# Device Memory support
AS_IF([test "x$with_dm" != xno],
[AC_CHECK_DECLS([ibv_exp_alloc_dm, ibv_exp_reg_mr, ibv_dereg_mr, ibv_exp_free_dm],
[AC_TRY_COMPILE([#include <infiniband/verbs_exp.h>],
[
struct ibv_exp_dm ibv_dm;
struct ibv_exp_alloc_dm_attr dm_attr;
void* a1 = ibv_exp_alloc_dm;
void* a2 = ibv_exp_reg_mr;
void* a3 = ibv_dereg_mr;
void* a4 = ibv_exp_free_dm;
],
[AC_DEFINE([HAVE_IBV_EXP_DM], 1, [Device Memory support])],
[],
[infiniband/verbs_exp.h])
[])
])
Expand Down
1 change: 0 additions & 1 deletion src/tools/info/ucx_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ int main(int argc, char **argv)

if (print_flags & UCS_CONFIG_PRINT_CONFIG) {
ucs_config_parser_print_all_opts(stdout, print_flags);
ucm_config_print(stdout, print_flags);
}

if (print_opts & PRINT_DEVICES) {
Expand Down
2 changes: 0 additions & 2 deletions src/ucm/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ noinst_HEADERS = \
malloc/malloc_hook.h \
malloc/allocator.h \
mmap/mmap.h \
util/ucm_config.h \
util/replace.h \
util/log.h \
util/reloc.h \
Expand All @@ -43,7 +42,6 @@ libucm_la_SOURCES = \
malloc/malloc_hook.c \
mmap/install.c \
util/replace.c \
util/ucm_config.c \
util/log.c \
util/reloc.c \
util/sys.c
Expand Down
42 changes: 21 additions & 21 deletions src/ucm/api/ucm.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ typedef union ucm_event {
} ucm_event_t;


/**
* @brief Global UCM configuration.
*
* Can be safely modified before using UCM functions.
*/
typedef struct ucm_global_config {
ucs_log_level_t log_level; /* Logging level */
int enable_events; /* Enable memory events */
int enable_mmap_reloc; /* Enable installing mmap relocations */
int enable_malloc_hooks; /* Enable installing malloc hooks */
int enable_malloc_reloc; /* Enable installing malloc relocations */
int enable_cuda_reloc; /* Enable installing CUDA relocations */
int enable_dynamic_mmap_thresh; /* Enable adaptive mmap threshold */
size_t alloc_alignment; /* Alignment for memory allocations */
} ucm_global_config_t;


/* Global UCM configuration */
extern ucm_global_config_t ucm_global_opts;


/**
* @brief Memory event callback.
*
Expand Down Expand Up @@ -190,27 +211,6 @@ typedef void (*ucm_event_callback_t)(ucm_event_type_t event_type,
ucm_event_t *event, void *arg);



/**
* @brief Print UCM global configuration to a stream.
*
* @param [in] stream Output stream to print to.
* @param [in] print_flags Controls how the configuration is printed.
*/
void ucm_config_print(FILE *stream, ucs_config_print_flags_t print_flags);


/**
* @brief Modify UCM global configuration.
*
* @param [in] name Configuration variable name.
* @param [in] value Value to set.
*
* @return Error code.
*/
ucs_status_t ucm_config_modify(const char *name, const char *value);


/**
* @brief Install a handler for memory events.
*
Expand Down
3 changes: 1 addition & 2 deletions src/ucm/cuda/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <ucm/event/event.h>
#include <ucm/util/log.h>
#include <ucm/util/reloc.h>
#include <ucm/util/ucm_config.h>
#include <ucs/sys/math.h>
#include <ucs/sys/preprocessor.h>

Expand Down Expand Up @@ -46,7 +45,7 @@ ucs_status_t ucm_cudamem_install()
ucm_reloc_patch_t *patch;
ucs_status_t status;

if (!ucm_global_config.enable_cuda_hooks) {
if (!ucm_global_opts.enable_cuda_reloc) {
ucm_debug("installing cudamem relocations is disabled by configuration");
return UCS_ERR_UNSUPPORTED;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ucm/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#if HAVE_CUDA
#include <ucm/cuda/cudamem.h>
#endif
#include <ucm/util/ucm_config.h>
#include <ucm/util/log.h>
#include <ucm/util/sys.h>
#include <ucs/arch/cpu.h>
Expand Down Expand Up @@ -673,7 +672,7 @@ ucs_status_t ucm_set_event_handler(int events, int priority,
ucm_event_handler_t *handler;
ucs_status_t status;

if (!ucm_global_config.enable_events) {
if (!ucm_global_opts.enable_events) {
return UCS_ERR_UNSUPPORTED;
}

Expand Down
17 changes: 10 additions & 7 deletions src/ucm/malloc/malloc_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <ucm/util/log.h>
#include <ucm/util/reloc.h>
#include <ucm/util/sys.h>
#include <ucm/util/ucm_config.h>
#include <ucs/datastruct/queue.h>
#include <ucs/type/component.h>
#include <ucs/type/spinlock.h>
Expand Down Expand Up @@ -226,8 +225,8 @@ static void *ucm_malloc_impl(size_t size, const char *debug_name)
void *ptr;

ucm_malloc_hook_state.hook_called = 1;
if (ucm_global_config.alloc_alignment > 1) {
ptr = ucm_dlmemalign(ucm_global_config.alloc_alignment, size);
if (ucm_global_opts.alloc_alignment > 1) {
ptr = ucm_dlmemalign(ucm_global_opts.alloc_alignment, size);
} else {
ptr = ucm_dlmalloc(size);
}
Expand All @@ -240,7 +239,11 @@ static void ucm_malloc_adjust_thresholds(size_t size)
int mmap_thresh;

if (size > ucm_malloc_hook_state.max_freed_size) {
if (ucm_global_config.enable_dynamic_mmap_thresh &&
/* Valgrind limits the size of brk() segments to 8mb, so must use mmap
* for large allocations.
*/
if (!RUNNING_ON_VALGRIND &&
ucm_global_opts.enable_dynamic_mmap_thresh &&
!ucm_malloc_hook_state.trim_thresh_set &&
!ucm_malloc_hook_state.mmap_thresh_set) {
/* new mmap threshold is increased to the size of released block,
Expand Down Expand Up @@ -287,7 +290,7 @@ static void *ucm_memalign_impl(size_t alignment, size_t size, const char *debug_
void *ptr;

ucm_malloc_hook_state.hook_called = 1;
ptr = ucm_dlmemalign(ucs_max(alignment, ucm_global_config.alloc_alignment), size);
ptr = ucm_dlmemalign(ucs_max(alignment, ucm_global_opts.alloc_alignment), size);
ucm_malloc_allocated(ptr, size, debug_name);
return ptr;
}
Expand Down Expand Up @@ -702,7 +705,7 @@ ucs_status_t ucm_malloc_install(int events)
* valgrind anyway.
*/
#if HAVE_MALLOC_HOOK
if (ucm_global_config.enable_malloc_hooks) {
if (ucm_global_opts.enable_malloc_hooks) {
/* Install using malloc hooks.
* TODO detect glibc support in configure-time.
*/
Expand All @@ -727,7 +730,7 @@ ucs_status_t ucm_malloc_install(int events)
}

/* Install using malloc symbols */
if (ucm_global_config.enable_malloc_reloc) {
if (ucm_global_opts.enable_malloc_reloc) {
if (!(ucm_malloc_hook_state.install_state & UCM_MALLOC_INSTALLED_MALL_SYMS)) {
ucm_debug("installing malloc relocations");
ucm_malloc_populate_glibc_cache();
Expand Down
3 changes: 1 addition & 2 deletions src/ucm/mmap/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <ucm/event/event.h>
#include <ucm/util/log.h>
#include <ucm/util/reloc.h>
#include <ucm/util/ucm_config.h>
#include <ucs/sys/math.h>

#include <sys/mman.h>
Expand Down Expand Up @@ -107,7 +106,7 @@ static ucs_status_t ucs_mmap_install_reloc(int events)
ucm_mmap_func_t *entry;
ucs_status_t status;

if (!ucm_global_config.enable_mmap_reloc) {
if (!ucm_global_opts.enable_mmap_reloc) {
ucm_debug("installing mmap relocations is disabled by configuration");
return UCS_ERR_UNSUPPORTED;
}
Expand Down
1 change: 1 addition & 0 deletions src/ucm/util/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
Expand Down
5 changes: 2 additions & 3 deletions src/ucm/util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
# include "config.h"
#endif

#include <ucm/api/ucm.h>
#include <ucs/config/types.h>

#include "ucm_config.h"


#define ucm_log(_level, _message, ...) \
if (((_level) <= UCS_MAX_LOG_LEVEL) && ((_level) <= ucm_global_config.log_level)) { \
if (((_level) <= UCS_MAX_LOG_LEVEL) && ((_level) <= ucm_global_opts.log_level)) { \
__ucm_log(__FILE__, __LINE__, __FUNCTION__, (_level), _message, \
## __VA_ARGS__); \
}
Expand Down
1 change: 0 additions & 1 deletion src/ucm/util/reloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <ucs/sys/compiler.h>
#include <ucs/type/component.h>
#include <ucm/util/log.h>
#include <ucm/util/ucm_config.h>

#include <sys/fcntl.h>
#include <sys/mman.h>
Expand Down
10 changes: 10 additions & 0 deletions src/ucm/util/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@

#define UCM_PROC_SELF_MAPS "/proc/self/maps"

ucm_global_config_t ucm_global_opts = {
.log_level = UCS_LOG_LEVEL_WARN,
.enable_events = 1,
.enable_mmap_reloc = 1,
.enable_malloc_hooks = 1,
.enable_malloc_reloc = 0,
.enable_cuda_reloc = 1,
.enable_dynamic_mmap_thresh = 1,
.alloc_alignment = 16
};

static size_t ucm_get_page_size()
{
Expand Down
Loading

0 comments on commit b873f3a

Please sign in to comment.