Commit eb9826bd authored by Jonathan Jenkins's avatar Jonathan Jenkins

rework config storage to a much tighter format

should do good things for codes-mapping lookup performance
parent 62e1153b
...@@ -16,26 +16,34 @@ ...@@ -16,26 +16,34 @@
#define CONFIGURATION_MAX_TYPES 10 #define CONFIGURATION_MAX_TYPES 10
#define CONFIGURATION_MAX_ANNOS 10 #define CONFIGURATION_MAX_ANNOS 10
// NOTE: direct offsets are used when first building the structure as we're
// building up one big buffer to hold entity names. Pointers are set after the
// initialization process during configuration_load
typedef union {
char const * ptr;
int offset;
} config_name_u;
typedef struct config_lptype_s typedef struct config_lptype_s
{ {
char name[CONFIGURATION_MAX_NAME]; config_name_u name;
char anno[CONFIGURATION_MAX_NAME]; config_name_u anno;
uint64_t count; int count;
} config_lptype_t; } config_lptype_t;
typedef struct config_lpgroup_s typedef struct config_lpgroup_s
{ {
char name[CONFIGURATION_MAX_NAME]; config_name_u name;
uint64_t repetitions; int repetitions;
int lptypes_count;
config_lptype_t lptypes[CONFIGURATION_MAX_TYPES]; config_lptype_t lptypes[CONFIGURATION_MAX_TYPES];
uint64_t lptypes_count;
} config_lpgroup_t; } config_lpgroup_t;
// mapping of lp type to the list of annotations used. Used for convenience when // mapping of lp type to the list of annotations used. Used for convenience when
// models are performing configuraiton code // models are performing configuraiton code
typedef struct config_anno_map_s typedef struct config_anno_map_s
{ {
char lp_name[CONFIGURATION_MAX_NAME]; config_name_u lp_name;
// only explicit annotations tracked here - use a flag to indicate a // only explicit annotations tracked here - use a flag to indicate a
// non-annotated LP type // non-annotated LP type
int has_unanno_lp; int has_unanno_lp;
...@@ -43,10 +51,10 @@ typedef struct config_anno_map_s ...@@ -43,10 +51,10 @@ typedef struct config_anno_map_s
// (annotation-ignoring) lookup semantics, provide a flag to determine if // (annotation-ignoring) lookup semantics, provide a flag to determine if
// the unannotated lp type is first // the unannotated lp type is first
int is_unanno_first; int is_unanno_first;
uint64_t num_annos; int num_annos;
// maintain the number of lps that have the particular annotation // maintain the number of lps that have the particular annotation
uint64_t num_anno_lps[CONFIGURATION_MAX_ANNOS]; int num_anno_lps[CONFIGURATION_MAX_ANNOS];
char * annotations[CONFIGURATION_MAX_ANNOS]; config_name_u annotations[CONFIGURATION_MAX_ANNOS];
} config_anno_map_t; } config_anno_map_t;
typedef struct config_lpgroups_s typedef struct config_lpgroups_s
......
This diff is collapsed.
...@@ -24,8 +24,9 @@ static int mini(int a, int b){ return a < b ? a : b; } ...@@ -24,8 +24,9 @@ static int mini(int a, int b){ return a < b ? a : b; }
// compare passed in annotation strings (NULL or nonempty) against annotation // compare passed in annotation strings (NULL or nonempty) against annotation
// strings in the config (empty or nonempty) // strings in the config (empty or nonempty)
static int cmp_anno(const char * anno_user, const char * anno_config){ static int cmp_anno(const char * anno_user, const char * anno_config){
return anno_user == NULL ? anno_config[0]=='\0' return anno_user == NULL ? anno_config == NULL
: !strcmp(anno_user, anno_config); : (anno_config != NULL
&& !strcmp(anno_user, anno_config));
} }
...@@ -91,7 +92,7 @@ int codes_mapping_get_group_reps(const char* group_name) ...@@ -91,7 +92,7 @@ int codes_mapping_get_group_reps(const char* group_name)
int grp; int grp;
for(grp = 0; grp < lpconf.lpgroups_count; grp++) for(grp = 0; grp < lpconf.lpgroups_count; grp++)
{ {
if(strcmp(lpconf.lpgroups[grp].name, group_name) == 0) if(strcmp(lpconf.lpgroups[grp].name.ptr, group_name) == 0)
return lpconf.lpgroups[grp].repetitions; return lpconf.lpgroups[grp].repetitions;
} }
return -1; return -1;
...@@ -113,14 +114,14 @@ int codes_mapping_get_lp_count( ...@@ -113,14 +114,14 @@ int codes_mapping_get_lp_count(
const config_lpgroup_t *lpg = &lpconf.lpgroups[g]; const config_lpgroup_t *lpg = &lpconf.lpgroups[g];
// iterate over the lps if the group is null (count across all groups) // iterate over the lps if the group is null (count across all groups)
// or if the group names match // or if the group names match
if (group_name == NULL || strcmp(lpg->name, group_name) == 0){ if (group_name == NULL || strcmp(lpg->name.ptr, group_name) == 0){
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
if (strcmp(lp_type_name, lpt->name) == 0){ if (strcmp(lp_type_name, lpt->name.ptr) == 0){
// increment the count if we are ignoring annotations, // increment the count if we are ignoring annotations,
// query and entry are both unannotated, or if the // query and entry are both unannotated, or if the
// annotations match // annotations match
if (ignore_annos || cmp_anno(annotation, lpt->anno)){ if (ignore_annos || cmp_anno(annotation, lpt->anno.ptr)){
if (ignore_repetitions) if (ignore_repetitions)
lp_type_ct_total += lpt->count; lp_type_ct_total += lpt->count;
else else
...@@ -158,15 +159,15 @@ void codes_mapping_get_lp_id( ...@@ -158,15 +159,15 @@ void codes_mapping_get_lp_id(
rep_count += lpg->lptypes[l].count; rep_count += lpg->lptypes[l].count;
} }
// does group name match? // does group name match?
if (strcmp(lpg->name, group_name) == 0){ if (strcmp(lpg->name.ptr, group_name) == 0){
tw_lpid local_lp_count = 0; tw_lpid local_lp_count = 0;
// for each lp type // for each lp type
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
// does lp name match? // does lp name match?
if (strcmp(lpt->name, lp_type_name) == 0){ if (strcmp(lpt->name.ptr, lp_type_name) == 0){
// does annotation match (or are we ignoring annotations?) // does annotation match (or are we ignoring annotations?)
if (ignore_anno || cmp_anno(annotation, lpt->anno)){ if (ignore_anno || cmp_anno(annotation, lpt->anno.ptr)){
// return if sane offset // return if sane offset
if (offset >= (int) lpt->count){ if (offset >= (int) lpt->count){
goto ERROR; goto ERROR;
...@@ -210,18 +211,18 @@ int codes_mapping_get_lp_relative_id( ...@@ -210,18 +211,18 @@ int codes_mapping_get_lp_relative_id(
local_lp_name, &lp_type_index, local_annotation, &rep_id, &offset); local_lp_name, &lp_type_index, local_annotation, &rep_id, &offset);
const char * anno = (local_annotation[0]=='\0') ? NULL : local_annotation; const char * anno = (local_annotation[0]=='\0') ? NULL : local_annotation;
uint64_t group_lp_count = 0; int group_lp_count = 0;
// if not group_specific, then count up LPs of all preceding groups // if not group_specific, then count up LPs of all preceding groups
if (!group_wise){ if (!group_wise){
for (int g = 0; g < group_index; g++){ for (int g = 0; g < group_index; g++){
uint64_t lp_count = 0; int lp_count = 0;
const config_lpgroup_t *lpg = &lpconf.lpgroups[g]; const config_lpgroup_t *lpg = &lpconf.lpgroups[g];
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
if (strcmp(local_lp_name, lpt->name) == 0){ if (strcmp(local_lp_name, lpt->name.ptr) == 0){
// increment the count if we are ignoring annotations, // increment the count if we are ignoring annotations,
// both LPs are unannotated, or if the annotations match // both LPs are unannotated, or if the annotations match
if (!annotation_wise || cmp_anno(anno, lpt->anno)){ if (!annotation_wise || cmp_anno(anno, lpt->anno.ptr)){
lp_count += lpt->count; lp_count += lpt->count;
} }
} }
...@@ -232,12 +233,12 @@ int codes_mapping_get_lp_relative_id( ...@@ -232,12 +233,12 @@ int codes_mapping_get_lp_relative_id(
// count up LPs within my group occuring before me // count up LPs within my group occuring before me
// (the loop is necessary because different annotated LPs may exist in the // (the loop is necessary because different annotated LPs may exist in the
// same group) // same group)
uint64_t lp_count = 0; int lp_count = 0;
uint64_t lp_pre_count = 0; int lp_pre_count = 0;
for (int l = 0; l < lpconf.lpgroups[group_index].lptypes_count; l++){ for (int l = 0; l < lpconf.lpgroups[group_index].lptypes_count; l++){
const config_lptype_t *lpt = &lpconf.lpgroups[group_index].lptypes[l]; const config_lptype_t *lpt = &lpconf.lpgroups[group_index].lptypes[l];
if (strcmp(local_lp_name, lpt->name) == 0){ if (strcmp(local_lp_name, lpt->name.ptr) == 0){
if (!annotation_wise || cmp_anno(anno, lpt->anno)){ if (!annotation_wise || cmp_anno(anno, lpt->anno.ptr)){
lp_count += lpt->count; lp_count += lpt->count;
// special case: if we find an LP entry that matches, but is not // special case: if we find an LP entry that matches, but is not
// the same entry where the input gid comes from, then increment // the same entry where the input gid comes from, then increment
...@@ -267,15 +268,15 @@ tw_lpid codes_mapping_get_lpid_from_relative( ...@@ -267,15 +268,15 @@ tw_lpid codes_mapping_get_lpid_from_relative(
tw_lpid gid_count = 0; tw_lpid gid_count = 0;
for (int g = 0; g < lpconf.lpgroups_count; g++){ for (int g = 0; g < lpconf.lpgroups_count; g++){
const config_lpgroup_t *lpg = &lpconf.lpgroups[g]; const config_lpgroup_t *lpg = &lpconf.lpgroups[g];
if (group_name == NULL || strcmp(group_name, lpg->name) == 0){ if (group_name == NULL || strcmp(group_name, lpg->name.ptr) == 0){
// consider this group for counting // consider this group for counting
tw_lpid local_gid_count = 0; tw_lpid local_gid_count = 0;
int local_rel_id_count = 0; int local_rel_id_count = 0;
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
local_gid_count += lpt->count; local_gid_count += lpt->count;
if (strcmp(lp_type_name, lpt->name) == 0 && if (strcmp(lp_type_name, lpt->name.ptr) == 0 &&
(!annotation_wise || cmp_anno(annotation, lpt->anno))){ (!annotation_wise || cmp_anno(annotation, lpt->anno.ptr))){
local_rel_id_count += lpt->count; local_rel_id_count += lpt->count;
} }
} }
...@@ -290,9 +291,9 @@ tw_lpid codes_mapping_get_lpid_from_relative( ...@@ -290,9 +291,9 @@ tw_lpid codes_mapping_get_lpid_from_relative(
// count up lps listed prior to this entry // count up lps listed prior to this entry
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
if ( strcmp(lp_type_name, lpt->name) == 0 && if ( strcmp(lp_type_name, lpt->name.ptr) == 0 &&
(!annotation_wise || (!annotation_wise ||
cmp_anno(annotation, lpt->anno))){ cmp_anno(annotation, lpt->anno.ptr))){
if (rem < (int) lpt->count){ if (rem < (int) lpt->count){
return gid + (tw_lpid) rem; return gid + (tw_lpid) rem;
} }
...@@ -358,7 +359,7 @@ void codes_mapping_get_lp_info( ...@@ -358,7 +359,7 @@ void codes_mapping_get_lp_info(
// we've found the group // we've found the group
tw_lpid rem = gid - id_total; tw_lpid rem = gid - id_total;
if (group_name != NULL) if (group_name != NULL)
strncpy(group_name, lpg->name, MAX_NAME_LENGTH); strncpy(group_name, lpg->name.ptr, MAX_NAME_LENGTH);
*group_index = g; *group_index = g;
// find repetition within group // find repetition within group
*rep_id = (int) (rem / num_id_per_rep); *rep_id = (int) (rem / num_id_per_rep);
...@@ -369,9 +370,13 @@ void codes_mapping_get_lp_info( ...@@ -369,9 +370,13 @@ void codes_mapping_get_lp_info(
if (rem < num_id_per_rep + lpt->count){ if (rem < num_id_per_rep + lpt->count){
// found the specific LP // found the specific LP
if (lp_type_name != NULL) if (lp_type_name != NULL)
strncpy(lp_type_name, lpt->name, MAX_NAME_LENGTH); strncpy(lp_type_name, lpt->name.ptr, MAX_NAME_LENGTH);
if (annotation != NULL) if (annotation != NULL) {
strncpy(annotation, lpt->anno, MAX_NAME_LENGTH); if (lpt->anno.ptr == NULL)
annotation[0] = '\0';
else
strncpy(annotation, lpt->anno.ptr, MAX_NAME_LENGTH);
}
*offset = (int) (rem - num_id_per_rep); *offset = (int) (rem - num_id_per_rep);
*lp_type_index = l; *lp_type_index = l;
return; // done return; // done
...@@ -510,16 +515,13 @@ const char* codes_mapping_get_annotation_by_name( ...@@ -510,16 +515,13 @@ const char* codes_mapping_get_annotation_by_name(
const char * lp_type_name){ const char * lp_type_name){
for (int g = 0; g < lpconf.lpgroups_count; g++){ for (int g = 0; g < lpconf.lpgroups_count; g++){
const config_lpgroup_t *lpg = &lpconf.lpgroups[g]; const config_lpgroup_t *lpg = &lpconf.lpgroups[g];
if (strcmp(lpg->name, group_name) == 0){ if (strcmp(lpg->name.ptr, group_name) == 0){
// group found, iterate through types // group found, iterate through types
for (int l = 0; l < lpg->lptypes_count; l++){ for (int l = 0; l < lpg->lptypes_count; l++){
const config_lptype_t *lpt = &lpg->lptypes[l]; const config_lptype_t *lpt = &lpg->lptypes[l];
if (strcmp(lpt->name, lp_type_name) == 0){ if (strcmp(lpt->name.ptr, lp_type_name) == 0){
// type found, return the annotation // type found, return the annotation
if (lpt->anno[0] == '\0') return lpt->anno.ptr;
return NULL;
else
return lpt->anno;
} }
} }
} }
...@@ -533,12 +535,7 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){ ...@@ -533,12 +535,7 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){
int group_index, lp_type_index, dummy; int group_index, lp_type_index, dummy;
codes_mapping_get_lp_info(gid, NULL, &group_index, NULL, &lp_type_index, codes_mapping_get_lp_info(gid, NULL, &group_index, NULL, &lp_type_index,
NULL, &dummy, &dummy); NULL, &dummy, &dummy);
const char * anno = return lpconf.lpgroups[group_index].lptypes[lp_type_index].anno.ptr;
lpconf.lpgroups[group_index].lptypes[lp_type_index].anno;
if (anno[0] == '\0')
return NULL;
else
return anno;
} }
/* /*
...@@ -549,7 +546,7 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){ ...@@ -549,7 +546,7 @@ const char* codes_mapping_get_annotation_by_lpid(tw_lpid gid){
const config_anno_map_t * const config_anno_map_t *
codes_mapping_get_lp_anno_map(const char *lp_name){ codes_mapping_get_lp_anno_map(const char *lp_name){
for (uint64_t i = 0; i < lpconf.lpannos_count; i++){ for (uint64_t i = 0; i < lpconf.lpannos_count; i++){
if (strcmp(lp_name, lpconf.lpannos[i].lp_name) == 0){ if (strcmp(lp_name, lpconf.lpannos[i].lp_name.ptr) == 0){
return &lpconf.lpannos[i]; return &lpconf.lpannos[i];
} }
} }
......
...@@ -337,7 +337,7 @@ int lsm_get_num_priorities( ...@@ -337,7 +337,7 @@ int lsm_get_num_priorities(
} }
else { else {
for (int i = 0; i < anno_map->num_annos; i++) { for (int i = 0; i < anno_map->num_annos; i++) {
if (strcmp(anno_map->annotations[i], annotation) == 0) if (strcmp(anno_map->annotations[i].ptr, annotation) == 0)
return models_anno[i].use_sched; return models_anno[i].use_sched;
} }
assert(0); assert(0);
...@@ -796,7 +796,7 @@ void lsm_register(void) ...@@ -796,7 +796,7 @@ void lsm_register(void)
} }
// read the configuration file for a given annotation // read the configuration file for a given annotation
static void read_config(ConfigHandle *ch, char * anno, disk_model_t *model) static void read_config(ConfigHandle *ch, char const * anno, disk_model_t *model)
{ {
char **values; char **values;
size_t length; size_t length;
...@@ -915,7 +915,7 @@ void lsm_configure(void) ...@@ -915,7 +915,7 @@ void lsm_configure(void)
} }
for (uint64_t i = 0; i < anno_map->num_annos; i++){ for (uint64_t i = 0; i < anno_map->num_annos; i++){
char * anno = anno_map->annotations[i]; char const * anno = anno_map->annotations[i].ptr;
read_config(&config, anno, &models_anno[i]); read_config(&config, anno, &models_anno[i]);
} }
} }
......
...@@ -440,11 +440,11 @@ void resource_lp_configure(){ ...@@ -440,11 +440,11 @@ void resource_lp_configure(){
} }
for (uint64_t i = 0; i < anno_map->num_annos; i++){ for (uint64_t i = 0; i < anno_map->num_annos; i++){
ret = configuration_get_value_longint(&config, RESOURCE_LP_NM, ret = configuration_get_value_longint(&config, RESOURCE_LP_NM,
"available", anno_map->annotations[i], &avail); "available", anno_map->annotations[i].ptr, &avail);
if (ret){ if (ret){
fprintf(stderr, fprintf(stderr,
"Could not find section:resource value:available@%s for " "Could not find section:resource value:available@%s for "
"resource LP\n", anno_map->annotations[i]); "resource LP\n", anno_map->annotations[i].ptr);
exit(1); exit(1);
} }
assert(avail > 0); assert(avail > 0);
......
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