[ofa-general] [PATCH 3/4 v2] opensm: eliminate node's physical ports table duplication in osm_port_t

Sasha Khapyorsky sashak at voltaire.com
Thu May 10 14:14:39 PDT 2007


Eliminate duplication of osm_node's physical ports table in osm_port_t
object.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/include/opensm/osm_port.h    |   34 +++++-------------
 osm/opensm/osm_pkey_rcv.c        |    2 +-
 osm/opensm/osm_port.c            |   70 ++++++++-----------------------------
 osm/opensm/osm_sa_link_record.c  |    4 +-
 osm/opensm/osm_sa_pkey_record.c  |    2 +-
 osm/opensm/osm_sa_slvl_record.c  |    2 +-
 osm/opensm/osm_sa_vlarb_record.c |    2 +-
 osm/opensm/osm_slvl_map_rcv.c    |    2 +-
 osm/opensm/osm_sm_state_mgr.c    |    2 +-
 osm/opensm/osm_vl_arb_rcv.c      |    2 +-
 10 files changed, 34 insertions(+), 88 deletions(-)

diff --git a/osm/include/opensm/osm_port.h b/osm/include/opensm/osm_port.h
index feebf63..0873a7e 100644
--- a/osm/include/opensm/osm_port.h
+++ b/osm/include/opensm/osm_port.h
@@ -1274,10 +1274,8 @@ typedef struct _osm_port
 	struct _osm_node		*p_node;
 	ib_net64_t			guid;
 	uint32_t			discovery_count;
-	uint8_t				default_port_num;
-	uint8_t				physp_tbl_size;
+	osm_physp_t			*p_physp;
 	cl_qlist_t			mcm_list;
-	osm_physp_t			*tbl[1];
 } osm_port_t;
 /*
 * FIELDS
@@ -1295,20 +1293,13 @@ typedef struct _osm_port
 *		during the current fabric sweep.  This number is reset
 *		to zero at the start of a sweep.
 *
-*	default_port_num
-*		Index of the physical port used when physical characteristics
-*		contained in the Physical Port are needed.
-*
-*	physp_tbl_size
-*		Number of physical ports associated with this logical port.
+*	p_physp
+*		The pointer to physical port used when physical
+*		characteristics contained in the Physical Port are needed.
 *
 *	mcm_list
 *		Multicast member list
 *
-*	tbl
-*		Array of pointers to Physical Port objects contained by this node.
-*     MUST BE LAST ELEMENT SINCE IT CAN GROW !!!
-*
 * SEE ALSO
 *	Port, Physical Port, Physical Port Table
 *********/
@@ -1386,10 +1377,8 @@ static inline ib_net16_t
 osm_port_get_base_lid(
 	IN const osm_port_t* const p_port )
 {
-	const osm_physp_t* const p_physp = p_port->tbl[p_port->default_port_num];
-	CL_ASSERT( p_physp );
-	CL_ASSERT( osm_physp_is_valid( p_physp ) );
-	return( osm_physp_get_base_lid( p_physp ));
+	CL_ASSERT( p_port->p_physp && osm_physp_is_valid( p_port->p_physp ) );
+	return( osm_physp_get_base_lid( p_port->p_physp ));
 }
 /*
 * PARAMETERS
@@ -1419,10 +1408,8 @@ static inline uint8_t
 osm_port_get_lmc(
 	IN const osm_port_t* const p_port )
 {
-	const osm_physp_t* const p_physp = p_port->tbl[p_port->default_port_num];
-	CL_ASSERT( p_physp );
-	CL_ASSERT( osm_physp_is_valid( p_physp ) );
-	return( osm_physp_get_lmc( p_physp ));
+	CL_ASSERT( p_port->p_physp && osm_physp_is_valid( p_port->p_physp ) );
+	return( osm_physp_get_lmc( p_port->p_physp ));
 }
 /*
 * PARAMETERS
@@ -1483,9 +1470,8 @@ osm_physp_t*
 osm_port_get_default_phys_ptr(
 	IN const osm_port_t* const p_port )
 {
-	CL_ASSERT( p_port->tbl[p_port->default_port_num] );
-	CL_ASSERT( osm_physp_is_valid( p_port->tbl[p_port->default_port_num] ) );
-	return( p_port->tbl[p_port->default_port_num] );
+	CL_ASSERT( osm_physp_is_valid( p_port->p_physp ) );
+	return p_port->p_physp;
 }
 /*
 * PARAMETERS
diff --git a/osm/opensm/osm_pkey_rcv.c b/osm/opensm/osm_pkey_rcv.c
index 76af9fc..0e0ec46 100644
--- a/osm/opensm/osm_pkey_rcv.c
+++ b/osm/opensm/osm_pkey_rcv.c
@@ -172,7 +172,7 @@ osm_pkey_rcv_process(
   else
   {
     p_physp = osm_port_get_default_phys_ptr(p_port);
-    port_num = p_port->default_port_num;
+    port_num = p_physp->port_num;
   }
 
   CL_ASSERT( p_physp );
diff --git a/osm/opensm/osm_port.c b/osm/opensm/osm_port.c
index 053fc22..30e2ab2 100644
--- a/osm/opensm/osm_port.c
+++ b/osm/opensm/osm_port.c
@@ -174,7 +174,6 @@ osm_port_init(
   uint32_t port_index;
   ib_net64_t port_guid;
   osm_physp_t *p_physp;
-  uint32_t size;
 
   CL_ASSERT( p_port );
   CL_ASSERT( p_ni );
@@ -187,39 +186,25 @@ osm_port_init(
   p_port->guid = port_guid;
 
   /*
-    See comment in port_new for info about this...
-  */
-  size = p_ni->num_ports;
-
-  p_port->physp_tbl_size = (uint8_t)(size + 1);
-
-  /*
     Get the pointers to the physical node objects "owned" by this
     logical port GUID.
     For switches, all the ports are owned; for HCA's and routers,
     only the singular part that has this GUID is owned.
   */
-  p_port->default_port_num = 0xFF;
-  for( port_index = 0; port_index < p_port->physp_tbl_size; port_index++ )
+  for( port_index = 0; port_index < p_parent_node->physp_tbl_size; port_index++ )
   {
     p_physp = osm_node_get_physp_ptr( p_parent_node, port_index );
+    /*
+      Because much of the PortInfo data is only valid
+      for port 0 on switches, try to keep the lowest
+      possible value of default_port_num.
+    */
     if( osm_physp_is_valid( p_physp ) &&
-        port_guid == osm_physp_get_port_guid( p_physp ) )
-    {
-      p_port->tbl[port_index] = p_physp;
-      /*
-        Because much of the PortInfo data is only valid
-        for port 0 on switches, try to keep the lowest
-        possible value of default_port_num.
-      */
-      if( port_index < p_port->default_port_num )
-        p_port->default_port_num = (uint8_t)port_index;
+        port_guid == osm_physp_get_port_guid( p_physp ) ) {
+      p_port->p_physp = p_physp;
+      break;
     }
-    else
-      p_port->tbl[port_index] = NULL;
   }
-
-  CL_ASSERT( p_port->default_port_num < 0xFF );
 }
 
 /**********************************************************************
@@ -230,21 +215,11 @@ osm_port_new(
   IN const osm_node_t* const p_parent_node )
 {
   osm_port_t*  p_port;
-  uint32_t size;
-
-  /*
-    The port object already contains one physical port object pointer.
-    Therefore, subtract 1 from the number of physical ports
-    used by the switch.  This is not done for CA's since they
-    need to occupy 1 more physp pointer than they physically have since
-    we still reserve room for a "port 0".
-  */
-  size = p_ni->num_ports;
 
-  p_port = malloc( sizeof(*p_port) + sizeof(void *) * size );
+  p_port = malloc( sizeof(*p_port) );
   if( p_port != NULL )
   {
-    memset( p_port, 0, sizeof(*p_port) + sizeof(void *) * size );
+    memset( p_port, 0, sizeof(*p_port) );
     osm_port_init( p_port, p_ni, p_parent_node );
   }
 
@@ -315,18 +290,11 @@ osm_port_add_new_physp(
   IN osm_port_t* const p_port,
   IN const uint8_t port_num )
 {
-  osm_node_t *p_node;
   osm_physp_t *p_physp;
 
-  CL_ASSERT( port_num < p_port->physp_tbl_size );
-
-  p_node = p_port->p_node;
-  CL_ASSERT( p_node );
-
-  p_physp = osm_node_get_physp_ptr( p_node, port_num );
+  p_physp = osm_node_get_physp_ptr( p_port->p_node, port_num );
   CL_ASSERT( osm_physp_is_valid( p_physp ) );
   CL_ASSERT( osm_physp_get_port_guid( p_physp ) == p_port->guid );
-  p_port->tbl[port_num] = p_physp;
 
   /*
     For switches, we generally want to use Port 0, which is
@@ -334,17 +302,9 @@ osm_port_add_new_physp(
     The LID value in the PortInfo for example, is only valid
     for port 0 on switches.
   */
-  if( !osm_physp_is_valid( p_port->tbl[p_port->default_port_num] ) )
-  {
-    p_port->default_port_num = port_num;
-  }
-  else
-  {
-    if(  port_num < p_port->default_port_num )
-    {
-      p_port->default_port_num = port_num;
-    }
-  }
+  if( !osm_physp_is_valid( osm_port_get_default_phys_ptr( p_port ) ) ||
+      port_num < p_port->p_physp->port_num )
+    p_port->p_physp = p_physp;
 }
 
 /**********************************************************************
diff --git a/osm/opensm/osm_sa_link_record.c b/osm/opensm/osm_sa_link_record.c
index c6b7a7c..5e4e35e 100644
--- a/osm/opensm/osm_sa_link_record.c
+++ b/osm/opensm/osm_sa_link_record.c
@@ -374,7 +374,7 @@ __osm_lr_rcv_get_port_links(
         port_num = p_lr->from_port_num;
         /* If the port number is out of the range of the p_src_port, then
            this couldn't be a relevant record. */
-        if (port_num < p_src_port->physp_tbl_size) 
+        if (port_num < p_src_port->p_node->physp_tbl_size)
         {          
           p_src_physp = osm_node_get_physp_ptr( p_src_port->p_node, port_num );
           if (p_src_physp)
@@ -409,7 +409,7 @@ __osm_lr_rcv_get_port_links(
         port_num = p_lr->to_port_num;
         /* If the port number is out of the range of the p_dest_port, then
            this couldn't be a relevant record. */
-        if (port_num < p_dest_port->physp_tbl_size ) 
+        if (port_num < p_dest_port->p_node->physp_tbl_size )
         {
           p_dest_physp = osm_node_get_physp_ptr(
             p_dest_port->p_node, port_num );
diff --git a/osm/opensm/osm_sa_pkey_record.c b/osm/opensm/osm_sa_pkey_record.c
index a943fe0..8a71314 100644
--- a/osm/opensm/osm_sa_pkey_record.c
+++ b/osm/opensm/osm_sa_pkey_record.c
@@ -239,7 +239,7 @@ __osm_sa_pkey_by_comp_mask(
   if ( p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH )
   {
     /* we put it in the comp mask and port num */
-    port_num = p_port->default_port_num;
+    port_num = p_port->p_physp->port_num;
     osm_log( p_rcv->p_log, OSM_LOG_DEBUG,
              "__osm_sa_pkey_by_comp_mask:  "
              "Using Physical Default Port Number: 0x%X (for End Node)\n",
diff --git a/osm/opensm/osm_sa_slvl_record.c b/osm/opensm/osm_sa_slvl_record.c
index 2f250d9..168901e 100644
--- a/osm/opensm/osm_sa_slvl_record.c
+++ b/osm/opensm/osm_sa_slvl_record.c
@@ -225,7 +225,7 @@ __osm_sa_slvl_by_comp_mask(
     osm_log( p_rcv->p_log, OSM_LOG_DEBUG,
              "__osm_sa_slvl_by_comp_mask:  "
              "Using Physical Default Port Number: 0x%X (for End Node)\n",
-             p_port->default_port_num );
+             p_port->p_physp->port_num );
     p_out_physp = osm_port_get_default_phys_ptr( p_port );
     /* check that the p_out_physp and the p_req_physp share a pkey */
     if (osm_physp_share_pkey( p_rcv->p_log, p_req_physp, p_out_physp ))
diff --git a/osm/opensm/osm_sa_vlarb_record.c b/osm/opensm/osm_sa_vlarb_record.c
index 9cd346c..a462ee9 100644
--- a/osm/opensm/osm_sa_vlarb_record.c
+++ b/osm/opensm/osm_sa_vlarb_record.c
@@ -243,7 +243,7 @@ __osm_sa_vl_arb_by_comp_mask(
   if ( p_port->p_node->node_info.node_type != IB_NODE_TYPE_SWITCH)
   {
     /* we put it in the comp mask and port num */
-    port_num = p_port->default_port_num;
+    port_num = p_port->p_physp->port_num;
     osm_log( p_rcv->p_log, OSM_LOG_DEBUG,
              "__osm_sa_vl_arb_by_comp_mask:  "
              "Using Physical Default Port Number: 0x%X (for End Node)\n",
diff --git a/osm/opensm/osm_slvl_map_rcv.c b/osm/opensm/osm_slvl_map_rcv.c
index 3fa3a7e..b109f75 100644
--- a/osm/opensm/osm_slvl_map_rcv.c
+++ b/osm/opensm/osm_slvl_map_rcv.c
@@ -183,7 +183,7 @@ osm_slvl_rcv_process(
   else
   {
     p_physp = osm_port_get_default_phys_ptr(p_port);
-    out_port_num = p_port->default_port_num;
+    out_port_num = p_physp->port_num;
     in_port_num  = 0;
   }
 
diff --git a/osm/opensm/osm_sm_state_mgr.c b/osm/opensm/osm_sm_state_mgr.c
index 3aa92c8..0034320 100644
--- a/osm/opensm/osm_sm_state_mgr.c
+++ b/osm/opensm/osm_sm_state_mgr.c
@@ -194,7 +194,7 @@ __osm_sm_state_mgr_send_local_port_info_req(
                          osm_physp_get_dr_path_ptr
                          ( osm_port_get_default_phys_ptr( p_port ) ),
                          IB_MAD_ATTR_PORT_INFO,
-                         cl_hton32( p_port->default_port_num ),
+                         cl_hton32( p_port->p_physp->port_num ),
                          CL_DISP_MSGID_NONE, &context );
 
    if( status != IB_SUCCESS )
diff --git a/osm/opensm/osm_vl_arb_rcv.c b/osm/opensm/osm_vl_arb_rcv.c
index 930360a..ed8dfc5 100644
--- a/osm/opensm/osm_vl_arb_rcv.c
+++ b/osm/opensm/osm_vl_arb_rcv.c
@@ -184,7 +184,7 @@ osm_vla_rcv_process(
   else
   {
     p_physp = osm_port_get_default_phys_ptr(p_port);
-    port_num = p_port->default_port_num;
+    port_num = p_physp->port_num;
   }
 
   CL_ASSERT( p_physp );
-- 
1.5.2.rc2.20.gac2a




More information about the general mailing list