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