[ofa-general] [PATCH] opensm: move event_plugin from perfmgr to opensm

Sasha Khapyorsky sashak at voltaire.com
Sat Jun 14 05:55:29 PDT 2008


OpenSM event_plugin can be used for various purposes and not only by
PerfMgr. So make it more OpenSM centric rather than PerfMgr specific.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_event_plugin.h |    2 -
 opensm/include/opensm/osm_opensm.h       |    3 ++
 opensm/include/opensm/osm_perfmgr.h      |   39 +++-----------------
 opensm/include/opensm/osm_perfmgr_db.h   |   11 +++---
 opensm/opensm/osm_console.c              |    4 +-
 opensm/opensm/osm_event_plugin.c         |    8 ----
 opensm/opensm/osm_opensm.c               |   21 ++++++-----
 opensm/opensm/osm_perfmgr.c              |   48 ++++++++++--------------
 opensm/opensm/osm_perfmgr_db.c           |   57 ++++++++++++++++--------------
 9 files changed, 78 insertions(+), 115 deletions(-)

diff --git a/opensm/include/opensm/osm_event_plugin.h b/opensm/include/opensm/osm_event_plugin.h
index 5f939b6..a7cad32 100644
--- a/opensm/include/opensm/osm_event_plugin.h
+++ b/opensm/include/opensm/osm_event_plugin.h
@@ -173,8 +173,6 @@ typedef struct osm_epi_plugin {
  */
 osm_epi_plugin_t *osm_epi_construct(osm_log_t * p_log, char *plugin_name);
 void osm_epi_destroy(osm_epi_plugin_t * plugin);
-void osm_epi_report(osm_epi_plugin_t * plugin,
-		    osm_epi_event_id_t event_id, void *event_data);
 
 /** =========================================================================
  * Helper functions
diff --git a/opensm/include/opensm/osm_opensm.h b/opensm/include/opensm/osm_opensm.h
index 92e4238..63d2247 100644
--- a/opensm/include/opensm/osm_opensm.h
+++ b/opensm/include/opensm/osm_opensm.h
@@ -495,6 +495,9 @@ osm_routing_engine_type_t osm_routing_engine_type(IN const char *str);
 * SEE ALSO
 *********/
 
+void osm_opensm_report_event(osm_opensm_t *osm, osm_epi_event_id_t event_id,
+			     void *event_data);
+
 /* dump helpers */
 void osm_dump_mcast_routes(osm_opensm_t * osm);
 void osm_dump_all(osm_opensm_t * osm);
diff --git a/opensm/include/opensm/osm_perfmgr.h b/opensm/include/opensm/osm_perfmgr.h
index 50a2c32..874f6cf 100644
--- a/opensm/include/opensm/osm_perfmgr.h
+++ b/opensm/include/opensm/osm_perfmgr.h
@@ -105,6 +105,7 @@ typedef struct _monitored_node {
 	redir_t redir_port[1];	/* redirection on a per port basis */
 } __monitored_node_t;
 
+struct _osm_opensm_t;
 /****s* OpenSM: PerfMgr/osm_perfmgr_t
 *  This object should be treated as opaque and should
 *  be manipulated only through the provided functions.
@@ -112,6 +113,7 @@ typedef struct _monitored_node {
 typedef struct _osm_perfmgr {
 	cl_event_t sig_sweep;
 	cl_timer_t sweep_timer;
+	struct _osm_opensm_t *osm;
 	osm_subn_t *subn;
 	osm_sm_t *sm;
 	cl_plock_t *lock;
@@ -130,7 +132,6 @@ typedef struct _osm_perfmgr {
 	uint32_t max_outstanding_queries;
 	cl_qmap_t monitored_map;	/* map the nodes we are tracking */
 	__monitored_node_t *remove_list;
-	osm_epi_plugin_t *event_plugin;
 } osm_perfmgr_t;
 /*
 * FIELDS
@@ -223,47 +224,19 @@ void osm_perfmgr_process(osm_perfmgr_t * pm);
 
 /****f* OpenSM: PerfMgr/osm_perfmgr_init */
 ib_api_status_t osm_perfmgr_init(osm_perfmgr_t * const perfmgr,
-				 osm_subn_t * const subn,
-				 osm_sm_t * const sm,
-				 osm_log_t * const log,
-				 osm_mad_pool_t * const mad_pool,
-				 osm_vendor_t * const vendor,
-				 cl_dispatcher_t * const disp,
-				 cl_plock_t * const lock,
-				 const osm_subn_opt_t * const p_opt,
-				 osm_epi_plugin_t * event_plugin);
+				 struct _osm_opensm_t *osm,
+				 const osm_subn_opt_t * const p_opt);
 /*
 * PARAMETERS
 *	perfmgr
 *		[in] Pointer to an osm_perfmgr_t object to initialize.
 *
-*	subn
-*		[in] Pointer to the Subnet object for this subnet.
-*
-*	sm
-*		[in] Pointer to the Subnet object for this subnet.
-*
-*	log
-*		[in] Pointer to the log object.
-*
-*	mad_pool
-*		[in] Pointer to the MAD pool.
-*
-*	vendor
-*		[in] Pointer to the vendor specific interfaces object.
-*
-*	disp
-*		[in] Pointer to the OpenSM central Dispatcher.
-*
-*	lock
-*		[in] Pointer to the OpenSM serializing lock.
+*	osm
+*		[in] Pointer to the OpenSM object.
 *
 *	p_opt
 *		[in] Starting options
 *
-*	event_plugin
-*		[in] Event plugin (Can be NULL if not available)
-*
 * RETURN VALUES
 *	IB_SUCCESS if the PerfMgr object was initialized successfully.
 *********/
diff --git a/opensm/include/opensm/osm_perfmgr_db.h b/opensm/include/opensm/osm_perfmgr_db.h
index 2c4c520..79f369e 100644
--- a/opensm/include/opensm/osm_perfmgr_db.h
+++ b/opensm/include/opensm/osm_perfmgr_db.h
@@ -34,12 +34,11 @@
 #ifndef _PERFMGR_EVENT_DB_H_
 #define _PERFMGR_EVENT_DB_H_
 
+#include <stdio.h>
 #include <time.h>
-#include <opensm/osm_log.h>
 #include <iba/ib_types.h>
 #include <complib/cl_qmap.h>
 #include <complib/cl_passivelock.h>
-#include <opensm/osm_event_plugin.h>
 
 #ifdef __cplusplus
 #  define BEGIN_C_DECLS extern "C" {
@@ -50,6 +49,8 @@
 #endif				/* __cplusplus */
 
 BEGIN_C_DECLS
+
+struct _osm_perfmgr;
 /****h* OpenSM/PerfMgr Event Database
 * DESCRIPTION
 *       Database interface to record subnet events
@@ -149,15 +150,13 @@ typedef struct _db_node {
 typedef struct _db {
 	cl_qmap_t pc_data;	/* stores type (_db_node_t *) */
 	cl_plock_t lock;
-	osm_log_t *osm_log;
-	osm_epi_plugin_t *event_plugin;
+	struct _osm_perfmgr *perfmgr;
 } perfmgr_db_t;
 
 /**
  * functions
  */
-perfmgr_db_t *perfmgr_db_construct(osm_log_t * p_log,
-				   osm_epi_plugin_t * event_plugin);
+perfmgr_db_t *perfmgr_db_construct(struct _osm_perfmgr *perfmgr);
 void perfmgr_db_destroy(perfmgr_db_t * db);
 
 perfmgr_db_err_t perfmgr_db_create_entry(perfmgr_db_t * db, uint64_t guid,
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index bda48a3..f74465e 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -1121,8 +1121,8 @@ static void perfmgr_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 			osm_perfmgr_get_sweep_time_s(&(p_osm->perfmgr)),
 			p_osm->perfmgr.outstanding_queries,
 			p_osm->perfmgr.max_outstanding_queries,
-			p_osm->perfmgr.event_plugin ?
-			p_osm->perfmgr.event_plugin->plugin_name : "NONE");
+			p_osm->event_plugin ?
+			p_osm->event_plugin->plugin_name : "NONE");
 	}
 }
 #endif				/* ENABLE_OSM_PERF_MGR */
diff --git a/opensm/opensm/osm_event_plugin.c b/opensm/opensm/osm_event_plugin.c
index 42282c6..3575060 100644
--- a/opensm/opensm/osm_event_plugin.c
+++ b/opensm/opensm/osm_event_plugin.c
@@ -137,11 +137,3 @@ void osm_epi_destroy(osm_epi_plugin_t * plugin)
 		free(plugin);
 	}
 }
-
-void
-osm_epi_report(osm_epi_plugin_t * plugin, osm_epi_event_id_t event_id,
-	       void *event_data)
-{
-	if (plugin && plugin->impl->report)
-		plugin->impl->report(plugin->plugin_data, event_id, event_data);
-}
diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index 167caab..a85bcb7 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -57,6 +57,7 @@
 #include <opensm/osm_subnet.h>
 #include <opensm/osm_sm.h>
 #include <opensm/osm_vl15intf.h>
+#include <opensm/osm_event_plugin.h>
 
 struct routing_engine_module {
 	const char *name;
@@ -351,15 +352,7 @@ osm_opensm_init(IN osm_opensm_t * const p_osm,
 						p_opt->event_plugin_name);
 
 #ifdef ENABLE_OSM_PERF_MGR
-	status = osm_perfmgr_init(&p_osm->perfmgr,
-				  &p_osm->subn,
-				  &p_osm->sm,
-				  &p_osm->log,
-				  &p_osm->mad_pool,
-				  p_osm->p_vendor,
-				  &p_osm->disp,
-				  &p_osm->lock, p_opt, p_osm->event_plugin);
-
+	status = osm_perfmgr_init(&p_osm->perfmgr, p_osm, p_opt);
 	if (status != IB_SUCCESS)
 		goto Exit;
 #endif				/* ENABLE_OSM_PERF_MGR */
@@ -407,3 +400,13 @@ Exit:
 	OSM_LOG_EXIT(&p_osm->log);
 	return (status);
 }
+
+/**********************************************************************
+ **********************************************************************/
+void osm_opensm_report_event(osm_opensm_t *osm, osm_epi_event_id_t event_id,
+			     void *event_data)
+{
+	if (osm->event_plugin && osm->event_plugin->impl->report)
+		osm->event_plugin->impl->report(osm->event_plugin->plugin_data,
+						event_id, event_data);
+}
diff --git a/opensm/opensm/osm_perfmgr.c b/opensm/opensm/osm_perfmgr.c
index 1633c41..315a065 100644
--- a/opensm/opensm/osm_perfmgr.c
+++ b/opensm/opensm/osm_perfmgr.c
@@ -51,18 +51,18 @@
 #include <stdint.h>
 #include <string.h>
 #include <poll.h>
-#include <netinet/in.h>
-#include <complib/cl_debug.h>
-#include <iba/ib_types.h>
 #include <errno.h>
 #include <sys/time.h>
+#include <netinet/in.h>
+#include <float.h>
+#include <iba/ib_types.h>
+#include <complib/cl_debug.h>
+#include <complib/cl_thread.h>
+#include <vendor/osm_vendor_api.h>
 #include <opensm/osm_perfmgr.h>
 #include <opensm/osm_log.h>
 #include <opensm/osm_node.h>
 #include <opensm/osm_opensm.h>
-#include <complib/cl_thread.h>
-#include <vendor/osm_vendor_api.h>
-#include <float.h>
 
 #define OSM_PERFMGR_INITIAL_TID_VALUE 0xcafe
 
@@ -1213,51 +1213,43 @@ Exit:
  * Initialize the PerfMgr object
  **********************************************************************/
 ib_api_status_t
-osm_perfmgr_init(osm_perfmgr_t * const pm,
-		 osm_subn_t * const subn,
-		 osm_sm_t * const sm,
-		 osm_log_t * const log,
-		 osm_mad_pool_t * const mad_pool,
-		 osm_vendor_t * const vendor,
-		 cl_dispatcher_t * const disp,
-		 cl_plock_t * const lock,
-		 const osm_subn_opt_t * const p_opt,
-		 osm_epi_plugin_t * event_plugin)
+osm_perfmgr_init(osm_perfmgr_t * const pm, osm_opensm_t *osm,
+		 const osm_subn_opt_t * const p_opt)
 {
 	ib_api_status_t status = IB_SUCCESS;
 
-	OSM_LOG_ENTER(log);
+	OSM_LOG_ENTER(&osm->log);
 
-	OSM_LOG(log, OSM_LOG_VERBOSE, "Initializing PerfMgr\n");
+	OSM_LOG(&osm->log, OSM_LOG_VERBOSE, "Initializing PerfMgr\n");
 
 	memset(pm, 0, sizeof(*pm));
 
 	cl_event_construct(&pm->sig_sweep);
 	cl_event_init(&pm->sig_sweep, FALSE);
-	pm->subn = subn;
-	pm->sm = sm;
-	pm->log = log;
-	pm->mad_pool = mad_pool;
-	pm->vendor = vendor;
+	pm->subn = &osm->subn;
+	pm->sm = &osm->sm;
+	pm->log = &osm->log;
+	pm->mad_pool = &osm->mad_pool;
+	pm->vendor = osm->p_vendor;
 	pm->trans_id = OSM_PERFMGR_INITIAL_TID_VALUE;
-	pm->lock = lock;
+	pm->lock = &osm->lock;
 	pm->state =
 	    p_opt->perfmgr ? PERFMGR_STATE_ENABLED : PERFMGR_STATE_DISABLE;
 	pm->sweep_time_s = p_opt->perfmgr_sweep_time_s;
 	pm->max_outstanding_queries = p_opt->perfmgr_max_outstanding_queries;
-	pm->event_plugin = event_plugin;
+	pm->osm = osm;
 
 	status = cl_timer_init(&pm->sweep_timer, perfmgr_sweep, pm);
 	if (status != IB_SUCCESS)
 		goto Exit;
 
-	pm->db = perfmgr_db_construct(pm->log, pm->event_plugin);
+	pm->db = perfmgr_db_construct(pm);
 	if (!pm->db) {
 		pm->state = PERFMGR_STATE_NO_DB;
 		goto Exit;
 	}
 
-	pm->pc_disp_h = cl_disp_register(disp, OSM_MSG_MAD_PORT_COUNTERS,
+	pm->pc_disp_h = cl_disp_register(&osm->disp, OSM_MSG_MAD_PORT_COUNTERS,
 					 osm_pc_rcv_process, pm);
 	if (pm->pc_disp_h == CL_DISP_INVALID_HANDLE)
 		goto Exit;
@@ -1267,7 +1259,7 @@ osm_perfmgr_init(osm_perfmgr_t * const pm,
 	cl_timer_start(&pm->sweep_timer, pm->sweep_time_s * 1000);
 
 Exit:
-	OSM_LOG_EXIT(log);
+	OSM_LOG_EXIT(pm->log);
 	return (status);
 }
 
diff --git a/opensm/opensm/osm_perfmgr_db.c b/opensm/opensm/osm_perfmgr_db.c
index 21ba923..031c9ac 100644
--- a/opensm/opensm/osm_perfmgr_db.c
+++ b/opensm/opensm/osm_perfmgr_db.c
@@ -42,11 +42,12 @@
 #include <sys/stat.h>
 
 #include <opensm/osm_perfmgr_db.h>
+#include <opensm/osm_perfmgr.h>
+#include <opensm/osm_opensm.h>
 
 /** =========================================================================
  */
-perfmgr_db_t *perfmgr_db_construct(osm_log_t * p_log,
-				   osm_epi_plugin_t * event_plugin)
+perfmgr_db_t *perfmgr_db_construct(osm_perfmgr_t *perfmgr)
 {
 	perfmgr_db_t *db = malloc(sizeof(*db));
 	if (!db)
@@ -55,8 +56,7 @@ perfmgr_db_t *perfmgr_db_construct(osm_log_t * p_log,
 	cl_qmap_init(&(db->pc_data));
 	cl_plock_construct(&(db->lock));
 	cl_plock_init(&(db->lock));
-	db->osm_log = p_log;
-	db->event_plugin = event_plugin;
+	db->perfmgr = perfmgr;
 	return ((void *)db);
 }
 
@@ -178,57 +178,59 @@ static inline void
 debug_dump_err_reading(perfmgr_db_t * db, uint64_t guid, uint8_t port_num,
 		       _db_port_t * port, perfmgr_db_err_reading_t * cur)
 {
-	if (!osm_log_is_active(db->osm_log, OSM_LOG_DEBUG))
+	osm_log_t *log = db->perfmgr->log;
+
+	if (!osm_log_is_active(log, OSM_LOG_DEBUG))
 		return;		/* optimize this a bit */
 
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"GUID 0x%" PRIx64 " Port %u:\n", guid, port_num);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"sym %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->symbol_err_cnt, port->err_previous.symbol_err_cnt,
 		port->err_total.symbol_err_cnt);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"ler %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->link_err_recover, port->err_previous.link_err_recover,
 		port->err_total.link_err_recover);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"ld %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->link_downed, port->err_previous.link_downed,
 		port->err_total.link_downed);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"re %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n", cur->rcv_err,
 		port->err_previous.rcv_err, port->err_total.rcv_err);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"rrp %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->rcv_rem_phys_err, port->err_previous.rcv_rem_phys_err,
 		port->err_total.rcv_rem_phys_err);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"rsr %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->rcv_switch_relay_err,
 		port->err_previous.rcv_switch_relay_err,
 		port->err_total.rcv_switch_relay_err);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"xd %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->xmit_discards, port->err_previous.xmit_discards,
 		port->err_total.xmit_discards);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"xce %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->xmit_constraint_err,
 		port->err_previous.xmit_constraint_err,
 		port->err_total.xmit_constraint_err);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"rce %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->rcv_constraint_err, port->err_previous.rcv_constraint_err,
 		port->err_total.rcv_constraint_err);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"li %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->link_integrity, port->err_previous.link_integrity,
 		port->err_total.link_integrity);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"bo %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->buffer_overrun, port->err_previous.buffer_overrun,
 		port->err_total.buffer_overrun);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"vld %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->vl15_dropped, port->err_previous.vl15_dropped,
 		port->err_total.vl15_dropped);
@@ -302,8 +304,8 @@ perfmgr_db_add_err_reading(perfmgr_db_t * db, uint64_t guid,
 
 	p_port->err_previous = *reading;
 
-	osm_epi_report(db->event_plugin, OSM_EVENT_ID_PORT_ERRORS,
-		       (void *)&epi_pe_data);
+	osm_opensm_report_event(db->perfmgr->osm, OSM_EVENT_ID_PORT_ERRORS,
+				&epi_pe_data);
 
 Exit:
 	cl_plock_release(&(db->lock));
@@ -356,21 +358,22 @@ static inline void
 debug_dump_dc_reading(perfmgr_db_t * db, uint64_t guid, uint8_t port_num,
 		      _db_port_t * port, perfmgr_db_data_cnt_reading_t * cur)
 {
-	if (!osm_log_is_active(db->osm_log, OSM_LOG_DEBUG))
+	osm_log_t *log = db->perfmgr->log;
+	if (!osm_log_is_active(log, OSM_LOG_DEBUG))
 		return;		/* optimize this a big */
 
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"xd %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->xmit_data, port->dc_previous.xmit_data,
 		port->dc_total.xmit_data);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"rd %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n", cur->rcv_data,
 		port->dc_previous.rcv_data, port->dc_total.rcv_data);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"xp %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n",
 		cur->xmit_pkts, port->dc_previous.xmit_pkts,
 		port->dc_total.xmit_pkts);
-	osm_log(db->osm_log, OSM_LOG_DEBUG,
+	osm_log(log, OSM_LOG_DEBUG,
 		"rp %" PRIu64 " <-- %" PRIu64 " (%" PRIu64 ")\n", cur->rcv_pkts,
 		port->dc_previous.rcv_pkts, port->dc_total.rcv_pkts);
 }
@@ -426,8 +429,8 @@ perfmgr_db_add_dc_reading(perfmgr_db_t * db, uint64_t guid,
 
 	p_port->dc_previous = *reading;
 
-	osm_epi_report(db->event_plugin, OSM_EVENT_ID_PORT_DATA_COUNTERS,
-		       (void *)&epi_dc_data);
+	osm_opensm_report_event(db->perfmgr->osm,
+				OSM_EVENT_ID_PORT_DATA_COUNTERS, &epi_dc_data);
 
 Exit:
 	cl_plock_release(&(db->lock));
-- 
1.5.5.1.178.g1f811




More information about the general mailing list