diff --git a/src/plugins/select/bluegene/bluegene.c b/src/plugins/select/bluegene/bluegene.c index b67d15647a938b762bcbe3c8cb0925c6769c4d04..4a0d0b781c853d3c991c6952b05262285ff01e02 100644 --- a/src/plugins/select/bluegene/bluegene.c +++ b/src/plugins/select/bluegene/bluegene.c @@ -28,6 +28,7 @@ #include "src/common/list.h" #include "src/common/read_config.h" #include "src/common/parse_spec.h" +#include "src/common/xstring.h" #include "bluegene.h" #include "partition_sys.h" #include "src/common/hostlist.h" @@ -35,10 +36,9 @@ #define RANGE_MAX 8192 #define BUF_SIZE 4096 -/* "etc/bluegene.conf"; */ char* bgl_conf = BLUEGENE_CONFIG_FILE; -/** some internally used functions */ + /** some internally used functions */ /** */ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_bitmap, @@ -51,7 +51,7 @@ int _get_request_dimensions(int* bl, int* tr, uint16_t** dim); /** */ int _extract_range(char* request, char** result); /** */ -int _create_bgl_partitions(); +int _wire_bgl_partitions(); /** */ void _get_bitmap(hostlist_t* hostlist, bitstr_t* bitmap); /** */ @@ -61,9 +61,9 @@ int _bgl_record_cmpf_dec(bgl_record_t* A, bgl_record_t* B); /** * to be used by list object to destroy the array elements */ -void _bgl_record_destroy(void* object); +void _destroy_bgl_record(void* object); /** */ -void _bgl_conf_record_destroy(void* object); +void _destroy_bgl_conf_record(void* object); /** */ void _print_bitmap(bitstr_t* bitmap); @@ -71,13 +71,13 @@ void _print_bitmap(bitstr_t* bitmap); /** */ void _process_config(); /** */ -static int _parse_bgl_spec(char *in_line); +int _parse_bgl_spec(char *in_line); /** */ -static int _copy_slurm_partition_list(); +int _copy_slurm_partition_list(); /** */ int _find_part_type(char* nodes, rm_partition_t** return_part_type); /** */ -static int _ListFindF_conf_part_record(bgl_conf_record_t* record, char *nodes); +int _listfindf_conf_part_record(bgl_conf_record_t* record, char *nodes); /** */ int _compute_part_size(char* nodes); @@ -94,18 +94,19 @@ int create_static_partitions() if (bgl_list){ list_destroy(bgl_list); } - bgl_list = list_create(_bgl_record_destroy); + bgl_list = list_create(_destroy_bgl_record); /** copy the slurm conf partition info, this will fill in bgl_list */ if (_copy_slurm_partition_list()){ return SLURM_ERROR; } - + _process_config(); /* after reading in the configuration, we have a list of partition requests (List <int*>) * that we can use to partition up the system */ - _create_bgl_partitions(); + _wire_bgl_partitions(); + return SLURM_SUCCESS; } @@ -113,13 +114,14 @@ int create_static_partitions() /** * IN - requests: list of bgl_record(s) */ -int _create_bgl_partitions() +int _wire_bgl_partitions() { bgl_record_t* cur_record; partition_t* cur_partition; - printf("bluegene::create_bgl_partitions\n"); + ListIterator itr; + debug("bluegene::wire_bgl_partitions"); - ListIterator itr = list_iterator_create(bgl_list); + itr = list_iterator_create(bgl_list); while ((cur_record = (bgl_record_t*) list_next(itr))) { cur_partition = (partition_t*) cur_record->alloc_part; if (configure_switches(cur_partition)){ @@ -128,7 +130,7 @@ int _create_bgl_partitions() } list_iterator_destroy(itr); - printf("create_bgl_partitions done\n"); + debug("wire_bgl_partitions done"); return SLURM_SUCCESS; } @@ -144,7 +146,7 @@ void _process_config() { ListIterator itr; bgl_record_t *bgl_part; - partition_t* request; + partition_t* request_result; itr = list_iterator_create(bgl_list); while ((bgl_part = (bgl_record_t*) list_next(itr))) { @@ -152,16 +154,17 @@ void _process_config() * parse request will fill up the partition_t's * bl_coord, tr_coord, dimensions, and size */ - if (_parse_request(bgl_part->nodes, &request) || request == NULL) - error("_process_config: error parsing request %s\n", bgl_part->nodes); - - /** - * bgl_part->part_type should have been extracted in - * copy_slurm_partition_list - */ - request->part_type = (rm_partition_t*) bgl_part->part_type; - request->bgl_record_ptr = bgl_part; - bgl_part->alloc_part = request; + if (_parse_request(bgl_part->nodes, &request_result) || request_result == NULL){ + error("_process_config: error parsing request %s", bgl_part->nodes); + } else { + /** + * bgl_part->part_type should have been extracted in + * copy_slurm_partition_list + */ + request_result->bgl_record_ptr = bgl_part; + request_result->part_type = (rm_partition_t*) bgl_part->part_type; + bgl_part->alloc_part = request_result; + } } list_iterator_destroy(itr); } @@ -170,16 +173,16 @@ void _process_config() * that we can maintain our own separate table of bgl_part_id to * slurm_part_id. */ -static int _copy_slurm_partition_list() +int _copy_slurm_partition_list() { struct part_record* slurm_part; bgl_record_t* bgl_record; ListIterator itr; - char* cur_nodes, *delimiter=",", *nodes_tmp, *next_ptr; - int err; + char* cur_nodes, *delimiter=",", *nodes_tmp, *next_ptr, *orig_ptr; + int err, rc; if (!slurm_part_list){ - error("_copy_slurm_partition_list: slurm_part_list is not initialized yet\n"); + error("_copy_slurm_partition_list: slurm_part_list is not initialized yet"); return SLURM_ERROR; } itr = list_iterator_create(slurm_part_list); @@ -188,16 +191,20 @@ static int _copy_slurm_partition_list() * nodes specified in the slurm_part_list, but if not * found, _find_part_type will default to RM_MESH */ + rc = SLURM_SUCCESS; while ((slurm_part = (struct part_record *) list_next(itr))) { - nodes_tmp = strdup(slurm_part->nodes); + nodes_tmp = xstrdup(slurm_part->nodes); + orig_ptr = nodes_tmp; cur_nodes = strtok_r(nodes_tmp, delimiter, &next_ptr); /** debugging info */ + /* { - debug("current slurm nodes to parse <%s>\n", slurm_part->nodes); - debug("slurm_part->node_bitmap"); - _print_bitmap(slurm_part->node_bitmap); + debug("current slurm nodes to parse <%s>", slurm_part->nodes); + debug("slurm_part->node_bitmap"); + _print_bitmap(slurm_part->node_bitmap); } + */ // debug("received token"); // debug("received token <%s>", cur_nodes); /** @@ -215,7 +222,7 @@ static int _copy_slurm_partition_list() goto cleanup_while; } - bgl_record->nodes = strdup(cur_nodes); + bgl_record->nodes = xstrdup(cur_nodes); bgl_record->slurm_part_id = slurm_part->name; bgl_record->part_type = (rm_partition_t*) xmalloc(sizeof(rm_partition_t)); if (!bgl_record->part_type){ @@ -244,20 +251,27 @@ static int _copy_slurm_partition_list() bgl_record->part_lifecycle = DYNAMIC; // print_bgl_record(bgl_record); list_push(bgl_list, bgl_record); + cleanup_while: - // dunno if we have to free this after inserting into the list - // free(bgl_record); - // bgl_record = NULL; - /* free(nodes_tmp); why does this interfere with strtok_r */ nodes_tmp = next_ptr; cur_nodes = strtok_r(nodes_tmp, delimiter, &next_ptr); if (err) { - return SLURM_ERROR; + rc = SLURM_ERROR; + goto cleanup; } + + } /* end while(cur_nodes) */ + + cleanup: + if (orig_ptr){ + xfree(orig_ptr); + orig_ptr = NULL; } - } + + } /* end while(slurm_part) */ list_iterator_destroy(itr); - return SLURM_SUCCESS; + + return rc; } int read_bgl_conf() @@ -310,7 +324,7 @@ int read_bgl_conf() /* parse what is left, non-comments */ /* partition configuration parameters */ if ((error_code = _parse_bgl_spec(in_line))) { - error("_parse_bgl_spec error, skipping this line\n"); + error("_parse_bgl_spec error, skipping this line"); } @@ -340,7 +354,7 @@ int read_bgl_conf() * global: part_list - global partition list pointer * default_part - default parameters for a partition */ -static int _parse_bgl_spec(char *in_line) +int _parse_bgl_spec(char *in_line) { int error_code = SLURM_SUCCESS; char *nodes = NULL, *part_type = NULL; @@ -359,8 +373,8 @@ static int _parse_bgl_spec(char *in_line) return error_code; } - // debug("parsed nodes %s\n", nodes); - // debug("partition type %s\n", part_type); + // debug("parsed nodes %s", nodes); + // debug("partition type %s", part_type); new_record = (bgl_conf_record_t*) xmalloc(sizeof(bgl_conf_record_t)); if (!new_record){ @@ -368,7 +382,7 @@ static int _parse_bgl_spec(char *in_line) return SLURM_ERROR; } - new_record->nodes = strdup(nodes); + new_record->nodes = xstrdup(nodes); new_record->part_type = xmalloc(sizeof(rm_partition_t)); if (strcasecmp(part_type, "TORUS") == 0){ // error("warning, TORUS specified, but I can't handle those yet! Defaulting to mesh"); @@ -389,7 +403,7 @@ static int _parse_bgl_spec(char *in_line) return SLURM_SUCCESS; } -void _bgl_record_destroy(void* object) +void _destroy_bgl_record(void* object) { bgl_record_t* this_record = (bgl_record_t*) object; if (this_record){ @@ -413,7 +427,7 @@ void _bgl_record_destroy(void* object) xfree(this_record); } -void _bgl_conf_record_destroy(void* object) +void _destroy_bgl_conf_record(void* object) { bgl_conf_record_t* this_record = (bgl_conf_record_t*) object; if (this_record){ @@ -434,7 +448,7 @@ int _find_part_type(char* nodes, rm_partition_t** return_part_type) bgl_conf_record_t* record = NULL; record = (bgl_conf_record_t*) list_find_first(bgl_conf_list, - (ListFindF) _ListFindF_conf_part_record, + (ListFindF) _listfindf_conf_part_record, nodes); *return_part_type = (rm_partition_t*) xmalloc(sizeof(rm_partition_t)); @@ -454,7 +468,7 @@ int _find_part_type(char* nodes, rm_partition_t** return_part_type) } /** nodes example: 000x111 */ -static int _ListFindF_conf_part_record(bgl_conf_record_t* record, char *nodes) +int _listfindf_conf_part_record(bgl_conf_record_t* record, char *nodes) { return (!strcasecmp(record->nodes, nodes)); } @@ -476,21 +490,22 @@ int _compute_part_size(char* nodes) */ int char2intptr(char* request, int** bl, int** tr) { - int i; - char *request_tmp, *delimit = "x,", *next_ptr; + int i, rc; + char *request_tmp, *delimit = ",x", *next_ptr, *orig_ptr; char zero = '0'; char* token; - //request_tmp = (char*) xmalloc(sizeof(char) * strlen(request)); - request_tmp = strdup(request); + + rc = SLURM_ERROR; + request_tmp = xstrdup(request); (*bl) = (int*) xmalloc(sizeof(int) * SYSTEM_DIMENSIONS); (*tr) = (int*) xmalloc(sizeof(int) * SYSTEM_DIMENSIONS); if (!request_tmp || !bl || !tr){ - error("char2intptr: not enough memory for char2intptr"); - return SLURM_ERROR; + error("char2intptr: not enough memory for new structs"); + goto cleanup; } - - // printf("char2intptr request <%s>\n", request_tmp); + + orig_ptr = request_tmp; token = strtok_r(request_tmp, delimit, &next_ptr); if (token == NULL) goto cleanup; @@ -507,36 +522,48 @@ int char2intptr(char* request, int** bl, int** tr) for (i=0; i<SYSTEM_DIMENSIONS; i++){ (*tr)[i] = (int)(token[i]-zero); } - return SLURM_SUCCESS; + + rc = SLURM_SUCCESS; cleanup: - error("char2intptr request string insufficient dimensions"); - xfree(request_tmp); - xfree(bl); - xfree(tr); - bl = NULL; tr = NULL; - return SLURM_ERROR; + if (rc == SLURM_ERROR){ + xfree(bl); + xfree(tr); + bl = NULL; tr = NULL; + } + + if (orig_ptr != NULL){ + xfree(orig_ptr); + } + + return rc; } /** - * tmp is of form ABCxXYZ - * + * parses the request_string */ -int _parse_request(char* request_string, partition_t** request) +int _parse_request(char* request_string, partition_t** request_result) { char* range; int *bl=NULL, *tr=NULL; uint16_t *dim=NULL; - int i; - (*request) = (partition_t*) xmalloc(sizeof(partition_t)); - if (!(*request)) { + int i, rc; + + rc = SLURM_ERROR; + if (!request_string) + goto cleanup; + + debug("incoming request %s", request_string); + (*request_result) = (partition_t*) xmalloc(sizeof(partition_t)); + if (!(*request_result)) { error("parse_request: not enough memory for request"); - return SLURM_ERROR; + goto cleanup; } - + /** token needs to be of the form 000x000 */ - if(_extract_range(request_string, &range)) - return SLURM_ERROR; + if(_extract_range(request_string, &range)){ + goto cleanup; + } if (char2intptr(range, &bl, &tr) || bl == NULL || tr == NULL || _get_request_dimensions(bl, tr, &dim)){ @@ -545,22 +572,36 @@ int _parse_request(char* request_string, partition_t** request) /** place all the correct values into the request */ for (i=0; i<SYSTEM_DIMENSIONS; i++){ - (*request)->bl_coord[i] = bl[i]; - (*request)->tr_coord[i] = tr[i]; - (*request)->dimensions[i] = dim[i]; + (*request_result)->bl_coord[i] = bl[i]; + (*request_result)->tr_coord[i] = tr[i]; + (*request_result)->dimensions[i] = dim[i]; } - (*request)->size = intArray_size(dim); - return SLURM_SUCCESS; - + (*request_result)->size = int_array_size(dim); + rc = SLURM_SUCCESS; + cleanup: - xfree(bl); - xfree(tr); - xfree(request); - xfree(dim); - bl = NULL; tr = NULL; dim = NULL; - request = NULL; - return SLURM_ERROR; + if (bl) { + xfree(bl); + bl = NULL; + } + if (tr) { + xfree(tr); + tr = NULL; + } + if (dim) { + xfree(dim); + dim = NULL; + } + if (range){ + xfree(range); + range = NULL; + } + if (rc == SLURM_ERROR){ + xfree(request_result); + request_result = NULL; + } + return rc; } int _get_request_dimensions(int* bl, int* tr, uint16_t** dim) @@ -600,16 +641,16 @@ int _get_request_dimensions(int* bl, int* tr, uint16_t** dim) int init_bgl() { - /** global variable */ - bgl_conf_list = (List) list_create(_bgl_conf_record_destroy); - #ifdef _RM_API_H__ - int rc = rm_get_BGL(&bgl); + int rc; + rc = rm_get_BGL(&bgl); if (rc != STATUS_OK){ - error("init_bgl: rm_get_BGL failed\n"); + error("init_bgl: rm_get_BGL failed"); return SLURM_ERROR; } #endif + /** global variable */ + bgl_conf_list = (List) list_create(_destroy_bgl_conf_record); return SLURM_SUCCESS; } @@ -621,9 +662,9 @@ int _extract_range(char* request, char** result) int start = 0, end = 0; if (!request) - return 1; + return SLURM_ERROR; if (!(*result)) { - *result = (char*) xmalloc(sizeof(RANGE_SIZE)); + *result = (char*) xmalloc(sizeof(RANGE_SIZE) + 1); if (!(*result)) { error("_extract_range: not enough memory for *result"); return SLURM_ERROR; @@ -680,7 +721,7 @@ void print_bgl_record(bgl_record_t* record) if (record->alloc_part){ debug(" \talloc_part:"); - printPartition(record->alloc_part); + print_partition(record->alloc_part); } else { debug(" \talloc_part: NULL"); } @@ -760,7 +801,6 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ error("FIXME: well, bad bad bad..."); continue; } - debug("A"); /** * first we check against the bitmap to see * if this partition can be used for this job. @@ -772,16 +812,15 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ * mean that some nodes in the slurm bitmap have been * "drained" or set otherwise unusable. */ - debug("- - - - - - - - - - - - -"); - debug("check partition bitmap"); - _print_bitmap(record->bitmap); - debug("superset? %d", (bit_super_set(record->bitmap, slurm_part_bitmap))); + // debug("- - - - - - - - - - - - -"); + // debug("check partition bitmap"); + // _print_bitmap(record->bitmap); if (!bit_super_set(record->bitmap, slurm_part_bitmap)){ debug("bgl partition %s unusable", record->nodes); continue; } - - debug("- - - - - - - - - - - - -"); + // debug("- - - - - - - - - - - - -"); + /*******************************************/ /** check that the number of nodes match */ /*******************************************/ @@ -791,7 +830,6 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ error("debug request num nodes doesn't fit"); continue; } - debug("C"); /***********************************************/ /* check the connection type specified matches */ /***********************************************/ @@ -806,7 +844,6 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ job_ptr->conn_type != RM_NAV){ continue; } - debug("E"); /*****************************************/ /** match up geometry as "best" possible */ /*****************************************/ @@ -815,12 +852,10 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ found_bgl_record = record; break; } - debug("F"); if (job_ptr->rotate) rotate_part(job_ptr->geometry, &geometry); cur_dim_match = 0; - debug("G"); for (i=0; i<SYSTEM_DIMENSIONS; i++){ if (!record->alloc_part) { error("warning, bgl_record %s has not found a home...", @@ -843,7 +878,6 @@ int _find_best_partition_match(struct job_record* job_ptr, bitstr_t* slurm_part_ if (num_dim_best == SYSTEM_DIMENSIONS) break; } - debug("H"); } /** set the bitmap and do other allocation activities */ @@ -916,9 +950,8 @@ int submit_job(struct job_record *job_ptr, bitstr_t *slurm_part_bitmap, int min_nodes, int max_nodes) { int spec = 1; // this will be like, keep TYPE a priority, etc, blah blah. - - ListIterator itr; bgl_record_t* record; + debug("bluegene::submit_job"); /* itr = list_iterator_create(bgl_list); @@ -974,6 +1007,7 @@ void update_bgl_node_bitmap(bitstr_t* bitmap) rm_BP_t *my_bp; rm_switch_t *my_switch; rm_wire_t *my_wire; + rm_BP_state_t bp_state; // rm_size3D_t bp_size,size_in_bp,m_size; // rm_size3D_t bp_size,size_in_bp,m_size; @@ -981,22 +1015,21 @@ void update_bgl_node_bitmap(bitstr_t* bitmap) error("error, BGL is not initialized"); } - printf("---------rm_get_BGL------------\n"); + debug("---------rm_get_BGL------------"); // rm_get_data(bgl,RM_BPsize,&bp_size); // rm_get_data(bgl,RM_Msize,&m_size); - printf("BP Size = (%d x %d x %d)\n",bp_size.X,bp_size.Y,bp_size.Z); + debug("BP Size = (%d x %d x %d)",bp_size.X,bp_size.Y,bp_size.Z); rm_get_data(bgl,RM_BPNum,&bp_num); - printf("- - - - - BPS (%d) - - - - - -\n",bp_num); + debug("- - - - - BPS (%d) - - - - - -",bp_num); for(i=0;i<bp_num;i++){ if(i==0) rm_get_data(bgl,RM_FirstBP,&my_bp); else rm_get_data(bgl,RM_NextBP,&my_bp); - rm_BP_state_t bp_state; - + // is this blocking call? rm_get_data(my_bp,RM_BPState,&bp_state); rm_get_data(my_bp,RM_BPState,&bp_state); diff --git a/src/plugins/select/bluegene/partition_sys.c b/src/plugins/select/bluegene/partition_sys.c index 6a9ecd60d8ec2bc247461a4b2bb185c9d69af3cb..c070bf79e8cbec4cbce5ef0e9ead2a0323da2915 100755 --- a/src/plugins/select/bluegene/partition_sys.c +++ b/src/plugins/select/bluegene/partition_sys.c @@ -70,12 +70,12 @@ List bgl_sys_free = NULL; List bgl_sys_allocated = NULL; void _init_sys(partition_t*); -int _isNotEqualsAllCoord(uint16_t* A, uint16_t* B); -int _isNotEqualsSomeCoord(uint16_t* A, uint16_t* B); +int _is_not_equals_all_coord(uint16_t* A, uint16_t* B); +int _is_not_equals_some_coord(uint16_t* A, uint16_t* B); #ifdef _RM_API_H__ /** - * _get_BP: get the BP at location loc + * _get_bp: get the BP at location loc * * IN - bgl: pointer to preinitialized bgl pointer * IN - bp: pointer to preinitailized rm_element_t that will @@ -84,38 +84,37 @@ int _isNotEqualsSomeCoord(uint16_t* A, uint16_t* B); * OUT - bp: will point to BP at location loc * OUT - rc: error code (0 = success) */ -int _get_BP(rm_element_t *bp, rm_location_t *loc); -int check_BP_status(rm_location_t *loc); -void pre_allocate(rm_partition_t* my_part, rm_connection_type_t* part_conn); -int post_allocate(rm_partition_t *my_part, pm_partition_id_t *part_id); -int get_switch(partition_t* partition, List switch_list); -int get_BP_by_location(int* cur_coord, rm_BP_t* BP); -void rm_switch_t_destroy(void* object); +int _get_bp(rm_element_t *bp, rm_location_t *loc); +int _check_bp_status(rm_location_t *loc); +void _pre_allocate(rm_partition_t* my_part, rm_connection_type_t* part_conn); +int _post_allocate(rm_partition_t *my_part, pm_partition_id_t *part_id); +int _get_switch(partition_t* partition, List switch_list); +int _get_bp_by_location(int* cur_coord, rm_BP_t* BP); +void _rm_switch_t_destroy(void* object); #else -int create_bgl_partitions(List requests); +int _create_bgl_partitions(List requests); #endif -int break_up_partition(List sys, partition_t* partition_to_break, int index); -int fit_request(List sys, List allocated, uint16_t* request); +int _break_up_partition(List sys, partition_t* partition_to_break, int index); +int _fit_request(List sys, List allocated, uint16_t* request); +void _int_array_destroy(void* object); +int _int_array_cmpf(uint16_t* A, uint16_t* B); -void int_array_destroy(void* object); -int intArray_CmpF(uint16_t* A, uint16_t* B); - -int partition_CmpF_inc(struct partition* A, struct partition* B); -int partition_CmpF_dec(struct partition* A, struct partition* B); +int _partition_cmpf_inc(struct partition* A, struct partition* B); +int _partition_cmpf_dec(struct partition* A, struct partition* B); #ifdef _RM_API_H__ -void preallocate(rm_BGL_t* bgl, rm_partition_t* my_part, +void _preallocate(rm_BGL_t* bgl, rm_partition_t* my_part, char* username, rm_connection_type_t* part_conn); -int postallocate(rm_BGL_t *bgl, rm_partition_t *my_part, +int _postallocate(rm_BGL_t *bgl, rm_partition_t *my_part, pm_partition_id_t *part_id); #endif -List get_bgl_sys_free(); -List get_bgl_sys_allocated(); +List _get_bgl_sys_free(); +List _get_bgl_sys_allocated(); #ifdef _UNIT_TESTS_ void debug(const char *fmt, ...); #endif @@ -150,14 +149,16 @@ int partition_sys(List requests) ListIterator itr; partition_t part; + uint16_t* request; + int all_success = 0; // 0 = yes, 1 = no /* 1) we sort in decreasing order by size */ - sortIntArrayByDecSize(requests); + sort_int_array_by_dec_size(requests); /* initialize the starting system */ _init_sys(&part); if (bgl_sys_allocated == NULL) - error("list_create failed for bgl_sys_allocated\n"); + error("list_create failed for bgl_sys_allocated"); /* 2) for each partition configuration, place them in * order @@ -165,27 +166,24 @@ int partition_sys(List requests) itr = list_iterator_create(requests); #ifdef DEBUG_PART - debug("REQUESTS: \n"); - printList(requests); + debug("REQUESTS: "); + print_list(requests); #endif - - uint16_t* request; - int all_success = 0; // 0 = yes, 1 = no while ((request = (uint16_t*) list_next(itr))) { - if (fit_request(bgl_sys_free, bgl_sys_allocated, request)){ + if (_fit_request(bgl_sys_free, bgl_sys_allocated, request)){ #ifdef DEBUG_PART - debug("failure in allocation!!!\n"); + debug("failure in allocation!!!"); #endif all_success = 1; } else { #ifdef DEBUG_PART - debug("success in allocation\n"); + debug("success in allocation"); #endif } } list_iterator_destroy(itr); - create_bgl_partitions(bgl_sys_allocated); + _create_bgl_partitions(bgl_sys_allocated); return all_success; } @@ -194,12 +192,13 @@ int partition_sys(List requests) * IN - requests: List <partition_t*> to wire up. * */ -int create_bgl_partitions(List requests) +int _create_bgl_partitions(List requests) { partition_t* cur_partition; + ListIterator itr; - printf("partition_sys::create_bgl_partitions\n"); - ListIterator itr = list_iterator_create(requests); + debug("partition_sys::_create_bgl_partitions"); + itr = list_iterator_create(requests); while ((cur_partition = (partition_t*) list_next(itr))) { configure_switches(cur_partition); } @@ -219,45 +218,47 @@ int create_bgl_partitions(List requests) * we assume that the partitioning done before hand * */ -int fit_request(List sys, List allocated, uint16_t* request) +int _fit_request(List sys, List allocated, uint16_t* request) { + int i, rc = 1; + uint16_t* new_request; + int request_size = int_array_size(request); + partition_t* cur_partition; + ListIterator itr; + partition_t* partition_to_break = NULL; + int partition_dim_max = -1; + int max_index = SYSTEM_DIMENSIONS; /* we want the earliest, so we'll + * set a good high point as the farthest + * dimesion */ + + if (sys == NULL || allocated == NULL || request == NULL) return 1; - int i, rc = 1; /** print out the request */ #ifdef DEBUG_PART debug("\nTrying to fit [ %d", request[0]); for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", request[i]); } - // debug(" ]\n"); - debug("current system list\n"); - printSysList(sys); + debug(" ]\n"); + debug("current system list"); + print_sys_list(sys); #endif /* ??? FIXME wtf, if rotate_part doesn't have something printed before it....it segfaults */ debug(""); - uint16_t* new_request; rotate_part(request, &new_request); xfree(request); request = new_request; /** */ - ListIterator itr = list_iterator_create(sys); - int request_size = intArray_size(request); - partition_t* cur_partition; - /** this stuff is for knowing which partition we want to select to break */ - partition_t* partition_to_break = NULL; - int partition_dim_max = -1; - int max_index = SYSTEM_DIMENSIONS; /* we want the earliest, so we'll - * set a good high point as the farthest - * dimesion */ + itr = list_iterator_create(sys); while ((cur_partition = (partition_t*) list_next(itr))) { - if (!isNotCorrectDimension(cur_partition->dimensions, request)){ + if (!is_not_correct_dimension(cur_partition->dimensions, request)){ #ifdef DEBUG_PART debug("\n!!!!!!!!!!!!!!!!!\n! FOUND FIT !\n!!!!!!!!!!!!!!!!!\n"); - printPartition(cur_partition); + print_partition(cur_partition); #endif list_push(allocated, cur_partition); @@ -300,16 +301,12 @@ int fit_request(List sys, List allocated, uint16_t* request) */ if (rc != 0 && partition_to_break != NULL){ /* break up the partition and do the RECURSIVE CALL! */ - break_up_partition(sys, partition_to_break, max_index); - rc = fit_request(sys, allocated, request); + _break_up_partition(sys, partition_to_break, max_index); + rc = _fit_request(sys, allocated, request); /** ??? FIXME, if something is not printed, the program will segfault, looks like * stdout just needs to be flushed or something */ /** 999 */ - debug(""); -#ifdef DEBUG_PART - ; -#endif } return rc; } @@ -323,38 +320,41 @@ int fit_request(List sys, List allocated, uint16_t* request) * odd number sizes, and dimensions will kill this!!! * */ -int break_up_partition(List sys, partition_t* partition_to_break, int index) +int _break_up_partition(List sys, partition_t* partition_to_break, int index) { + /* the two new partitions to create */ + partition_t *first_part, *second_part; + double diff; + partition_t* next; + ListIterator itr; + if (sys == NULL || partition_to_break == NULL) return 1; - /* the two new partitions to create */ - partition_t *first_part, *second_part; first_part = (partition_t*) xmalloc(sizeof(partition_t)); second_part = (partition_t*) xmalloc(sizeof(partition_t)); if (!first_part || !second_part){ - error("break_up_partition: not enough memory to break up partitions"); + error("_break_up_partition: not enough memory to break up partitions"); return 1; } - copyPartition(partition_to_break, first_part); - copyPartition(partition_to_break, second_part); + copy_partition(partition_to_break, first_part); + copy_partition(partition_to_break, second_part); first_part->size /= 2; second_part->size /= 2; first_part->dimensions[index] /= 2; second_part->dimensions[index] /= 2; - double diff = partition_to_break->tr_coord[index] - partition_to_break->bl_coord[index]; + diff = partition_to_break->tr_coord[index] - partition_to_break->bl_coord[index]; first_part->tr_coord[index] = floor(diff/2); second_part->bl_coord[index] = ceil(diff/2); - ListIterator itr; - partition_t* next; + itr = list_iterator_create(sys); while ((next = (partition_t*) list_next(itr))) { - if(!isNotCorrectDimension(next->dimensions, partition_to_break->dimensions)){ + if(!is_not_correct_dimension(next->dimensions, partition_to_break->dimensions)){ /* next we remove the old partition */ list_remove(itr); @@ -368,27 +368,28 @@ int break_up_partition(List sys, partition_t* partition_to_break, int index) return 0; } -void printPartition(partition_t* part) +void print_partition(partition_t* part) { if (part == NULL) return; - debug("\tdimensions: [ %d %d %d ]\n", part->dimensions[0], + debug("\tdimensions: [ %d %d %d ]", part->dimensions[0], part->dimensions[1], part->dimensions[2]); - debug("\tbl coord: [ %d %d %d ]\n", part->bl_coord[0], + debug("\tbl coord: [ %d %d %d ]", part->bl_coord[0], part->bl_coord[1], part->bl_coord[2]); - debug("\ttr coord: [ %d %d %d ]\n", part->tr_coord[0], + debug("\ttr coord: [ %d %d %d ]", part->tr_coord[0], part->tr_coord[1], part->tr_coord[2]); - debug("\tsize: %d\n", part->size); - debug("\tbgl_record_ptr addr: %d\n", part->bgl_record_ptr); + debug("\tsize: %d", part->size); + debug("\tbgl_record_ptr addr: %d", part->bgl_record_ptr); } -void copyPartition(partition_t* src, partition_t* dest) +void copy_partition(partition_t* src, partition_t* dest) { + int i; + if (src == NULL || dest == NULL) return; - int i; for (i=0; i<SYSTEM_DIMENSIONS; i++){ dest->bl_coord[i] = src->bl_coord[i]; dest->tr_coord[i] = src->tr_coord[i]; @@ -400,7 +401,7 @@ void copyPartition(partition_t* src, partition_t* dest) /** * returns 0 for equals, 1 for not equals */ -int isPartitionNotEquals(partition_t* A, partition_t* B) +int is_partition_not_equals(partition_t* A, partition_t* B) { if (A == NULL || B == NULL) return 1; @@ -415,13 +416,13 @@ int isPartitionNotEquals(partition_t* A, partition_t* B) /** * return - the int array's size */ -int intArray_size(uint16_t* part_geometry){ - if (part_geometry == NULL) - return 0; - +int int_array_size(uint16_t* part_geometry){ int size = 1; int i; + if (part_geometry == NULL) + return 0; + for(i=0; i<SYSTEM_DIMENSIONS; i++){ size *= part_geometry[i]; } @@ -432,16 +433,19 @@ int intArray_size(uint16_t* part_geometry){ /** * print out a list */ -void printList(List list) +void print_list(List list) { + int* stuff = NULL, i = 0; + ListIterator itr; + if (list == NULL) return; - debug("trying to get the list iterator\n"); - ListIterator itr = list_iterator_create(list); - debug("doen\n"); - int* stuff = NULL, i = 0; - debug("printing list\n"); + debug("trying to get the list iterator"); + itr = list_iterator_create(list); + debug("done"); + + debug("printing list"); while ((stuff = (int*) list_next(itr))) { debug("stuff %d", stuff); if (stuff == NULL){ @@ -452,7 +456,7 @@ void printList(List list) for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", stuff[i]); } - debug(" ]\n"); + debug(" ]"); } list_iterator_destroy(itr); } @@ -460,16 +464,18 @@ void printList(List list) /** * print out list of the system partitions */ -void printSysList(List list) +void print_sys_list(List list) { + ListIterator itr; + int i, part_count=0; + partition_t* stuff; + if (list == NULL){ - debug("List is empty (NULL)\n"); + debug("List is empty (NULL)"); return; } - ListIterator itr = list_iterator_create(list); - int i, part_count=0; - partition_t* stuff; + itr = list_iterator_create(list); while ((stuff = (partition_t*) list_next(itr))) { if (stuff == NULL){ break; @@ -479,19 +485,19 @@ void printSysList(List list) for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", stuff->dimensions[i]); } - debug(" ]\n"); + debug(" ]"); debug("bl coord [ %d", stuff->bl_coord[0]); for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", stuff->bl_coord[i]); } - debug(" ]\n"); + debug(" ]"); debug("tr coord [ %d", stuff->tr_coord[0]); for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", stuff->tr_coord[i]); } - debug(" ]\n"); + debug(" ]"); } list_iterator_destroy(itr); @@ -500,10 +506,10 @@ void printSysList(List list) /** * sort the configurations by decreasing size */ -void sortIntArrayByDecSize(List configs){ +void sort_int_array_by_dec_size(List configs){ if (configs == NULL) return; - list_sort(configs, (ListCmpF) intArray_CmpF); + list_sort(configs, (ListCmpF) _int_array_cmpf); } /** @@ -514,13 +520,15 @@ void sortIntArrayByDecSize(List configs){ * Note: return values are "reversed" so that we can have the list * sorted in decreasing order (largest to smallest) */ -int intArray_CmpF(uint16_t* A, uint16_t* B) +int _int_array_cmpf(uint16_t* A, uint16_t* B) { + int volA, volB; + if (A == NULL || B == NULL) return -9; - int volA = intArray_size(A); - int volB = intArray_size(B); + volA = int_array_size(A); + volB = int_array_size(B); if (volA > volB) return -1; else if (volA < volB) @@ -537,21 +545,23 @@ int intArray_CmpF(uint16_t* A, uint16_t* B) #ifdef _RM_API_H__ int configure_switches(rm_partition_t* partition, partition_t* partition) #else - int configure_switches(partition_t* partition) +int configure_switches(partition_t* partition) #endif { - if (partition == NULL){ - return 1; - } - + bgl_record_t* bgl_rec; int cur_coord[SYSTEM_DIMENSIONS]; pm_partition_id_t* bgl_part_id; #ifdef _RM_API_H__ BGL_switch_t* bgl_switch; rm_partition_t *bgl_part; + pre_allocate(bgl_part, cur_partition->part_type); #endif + if (partition == NULL){ + return 1; + } + /** FIXME * right now the loop is (for example): * for bl: 102 to tr 323 (dim = 3x3x2 volume = 18) @@ -586,10 +596,11 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) /***** BGL SPECIFIC ******/ /** below, we wire up each all three switches of each BP **/ /* SPECIAL CASE FIRST BP */ - if (!_isNotEqualsSomeCoord(cur_coord, partition->bl_coord)){ + if (!_is_not_equals_some_coord(cur_coord, partition->bl_coord)){ List switch_list; ListIterator itr; rm_switch_t* cur_switch; + if (get_switch(cur_coord, switch_list)){ error("configure_switches, error in getting bgl switch"); } @@ -633,7 +644,7 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) * bgl_part_id */ /* SPECIAL CASE END BP */ - } else if (!_isNotEqualsSomeCoord(cur_coord, partition->tr_coord)){ + } else if (!_is_not_equals_some_coord(cur_coord, partition->tr_coord)){ ; /* NORMAL CASE, IN BETWEEN */ @@ -645,21 +656,21 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) #ifdef DEBUG_ALLOCATE /***** DEBUG SPECIFIC (PRINT OUT RESULTS) ******/ /* SPECIAL CASE FIRST BP */ - if (!_isNotEqualsSomeCoord(cur_coord, partition->bl_coord)){ + if (!_is_not_equals_some_coord(cur_coord, partition->bl_coord)){ debug("allocate: connecting 1-3 of BP %d", cur_coord[0]); for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", cur_coord[i]); } - debug("\n"); + debug(""); /* SPECIAL CASE END BP */ - } else if (!_isNotEqualsSomeCoord(cur_coord, partition->tr_coord)){ + } else if (!_is_not_equals_some_coord(cur_coord, partition->tr_coord)){ debug("allocate: connecting 0-4 of BP %d", cur_coord[0]); for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", cur_coord[i]); } - debug("\n"); + debug(""); /* NORMAL CASE, IN BETWEEN */ } else { @@ -667,7 +678,7 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) for (i=1; i<SYSTEM_DIMENSIONS; i++){ debug(" x %d", cur_coord[i]); } - debug("\n"); + debug(""); } #endif #endif @@ -678,7 +689,7 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) #ifdef _RM_API_H__ post_allocate(bgl_part, bgl_part_id); - bgl_record_t* bgl_rec = (bgl_record_t*) partition->bgl_record_ptr; + bgl_rec = (bgl_record_t*) partition->bgl_record_ptr; bgl_rec->bgl_part_id = bgl_part_id; partition->bgl_part_id = bgl_part_id; @@ -687,10 +698,9 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) bgl_part_id = (pm_partition_id_t*) xmalloc(sizeof(pm_partition_id_t)); // *bgl_part_id = (int)(rand()%100); *bgl_part_id = BGL_PARTITION_NUMBER++; - bgl_record_t* bgl_rec = (bgl_record_t*) partition->bgl_record_ptr; + bgl_rec = (bgl_record_t*) partition->bgl_record_ptr; bgl_rec->bgl_part_id = bgl_part_id; partition->bgl_part_id = bgl_part_id; - // debug("999 partition id %d\n", *bgl_part_id); #endif return 0; @@ -700,21 +710,21 @@ int configure_switches(rm_partition_t* partition, partition_t* partition) * find if the cur_part fits the same dimensions as the given request * return 0 for affirmative (correct dimension), and 1 for negative (not correct dimension) */ -int isNotCorrectDimension(uint16_t* cur_part, uint16_t* request) +int is_not_correct_dimension(uint16_t* cur_part, uint16_t* request) { - if (cur_part == NULL || request == NULL) - return 1; - int i, j; int cur_part_tmp[SYSTEM_DIMENSIONS]; + int end_of_array = SYSTEM_DIMENSIONS; + int tmp, found_match; + + if (cur_part == NULL || request == NULL) + return 1; /* copy over arrays into temporary arrays */ for(i=0; i<SYSTEM_DIMENSIONS; i++){ cur_part_tmp[i] = cur_part[i]; } - - int end_of_array = SYSTEM_DIMENSIONS; - int tmp, found_match; + for(i=0; i<SYSTEM_DIMENSIONS; i++){ found_match = 0; for(j=0; j<end_of_array; j++){ @@ -729,7 +739,6 @@ int isNotCorrectDimension(uint16_t* cur_part, uint16_t* request) } } if (!found_match){ - /* debug("didn't find match for %d\n", request[i]); */ break; } } @@ -738,10 +747,8 @@ int isNotCorrectDimension(uint16_t* cur_part, uint16_t* request) * should be 0 */ if (!end_of_array){ - /* debug("success, all elements found!\n"); */ return 0; } else { - /* debug("failure, some elements not found!\n"); */ return 1; } } @@ -787,7 +794,7 @@ void rotate_part(const uint16_t* config, uint16_t** new_config) (*new_config) = (uint16_t*) calloc(SYSTEM_DIMENSIONS, sizeof(uint16_t)); if (!(*new_config)){ - // printf("error: rotate_part: not enough memory for new array\n"); + // error("error: rotate_part: not enough memory for new array"); return; } @@ -840,7 +847,7 @@ void rotate_part(const uint16_t* config, uint16_t** new_config) void _init_sys(partition_t *part) { /* initialize the system wide partition */ - bgl_sys_free = list_create((ListDelF) int_array_destroy); + bgl_sys_free = list_create((ListDelF) _int_array_destroy); part->bl_coord[0] = 0; part->bl_coord[1] = 0; @@ -857,13 +864,13 @@ void _init_sys(partition_t *part) * the following two statements. WHY??? */ list_push(bgl_sys_free, part); - bgl_sys_allocated = list_create((ListDelF) int_array_destroy); + bgl_sys_allocated = list_create((ListDelF) _int_array_destroy); } /** * to be used by list object to destroy the array elements */ -void int_array_destroy(void* object) +void _int_array_destroy(void* object) { xfree(object); } @@ -893,7 +900,7 @@ int post_allocate(rm_partition_t *my_part, pm_partition_id_t *part_id) //Add partition record to the DB rc = rm_add_partition(my_part); if (rc != STATUS_OK){ - error("Error adding partition\n"); + error("Error adding partition"); return(-1); } @@ -901,17 +908,17 @@ int post_allocate(rm_partition_t *my_part, pm_partition_id_t *part_id) rm_get_data(my_part, RM_PartitionID, &part_id); //Initiate boot of the partition - debug("Booting Partition %s\n", part_id); + debug("Booting Partition %s", part_id); rc = pm_create_partition(part_id); if (rc != STATUS_OK){ - error("Error booting_partition partition\n"); + error("Error booting_partition partition"); return(-1); } //Wait for Partition to be booted rc = rm_get_partition(part_id, &my_part); if (rc != STATUS_OK){ - error("Error in GetPartition\n"); + error("Error in GetPartition"); return(-1); } @@ -938,7 +945,7 @@ int get_switch(int* cur_coord, List switch_list) switch_list = list_create(rm_switch_t_destroy); } - if (get_BP_by_location(cur_coord, bp)){ + if (get_bp_by_location(cur_coord, bp)){ return SLURM_ERROR; } @@ -993,10 +1000,11 @@ void rm_switch_t_destroy(void* object) * this is just stupid. there are some implicit rules for where * "NextBP" goes to, but we don't know, so we have to do this. */ -int get_BP_by_location(int* cur_coord, rm_BP_t* BP) +int get_bp_by_location(int* cur_coord, rm_BP_t* BP) { int BP_num; rm_location_t* loc; + rm_get_data(bgl, RM_BPNum, &bp_num); rm_get_data(bgl, RM_FirstBP, &BP); for (i=0; i<BP_num; i++){ @@ -1007,7 +1015,7 @@ int get_BP_by_location(int* cur_coord, rm_BP_t* BP) rm_get_data(bgl, RM_NextBP, &BP); } - error("get_BP_by_location: could not find specified BP.\n"); + error("get_bp_by_location: could not find specified BP."); return SLURM_ERROR; } #endif @@ -1017,7 +1025,7 @@ int get_BP_by_location(int* cur_coord, rm_BP_t* BP) * * returns 0 if equals, 1 if not equals */ -int _isNotEqualsSomeCoord(uint16_t* A, uint16_t* B) +int _is_not_equals_some_coord(uint16_t* A, uint16_t* B) { int i; for (i=0; i<SYSTEM_DIMENSIONS; i++){ @@ -1032,7 +1040,7 @@ int _isNotEqualsSomeCoord(uint16_t* A, uint16_t* B) * * returns 0 if equals, 1 if not equals */ -int _isNotEqualsAllCoord(uint16_t* A, uint16_t* B) +int _is_not_equals_all_coord(uint16_t* A, uint16_t* B) { int i; for (i=0; i<SYSTEM_DIMENSIONS; i++){ @@ -1045,19 +1053,19 @@ int _isNotEqualsAllCoord(uint16_t* A, uint16_t* B) /** * sort the partitions by increasing size */ -void sortPartitionsByIncSize(List parts){ +void sort_partitions_by_inc_size(List parts){ if (parts == NULL) return; - list_sort(parts, (ListCmpF) partition_CmpF_inc); + list_sort(parts, (ListCmpF) _partition_cmpf_inc); } /** * sort the partitions by decreasing size */ -void sortPartitionsByDecSize(List parts){ +void sort_partitions_by_dec_size(List parts){ if (parts == NULL) return; - list_sort(parts, (ListCmpF) partition_CmpF_dec); + list_sort(parts, (ListCmpF) _partition_cmpf_dec); } @@ -1067,7 +1075,7 @@ void sortPartitionsByDecSize(List parts){ * returns: -1: A greater than B 0: A equal to B 1: A less than B * */ -int partition_CmpF_inc(struct partition* A, struct partition* B) +int _partition_cmpf_inc(struct partition* A, struct partition* B) { if (A->size < B->size) return -1; @@ -1083,7 +1091,7 @@ int partition_CmpF_inc(struct partition* A, struct partition* B) * returns: -1: A greater than B 0: A equal to B 1: A less than B * */ -int partition_CmpF_dec(struct partition* A, struct partition* B) +int _partition_cmpf_dec(struct partition* A, struct partition* B) { if (A->size > B->size) return -1; @@ -1093,13 +1101,14 @@ int partition_CmpF_dec(struct partition* A, struct partition* B) return 0; } - -List get_bgl_sys_allocated() +/** */ +List _get_bgl_sys_allocated() { return bgl_sys_allocated; } -List get_bgl_sys_free() +/** */ +List _get_bgl_sys_free() { return bgl_sys_free; } diff --git a/src/plugins/select/bluegene/partition_sys.h b/src/plugins/select/bluegene/partition_sys.h index 54cdb5a0bd66b9bb32dcc14301723bb988e2964b..dae879e56d1ee0aead14a881000bbba519667cd0 100644 --- a/src/plugins/select/bluegene/partition_sys.h +++ b/src/plugins/select/bluegene/partition_sys.h @@ -55,19 +55,19 @@ typedef struct partition{ int configure_switches(partition_t* partition); int partition_sys(List requests); -void copyPartition(partition_t* A, partition_t* B); -void printPartition(partition_t* part); -void printList(List list); -void printSysList(List list); +void copy_partition(partition_t* A, partition_t* B); +void print_partition(partition_t* part); +void print_list(List list); +void print_sys_list(List list); -int isNotCorrectDimension(ushort* cur_part, ushort* req); -int isPartitionNotEquals(partition_t* A, partition_t* B); +int is_not_correct_dimension(ushort* cur_part, ushort* req); +int is_partition_not_equals(partition_t* A, partition_t* B); void rotate_part(const ushort* config, ushort** new_config); -int intArray_size(ushort* part_geometry); -void sortIntArrayByDecSize(List configs); -void sortPartitionsByIncSize(List partitions); -void sortPartitionsByDecSize(List partitions); +int int_array_size(ushort* part_geometry); +void sort_int_array_by_dec_size(List configs); +void sort_partitions_by_inc_size(List partitions); +void sort_partitions_by_dec_size(List partitions); #endif /* _PARTITION_SYS_H_ */