Пример #1
0
/**
 * @brief
 *		cmp_placement_sets - sort placement sets by
 *			total cpus
 *			total memory
 *			free cpus
 *			free memory
 *
 * @param[in]	v1	-	node partition 1
 * @param[in]	v2	-	node partition 2
 *
 * @return	int
 * @retval	-1	: if v1 < v2
 * @retval	0 	: if v1 == v2
 * @retval	1  	: if v1 > v2
 */
int
cmp_placement_sets(const void *v1, const void *v2)
{
	node_partition *np1, *np2;
	schd_resource *ncpus1, *ncpus2;
	schd_resource *mem1, *mem2;
	int rc = 0;


	if (v1 == NULL && v2 == NULL)
		return 0;

	if (v1 == NULL && v2 != NULL)
		return -1;

	if (v1 != NULL && v2 == NULL)
		return 1;

	np1 = *((node_partition **) v1);
	np2 = *((node_partition **) v2);

	ncpus1 = find_resource(np1->res, getallres(RES_NCPUS));
	ncpus2 = find_resource(np2->res, getallres(RES_NCPUS));

	if (ncpus1 != NULL && ncpus2 != NULL)
		rc = cmpres(ncpus1->avail, ncpus2->avail);

	if (!rc) {
		mem1 = find_resource(np1->res, getallres(RES_MEM));
		mem2 = find_resource(np2->res, getallres(RES_MEM));

		if (mem1 != NULL && mem2 != NULL)
			rc = cmpres(mem1->avail, mem2->avail);
	}

	if (!rc) {
		if (ncpus1 != NULL && ncpus2 != NULL)
			rc = cmpres(dynamic_avail(ncpus1), dynamic_avail(ncpus2));
	}


	if (!rc) {
		if (mem1 != NULL && mem2 != NULL)
			rc = cmpres(dynamic_avail(mem1), dynamic_avail(mem2));
	}

	return rc;

}
Пример #2
0
/**
 * @brief
 * 		create the placement sets for the server and queues
 *
 * @param[in]	policy	-	policy info
 * @param[in]	sinfo	-	the server
 *
 * @return	int
 * @retval	1	: success
 * @retval	0	: failure
 */
int
create_placement_sets(status *policy, server_info *sinfo)
{
	int i;
	int is_success = 1;
	char *resstr[] = {"host", NULL};
	int num;

	sinfo->allpart = create_specific_nodepart(policy, "all", sinfo->unassoc_nodes);
	if (sinfo->has_multi_vnode) {
		sinfo->hostsets = create_node_partitions(policy, sinfo->nodes,
			resstr, policy->only_explicit_psets ? NO_FLAGS : NP_CREATE_REST, &num);
		if (sinfo->hostsets != NULL) {
			sinfo->num_hostsets = num;
			for (i = 0; sinfo->nodes[i] != NULL; i++) {
				schd_resource *hostres;
				char hostbuf[256];

				hostres = find_resource(sinfo->nodes[i]->res, getallres(RES_HOST));
				if (hostres != NULL) {
					snprintf(hostbuf, sizeof(hostbuf), "host=%s", hostres->str_avail[0]);
					sinfo->nodes[i]->hostset =
						find_node_partition(sinfo->hostsets, hostbuf);
				}
				else {
					snprintf(hostbuf, sizeof(hostbuf), "host=\"\"");
					sinfo->nodes[i]->hostset =
						find_node_partition(sinfo->hostsets, hostbuf);
				}
			}
		}
		else {
			schdlog(PBSEVENT_DEBUG, PBS_EVENTCLASS_SERVER, LOG_DEBUG, "",
				"Failed to create host sets for server");
			is_success = 0;
		}
	}

	if (sinfo->node_group_enable && sinfo->node_group_key != NULL) {
		sinfo->nodepart = create_node_partitions(policy, sinfo->unassoc_nodes,
			sinfo->node_group_key,
			policy->only_explicit_psets ? NO_FLAGS : NP_CREATE_REST,
			&sinfo->num_parts);

		if (sinfo->nodepart != NULL) {
			qsort(sinfo->nodepart, sinfo->num_parts,
				sizeof(node_partition *), cmp_placement_sets);
		}
		else {
			schdlog(PBSEVENT_DEBUG, PBS_EVENTCLASS_SERVER, LOG_DEBUG, "",
				"Failed to create node partitions for server");
			is_success = 0;
		}
	}

	for (i = 0; sinfo->queues[i] != NULL; i++) {
		node_info **ngroup_nodes;
		char **ngkey;
		queue_info *qinfo = sinfo->queues[i];

		if (qinfo->has_nodes)
			qinfo->allpart = create_specific_nodepart(policy, "all", qinfo->nodes);

		if (sinfo->node_group_enable && (qinfo->has_nodes || qinfo->node_group_key)) {
			if (qinfo->has_nodes)
				ngroup_nodes = qinfo->nodes;
			else
				ngroup_nodes = sinfo->unassoc_nodes;

			if(qinfo->node_group_key)
				ngkey = qinfo->node_group_key;
			else
				ngkey = sinfo->node_group_key;

			qinfo->nodepart = create_node_partitions(policy, ngroup_nodes,
				ngkey, policy->only_explicit_psets ? NO_FLAGS : NP_CREATE_REST,
				&(qinfo->num_parts));
			if (qinfo->nodepart != NULL) {
				qsort(qinfo->nodepart, qinfo->num_parts,
					sizeof(node_partition *), cmp_placement_sets);
			}
			else {
				schdlog(PBSEVENT_DEBUG, PBS_EVENTCLASS_QUEUE, LOG_DEBUG, qinfo->name,
					"Failed to create node partitions for queue.");
				is_success = 0;
			}
		}
	}
	return is_success;
}