[ofa-general] [PATCH 1/2] opensm: wait_for_pending_transaction() generalization

Sasha Khapyorsky sashak at voltaire.com
Wed Jan 30 10:54:41 PST 2008


Function wait_for_pending_transaction() is global now and moved from
PerfMgr to StateMgr, all related objects are generalized.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_stats.h |    4 ----
 opensm/opensm/main.c              |    2 --
 opensm/opensm/osm_opensm.c        |   16 +++++++++++++++-
 opensm/opensm/osm_perfmgr.c       |   35 ++---------------------------------
 opensm/opensm/osm_sm_mad_ctrl.c   |    2 --
 opensm/opensm/osm_state_mgr.c     |   18 ++++++++++++++++++
 6 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/opensm/include/opensm/osm_stats.h b/opensm/include/opensm/osm_stats.h
index b5100f2..ecd752b 100644
--- a/opensm/include/opensm/osm_stats.h
+++ b/opensm/include/opensm/osm_stats.h
@@ -48,13 +48,11 @@
 #ifndef _OSM_STATS_H_
 #define _OSM_STATS_H_
 
-#ifdef ENABLE_OSM_PERF_MGR
 #ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
 #else
 #include <complib/cl_event.h>
 #endif
-#endif
 #include <complib/cl_atomic.h>
 #include <opensm/osm_base.h>
 
@@ -100,14 +98,12 @@ typedef struct _osm_stats {
 	atomic32_t sa_mads_sent;
 	atomic32_t sa_mads_rcvd_unknown;
 	atomic32_t sa_mads_ignored;
-#ifdef ENABLE_OSM_PERF_MGR
 #ifdef HAVE_LIBPTHREAD
 	pthread_mutex_t mutex;
 	pthread_cond_t cond;
 #else
 	cl_event_t event;
 #endif
-#endif
 } osm_stats_t;
 /*
 * FIELDS
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index 7c435a0..703a242 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -1044,13 +1044,11 @@ int main(int argc, char *argv[])
 		fprintf(stdout,
 			"There are still %u MADs out. Forcing the exit of the OpenSM application...\n",
 			osm.mad_pool.mads_out);
-#ifdef ENABLE_OSM_PERF_MGR
 #ifdef HAVE_LIBPTHREAD
 		pthread_cond_signal(&osm.stats.cond);
 #else
 		cl_event_signal(&osm.stats.event);
 #endif
-#endif
 	}
 
 Exit:
diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index a78307c..fa517d0 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -236,7 +236,12 @@ void osm_opensm_destroy(IN osm_opensm_t * const p_osm)
 	osm_vendor_delete(&p_osm->p_vendor);
 	osm_subn_destroy(&p_osm->subn);
 	cl_disp_destroy(&p_osm->disp);
-
+#ifdef HAVE_LIBPTHREAD
+	pthread_cond_destroy(&p_osm->stats.cond);
+	pthread_mutex_destroy(&p_osm->stats.mutex);
+#else
+	cl_event_destroy(&p_osm->stats.event);
+#endif
 	close_node_name_map(p_osm->node_name_map);
 
 	cl_plock_destroy(&p_osm->lock);
@@ -277,6 +282,15 @@ osm_opensm_init(IN osm_opensm_t * const p_osm,
 	if (status != IB_SUCCESS)
 		goto Exit;
 
+#ifdef HAVE_LIBPTHREAD
+	pthread_mutex_init(&p_osm->stats.mutex, NULL);
+	pthread_cond_init(&p_osm->stats.cond, NULL);
+#else
+	status = cl_event_init(&p_osm->stats.event, FALSE);
+	if (status != IB_SUCCESS)
+		goto Exit;
+#endif
+
 	if (p_opt->single_thread) {
 		osm_log(&p_osm->log, OSM_LOG_INFO,
 			"osm_opensm_init: Forcing single threaded dispatcher\n");
diff --git a/opensm/opensm/osm_perfmgr.c b/opensm/opensm/osm_perfmgr.c
index 6c0c6cd..dd6e662 100644
--- a/opensm/opensm/osm_perfmgr.c
+++ b/opensm/opensm/osm_perfmgr.c
@@ -117,6 +117,8 @@ static inline void diff_time(struct timeval *before,
 
 #endif
 
+extern int wait_for_pending_transactions(osm_stats_t * stats);
+
 /**********************************************************************
  * Internal helper functions.
  **********************************************************************/
@@ -717,24 +719,6 @@ static int sweep_hop_0(osm_sm_t * const sm)
 	return (status);
 }
 
-static int wait_for_pending_transactions(osm_stats_t * stats)
-{
-#ifdef HAVE_LIBPTHREAD
-	pthread_mutex_lock(&stats->mutex);
-	while (stats->qp0_mads_outstanding && !osm_exit_flag)
-		pthread_cond_wait(&stats->cond, &stats->mutex);
-	pthread_mutex_unlock(&stats->mutex);
-#else
-	while (1) {
-		unsigned count = stats->qp0_mads_outstanding;
-		if (!count || osm_exit_flag)
-			break;
-		cl_event_wait_on(&stats->event, EVENT_NO_TIMEOUT, TRUE);
-	}
-#endif
-	return osm_exit_flag;
-}
-
 static void reset_node_count(cl_map_item_t * const p_map_item, void *cxt)
 {
 	osm_node_t *p_node = (osm_node_t *) p_map_item;
@@ -898,12 +882,6 @@ void osm_perfmgr_destroy(osm_perfmgr_t * const pm)
 	free(pm->event_db_dump_file);
 	perfmgr_db_destroy(pm->db);
 	cl_timer_destroy(&pm->sweep_timer);
-#ifdef HAVE_LIBPTHREAD
-	pthread_cond_destroy(&pm->subn->p_osm->stats.cond);
-	pthread_mutex_destroy(&pm->subn->p_osm->stats.mutex);
-#else
-	cl_event_destroy(&pm->subn->p_osm->stats.event);
-#endif
 	OSM_LOG_EXIT(pm->log);
 }
 
@@ -1300,15 +1278,6 @@ osm_perfmgr_init(osm_perfmgr_t * const pm,
 	pm->max_outstanding_queries = p_opt->perfmgr_max_outstanding_queries;
 	pm->event_plugin = event_plugin;
 
-#ifdef HAVE_LIBPTHREAD
-	pthread_mutex_init(&subn->p_osm->stats.mutex, NULL);
-	pthread_cond_init(&subn->p_osm->stats.cond, NULL);
-#else
-	status = cl_event_init(&subn->p_osm->stats.event, FALSE);
-	if (status != IB_SUCCESS)
-		goto Exit;
-#endif
-
 	status = cl_timer_init(&pm->sweep_timer, perfmgr_sweep, pm);
 	if (status != IB_SUCCESS)
 		goto Exit;
diff --git a/opensm/opensm/osm_sm_mad_ctrl.c b/opensm/opensm/osm_sm_mad_ctrl.c
index 2638357..c6624a1 100644
--- a/opensm/opensm/osm_sm_mad_ctrl.c
+++ b/opensm/opensm/osm_sm_mad_ctrl.c
@@ -108,13 +108,11 @@ __osm_sm_mad_ctrl_retire_trans_mad(IN osm_sm_mad_ctrl_t * const p_ctrl,
 
 		osm_sm_signal(&p_ctrl->p_subn->p_osm->sm,
 			      OSM_SIGNAL_NO_PENDING_TRANSACTIONS);
-#ifdef ENABLE_OSM_PERF_MGR
 #ifdef HAVE_LIBPTHREAD
 		pthread_cond_signal(&p_ctrl->p_stats->cond);
 #else
 		cl_event_signal(&p_ctrl->p_stats->event);
 #endif
-#endif
 	}
 
 	OSM_LOG_EXIT(p_ctrl->p_log);
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index 93fd880..3746389 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -1314,6 +1314,24 @@ static void __osm_state_mgr_check_tbl_consistency(IN osm_state_mgr_t *
 
 /**********************************************************************
  **********************************************************************/
+int wait_for_pending_transactions(osm_stats_t * stats)
+{
+#ifdef HAVE_LIBPTHREAD
+	pthread_mutex_lock(&stats->mutex);
+	while (stats->qp0_mads_outstanding && !osm_exit_flag)
+		pthread_cond_wait(&stats->cond, &stats->mutex);
+	pthread_mutex_unlock(&stats->mutex);
+#else
+	while (1) {
+		unsigned count = stats->qp0_mads_outstanding;
+		if (!count || osm_exit_flag)
+			break;
+		cl_event_wait_on(&stats->event, EVENT_NO_TIMEOUT, TRUE);
+	}
+#endif
+	return osm_exit_flag;
+}
+
 void osm_state_mgr_process(IN osm_state_mgr_t * const p_mgr,
 			   IN osm_signal_t signal)
 {
-- 
1.5.4.rc2.60.gb2e62




More information about the general mailing list