[ofa-general] [PATCH] opensm: find MC group by MGID using fleximap
Sasha Khapyorsky
sashak at voltaire.com
Tue Jul 21 08:32:28 PDT 2009
Find MC group by MGID value using fleximap, rather than looping over
mlid array.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
Did this some time ago... Not heavy tested yet.
opensm/include/opensm/osm_multicast.h | 5 +++--
opensm/include/opensm/osm_subnet.h | 2 ++
opensm/opensm/osm_mcast_mgr.c | 2 ++
opensm/opensm/osm_sa_mcmember_record.c | 30 ++++++++++++------------------
opensm/opensm/osm_subnet.c | 8 ++++++++
5 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/opensm/include/opensm/osm_multicast.h b/opensm/include/opensm/osm_multicast.h
index a871306..9a47de5 100644
--- a/opensm/include/opensm/osm_multicast.h
+++ b/opensm/include/opensm/osm_multicast.h
@@ -45,6 +45,7 @@
#include <iba/ib_types.h>
#include <complib/cl_qmap.h>
+#include <complib/cl_fleximap.h>
#include <complib/cl_qlist.h>
#include <complib/cl_spinlock.h>
#include <opensm/osm_base.h>
@@ -120,7 +121,7 @@ typedef struct osm_mcast_mgr_ctxt {
* SYNOPSIS
*/
typedef struct osm_mgrp {
- cl_map_item_t map_item;
+ cl_fmap_item_t map_item;
ib_net16_t mlid;
osm_mtree_node_t *p_root;
cl_qmap_t mcm_port_tbl;
@@ -134,7 +135,7 @@ typedef struct osm_mgrp {
/*
* FIELDS
* map_item
-* Map Item for qmap linkage. Must be first element!!
+* Map Item for fmap linkage. Must be first element!!
*
* mlid
* The network ordered LID of this Multicast Group (must be
diff --git a/opensm/include/opensm/osm_subnet.h b/opensm/include/opensm/osm_subnet.h
index 59a32ad..c055add 100644
--- a/opensm/include/opensm/osm_subnet.h
+++ b/opensm/include/opensm/osm_subnet.h
@@ -46,6 +46,7 @@
#include <iba/ib_types.h>
#include <complib/cl_qmap.h>
+#include <complib/cl_fleximap.h>
#include <complib/cl_map.h>
#include <complib/cl_ptr_vector.h>
#include <complib/cl_list.h>
@@ -508,6 +509,7 @@ typedef struct osm_subn {
boolean_t first_time_master_sweep;
boolean_t coming_out_of_standby;
unsigned need_update;
+ cl_fmap_t mgrp_mgid_tbl;
void *mgroups[IB_LID_MCAST_END_HO - IB_LID_MCAST_START_HO + 1];
} osm_subn_t;
/*
diff --git a/opensm/opensm/osm_mcast_mgr.c b/opensm/opensm/osm_mcast_mgr.c
index ea49588..268e1ab 100644
--- a/opensm/opensm/osm_mcast_mgr.c
+++ b/opensm/opensm/osm_mcast_mgr.c
@@ -1093,6 +1093,8 @@ static ib_api_status_t mcast_mgr_process_mgrp(osm_sm_t * sm,
cl_ntoh16(p_mgrp->mlid));
sm->p_subn->mgroups[cl_ntoh16(p_mgrp->mlid) -
IB_LID_MCAST_START_HO] = NULL;
+ cl_fmap_remove_item(&sm->p_subn->mgrp_mgid_tbl,
+ &p_mgrp->map_item);
osm_mgrp_delete(p_mgrp);
}
diff --git a/opensm/opensm/osm_sa_mcmember_record.c b/opensm/opensm/osm_sa_mcmember_record.c
index 5543221..a9e0a3b 100644
--- a/opensm/opensm/osm_sa_mcmember_record.c
+++ b/opensm/opensm/osm_sa_mcmember_record.c
@@ -148,6 +148,8 @@ static void cleanup_mgrp(IN osm_sa_t * sa, osm_mgrp_t * mgrp)
if (cl_is_qmap_empty(&mgrp->mcm_port_tbl) && !mgrp->well_known) {
sa->p_subn->mgroups[cl_ntoh16(mgrp->mlid) -
IB_LID_MCAST_START_HO] = NULL;
+ cl_fmap_remove_item(&sa->p_subn->mgrp_mgid_tbl,
+ &mgrp->map_item);
osm_mgrp_delete(mgrp);
}
}
@@ -922,9 +924,14 @@ ib_api_status_t osm_mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa,
"Destroying it first\n", cl_ntoh16(mlid));
sa->p_subn->mgroups[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO] =
NULL;
+ cl_fmap_remove_item(&sa->p_subn->mgrp_mgid_tbl,
+ &p_prev_mgrp->map_item);
osm_mgrp_delete(p_prev_mgrp);
}
+ cl_fmap_insert(&sa->p_subn->mgrp_mgid_tbl,
+ &(*pp_mgrp)->mcmember_rec.mgid, &(*pp_mgrp)->map_item);
+
sa->p_subn->mgroups[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO] = *pp_mgrp;
Exit:
@@ -933,18 +940,6 @@ Exit:
}
/**********************************************************************
- *********************************************************************/
-static unsigned match_mgrp_by_mgid(IN osm_mgrp_t * p_mgrp, ib_gid_t * mgid)
-{
- /* ignore groups marked for deletion */
- if (p_mgrp->to_be_deleted ||
- memcmp(&p_mgrp->mcmember_rec.mgid, mgid, sizeof(ib_gid_t)))
- return 0;
- else
- return 1;
-}
-
-/**********************************************************************
**********************************************************************/
#define PREFIX_MASK CL_HTON64(0xff10ffff0000ffffULL)
#define PREFIX_SIGNATURE CL_HTON64(0xff10601b00000000ULL)
@@ -968,7 +963,7 @@ static unsigned match_and_update_ipv6_snm_mgid(ib_gid_t * mgid)
osm_mgrp_t *osm_get_mgrp_by_mgid(IN osm_sa_t * sa, IN ib_gid_t * p_mgid)
{
- int i;
+ osm_mgrp_t *mg;
if (sa->p_subn->opt.consolidate_ipv6_snm_req &&
match_and_update_ipv6_snm_mgid(p_mgid)) {
@@ -979,11 +974,10 @@ osm_mgrp_t *osm_get_mgrp_by_mgid(IN osm_sa_t * sa, IN ib_gid_t * p_mgid)
sizeof gid_str));
}
- for (i = 0; i <= sa->p_subn->max_mcast_lid_ho - IB_LID_MCAST_START_HO;
- i++)
- if (sa->p_subn->mgroups[i] &&
- match_mgrp_by_mgid(sa->p_subn->mgroups[i], p_mgid))
- return sa->p_subn->mgroups[i];
+ mg = (osm_mgrp_t *)cl_fmap_get(&sa->p_subn->mgrp_mgid_tbl, p_mgid);
+ if (mg != (osm_mgrp_t *)cl_fmap_end(&sa->p_subn->mgrp_mgid_tbl)
+ && !mg->to_be_deleted)
+ return mg;
return NULL;
}
diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index ec15f8a..e686e3c 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -394,6 +394,11 @@ static const opt_rec_t opt_tbl[] = {
/**********************************************************************
**********************************************************************/
+static long compar_mgids(const void *m1, const void *m2)
+{
+ return memcmp(m1, m2, sizeof(ib_gid_t));
+}
+
void osm_subn_construct(IN osm_subn_t * const p_subn)
{
memset(p_subn, 0, sizeof(*p_subn));
@@ -407,6 +412,7 @@ void osm_subn_construct(IN osm_subn_t * const p_subn)
cl_qlist_init(&p_subn->prefix_routes_list);
cl_qmap_init(&p_subn->rtr_guid_tbl);
cl_qmap_init(&p_subn->prtn_pkey_tbl);
+ cl_fmap_init(&p_subn->mgrp_mgid_tbl, compar_mgids);
}
/**********************************************************************
@@ -462,6 +468,8 @@ void osm_subn_destroy(IN osm_subn_t * const p_subn)
osm_prtn_delete(&p_prtn);
}
+ cl_fmap_remove_all(&p_subn->mgrp_mgid_tbl);
+
for (i = 0; i <= p_subn->max_mcast_lid_ho - IB_LID_MCAST_START_HO;
i++) {
p_mgrp = p_subn->mgroups[i];
--
1.6.3.3
More information about the general
mailing list