[ofa-general] [PATCH] opensm: port object reference in mcm ports list

Sasha Khapyorsky sashak at voltaire.com
Mon Sep 7 08:47:47 PDT 2009


This adds port object reference to port related structures list in
multicast group. In this way we are saving couple of lookups over port
guid table and simplifying some interfaces.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_mcm_port.h   |   24 +++++++++-----
 opensm/include/opensm/osm_multicast.h  |   14 +++++---
 opensm/opensm/osm_mcast_mgr.c          |   54 ++-----------------------------
 opensm/opensm/osm_mcm_port.c           |   11 +++---
 opensm/opensm/osm_multicast.c          |   16 +++------
 opensm/opensm/osm_sa.c                 |   24 +++++++-------
 opensm/opensm/osm_sa_mcmember_record.c |   13 +++-----
 7 files changed, 56 insertions(+), 100 deletions(-)

diff --git a/opensm/include/opensm/osm_mcm_port.h b/opensm/include/opensm/osm_mcm_port.h
index c2b18de..99ded21 100644
--- a/opensm/include/opensm/osm_mcm_port.h
+++ b/opensm/include/opensm/osm_mcm_port.h
@@ -46,6 +46,7 @@
 #include <iba/ib_types.h>
 #include <complib/cl_qmap.h>
 #include <opensm/osm_base.h>
+#include <opensm/osm_port.h>
 
 #ifdef __cplusplus
 #  define BEGIN_C_DECLS extern "C" {
@@ -71,6 +72,7 @@ BEGIN_C_DECLS
 */
 typedef struct osm_mcm_port {
 	cl_map_item_t map_item;
+	const osm_port_t *port;
 	ib_gid_t port_gid;
 	uint8_t scope_state;
 	boolean_t proxy_join;
@@ -80,6 +82,9 @@ typedef struct osm_mcm_port {
 *	map_item
 *		Map Item for qmap linkage.  Must be first element!!
 *
+*	port
+*		Reference to the parent port.
+*
 *	port_gid
 *		GID of the member port.
 *
@@ -106,19 +111,20 @@ typedef struct osm_mcm_port {
 *
 * SYNOPSIS
 */
-osm_mcm_port_t *osm_mcm_port_new(IN const ib_gid_t * const p_port_gid,
-				 IN const uint8_t scope_state,
-				 IN const boolean_t proxy_join);
+osm_mcm_port_t *osm_mcm_port_new(IN const osm_port_t * port,
+				 IN ib_member_rec_t *mcmr,
+				 IN boolean_t proxy_join);
 /*
 * PARAMETERS
-*	p_port_gid
-*		[in] Pointer to the GID of the port to add to the multicast group.
+*	port
+*		[in] Pointer to the port object.
+*		GID of the port to add to the multicast group.
 *
-*	scope_state
-*		[in] scope state of the join request
+*	mcmr
+*		[in] Pointer to MCMember record of the join request
 *
-*  proxy_join
-*     [in] proxy_join state analyzed from the request
+*	proxy_join
+*		[in] proxy_join state analyzed from the request
 *
 * RETURN VALUES
 *	Pointer to the allocated and initialized MCM Port object.
diff --git a/opensm/include/opensm/osm_multicast.h b/opensm/include/opensm/osm_multicast.h
index 181f0db..759fba1 100644
--- a/opensm/include/opensm/osm_multicast.h
+++ b/opensm/include/opensm/osm_multicast.h
@@ -310,19 +310,21 @@ static inline ib_net16_t osm_mgrp_get_mlid(IN const osm_mgrp_t * const p_mgrp)
 */
 osm_mcm_port_t *osm_mgrp_add_port(osm_subn_t *subn, osm_log_t *log,
 				  IN osm_mgrp_t * const p_mgrp,
-				  IN const ib_gid_t * const p_port_gid,
-				  IN const uint8_t join_state,
+				  IN osm_port_t *port, IN ib_member_rec_t *mcmr,
 				  IN boolean_t proxy_join);
 /*
 * PARAMETERS
 *	p_mgrp
 *		[in] Pointer to an osm_mgrp_t object to initialize.
 *
-*	p_port_gid
-*		[in] Pointer to the GID of the port to add to the multicast group.
+*	port
+*		[in] Pointer to an osm_port_t object
 *
-*	join_state
-*		[in] The join state for this port in the group.
+*	mcmr
+*		[in] Pointer to MCMember record received for the join
+*
+*	proxy_join
+*		[in] The proxy join state for this port in the group.
 *
 * RETURN VALUES
 *	IB_SUCCESS
diff --git a/opensm/opensm/osm_mcast_mgr.c b/opensm/opensm/osm_mcast_mgr.c
index c1d1916..3894677 100644
--- a/opensm/opensm/osm_mcast_mgr.c
+++ b/opensm/opensm/osm_mcast_mgr.c
@@ -132,7 +132,6 @@ static float osm_mcast_mgr_compute_avg_hops(osm_sm_t * sm,
 	float avg_hops = 0;
 	uint32_t hops = 0;
 	uint32_t num_ports = 0;
-	const osm_port_t *p_port;
 	const osm_mcm_port_t *p_mcm_port;
 	const cl_qmap_t *p_mcm_tbl;
 
@@ -148,23 +147,7 @@ static float osm_mcast_mgr_compute_avg_hops(osm_sm_t * sm,
 	     p_mcm_port != (osm_mcm_port_t *) cl_qmap_end(p_mcm_tbl);
 	     p_mcm_port =
 	     (osm_mcm_port_t *) cl_qmap_next(&p_mcm_port->map_item)) {
-		/*
-		   Acquire the port object for this port guid, then create
-		   the new worker object to build the list.
-		 */
-		p_port = osm_get_port_by_guid(sm->p_subn,
-					      ib_gid_get_guid(&p_mcm_port->
-							      port_gid));
-
-		if (!p_port) {
-			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0A18: "
-				"No port object for port 0x%016" PRIx64 "\n",
-				cl_ntoh64(ib_gid_get_guid
-					  (&p_mcm_port->port_gid)));
-			continue;
-		}
-
-		hops += osm_switch_get_port_least_hops(p_sw, p_port);
+		hops += osm_switch_get_port_least_hops(p_sw, p_mcm_port->port);
 		num_ports++;
 	}
 
@@ -190,7 +173,6 @@ static float osm_mcast_mgr_compute_max_hops(osm_sm_t * sm,
 {
 	uint32_t max_hops = 0;
 	uint32_t hops = 0;
-	const osm_port_t *p_port;
 	const osm_mcm_port_t *p_mcm_port;
 	const cl_qmap_t *p_mcm_tbl;
 
@@ -206,23 +188,7 @@ static float osm_mcast_mgr_compute_max_hops(osm_sm_t * sm,
 	     p_mcm_port != (osm_mcm_port_t *) cl_qmap_end(p_mcm_tbl);
 	     p_mcm_port =
 	     (osm_mcm_port_t *) cl_qmap_next(&p_mcm_port->map_item)) {
-		/*
-		   Acquire the port object for this port guid, then create
-		   the new worker object to build the list.
-		 */
-		p_port = osm_get_port_by_guid(sm->p_subn,
-					      ib_gid_get_guid(&p_mcm_port->
-							      port_gid));
-
-		if (!p_port) {
-			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0A1A: "
-				"No port object for port 0x%016" PRIx64 "\n",
-				cl_ntoh64(ib_gid_get_guid
-					  (&p_mcm_port->port_gid)));
-			continue;
-		}
-
-		hops = osm_switch_get_port_least_hops(p_sw, p_port);
+		hops = osm_switch_get_port_least_hops(p_sw, p_mcm_port->port);
 		if (hops > max_hops)
 			max_hops = hops;
 	}
@@ -714,7 +680,6 @@ static ib_api_status_t mcast_mgr_build_spanning_tree(osm_sm_t * sm,
 						     osm_mgrp_t * p_mgrp)
 {
 	const cl_qmap_t *p_mcm_tbl;
-	const osm_port_t *p_port;
 	const osm_mcm_port_t *p_mcm_port;
 	uint32_t num_ports;
 	cl_qlist_t port_list;
@@ -781,23 +746,12 @@ static ib_api_status_t mcast_mgr_build_spanning_tree(osm_sm_t * sm,
 		   Acquire the port object for this port guid, then create
 		   the new worker object to build the list.
 		 */
-		p_port = osm_get_port_by_guid(sm->p_subn,
-					      ib_gid_get_guid(&p_mcm_port->
-							      port_gid));
-		if (!p_port) {
-			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0A09: "
-				"No port object for port 0x%016" PRIx64 "\n",
-				cl_ntoh64(ib_gid_get_guid
-					  (&p_mcm_port->port_gid)));
-			continue;
-		}
-
-		p_wobj = mcast_work_obj_new(p_port);
+		p_wobj = mcast_work_obj_new(p_mcm_port->port);
 		if (p_wobj == NULL) {
 			OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 0A10: "
 				"Insufficient memory to route port 0x%016"
 				PRIx64 "\n",
-				cl_ntoh64(osm_port_get_guid(p_port)));
+				cl_ntoh64(osm_port_get_guid(p_mcm_port->port)));
 			continue;
 		}
 
diff --git a/opensm/opensm/osm_mcm_port.c b/opensm/opensm/osm_mcm_port.c
index b6b6149..7f5e9ff 100644
--- a/opensm/opensm/osm_mcm_port.c
+++ b/opensm/opensm/osm_mcm_port.c
@@ -50,17 +50,18 @@
 
 /**********************************************************************
  **********************************************************************/
-osm_mcm_port_t *osm_mcm_port_new(IN const ib_gid_t * const p_port_gid,
-				 IN const uint8_t scope_state,
-				 IN const boolean_t proxy_join)
+osm_mcm_port_t *osm_mcm_port_new(IN const osm_port_t *port,
+				 IN ib_member_rec_t *mcmr,
+				 IN boolean_t proxy_join)
 {
 	osm_mcm_port_t *p_mcm;
 
 	p_mcm = malloc(sizeof(*p_mcm));
 	if (p_mcm) {
 		memset(p_mcm, 0, sizeof(*p_mcm));
-		p_mcm->port_gid = *p_port_gid;
-		p_mcm->scope_state = scope_state;
+		p_mcm->port = port;
+		p_mcm->port_gid = mcmr->port_gid;
+		p_mcm->scope_state = mcmr->scope_state;
 		p_mcm->proxy_join = proxy_join;
 	}
 
diff --git a/opensm/opensm/osm_multicast.c b/opensm/opensm/osm_multicast.c
index 242eae7..b0ab4df 100644
--- a/opensm/opensm/osm_multicast.c
+++ b/opensm/opensm/osm_multicast.c
@@ -131,23 +131,19 @@ static void mgrp_send_notice(osm_subn_t * subn, osm_log_t * log,
 /**********************************************************************
  **********************************************************************/
 osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, osm_log_t * log,
-				  IN osm_mgrp_t * p_mgrp,
-				  IN const ib_gid_t * p_port_gid,
-				  IN const uint8_t join_state,
+				  IN osm_mgrp_t * p_mgrp, osm_port_t *port,
+				  IN ib_member_rec_t *mcmr,
 				  IN boolean_t proxy_join)
 {
-	ib_net64_t port_guid;
 	osm_mcm_port_t *p_mcm_port;
 	cl_map_item_t *prev_item;
-	uint8_t prev_join_state = 0;
+	uint8_t prev_join_state = 0, join_state = mcmr->scope_state;
 	uint8_t prev_scope;
 
-	p_mcm_port = osm_mcm_port_new(p_port_gid, join_state, proxy_join);
+	p_mcm_port = osm_mcm_port_new(port, mcmr, proxy_join);
 	if (!p_mcm_port)
 		return NULL;
 
-	port_guid = p_port_gid->unicast.interface_id;
-
 	/*
 	   prev_item = cl_qmap_insert(...)
 	   Pointer to the item in the map with the specified key.  If insertion
@@ -155,8 +151,8 @@ osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, osm_log_t * log,
 	   specified key already exists in the map, the pointer to that item is
 	   returned.
 	 */
-	prev_item = cl_qmap_insert(&p_mgrp->mcm_port_tbl,
-				   port_guid, &p_mcm_port->map_item);
+	prev_item = cl_qmap_insert(&p_mgrp->mcm_port_tbl, port->guid,
+				   &p_mcm_port->map_item);
 
 	/* if already exists - revert the insertion and only update join state */
 	if (prev_item != &p_mcm_port->map_item) {
diff --git a/opensm/opensm/osm_sa.c b/opensm/opensm/osm_sa.c
index fcc3f27..02737c2 100644
--- a/opensm/opensm/osm_sa.c
+++ b/opensm/opensm/osm_sa.c
@@ -995,26 +995,26 @@ int osm_sa_db_file_load(osm_opensm_t * p_osm)
 			if (!p_mgrp)
 				rereg_clients = 1;
 		} else if (p_mgrp && !strncmp(p, "mcm_port", 8)) {
-			ib_gid_t port_gid;
+			ib_member_rec_t mcmr;
 			ib_net64_t guid;
-			uint8_t scope_state;
-			boolean_t proxy_join;
+			osm_port_t *port;
+			boolean_t proxy;
 
 			PARSE_AHEAD(p, net64, " port_gid=0x",
-				    &port_gid.unicast.prefix);
+				    &mcmr.port_gid.unicast.prefix);
 			PARSE_AHEAD(p, net64, ":0x",
-				    &port_gid.unicast.interface_id);
-			PARSE_AHEAD(p, net8, " scope_state=0x", &scope_state);
+				    &mcmr.port_gid.unicast.interface_id);
+			PARSE_AHEAD(p, net8, " scope_state=0x", &mcmr.scope_state);
 			PARSE_AHEAD(p, net8, " proxy_join=0x", &val);
-			proxy_join = val;
+			proxy = val;
 
-			guid = port_gid.unicast.interface_id;
-			if (cl_qmap_get(&p_mgrp->mcm_port_tbl,
-					port_gid.unicast.interface_id) ==
+			guid = mcmr.port_gid.unicast.interface_id;
+			port = osm_get_port_by_guid(&p_osm->subn, guid);
+			if (port &&
+			    cl_qmap_get(&p_mgrp->mcm_port_tbl, guid) ==
 			    cl_qmap_end(&p_mgrp->mcm_port_tbl))
 				osm_mgrp_add_port(&p_osm->subn, &p_osm->log,
-						  p_mgrp, &port_gid,
-						  scope_state, proxy_join);
+						  p_mgrp, port, &mcmr, proxy);
 		} else if (!strncmp(p, "Service Record:", 15)) {
 			ib_service_record_t s_rec;
 			uint32_t modified_time, lease_period;
diff --git a/opensm/opensm/osm_sa_mcmember_record.c b/opensm/opensm/osm_sa_mcmember_record.c
index 5fc1064..c2027d1 100644
--- a/opensm/opensm/osm_sa_mcmember_record.c
+++ b/opensm/opensm/osm_sa_mcmember_record.c
@@ -137,6 +137,7 @@ static ib_net16_t get_new_mlid(osm_sa_t * sa, ib_net16_t requested_mlid)
  requester gids.
 **********************************************************************/
 static ib_api_status_t add_new_mgrp_port(osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
+					 IN osm_port_t *port,
 					 IN ib_member_rec_t *
 					 p_recvd_mcmember_rec,
 					 IN osm_mad_addr_t * p_mad_addr,
@@ -172,10 +173,8 @@ static ib_api_status_t add_new_mgrp_port(osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
 			"Create new port with proxy_join TRUE\n");
 	}
 
-	*pp_mcmr_port = osm_mgrp_add_port(sa->p_subn, sa->p_log, p_mgrp,
-					  &p_recvd_mcmember_rec->port_gid,
-					  p_recvd_mcmember_rec->scope_state,
-					  proxy_join);
+	*pp_mcmr_port = osm_mgrp_add_port(sa->p_subn, sa->p_log, p_mgrp, port,
+					  p_recvd_mcmember_rec, proxy_join);
 	if (*pp_mcmr_port == NULL) {
 		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1B06: "
 			"osm_mgrp_add_port failed\n");
@@ -410,7 +409,6 @@ static boolean_t validate_modify(IN osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
 		   if the requester GID == PortGID */
 		res = osm_get_gid_by_mad_addr(sa->p_log, sa->p_subn, p_mad_addr,
 					      &request_gid);
-
 		if (res != IB_SUCCESS) {
 			OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
 				"Could not find port for requested address\n");
@@ -443,8 +441,7 @@ static boolean_t validate_modify(IN osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
 			OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
 				"ProxyJoin but port not in partition. stored:"
 				"0x%016" PRIx64 " request:0x%016" PRIx64 "\n",
-				cl_ntoh64((*pp_mcm_port)->port_gid.unicast.
-					  interface_id),
+				cl_ntoh64((*pp_mcm_port)->port->guid),
 				cl_ntoh64(p_mad_addr->addr_type.gsi.grh_info.
 					  src_gid.unicast.interface_id));
 			return FALSE;
@@ -1225,7 +1222,7 @@ static void mcmr_rcv_join_mgrp(IN osm_sa_t * sa, IN osm_madw_t * p_madw)
 	}
 
 	/* create or update existing port (join-state will be updated) */
-	status = add_new_mgrp_port(sa, p_mgrp, p_recvd_mcmember_rec,
+	status = add_new_mgrp_port(sa, p_mgrp, p_port, p_recvd_mcmember_rec,
 				   osm_madw_get_mad_addr_ptr(p_madw),
 				   &p_mcmr_port);
 	if (status != IB_SUCCESS) {
-- 
1.6.4.2




More information about the general mailing list