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

Sasha Khapyorsky sashak at voltaire.com
Tue Sep 15 03:31:29 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>
---
Changes from v1:
Unify osm_mgrp_remove_port() and osm_mgrp_add_port() function calls

 opensm/include/opensm/osm_mcm_port.h   |   23 ++++++++-----
 opensm/include/opensm/osm_multicast.h  |   23 +++++++------
 opensm/opensm/osm_mcast_mgr.c          |   54 ++-----------------------------
 opensm/opensm/osm_mcm_port.c           |   10 +++---
 opensm/opensm/osm_multicast.c          |   30 +++++++++---------
 opensm/opensm/osm_sa.c                 |   24 +++++++-------
 opensm/opensm/osm_sa_mcmember_record.c |   26 +++++----------
 7 files changed, 70 insertions(+), 120 deletions(-)

diff --git a/opensm/include/opensm/osm_mcm_port.h b/opensm/include/opensm/osm_mcm_port.h
index c2b18de..74b6615 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;
+	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,19 @@ 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 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 e6221cb..7fcbb1a 100644
--- a/opensm/include/opensm/osm_multicast.h
+++ b/opensm/include/opensm/osm_multicast.h
@@ -309,20 +309,21 @@ static inline ib_net16_t osm_mgrp_get_mlid(IN const osm_mgrp_t * const p_mgrp)
 * SYNOPSIS
 */
 osm_mcm_port_t *osm_mgrp_add_port(osm_subn_t *subn, osm_log_t *log,
-				  IN osm_mgrp_t * mgrp,
-				  IN const ib_gid_t * port_gid,
-				  IN const uint8_t join_state,
-				  IN boolean_t proxy);
+				  IN osm_mgrp_t * mgrp, IN osm_port_t *port,
+				  IN ib_member_rec_t *mcmr, IN boolean_t proxy);
 /*
 * PARAMETERS
 *	mgrp
 *		[in] Pointer to an osm_mgrp_t object to initialize.
 *
-*	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
+*		[in] The proxy join state for this port in the group.
 *
 * RETURN VALUES
 *	IB_SUCCESS
@@ -402,9 +403,9 @@ void osm_mgrp_delete_port(IN osm_subn_t * subn, IN osm_log_t * log,
 * SEE ALSO
 *********/
 
-int osm_mgrp_remove_port(osm_subn_t *subn, osm_log_t *log, osm_mgrp_t *mgrp,
-			 osm_mcm_port_t *mcm, uint8_t join_state);
-void osm_mgrp_cleanup(osm_subn_t *subn, osm_mgrp_t *mpgr);
+int osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
+			 osm_mcm_port_t * mcm_port, ib_member_rec_t * mcmr);
+void osm_mgrp_cleanup(osm_subn_t * subn, osm_mgrp_t * mpgr);
 
 END_C_DECLS
 #endif				/* _OSM_MULTICAST_H_ */
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..9381bff 100644
--- a/opensm/opensm/osm_mcm_port.c
+++ b/opensm/opensm/osm_mcm_port.c
@@ -50,17 +50,17 @@
 
 /**********************************************************************
  **********************************************************************/
-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 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 bcf8b0b..f548990 100644
--- a/opensm/opensm/osm_multicast.c
+++ b/opensm/opensm/osm_multicast.c
@@ -131,23 +131,18 @@ 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 * mgrp,
-				  IN const ib_gid_t * port_gid,
-				  IN const uint8_t join_state,
-				  IN boolean_t proxy)
+				  IN osm_mgrp_t * mgrp, osm_port_t *port,
+				  IN ib_member_rec_t *mcmr, IN boolean_t proxy)
 {
-	ib_net64_t port_guid;
 	osm_mcm_port_t *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;
 
-	mcm_port = osm_mcm_port_new(port_gid, join_state, proxy);
+	mcm_port = osm_mcm_port_new(port, mcmr, proxy);
 	if (!mcm_port)
 		return NULL;
 
-	port_guid = port_gid->unicast.interface_id;
-
 	/*
 	   prev_item = cl_qmap_insert(...)
 	   Pointer to the item in the map with the specified key.  If insertion
@@ -155,7 +150,7 @@ 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(&mgrp->mcm_port_tbl, port_guid,
+	prev_item = cl_qmap_insert(&mgrp->mcm_port_tbl, port->guid,
 				   &mcm_port->map_item);
 
 	/* if already exists - revert the insertion and only update join state */
@@ -186,11 +181,11 @@ osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, osm_log_t * log,
 /**********************************************************************
  **********************************************************************/
 int osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
-			 osm_mcm_port_t * mcm_port, uint8_t join_state)
+			 osm_mcm_port_t * mcm_port, ib_member_rec_t *mcmr)
 {
 	int ret;
-	uint8_t port_join_state;
-	uint8_t new_join_state;
+	uint8_t join_state = mcmr->scope_state & 0xf;
+	uint8_t port_join_state, new_join_state;
 
 	/*
 	 * according to the same o15-0.1.14 we get the stored
@@ -207,8 +202,10 @@ int osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
 			"updating port 0x%" PRIx64 " JoinState 0x%x -> 0x%x\n",
 			cl_ntoh64(mcm_port->port_gid.unicast.interface_id),
 			port_join_state, new_join_state);
+		mcmr->scope_state = mcm_port->scope_state;
 		ret = 0;
 	} else {
+		mcmr->scope_state = mcm_port->scope_state;
 		cl_qmap_remove_item(&mgrp->mcm_port_tbl, &mcm_port->map_item);
 		OSM_LOG(log, OSM_LOG_DEBUG, "removing port 0x%" PRIx64 "\n",
 			cl_ntoh64(mcm_port->port_gid.unicast.interface_id));
@@ -228,11 +225,14 @@ int osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
 void osm_mgrp_delete_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
 			  ib_net64_t port_guid)
 {
+	ib_member_rec_t mcmrec;
 	cl_map_item_t *item = cl_qmap_get(&mgrp->mcm_port_tbl, port_guid);
 
-	if (item != cl_qmap_end(&mgrp->mcm_port_tbl))
+	if (item != cl_qmap_end(&mgrp->mcm_port_tbl)) {
+		mcmrec.scope_state = 0xf;
 		osm_mgrp_remove_port(subn, log, mgrp, (osm_mcm_port_t *) item,
-				     0xf);
+				     &mcmrec);
+	}
 	osm_mgrp_cleanup(subn, mgrp);
 }
 
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..a51c839 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;
@@ -1018,16 +1015,9 @@ static void mcmr_rcv_leave_mgrp(IN osm_sa_t * sa, IN osm_madw_t * p_madw)
 		goto Exit;
 	}
 
-	/* store state - we'll need it if the port is removed */
-	mcmember_rec.scope_state = p_mcm_port->scope_state;
-
-	/* remove port or update join state */
-	removed =
-	    osm_mgrp_remove_port(sa->p_subn, sa->p_log, p_mgrp, p_mcm_port,
-				 p_recvd_mcmember_rec->scope_state & 0x0F);
-	if (!removed)
-		mcmember_rec.scope_state = p_mcm_port->scope_state;
-
+	/* remove port and/or update join state */
+	removed = osm_mgrp_remove_port(sa->p_subn, sa->p_log, p_mgrp,
+				       p_mcm_port, &mcmember_rec);
 	CL_PLOCK_RELEASE(sa->p_lock);
 
 	/* we can leave if port was deleted from MCG */
@@ -1225,7 +1215,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