Commit 06623964 authored by Jonathan Jenkins's avatar Jonathan Jenkins

configuration interface support for annotations

Not yet supported in models (annotation=NULL), will enable in future commits.
parent 6d3f2a0a
......@@ -64,12 +64,14 @@ int configuration_free (ConfigHandle *handle);
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - pointer to string
* length - maximum length of string
*/
int configuration_get_value(ConfigHandle *handle,
const char * section_name,
const char * key_name,
const char * annotation,
char *value,
size_t length);
......@@ -82,12 +84,14 @@ int configuration_get_value(ConfigHandle *handle,
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - pointer to string
* length - maximum length of string */
int configuration_get_value_relpath(
ConfigHandle *handle,
const char * section_name,
const char * key_name,
const char * annotation,
char *value,
size_t length);
......@@ -100,12 +104,14 @@ int configuration_get_value_relpath(
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* values - array of points to values (must be freed by caller)
* length - number of value items
*/
int configuration_get_multivalue(ConfigHandle *handle,
const char * section_name,
const char * key_name,
const char * annotation,
char ***values,
size_t *length);
......@@ -116,11 +122,13 @@ int configuration_get_multivalue(ConfigHandle *handle,
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - returned as a pointer to an integer
*/
int configuration_get_value_int (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char * annotation,
int *value);
/*
......@@ -131,11 +139,13 @@ int configuration_get_value_int (ConfigHandle *handle,
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - returned as a pointer to an unsigned integer
*/
int configuration_get_value_uint (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char * annotation,
unsigned int *value);
/*
......@@ -145,11 +155,13 @@ int configuration_get_value_uint (ConfigHandle *handle,
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - returned as a pointer to a long integer
*/
int configuration_get_value_longint (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char * annotation,
long int *value);
/*
......@@ -159,11 +171,13 @@ int configuration_get_value_longint (ConfigHandle *handle,
* handle - configuration handle
* section_name - name of the section the key is in
* key_name - name of the key
* annotation - optional annotation to look for (NULL -> no annotation)
* value - returned as a pointer to a double
*/
int configuration_get_value_double (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char * annotation,
double *value);
/*
......
......@@ -308,7 +308,7 @@ void codes_mapping_setup()
g_tw_custom_initial_mapping=&codes_mapping_init;
g_tw_custom_lp_global_to_local_map=&codes_mapping_to_lp;
g_tw_events_per_pe = mem_factor * codes_mapping_get_lps_for_pe();
configuration_get_value_int(&config, "PARAMS", "message_size", &message_size);
configuration_get_value_int(&config, "PARAMS", "message_size", NULL, &message_size);
if(!message_size)
{
message_size = 256;
......
......@@ -77,16 +77,30 @@ int configuration_load (const char *filepath,
int configuration_get_value(ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
char *value,
size_t len)
{
SectionHandle section_handle;
int rc;
// reading directly from the config, so need to inject the annotation
// directly into the search string
char key_name_tmp[CONFIGURATION_MAX_NAME];
char *key_name_full;
if (annotation==NULL){
// sorry const type... we promise we won't change you
key_name_full = (char*) key_name;
}
else{
assert(snprintf(key_name_tmp, CONFIGURATION_MAX_NAME, "%s@%s",
key_name, annotation) < CONFIGURATION_MAX_NAME);
key_name_full = key_name_tmp;
}
rc = cf_openSection(*handle, ROOT_SECTION, section_name, &section_handle);
assert(rc == 1);
rc = cf_getKey(*handle, section_handle, key_name, value, len);
rc = cf_getKey(*handle, section_handle, key_name_full, value, len);
assert(rc);
(void) cf_closeSection(*handle, section_handle);
......@@ -98,11 +112,13 @@ int configuration_get_value_relpath(
ConfigHandle *handle,
const char * section_name,
const char * key_name,
const char *annotation,
char *value,
size_t length){
char *tmp = malloc(length);
configuration_get_value(handle, section_name, key_name, tmp, length);
configuration_get_value(handle, section_name, key_name, annotation, tmp,
length);
/* concat the configuration value with the directory */
int w = snprintf(value, length, "%s/%s", (*handle)->config_dir, tmp);
......@@ -114,16 +130,30 @@ int configuration_get_value_relpath(
int configuration_get_multivalue(ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
char ***values,
size_t *len)
{
SectionHandle section_handle;
int rc;
// reading directly from the config, so need to inject the annotation
// directly into the search string
char key_name_tmp[CONFIGURATION_MAX_NAME];
char *key_name_full;
if (annotation==NULL){
// sorry const type... we promise we won't change you
key_name_full = (char*) key_name;
}
else{
assert(snprintf(key_name_tmp, CONFIGURATION_MAX_NAME, "%s@%s",
key_name, annotation) < CONFIGURATION_MAX_NAME);
key_name_full = key_name_tmp;
}
rc = cf_openSection(*handle, ROOT_SECTION, section_name, &section_handle);
assert(rc == 1);
rc = cf_getMultiKey(*handle, section_handle, key_name, values, len);
rc = cf_getMultiKey(*handle, section_handle, key_name_full, values, len);
assert(rc);
(void) cf_closeSection(*handle, section_handle);
......@@ -134,6 +164,7 @@ int configuration_get_multivalue(ConfigHandle *handle,
int configuration_get_value_int (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
int *value)
{
char valuestr[256];
......@@ -143,6 +174,7 @@ int configuration_get_value_int (ConfigHandle *handle,
r = configuration_get_value(handle,
section_name,
key_name,
annotation,
valuestr,
sizeof(valuestr));
if (r > 0)
......@@ -157,6 +189,7 @@ int configuration_get_value_int (ConfigHandle *handle,
int configuration_get_value_uint (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
unsigned int *value)
{
char valuestr[256];
......@@ -166,6 +199,7 @@ int configuration_get_value_uint (ConfigHandle *handle,
r = configuration_get_value(handle,
section_name,
key_name,
annotation,
valuestr,
sizeof(valuestr));
if (r > 0)
......@@ -180,6 +214,7 @@ int configuration_get_value_uint (ConfigHandle *handle,
int configuration_get_value_longint (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
long int *value)
{
char valuestr[256];
......@@ -189,6 +224,7 @@ int configuration_get_value_longint (ConfigHandle *handle,
r = configuration_get_value(handle,
section_name,
key_name,
annotation,
valuestr,
sizeof(valuestr));
if (r > 0)
......@@ -204,6 +240,7 @@ int configuration_get_value_longint (ConfigHandle *handle,
int configuration_get_value_double (ConfigHandle *handle,
const char *section_name,
const char *key_name,
const char *annotation,
double *value)
{
char valuestr[256];
......@@ -213,6 +250,7 @@ int configuration_get_value_double (ConfigHandle *handle,
r = configuration_get_value(handle,
section_name,
key_name,
annotation,
valuestr,
sizeof(valuestr));
if (r > 0)
......
......@@ -176,7 +176,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
assert(model);
// request sizes
rc = configuration_get_multivalue(ch, name, "request_sizes",&values,&length);
rc = configuration_get_multivalue(ch, name, "request_sizes", NULL,
&values,&length);
assert(rc == 1);
model->request_sizes = malloc(sizeof(int)*length);
assert(model->request_sizes);
......@@ -188,7 +189,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// write rates
rc = configuration_get_multivalue(ch, name, "write_rates",&values,&length);
rc = configuration_get_multivalue(ch, name, "write_rates", NULL,
&values,&length);
assert(rc == 1);
model->write_rates = malloc(sizeof(double)*length);
assert(model->write_rates);
......@@ -200,7 +202,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// read rates
rc = configuration_get_multivalue(ch, name, "read_rates",&values,&length);
rc = configuration_get_multivalue(ch, name, "read_rates", NULL,
&values,&length);
assert(rc == 1);
model->read_rates = malloc(sizeof(double)*length);
assert(model->read_rates);
......@@ -212,7 +215,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// write overheads
rc = configuration_get_multivalue(ch, name, "write_overheads",&values,&length);
rc = configuration_get_multivalue(ch, name, "write_overheads", NULL,
&values,&length);
assert(rc == 1);
model->write_overheads = malloc(sizeof(double)*length);
assert(model->write_overheads);
......@@ -224,7 +228,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// read overheades
rc = configuration_get_multivalue(ch, name, "read_overheads",&values,&length);
rc = configuration_get_multivalue(ch, name, "read_overheads", NULL,
&values,&length);
assert(rc == 1);
model->read_overheads = malloc(sizeof(double)*length);
assert(model->read_overheads);
......@@ -236,7 +241,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// write seek latency
rc = configuration_get_multivalue(ch, name, "write_seeks",&values,&length);
rc = configuration_get_multivalue(ch, name, "write_seeks", NULL,
&values,&length);
assert(rc == 1);
model->write_seeks = malloc(sizeof(double)*length);
assert(model->write_seeks);
......@@ -248,7 +254,8 @@ static void lsm_load_config (ConfigHandle *ch, char *name, lsm_state_t *ns)
free(values);
// read seek latency
rc = configuration_get_multivalue(ch, name, "read_seeks",&values,&length);
rc = configuration_get_multivalue(ch, name, "read_seeks", NULL,
&values,&length);
assert(rc == 1);
model->read_seeks = malloc(sizeof(double)*length);
assert(model->read_seeks);
......
......@@ -432,7 +432,7 @@ void resource_lp_init(){
void resource_lp_configure(){
long int avail;
int ret = configuration_get_value_longint(&config, "resource",
"available", &avail);
"available", NULL, &avail);
if (ret){
fprintf(stderr, "Could not find section:resource value:available for "
"resource LP\n");
......
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