[ofa-general] [PATCH] opensm: timer driven periodic sweep

Sasha Khapyorsky sashak at voltaire.com
Wed Aug 29 09:27:54 PDT 2007


Periodic SM sweep (as specified by sweep_interval) is driven by cl_timer
now.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_sm.h |    1 +
 opensm/opensm/osm_sm.c         |   31 ++++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/opensm/include/opensm/osm_sm.h b/opensm/include/opensm/osm_sm.h
index 341ec5a..4c6ce27 100644
--- a/opensm/include/opensm/osm_sm.h
+++ b/opensm/include/opensm/osm_sm.h
@@ -129,6 +129,7 @@ typedef struct osm_sm {
 	cl_spinlock_t signal_lock;
 	cl_event_t signal_event;
 	cl_event_t subnet_up_event;
+	cl_timer_t sweep_timer;
 	cl_thread_t sweeper;
 	osm_subn_t *p_subn;
 	osm_db_t *p_db;
diff --git a/opensm/opensm/osm_sm.c b/opensm/opensm/osm_sm.c
index c698492..154ac8e 100644
--- a/opensm/opensm/osm_sm.c
+++ b/opensm/opensm/osm_sm.c
@@ -83,9 +83,7 @@ static void __osm_sm_sweeper(IN void *p_ptr)
 		 * signaling the event.
 		 */
 		status = cl_event_wait_on(&p_sm->signal_event,
-					  p_sm->p_subn->opt.sweep_interval ?
-					  p_sm->p_subn->opt.sweep_interval *
-					  1000000 : EVENT_NO_TIMEOUT, TRUE);
+					  EVENT_NO_TIMEOUT, TRUE);
 
 		if (status == CL_SUCCESS)
 			osm_log(p_sm->p_log, OSM_LOG_DEBUG,
@@ -104,12 +102,6 @@ static void __osm_sm_sweeper(IN void *p_ptr)
 		p_sm->signal_mask = 0;
 		cl_spinlock_release(&p_sm->signal_lock);
 
-		/*  do the sweep only if we are in MASTER state */
-		if (status == CL_TIMEOUT &&
-		    (p_sm->p_subn->sm_state == IB_SMINFO_STATE_MASTER ||
-		     p_sm->p_subn->sm_state == IB_SMINFO_STATE_DISCOVERING))
-			signals |= 1 << OSM_SIGNAL_SWEEP;
-
 		for (i = 0 ; signals ; signals >>= 1 , i++)
 			if (signals&1)
 				osm_state_mgr_process(&p_sm->state_mgr, i);
@@ -118,6 +110,17 @@ static void __osm_sm_sweeper(IN void *p_ptr)
 	OSM_LOG_EXIT(p_sm->p_log);
 }
 
+static void sm_sweep(void *arg)
+{
+	osm_sm_t *sm = arg;
+
+	/*  do the sweep only if we are in MASTER state */
+	if (sm->p_subn->sm_state == IB_SMINFO_STATE_MASTER ||
+	    sm->p_subn->sm_state == IB_SMINFO_STATE_DISCOVERING)
+		osm_sm_signal(sm, OSM_SIGNAL_SWEEP);
+	cl_timer_start(&sm->sweep_timer, sm->p_subn->opt.sweep_interval*1000);
+}
+
 /**********************************************************************
  **********************************************************************/
 void osm_sm_construct(IN osm_sm_t * const p_sm)
@@ -176,6 +179,7 @@ void osm_sm_shutdown(IN osm_sm_t * const p_sm)
 	if (signal_event)
 		cl_event_signal(&p_sm->signal_event);
 
+	cl_timer_stop(&p_sm->sweep_timer);
 	cl_thread_destroy(&p_sm->sweeper);
 
 	/*
@@ -225,6 +229,7 @@ void osm_sm_destroy(IN osm_sm_t * const p_sm)
 	osm_state_mgr_destroy(&p_sm->state_mgr);
 	osm_sm_state_mgr_destroy(&p_sm->sm_state_mgr);
 	osm_mcast_mgr_destroy(&p_sm->mcast_mgr);
+	cl_timer_destroy(&p_sm->sweep_timer);
 	cl_event_destroy(&p_sm->signal_event);
 	cl_event_destroy(&p_sm->subnet_up_event);
 	cl_spinlock_destroy(&p_sm->signal_lock);
@@ -271,6 +276,10 @@ osm_sm_init(IN osm_sm_t * const p_sm,
 	if (status != CL_SUCCESS)
 		goto Exit;
 
+	status = cl_timer_init(&p_sm->sweep_timer, sm_sweep, p_sm);
+	if (status != CL_SUCCESS)
+		goto Exit;
+
 	status = osm_sm_mad_ctrl_init(&p_sm->mad_ctrl,
 				      p_sm->p_subn,
 				      p_sm->p_mad_pool,
@@ -481,6 +490,10 @@ osm_sm_init(IN osm_sm_t * const p_sm,
 	if (status != IB_SUCCESS)
 		goto Exit;
 
+	if (p_sm->p_subn->opt.sweep_interval)
+		cl_timer_start(&p_sm->sweep_timer,
+			       p_sm->p_subn->opt.sweep_interval*1000);
+
       Exit:
 	OSM_LOG_EXIT(p_log);
 	return (status);
-- 
1.5.3.rc2.38.g11308




More information about the general mailing list