Skip to contentSkip to conversation

opensm/osm_ucast_updn.c: Further reduction in cas_per_sw memory allocation

PATCH Superseded Hal Rosenstock 2 participants 2 messages Oct 15, 2009 1 message not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 opensm/osm_ucast_updn.c: Further reduction in cas_per_sw memory allocation

---

opensm/opensm/osm_ucast_updn.c +11 -3
index ced076a..c46b033 100644
@@ -424,7 +424,7 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)
 	double thd1, thd2;
 	unsigned i, cas_num = 0;
 	unsigned *cas_per_sw;
-	uint16_t lid_ho;
+	uint16_t lid_ho = 0;
 
 	OSM_LOG_ENTER(&p_osm->log);
 
@@ -432,13 +432,21 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)
 		"Current number of ports in the subnet is %d\n",
 		cl_qmap_count(&p_osm->subn.port_guid_tbl));
 
-	cas_per_sw = malloc(p_osm->subn.max_ucast_lid_ho * sizeof(*cas_per_sw));
+	for (item = cl_qmap_head(&p_updn->p_osm->subn.sw_guid_tbl);
+	     item != cl_qmap_end(&p_updn->p_osm->subn.sw_guid_tbl);
+	     item = cl_qmap_next(item)) {
+		p_sw = (osm_switch_t *)item;
+		if (p_sw->lft_size > lid_ho)
+			lid_ho = p_sw->lft_size;
+	}
+
+	cas_per_sw = malloc(lid_ho * sizeof(*cas_per_sw));
 	if (!cas_per_sw) {
 		OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR AA14: "
 			"cannot alloc mem for CAs per switch counter array\n");
 		goto _exit;
 	}
-	memset(cas_per_sw, 0, p_osm->subn.max_ucast_lid_ho * sizeof(*cas_per_sw));
+	memset(cas_per_sw, 0, lid_ho * sizeof(*cas_per_sw));
 
 	/* Find the Maximum number of CAs (and routers) for histogram normalization */
 	OSM_LOG(&p_osm->log, OSM_LOG_VERBOSE,

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to a message not in the archive
Quoted 18 lines · Hal Rosenstock

---

opensm/opensm/osm_ucast_updn.c +1 -1
index ced076a..c46b033 100644
@@ -424,7 +424,7 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)
 	double thd1, thd2;
 	unsigned i, cas_num = 0;
 	unsigned *cas_per_sw;
-	uint16_t lid_ho;
+	uint16_t lid_ho = 0;
 
 	OSM_LOG_ENTER(&p_osm->log);
 
@@ -432,13 +432,21 @@ static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn)
 		"Current number of ports in the subnet is %d\n",

opensm/opensm/osm_ucast_updn.c static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn) · line 441

Quoted 10 lines
opensm/opensm/osm_ucast_updn.c +7 -1
 		cl_qmap_count(&p_osm->subn.port_guid_tbl));
 
-	cas_per_sw = malloc(p_osm->subn.max_ucast_lid_ho * sizeof(*cas_per_sw));
+	for (item = cl_qmap_head(&p_updn->p_osm->subn.sw_guid_tbl);
+	     item != cl_qmap_end(&p_updn->p_osm->subn.sw_guid_tbl);
+	     item = cl_qmap_next(item)) {
+		p_sw = (osm_switch_t *)item;
+		if (p_sw->lft_size > lid_ho)
+			lid_ho = p_sw->lft_size;
+	}

It doesn't look very effective to me - lft_size can be larger than max_lid_ho + 1 and never smaller. Also I don't like looping here. Why to not just:

	lid_ho = cl_ptr_vector_get_size(&p_subn->port_lid_tbl);

?

Sasha

opensm/opensm/osm_ucast_updn.c static void updn_find_root_nodes_by_min_hop(OUT updn_t * p_updn) · line 452

Quoted 13 lines
opensm/opensm/osm_ucast_updn.c +3 -1
+
+	cas_per_sw = malloc(lid_ho * sizeof(*cas_per_sw));
 	if (!cas_per_sw) {
 		OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR AA14: "
 			"cannot alloc mem for CAs per switch counter array\n");
 		goto _exit;
 	}
-	memset(cas_per_sw, 0, p_osm->subn.max_ucast_lid_ho * sizeof(*cas_per_sw));
+	memset(cas_per_sw, 0, lid_ho * sizeof(*cas_per_sw));
 
 	/* Find the Maximum number of CAs (and routers) for histogram normalization */
 	OSM_LOG(&p_osm->log, OSM_LOG_VERBOSE,

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html