[ofa-general] [PATCH 3/3] opensm/perfmgr: add support for non-pthread systems

Sasha Khapyorsky sashak at voltaire.com
Sun Jan 27 16:14:00 PST 2008


This makes it possible to use PerfMgr on system which doesn't have
pthread library. Only compilation was tested.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_stats.h |   10 +++++++++-
 opensm/opensm/main.c              |    4 ++++
 opensm/opensm/osm_perfmgr.c       |   19 +++++++++++++++++++
 opensm/opensm/osm_sm_mad_ctrl.c   |    4 ++++
 4 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/opensm/include/opensm/osm_stats.h b/opensm/include/opensm/osm_stats.h
index 51424d1..b5100f2 100644
--- a/opensm/include/opensm/osm_stats.h
+++ b/opensm/include/opensm/osm_stats.h
@@ -49,10 +49,14 @@
 #define _OSM_STATS_H_
 
 #ifdef ENABLE_OSM_PERF_MGR
+#ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
+#else
+#include <complib/cl_event.h>
+#endif
 #endif
-#include <opensm/osm_base.h>
 #include <complib/cl_atomic.h>
+#include <opensm/osm_base.h>
 
 #ifdef __cplusplus
 #  define BEGIN_C_DECLS extern "C" {
@@ -97,8 +101,12 @@ typedef struct _osm_stats {
 	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;
 /*
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index a21cfcc..a2c50f2 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -1044,7 +1044,11 @@ int main(int argc, char *argv[])
 			"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
 	}
 
diff --git a/opensm/opensm/osm_perfmgr.c b/opensm/opensm/osm_perfmgr.c
index 1d92b3b..7c15e74 100644
--- a/opensm/opensm/osm_perfmgr.c
+++ b/opensm/opensm/osm_perfmgr.c
@@ -719,10 +719,19 @@ static int sweep_hop_0(osm_sm_t * const sm)
 
 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;
 }
 
@@ -889,8 +898,12 @@ 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);
 }
 
@@ -1285,8 +1298,14 @@ 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)
diff --git a/opensm/opensm/osm_sm_mad_ctrl.c b/opensm/opensm/osm_sm_mad_ctrl.c
index 5981ca3..2638357 100644
--- a/opensm/opensm/osm_sm_mad_ctrl.c
+++ b/opensm/opensm/osm_sm_mad_ctrl.c
@@ -109,7 +109,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
 	}
 
-- 
1.5.4.rc5




More information about the general mailing list