Ejemplo n.º 1
0
Archivo: sm_jm.c Proyecto: 01org/opa-fm
Status_t
sm_jm_alloc_job(JmEntry_t **job)
{
	Status_t s;
	JmEntry_t *j;

	s = vs_lock(&smJobTable.lock);
	if (s != VSTATUS_OK) {
		IB_LOG_ERROR_FMT(__func__,
			"Failed to take job table lock (status %d)", s);
		return s;
	}

	s = vs_pool_alloc(&sm_pool, sizeof(JmEntry_t), (void *)&j);
	if (s != VSTATUS_OK) {
		(void)vs_unlock(&smJobTable.lock);
		IB_LOG_ERROR_FMT(__func__,
			"Failed to allocate job entry (status %d)", s);
		return s;
	}

	(void)vs_unlock(&smJobTable.lock);
	memset(j, 0, sizeof(*j));
	*job = j;

	return VSTATUS_OK;
}
Ejemplo n.º 2
0
Status_t
sa_cntxt_data( sa_cntxt_t* sa_cntxt, void* buf, uint32_t len )
{
	Status_t	status ;

	IB_ENTER( "sa_cntxt_data", sa_cntxt, buf, len, 0 );

	status = VSTATUS_OK ;

	if (!buf || !len) {
		sa_cntxt->data = NULL;
        sa_cntxt->len = 0;
		sa_cntxt->freeDataFunc = NULL;
		goto done;
	}

	status = vs_pool_alloc(&sm_pool, len, (void*)&sa_cntxt->data);
	if (status == VSTATUS_OK) {
		sa_cntxt->len = len;
		memcpy(sa_cntxt->data, buf, len);
		sa_cntxt->freeDataFunc = sa_cntxt_free_data;
	} else {
        sa_cntxt->len = 0;
		sa_cntxt->data = NULL; /* If data is NULL, sa_send_reply will send error response to caller */
		sa_cntxt->freeDataFunc = NULL;
	}

done:
	IB_EXIT("sa_cntxt_data", status);
	return status ;
}
Ejemplo n.º 3
0
Status_t
sm_routing_alloc_cost_matrix(Topology_t *topop)
{
	Status_t status;
	size_t   bytesCost;

	/* Allocate space for the cost array. */
	bytesCost = topop->max_sws * topop->max_sws * sizeof(uint16_t);
	if (bytesCost > topop->bytes) {
		topop->bytes = 0;

		if (topop->cost != NULL) {
			(void)vs_pool_free(&sm_pool, (void *)topop->cost);
			topop->cost = NULL;
		}

		status = vs_pool_alloc(&sm_pool, bytesCost, (void *)&topop->cost);
		if (status != VSTATUS_OK) {
			IB_LOG_ERRORRC("can't malloc cost array rc:", status);
			IB_EXIT(__func__, status);
			return status;
		}

		topop->bytes = bytesCost;
	}

	return VSTATUS_OK;
}
Ejemplo n.º 4
0
Archivo: sm_jm.c Proyecto: 01org/opa-fm
Status_t
sm_jm_get_cost
	( Topology_t *topop
	, JmEntry_t *job
	, uint16_t **outCost
	, int *outLen
	)
{
	Status_t s;
	uint16_t *cost;
	int len;
	int pos = 0;
	uint16_t js1, js2; // job switch indicies
	uint16_t ts1, ts2; // topology switch indices

	// don't allocate for the case of 1 switch
	if (job->switchCount <= 1) {
		*outCost = NULL;
		*outLen = 0;
		return VSTATUS_OK;
	}

	// allocate space for triangular matrix minus the diagonal, so:
	//   1 + 2 + ... + (n - 1) ==> n * (n - 1) / 2
	len = job->switchCount * (job->switchCount - 1) / 2;
	s = vs_pool_alloc(&sm_pool, len * sizeof(uint16_t), (void *)&cost);
	if (s != VSTATUS_OK) {
		IB_LOG_ERROR_FMT(__func__,
			"Failed to allocate space for cost matrix (status %d)", s);
		return VSTATUS_BAD;
	}

	// encode all <src,dst> pairs where src < dst (upper-right triangle)
	for (js1 = 0; js1 < job->switchCount; ++js1) {
		ts1 = job->jobSwToTopoSwMap[js1];
		if (ts1 == 0xffff) {
			memset(cost + pos, 0xff, (job->switchCount - js1 - 1) * sizeof(uint16_t));
			pos += job->switchCount - js1 - 1;
			continue;
		}
		for (js2 = js1 + 1; js2 < job->switchCount; ++js2) {
			ts2 = job->jobSwToTopoSwMap[js2];
			if (ts2 == 0xffff)
				cost[pos++] = 0xffff;
			else
				cost[pos++] = topop->cost[Index(ts1, ts2)];
		}
	}

	*outCost = cost;
	*outLen = len;

	return VSTATUS_OK;
}
Ejemplo n.º 5
0
void*
getFeXmlParserMemory(uint32_t size, char* info) {
	void        *address;
	Status_t    status;

#ifdef XML_MEMORY
	printf("called getFeXmlParserMemory() size (%u) (%s) from fe_main.c\n", size, info);
#endif
	status = vs_pool_alloc(&fe_xml_pool, size, (void*)&address);
	if (status != VSTATUS_OK || !address)
		return NULL;
	return address;
}
Ejemplo n.º 6
0
int bitset_init(Pool_t* pool, bitset_t *bitset, size_t nbits) {
    Status_t	status;

	bitset->pool_m = pool;
	bitset->bits_m = NULL;
	bitset->nset_m = 0;
	bitset->nbits_m = nbits;
	bitset->nwords_m = (nbits/32);
	if (nbits%32) {
		bitset->nwords_m++;
	}
	status = vs_pool_alloc(pool, sizeof(uint32_t)*bitset->nwords_m, (void *)&bitset->bits_m);
	if (status != VSTATUS_OK) {
		IB_LOG_ERRORRC("can't allocate space for bitset, rc:", status);
		memset(bitset, 0, sizeof(bitset_t));
		return 0;
	}
	memset(bitset->bits_m, 0, sizeof(uint32_t)*bitset->nwords_m);
	return 1;
}
Ejemplo n.º 7
0
Status_t
sm_routing_makeModule(const char * name, RoutingModule_t ** module)
{
	cl_map_item_t * it;
	*module = NULL;

	if (name == NULL || strlen(name) == 0)
		return VSTATUS_ILLPARM;

	if ((it = cl_qmap_get(&moduleFacMap, UGLY_CHAR_U64(name))) == cl_qmap_end(&moduleFacMap))
		return VSTATUS_BAD;

	routing_mod_factory fac = cl_qmap_obj((const cl_map_obj_t * const) it);

	Status_t s;
	if ((s = vs_pool_alloc(&sm_pool, sizeof(RoutingModule_t), (void*)module)) != VSTATUS_OK) {
		return s;
	}
	memset(*module, 0, sizeof(RoutingModule_t));

	return fac(*module);
}
Ejemplo n.º 8
0
Status_t
sm_routing_addModuleFac(const char * name, routing_mod_factory fac)
{
	Status_t s;
	cl_map_obj_t * wrp = NULL;

	if (name == NULL || strlen(name) == 0 || fac == NULL)
		return VSTATUS_ILLPARM;

	if (cl_qmap_get(&moduleFacMap, UGLY_CHAR_U64(name)) != cl_qmap_end(&moduleFacMap))
		return VSTATUS_BAD;

	if ((s = vs_pool_alloc(&sm_pool, sizeof(cl_map_obj_t), (void*)&wrp)) != VSTATUS_OK)
		return s;

	memset(wrp, 0, sizeof(*wrp));

	wrp->p_object = fac;

	if (cl_qmap_insert(&moduleFacMap, UGLY_CHAR_U64(name), &wrp->item) == NULL)
		return VSTATUS_BAD;

	return VSTATUS_OK;
}
Ejemplo n.º 9
0
int
sa_main(void) {
	Status_t		status;
	int 			i;

	IB_ENTER("sa_main", 0, 0, 0, 0);

    if (sa_SubscriberInit() != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: Can't allocate Subscriber hash table");
		return 1;
	}
    
    if (sa_ServiceRecInit() != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: Can't allocate Service Record hash table");
		return 1;
	}
    
    // 
    //  Zero context hash table
    //
	memset( sa_hash, 0, sizeof( sa_hash ));
	sa_cntxt_pool = NULL;
    IB_LOG_VERBOSE("sa_main: Allocating SA context pool with num entries=", sa_max_cntxt);
	status = vs_pool_alloc(&sm_pool, sizeof(sa_cntxt_t) * sa_max_cntxt, (void *)&sa_cntxt_pool);
	if (status != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: Can't allocate SA context pool");
		return 2;
	}
	memset( sa_cntxt_pool, 0, sizeof( sa_cntxt_t ) * sa_max_cntxt);
	sa_cntxt_free_list = NULL ;
	for( i = 0 ; i < sa_max_cntxt ; ++i ) {
		sa_cntxt_insert_head( sa_cntxt_free_list, &sa_cntxt_pool[i] );
	}
    sa_cntxt_nfree = sa_max_cntxt;
    sa_cntxt_nalloc = 0;

    // initialize SA context lock
	status = vs_lock_init(&sa_cntxt_lock, VLOCK_FREE, VLOCK_THREAD);
	if (status != VSTATUS_OK) {
		IB_LOG_ERRORRC("sa_main: can't initialize SA context pool lock rc:", status);
        return 3;
	}
    //
    //	Allocate the SA storage pool.
    //
	status = vs_pool_alloc(&sm_pool, sa_data_length, (void*)&sa_data);
	if (status != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: can't allocate sa data");
		return 4;
	}

    //
    //	Fill in my ClassPortInfo_t and add it to the database.
    //
	(void)memset((void *)&saClassPortInfo, 0, sizeof(STL_CLASS_PORT_INFO));
	saClassPortInfo.BaseVersion = STL_BASE_VERSION; //MAD_BVERSION;
	saClassPortInfo.ClassVersion = STL_SA_CLASS_VERSION; //SA_MAD_CVERSION;
	saClassPortInfo.CapMask =
		STL_CLASS_PORT_CAPMASK_CM2 |
		STL_SA_CAPABILITY_MULTICAST_SUPPORT |
		STL_SA_CAPABILITY_PORTINFO_CAPMASK_MATCH |
		STL_SA_CAPABILITY_PA_SERVICES_SUPPORT;
	saClassPortInfo.u1.s.CapMask2 =
		STL_SA_CAPABILITY2_QOS_SUPPORT |
		STL_SA_CAPABILITY2_MFTTOP_SUPPORT |
		STL_SA_CAPABILITY2_FULL_PORTINFO |
		STL_SA_CAPABILITY2_EXT_SUPPORT;
	saClassPortInfo.u1.s.RespTimeValue = sm_config.sa_resp_time_n2;
	saClassPortInfo.u3.s.RedirectQP = 1;
	saClassPortInfo.u5.s.TrapHopLimit = 0xff;
	saClassPortInfo.u5.s.TrapQP = 1;

    //
    //	Init Sa Groups table and Set up the default Multicast group if one is set.
    //
    status = sa_McGroupInit();
	if (status != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: can't initialize SA McMember/Groups table lock");
        return 5;
	}
	sa_SetDefBcGrp();

	//
	//	Init SA caching
	//
	status = sa_cache_init();
	if (status != VSTATUS_OK) {
		IB_FATAL_ERROR("sa_main: can't initialize SA caching");
		return 6;
	}

	return 0;
}
Ejemplo n.º 10
0
Archivo: sm_jm.c Proyecto: 01org/opa-fm
// outCount wil be set to the number of ports actually found and valid in the
// topology
//
Status_t
sm_jm_fill_ports
	( Topology_t *topop
	, JmMsgReqCreate_t *input
	, JmEntry_t *job
	, uint16_t *outCount
	)
{
	Status_t s;
	int i;
	Node_t *nodep;
	Port_t *portp;
	int count = 0, nextIdx = 0;
	uint16_t *topoSwToJobSwMap;

	s = vs_pool_alloc(&sm_pool, input->guids.count * sizeof(JmPort_t),
		(void *)&job->ports);
	if (s != VSTATUS_OK) {
		IB_LOG_ERROR_FMT(__func__,
			"Failed to allocate space for PortGuid list (status %d)", s);
		goto fail1;
	}

	s = vs_pool_alloc(&sm_pool, input->guids.count * sizeof(uint16_t),
		(void *)&job->jobSwToTopoSwMap);
	if (s != VSTATUS_OK) {
		IB_LOG_ERROR_FMT(__func__,
			"Failed to allocate space for switch translation map (status %d)", s);
		goto fail2;
	}

	s = vs_pool_alloc(&sm_pool, topop->max_sws * sizeof(uint16_t),
		(void *)&topoSwToJobSwMap);
	if (s != VSTATUS_OK) {
		IB_LOG_ERROR_FMT(__func__,
			"Failed to allocate space for switch translation map (status %d)", s);
		goto fail3;
	}
	memset(topoSwToJobSwMap, 0xff, topop->max_sws * sizeof(uint16_t));

	// for each portguid: find the port/switch in the topology
	for (i = 0; i < input->guids.count; ++i) {
		job->ports[i].guid = input->guids.entries[i];
		portp = sm_find_port_guid(topop, input->guids.entries[i]);
		if (  !sm_valid_port(portp)
		   || portp->state < IB_PORT_INIT
		   || portp->portData->nodePtr->nodeInfo.NodeType == NI_TYPE_SWITCH) {
			// port not found; clear port in job
			job->ports[i].portp = NULL;
			job->ports[i].jobSwIdx = 0xffff;
		} else {
			// port found; find neighbor switch
			job->ports[i].portp = portp;
			nodep = sm_find_node(topop, portp->nodeno);
			if (nodep == NULL) {
				// switch not found; clear port in job
				job->ports[i].jobSwIdx = 0xffff;
			} else {
				// switch found; determine job-specific switch index
				if (topoSwToJobSwMap[nodep->swIdx] != 0xffff) {
					// index already created; use it
					job->ports[i].jobSwIdx = topoSwToJobSwMap[nodep->swIdx];
				} else {
					// index not created; use next available
					job->ports[i].jobSwIdx = topoSwToJobSwMap[nodep->swIdx] = nextIdx;
					job->jobSwToTopoSwMap[nextIdx] = nodep->swIdx;
					++nextIdx;
				}
				++count;
			}
		}
	}

	(void)vs_pool_free(&sm_pool, topoSwToJobSwMap);

	job->portCount = input->guids.count;
	job->switchCount = nextIdx;
	*outCount = count;

	return VSTATUS_OK;

fail3:
	(void)vs_pool_free(&sm_pool, job->jobSwToTopoSwMap);
fail2:
	(void)vs_pool_free(&sm_pool, job->ports);
fail1:
	return VSTATUS_BAD;
}
Ejemplo n.º 11
0
//
//  This uses log level INFINI_INFO and should probably only
//  be called under debug mode.
//
void bitset_info_log(bitset_t* bitset, char* prelude) {
	char*	string = NULL;
	int		first = 1;
	int		range = 0;
	int		range_start = -1;
	int		prev = -1;
	int		bit = -1;
	size_t	max_str_len = bitset->nset_m*5+1;
	size_t	pos = 0;
	int		res = 0;
    Status_t	status;
	
	if (!bitset) return;

	if (bitset->bits_m == NULL) {
		IB_LOG_INFINI_INFO_FMT( __func__, "NOBITS");
		return;
	}

	if (bitset->nset_m == 0) {
		if (prelude) {
			IB_LOG_INFINI_INFO_FMT(__func__, "%s <nil>", prelude);
		} else {
			IB_LOG_INFINI_INFO_FMT(__func__, "<nil>");
		}
		return;

	} else if (!bitset->pool_m || (bitset->nset_m>500)) {
		if (prelude) {
			IB_LOG_INFINI_INFO_FMT(__func__, "%s, nset= %d", prelude, (int)bitset->nset_m);
		} else {
			IB_LOG_INFINI_INFO_FMT(__func__, "nset= %d", (int)bitset->nset_m);
		}
		return;
	}

	status = vs_pool_alloc(bitset->pool_m, max_str_len, (void *)&string);
	if (status != VSTATUS_OK) {
		if (prelude) {
			IB_LOG_INFINI_INFO_FMT(__func__, "%s, nset= %d", prelude, (int)bitset->nset_m);
		} else {
			IB_LOG_INFINI_INFO_FMT(__func__, "nset= %d", (int)bitset->nset_m);
		}
		return;
	}
	string[0] = '\0';

	bit = bitset_find_first_one(bitset);

	while (bit != -1) {
		if (first) {
			res = snprintf(string + pos, max_str_len - pos, "%d", bit);
			if (res > 0){
				pos += res;
			} else {
				if (res == 0)
					break;
				else
					goto bail;
			}
			first = 0;
		} else {
			if (range && (prev != bit-1)) {
				range = 0;
				if ((prev - range_start) > 1) {
					res = snprintf(string + pos, max_str_len - pos, "-%d,%d", prev, bit);
				} else {
					res = snprintf(string + pos, max_str_len - pos, ",%d,%d", prev, bit);
				}
				if (res > 0){
					pos += res;
				} else {
					if (res == 0)
						break;
					else
						goto bail;
				}
				prev = -1;
				range_start = -1;
			} else if (!range && (prev == bit-1)) {
				range_start = prev;
				range = 1;
			} else if (!range) {
				res = snprintf(string + pos, max_str_len - pos, ",%d", bit);
				if (res > 0){
					pos += res;
				} else {
					if (res == 0)
						break;
					else
						goto bail;
				}
			}
		}
		prev = bit;
		bit = bitset_find_next_one(bitset, bit+1);
	}

	if (range && (prev != -1)) {
		if ((prev - range_start) > 1) {
			res = snprintf(string + pos, max_str_len - pos, "-%d", prev);
		} else {
			res = snprintf(string + pos, max_str_len - pos, ",%d", prev);
		}
		if (res > 0){
			pos += res;
		}
	}

bail:  
	if (prelude) {
		IB_LOG_INFINI_INFO_FMT(__func__, "%s %s", prelude, string);
	} else {
		IB_LOG_INFINI_INFO_FMT(__func__, "%s", string);
	}

	if ((status = vs_pool_free(bitset->pool_m, string)) != VSTATUS_OK) {
		IB_LOG_ERRORRC("can't free allocated space for bitset log, rc:", status);
	}
}