예제 #1
0
/**
 * @brief
 * 		update the meta data about a node partition
 *			like free_nodes and consumable resources in res
 *
 * @param[in]	policy	-	policy info
 * @param[in]	np	-	the node partition to update
 * @param[in]	nodes	-	the entire node array used to create these node partitions
 *
 * @return	int
 * @retval	1	: on success
 * @retval	0	: on failure
 *
 */
int
node_partition_update(status *policy, node_partition *np)
{
	int i;
	int rc = 1;
	schd_resource *res;
	unsigned int arl_flags = USE_RESOURCE_LIST;

	if (np == NULL)
		return 0;

	/* if res is not NULL, we are updating.  Clear the meta data for the update*/
	if (np->res != NULL) {
		arl_flags |= NO_UPDATE_NON_CONSUMABLE;
		for (res = np->res; res != NULL; res = res->next) {
			if (res->type.is_consumable) {
				res->assigned = 0;
				res->avail = 0;
			}
		}
	}
	else
		arl_flags |= ADD_UNSET_BOOLS_FALSE;

	np->free_nodes = 0;

	for (i = 0; i < np->tot_nodes; i++) {
		if (np->ninfo_arr[i]->is_free) {
			np->free_nodes++;
			arl_flags &= ~ADD_AVAIL_ASSIGNED;
		} else
			arl_flags |= ADD_AVAIL_ASSIGNED;

		if (np->res == NULL)
			np->res = dup_selective_resource_list(np->ninfo_arr[i]->res,
				policy->resdef_to_check, arl_flags);
		else if (!add_resource_list(policy, np->res, np->ninfo_arr[i]->res,
			arl_flags)) {
			log_err(errno, __func__, MEM_ERR_MSG);
			rc = 0;
			break;
		}
	}

	if (policy->node_sort[0].res_name != NULL && conf.node_sort_unused) {
		/* Resort the nodes in the partition so that selection works correctly. */
		qsort(np->ninfo_arr, np->tot_nodes, sizeof(node_info*),
			multi_node_sort);
	}

	return rc;
}
예제 #2
0
파일: task_lists.c 프로젝트: acassis/rtsim
list_resource_t* load_resource_file(char* file, task_set_t* task, list_resource_t* resource_list)
{
	FILE *in_file; /* Input file */
	char line[255]; /* Input line */
	list_resource_t new_res;
	list_resource_t* list = resource_list;
	task_resource_t new_task_res;

	int d1, d2;
	int i, r;
	int task_res = 0;
	int res = 0;
	//char filename[255];
	//strcpy(filename, file);
	//strcat(&filename[0], RESOURCE_SUBFIX);

	in_file = fopen(file, "r");

	if (!in_file) {
		return 0;
	}

	//skip lines
	for (i = 0; i < (task->id); i++) {
		fgets(line, sizeof(line), in_file);
	}

	new_res.id = 0;
	new_res.next = NULL;

	task_res = 0;
	fscanf(in_file, "%d", &task_res);
	if (task_res > 0) {

		for (r = 0; r < task_res; r++) {
			new_task_res.id = 0;
			new_task_res.c = 0;
			new_task_res.e = 0;
			new_task_res.cet = 0;
			new_task_res.f = 0;
			new_task_res.next = NULL;

			fscanf(in_file, "%d%d%d", &res, &d1, &d2);
			new_task_res.id = res;
			new_task_res.f = d1;
			new_task_res.c = d2;

			if (res > 0) {
				task->res = (task_resource_t*)add_resource_task(new_task_res, (task_resource_t*)task->res);
				if (is_id_in_resource_list(res, resource_list) == 0) {
					new_res.id = res;
					resource_list = add_resource_list(resource_list, new_res);
				}
			}
		}
	}

	fclose(in_file);
	return resource_list;

}