Commit d3b5e2d9 authored by Philip Carns's avatar Philip Carns
Browse files

Merge branch 'carns/dev-json-config' into 'master'

switch to mochi-cfg (json) configuration

See merge request !2
parents 19bf8125 904dbbde
...@@ -50,6 +50,12 @@ LIBS="$ARGOBOTS_LIBS $LIBS" ...@@ -50,6 +50,12 @@ LIBS="$ARGOBOTS_LIBS $LIBS"
CPPFLAGS="$ARGOBOTS_CFLAGS $CPPFLAGS" CPPFLAGS="$ARGOBOTS_CFLAGS $CPPFLAGS"
CFLAGS="$ARGOBOTS_CFLAGS $CFLAGS" CFLAGS="$ARGOBOTS_CFLAGS $CFLAGS"
PKG_CHECK_MODULES([MOCHICFG],[mochi-cfg],[],
[AC_MSG_ERROR([Could not find working mochi-cfg installation!])])
LIBS="$MOCHICFG_LIBS $LIBS"
CPPFLAGS="$MOCHICFG_CFLAGS $CPPFLAGS"
CFLAGS="$MOCHICFG_CFLAGS $CFLAGS"
AC_MSG_CHECKING([for fallocate]) AC_MSG_CHECKING([for fallocate])
AC_TRY_COMPILE([ AC_TRY_COMPILE([
#define _GNU_SOURCE #define _GNU_SOURCE
......
...@@ -176,6 +176,7 @@ static void abt_bench(int buffer_per_thread, unsigned int concurrency, size_t si ...@@ -176,6 +176,7 @@ static void abt_bench(int buffer_per_thread, unsigned int concurrency, size_t si
int fd; int fd;
void *buffer; void *buffer;
double start; double start;
char *cfg_str;
fd = open(filename, OFLAGS, S_IWUSR|S_IRUSR); fd = open(filename, OFLAGS, S_IWUSR|S_IRUSR);
if(!fd) if(!fd)
...@@ -203,6 +204,10 @@ static void abt_bench(int buffer_per_thread, unsigned int concurrency, size_t si ...@@ -203,6 +204,10 @@ static void abt_bench(int buffer_per_thread, unsigned int concurrency, size_t si
aid = abt_io_init(concurrency); aid = abt_io_init(concurrency);
assert(aid != NULL); assert(aid != NULL);
cfg_str = abt_io_get_config(aid);
printf("%s\n", cfg_str);
free(cfg_str);
ABT_mutex_create(&mutex); ABT_mutex_create(&mutex);
if (buffer_per_thread) if (buffer_per_thread)
...@@ -294,6 +299,7 @@ static void abt_bench_nb(int buffer_per_thread, unsigned int concurrency, size_t ...@@ -294,6 +299,7 @@ static void abt_bench_nb(int buffer_per_thread, unsigned int concurrency, size_t
double start_time; double start_time;
abt_io_op_t **ops; abt_io_op_t **ops;
ssize_t *wrets; ssize_t *wrets;
char *cfg_str;
fd = open(filename, OFLAGS, S_IWUSR|S_IRUSR); fd = open(filename, OFLAGS, S_IWUSR|S_IRUSR);
if(!fd) if(!fd)
...@@ -312,6 +318,10 @@ static void abt_bench_nb(int buffer_per_thread, unsigned int concurrency, size_t ...@@ -312,6 +318,10 @@ static void abt_bench_nb(int buffer_per_thread, unsigned int concurrency, size_t
aid = abt_io_init(concurrency); aid = abt_io_init(concurrency);
assert(aid != NULL); assert(aid != NULL);
cfg_str = abt_io_get_config(aid);
printf("%s\n", cfg_str);
free(cfg_str);
/* set up buffers */ /* set up buffers */
num_buffers = buffer_per_thread ? concurrency : 1; num_buffers = buffer_per_thread ? concurrency : 1;
buffers = malloc(num_buffers*sizeof(*buffers)); buffers = malloc(num_buffers*sizeof(*buffers));
......
/* /*
* (C) 2015 The University of Chicago * (C) 2015 The University of Chicago
* *
* See COPYRIGHT in top-level directory. * See COPYRIGHT in top-level directory.
*/ */
...@@ -34,6 +34,15 @@ typedef struct abt_io_op abt_io_op_t; ...@@ -34,6 +34,15 @@ typedef struct abt_io_op abt_io_op_t;
*/ */
abt_io_instance_id abt_io_init(int backing_thread_count); abt_io_instance_id abt_io_init(int backing_thread_count);
/**
* Initializes abt_io library using configuration parameters specified in
* json_cfg_string
*
* @param [in] json_cfg_string configuration parameters
* @returns abt_io instance id on success, NULL upon error
*/
abt_io_instance_id abt_io_init_json(const char* json_cfg_string);
/** /**
* Initializes abt_io library using the specified Argobots pool for operation * Initializes abt_io library using the specified Argobots pool for operation
* dispatch. * dispatch.
...@@ -42,6 +51,14 @@ abt_io_instance_id abt_io_init(int backing_thread_count); ...@@ -42,6 +51,14 @@ abt_io_instance_id abt_io_init(int backing_thread_count);
*/ */
abt_io_instance_id abt_io_init_pool(ABT_pool progress_pool); abt_io_instance_id abt_io_init_pool(ABT_pool progress_pool);
/**
* Retrieves complete configuration of abt_io, encoded as json
*
* @param [in] aid abt-io instance
* @returns null terminated string that must be free'd by caller
*/
char* abt_io_get_config(abt_io_instance_id aid);
/** /**
* Shuts down abt_io library and its underlying resources. Waits for underlying * Shuts down abt_io library and its underlying resources. Waits for underlying
* operations to complete in the case abt_io_init was called, otherwise returns * operations to complete in the case abt_io_init was called, otherwise returns
......
/* /*
* (C) 2015 The University of Chicago * (C) 2015 The University of Chicago
* *
* See COPYRIGHT in top-level directory. * See COPYRIGHT in top-level directory.
*/ */
...@@ -17,15 +17,24 @@ ...@@ -17,15 +17,24 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <jansson.h>
#include <abt.h> #include <abt.h>
#include <mochi-cfg.h>
#include "abt-io.h" #include "abt-io.h"
# define ABT_IO_DEFAULT_CFG \
"{ \"abt-io\": {" \
" \"version\": \"" PACKAGE_VERSION "\"," \
" \"thread_count\": 16" \
"}}"
struct abt_io_instance struct abt_io_instance
{ {
ABT_pool progress_pool; ABT_pool progress_pool;
ABT_xstream *progress_xstreams; ABT_xstream *progress_xstreams;
int num_xstreams; int num_xstreams;
json_t *component_cfg;
}; };
struct abt_io_op struct abt_io_op
...@@ -35,7 +44,7 @@ struct abt_io_op ...@@ -35,7 +44,7 @@ struct abt_io_op
void (*free_fn)(void*); void (*free_fn)(void*);
}; };
abt_io_instance_id abt_io_init(int backing_thread_count) abt_io_instance_id abt_io_init_json(const char* json_cfg_string)
{ {
struct abt_io_instance *aid; struct abt_io_instance *aid;
ABT_pool pool; ABT_pool pool;
...@@ -44,30 +53,54 @@ abt_io_instance_id abt_io_init(int backing_thread_count) ...@@ -44,30 +53,54 @@ abt_io_instance_id abt_io_init(int backing_thread_count)
ABT_sched *progress_scheds = NULL; ABT_sched *progress_scheds = NULL;
int ret; int ret;
int i; int i;
int thread_count;
if (backing_thread_count < 0) return NULL; aid = calloc(1, sizeof(*aid));
aid = malloc(sizeof(*aid));
if (aid == NULL) return ABT_IO_INSTANCE_NULL; if (aid == NULL) return ABT_IO_INSTANCE_NULL;
if (backing_thread_count == 0) { aid->component_cfg = mochi_cfg_get_component(json_cfg_string, "abt-io", ABT_IO_DEFAULT_CFG);
if(!aid->component_cfg)
{
fprintf(stderr, "Error: unable to set up abt-io config.\n");
return(ABT_IO_INSTANCE_NULL);
}
ret = mochi_cfg_get_value_int(aid->component_cfg, "thread_count", &thread_count);
if(ret < 0 || thread_count < 0)
{
mochi_cfg_release_component(aid->component_cfg);
free(aid);
return(ABT_IO_INSTANCE_NULL);
}
if (thread_count == 0) {
aid->num_xstreams = 0; aid->num_xstreams = 0;
ret = ABT_xstream_self(&self_xstream); ret = ABT_xstream_self(&self_xstream);
if (ret != ABT_SUCCESS) { free(aid); return ABT_IO_INSTANCE_NULL; } if (ret != ABT_SUCCESS) {
mochi_cfg_release_component(aid->component_cfg);
free(aid);
return ABT_IO_INSTANCE_NULL;
}
ret = ABT_xstream_get_main_pools(self_xstream, 1, &pool); ret = ABT_xstream_get_main_pools(self_xstream, 1, &pool);
if (ret != ABT_SUCCESS) { free(aid); return ABT_IO_INSTANCE_NULL; } if (ret != ABT_SUCCESS) {
mochi_cfg_release_component(aid->component_cfg);
free(aid);
return ABT_IO_INSTANCE_NULL;
}
} }
else { else {
aid->num_xstreams = backing_thread_count; aid->num_xstreams = thread_count;
progress_xstreams = malloc( progress_xstreams = malloc(
backing_thread_count * sizeof(*progress_xstreams)); thread_count * sizeof(*progress_xstreams));
if (progress_xstreams == NULL) { if (progress_xstreams == NULL) {
mochi_cfg_release_component(aid->component_cfg);
free(aid); free(aid);
return ABT_IO_INSTANCE_NULL; return ABT_IO_INSTANCE_NULL;
} }
progress_scheds = malloc( progress_scheds = malloc(
backing_thread_count * sizeof(*progress_scheds)); thread_count * sizeof(*progress_scheds));
if (progress_scheds == NULL) { if (progress_scheds == NULL) {
mochi_cfg_release_component(aid->component_cfg);
free(progress_xstreams); free(progress_xstreams);
free(aid); free(aid);
return ABT_IO_INSTANCE_NULL; return ABT_IO_INSTANCE_NULL;
...@@ -77,17 +110,19 @@ abt_io_instance_id abt_io_init(int backing_thread_count) ...@@ -77,17 +110,19 @@ abt_io_instance_id abt_io_init(int backing_thread_count)
ABT_TRUE, &pool); ABT_TRUE, &pool);
if(ret != ABT_SUCCESS) if(ret != ABT_SUCCESS)
{ {
mochi_cfg_release_component(aid->component_cfg);
free(progress_xstreams); free(progress_xstreams);
free(progress_scheds); free(progress_scheds);
free(aid); free(aid);
return ABT_IO_INSTANCE_NULL; return ABT_IO_INSTANCE_NULL;
} }
for(i=0; i<backing_thread_count; i++) for(i=0; i<thread_count; i++)
{ {
ret = ABT_sched_create_basic(ABT_SCHED_BASIC_WAIT, 1, &pool, ret = ABT_sched_create_basic(ABT_SCHED_BASIC_WAIT, 1, &pool,
ABT_SCHED_CONFIG_NULL, &progress_scheds[i]); ABT_SCHED_CONFIG_NULL, &progress_scheds[i]);
if (ret != ABT_SUCCESS) { if (ret != ABT_SUCCESS) {
mochi_cfg_release_component(aid->component_cfg);
free(progress_xstreams); free(progress_xstreams);
free(progress_scheds); free(progress_scheds);
free(aid); free(aid);
...@@ -95,6 +130,7 @@ abt_io_instance_id abt_io_init(int backing_thread_count) ...@@ -95,6 +130,7 @@ abt_io_instance_id abt_io_init(int backing_thread_count)
} }
ret = ABT_xstream_create(progress_scheds[i], &progress_xstreams[i]); ret = ABT_xstream_create(progress_scheds[i], &progress_xstreams[i]);
if (ret != ABT_SUCCESS) { if (ret != ABT_SUCCESS) {
mochi_cfg_release_component(aid->component_cfg);
free(progress_xstreams); free(progress_xstreams);
free(progress_scheds); free(progress_scheds);
free(aid); free(aid);
...@@ -109,6 +145,23 @@ abt_io_instance_id abt_io_init(int backing_thread_count) ...@@ -109,6 +145,23 @@ abt_io_instance_id abt_io_init(int backing_thread_count)
return aid; return aid;
} }
abt_io_instance_id abt_io_init(int thread_count)
{
char cfg_string[64];
/* NOTE: jansson could be used for more complex encodings, but this one
* is trivial enough to just do with snprintf()
*/
snprintf(cfg_string, 64, "{\"abt-io\": {\"thread_count\": %d }}", thread_count);
return(abt_io_init_json(cfg_string));
}
char* abt_io_get_config(abt_io_instance_id aid)
{
return(mochi_cfg_emit(aid->component_cfg, "abt-io"));
}
abt_io_instance_id abt_io_init_pool(ABT_pool progress_pool) abt_io_instance_id abt_io_init_pool(ABT_pool progress_pool)
{ {
struct abt_io_instance *aid; struct abt_io_instance *aid;
...@@ -136,6 +189,9 @@ void abt_io_finalize(abt_io_instance_id aid) ...@@ -136,6 +189,9 @@ void abt_io_finalize(abt_io_instance_id aid)
// pool gets implicitly freed // pool gets implicitly freed
} }
if(aid->component_cfg)
mochi_cfg_release_component(aid->component_cfg);
free(aid); free(aid);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment