[ofa-general] [PATCH] opensm: cleanup sm->state field

Sasha Khapyorsky sashak at voltaire.com
Sun Feb 10 11:51:30 PST 2008


Remove actually duplicated sm->state, instead refer sm_state only.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_base.h   |   25 +--------
 opensm/include/opensm/osm_helper.h |   23 ---------
 opensm/include/opensm/osm_sm.h     |    1 -
 opensm/opensm/osm_console.c        |   27 ++--------
 opensm/opensm/osm_helper.c         |   19 +-------
 opensm/opensm/osm_perfmgr.c        |    9 +---
 opensm/opensm/osm_sm.c             |    2 -
 opensm/opensm/osm_sm_state_mgr.c   |    5 +-
 opensm/opensm/osm_state_mgr.c      |   97 ++++++++----------------------------
 9 files changed, 35 insertions(+), 173 deletions(-)

diff --git a/opensm/include/opensm/osm_base.h b/opensm/include/opensm/osm_base.h
index d5e3c27..1a9abf0 100644
--- a/opensm/include/opensm/osm_base.h
+++ b/opensm/include/opensm/osm_base.h
@@ -740,24 +740,6 @@ typedef enum _osm_thread_state {
 #define OSM_CAP2_IS_QOS_SUPPORTED (1 << 1)
 /***********/
 
-/****d* OpenSM: Base/osm_sm_state_t
-* NAME
-*	osm_sm_state_t
-*
-* DESCRIPTION
-*	Enumerates the possible states of the SM object.
-*
-* SYNOPSIS
-*/
-typedef enum _osm_sm_state {
-	OSM_SM_STATE_NO_STATE = 0,
-	OSM_SM_STATE_INIT,
-	OSM_SM_STATE_IDLE,
-	OSM_SM_STATE_STANDBY,
-	OSM_SM_STATE_MAX
-} osm_sm_state_t;
-/***********/
-
 /****d* OpenSM: Base/osm_signal_t
 * NAME
 *	osm_signal_t
@@ -773,15 +755,14 @@ typedef enum _osm_sm_state {
 #define OSM_SIGNAL_NONE				0
 #define OSM_SIGNAL_SWEEP			1
 #define OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST	2
-#define OSM_SIGNAL_EXIT_STBY			3
-#define OSM_SIGNAL_PERFMGR_SWEEP		4
-#define OSM_SIGNAL_MAX				4
+#define OSM_SIGNAL_PERFMGR_SWEEP		3
+#define OSM_SIGNAL_MAX				3
 
 /* status values for sweep managers - can be removed later */
 #define OSM_SIGNAL_DONE		16
 #define OSM_SIGNAL_DONE_PENDING	17
 
-typedef uintn_t osm_signal_t;
+typedef unsigned int osm_signal_t;
 /***********/
 
 /****d* OpenSM: Base/osm_sm_signal_t
diff --git a/opensm/include/opensm/osm_helper.h b/opensm/include/opensm/osm_helper.h
index 5cbb8f0..bd885d7 100644
--- a/opensm/include/opensm/osm_helper.h
+++ b/opensm/include/opensm/osm_helper.h
@@ -446,29 +446,6 @@ void osm_dump_sa_mad(IN osm_log_t * const p_log,
 		     IN const ib_sa_mad_t * const p_smp,
 		     IN const osm_log_level_t level);
 
-/****f* IBA Base: Types/osm_get_sm_state_str
-* NAME
-*	osm_get_sm_state_str
-*
-* DESCRIPTION
-*	Returns a string for the specified SM state.
-*
-* SYNOPSIS
-*/
-const char *osm_get_sm_state_str(IN osm_sm_state_t state);
-/*
-* PARAMETERS
-*	state
-*		[in] SM State value
-*
-* RETURN VALUES
-*	Pointer to the state discription string.
-*
-* NOTES
-*
-* SEE ALSO
-*********/
-
 /****f* IBA Base: Types/osm_get_sm_signal_str
 * NAME
 *	osm_get_sm_signal_str
diff --git a/opensm/include/opensm/osm_sm.h b/opensm/include/opensm/osm_sm.h
index 25d0983..e77222d 100644
--- a/opensm/include/opensm/osm_sm.h
+++ b/opensm/include/opensm/osm_sm.h
@@ -112,7 +112,6 @@ BEGIN_C_DECLS
 */
 typedef struct osm_sm {
 	osm_thread_state_t thread_state;
-	osm_sm_state_t state;
 	unsigned signal_mask;
 	cl_spinlock_t signal_lock;
 	cl_spinlock_t state_lock;
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index 86f89ea..4597bde 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -289,33 +289,16 @@ static char *sa_state_str(osm_sa_state_t state)
 	return ("UNKNOWN");
 }
 
-static char *sm_state_mgr_str(osm_sm_state_t state)
-{
-	switch (state) {
-	case OSM_SM_STATE_NO_STATE:
-		return ("No State");
-	case OSM_SM_STATE_INIT:
-		return ("Init");
-	case OSM_SM_STATE_IDLE:
-		return ("Idle");
-	case OSM_SM_STATE_STANDBY:
-		return ("Standby");
-	default:
-		return ("Unknown State");
-	}
-}
-
 static void print_status(osm_opensm_t * p_osm, FILE * out)
 {
 	if (out) {
 		cl_plock_acquire(&p_osm->lock);
-		fprintf(out, "   OpenSM Version     : %s\n", OSM_VERSION);
-		fprintf(out, "   SM State/Mgr State : %s/%s\n",
-			sm_state_str(p_osm->subn.sm_state),
-			sm_state_mgr_str(p_osm->sm.state));
-		fprintf(out, "   SA State           : %s\n",
+		fprintf(out, "   OpenSM Version: %s\n", OSM_VERSION);
+		fprintf(out, "   SM State      : %s\n",
+			sm_state_str(p_osm->subn.sm_state));
+		fprintf(out, "   SA State      : %s\n",
 			sa_state_str(p_osm->sa.state));
-		fprintf(out, "   Routing Engine     : %s\n",
+		fprintf(out, "   Routing Engine: %s\n",
 			osm_routing_engine_type_str(p_osm->
 						    routing_engine_used));
 #ifdef ENABLE_OSM_PERF_MGR
diff --git a/opensm/opensm/osm_helper.c b/opensm/opensm/osm_helper.c
index 0c11198..cbc2a99 100644
--- a/opensm/opensm/osm_helper.c
+++ b/opensm/opensm/osm_helper.c
@@ -2060,15 +2060,7 @@ osm_dump_smp_dr_path(IN osm_log_t * const p_log,
 	}
 }
 
-const char *const __osm_sm_state_str[] = {
-	"OSM_SM_STATE_NO_STATE",	/* 0 */
-	"OSM_SM_STATE_INIT",	/* 1 */
-	"OSM_SM_STATE_IDLE",	/* 2 */
-	"OSM_SM_STATE_STANDBY",	/* 3 */
-	"UNKNOWN STATE!!"	/* 4 */
-};
-
-const char *const __osm_sm_signal_str[] = {
+static const char *const __osm_sm_signal_str[] = {
 	"OSM_SIGNAL_NONE",	/* 0 */
 	"OSM_SIGNAL_SWEEP",	/* 1 */
 	"OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST",	/* 2 */
@@ -2079,15 +2071,6 @@ const char *const __osm_sm_signal_str[] = {
 
 /**********************************************************************
  **********************************************************************/
-const char *osm_get_sm_state_str(IN osm_sm_state_t state)
-{
-	if (state > OSM_SM_STATE_MAX)
-		state = OSM_SM_STATE_MAX;
-	return (__osm_sm_state_str[state]);
-}
-
-/**********************************************************************
- **********************************************************************/
 const char *osm_get_sm_signal_str(IN osm_signal_t signal)
 {
 	if (signal > OSM_SIGNAL_MAX)
diff --git a/opensm/opensm/osm_perfmgr.c b/opensm/opensm/osm_perfmgr.c
index 1099445..2b0d6f0 100644
--- a/opensm/opensm/osm_perfmgr.c
+++ b/opensm/opensm/osm_perfmgr.c
@@ -790,13 +790,8 @@ void osm_perfmgr_process(osm_perfmgr_t * pm)
 	if (pm->state != PERFMGR_STATE_ENABLED)
 		return;
 
-	if (pm->sm->state != OSM_SM_STATE_IDLE &&
-	    pm->sm->state != OSM_SM_STATE_STANDBY)
-		return;
-
-	if (pm->sm->state == OSM_SM_STATE_STANDBY ||
-	    (pm->sm->state == OSM_SM_STATE_IDLE &&
-	     pm->subn->sm_state == IB_SMINFO_STATE_NOTACTIVE))
+	if (pm->subn->sm_state == IB_SMINFO_STATE_STANDBY ||
+	    pm->subn->sm_state == IB_SMINFO_STATE_NOTACTIVE)
 		perfmgr_discovery(pm->subn->p_osm);
 
 #if ENABLE_OSM_PERF_MGR_PROFILE
diff --git a/opensm/opensm/osm_sm.c b/opensm/opensm/osm_sm.c
index f2cc550..bdbb2e6 100644
--- a/opensm/opensm/osm_sm.c
+++ b/opensm/opensm/osm_sm.c
@@ -157,7 +157,6 @@ void osm_sm_construct(IN osm_sm_t * const p_sm)
 {
 	memset(p_sm, 0, sizeof(*p_sm));
 	p_sm->thread_state = OSM_THREAD_STATE_NONE;
-	p_sm->state = OSM_SM_STATE_INIT;
 	p_sm->sm_trans_id = OSM_SM_INITIAL_TID_VALUE;
 	cl_spinlock_construct(&p_sm->signal_lock);
 	cl_spinlock_construct(&p_sm->state_lock);
@@ -406,7 +405,6 @@ osm_sm_init(IN osm_sm_t * const p_sm,
 	 * the sweeper thread if the user wants sweeping.
 	 */
 	p_sm->thread_state = OSM_THREAD_STATE_RUN;
-	p_sm->state = OSM_SM_STATE_IDLE;
 	status = cl_thread_init(&p_sm->sweeper, __osm_sm_sweeper, p_sm,
 				"opensm sweeper");
 	if (status != IB_SUCCESS)
diff --git a/opensm/opensm/osm_sm_state_mgr.c b/opensm/opensm/osm_sm_state_mgr.c
index fab90bf..9c1c1f3 100644
--- a/opensm/opensm/osm_sm_state_mgr.c
+++ b/opensm/opensm/osm_sm_state_mgr.c
@@ -391,7 +391,7 @@ ib_api_status_t osm_sm_state_mgr_process(osm_sm_t *sm,
 			sm->p_subn->sm_state = IB_SMINFO_STATE_DISCOVERING;
 			osm_report_sm_state(sm);
 			sm->p_subn->coming_out_of_standby = TRUE;
-			osm_sm_signal(sm, OSM_SIGNAL_EXIT_STBY);
+			osm_sm_signal(sm, OSM_SIGNAL_SWEEP);
 			break;
 		case OSM_SM_SIGNAL_DISABLE:
 			/*
@@ -399,6 +399,7 @@ ib_api_status_t osm_sm_state_mgr_process(osm_sm_t *sm,
 			 */
 			sm->p_subn->sm_state = IB_SMINFO_STATE_NOTACTIVE;
 			osm_report_sm_state(sm);
+			osm_vendor_set_sm(sm->mad_ctrl.h_bind, FALSE);
 			break;
 		case OSM_SM_SIGNAL_HANDOVER:
 			/*
@@ -423,7 +424,7 @@ ib_api_status_t osm_sm_state_mgr_process(osm_sm_t *sm,
 			sm->p_subn->master_sm_base_lid =
 			    sm->p_subn->sm_base_lid;
 			sm->p_subn->coming_out_of_standby = TRUE;
-			osm_sm_signal(sm, OSM_SIGNAL_EXIT_STBY);
+			osm_sm_signal(sm, OSM_SIGNAL_SWEEP);
 			break;
 		case OSM_SM_SIGNAL_ACKNOWLEDGE:
 			/*
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index c53ed45..2f3c366 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -94,37 +94,6 @@ static void __osm_state_mgr_up_msg(IN const osm_sm_t *sm)
 
 /**********************************************************************
  **********************************************************************/
-static void
-__osm_state_mgr_signal_warning(IN osm_sm_t *sm,
-			       IN const osm_signal_t signal)
-{
-	osm_log(sm->p_log, OSM_LOG_VERBOSE,
-		"__osm_state_mgr_signal_warning: "
-		"Invalid signal %s(%lu) in state %s\n",
-		osm_get_sm_signal_str(signal), signal,
-		osm_get_sm_state_str(sm->state));
-}
-
-/**********************************************************************
- **********************************************************************/
-static void
-__osm_state_mgr_signal_error(IN osm_sm_t *sm,
-			     IN const osm_signal_t signal)
-{
-	/* the Request for IDLE processing can come async to the state so it
-	 * really is just verbose ... */
-	if (signal == OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST)
-		__osm_state_mgr_signal_warning(sm, signal);
-	else
-		osm_log(sm->p_log, OSM_LOG_ERROR,
-			"__osm_state_mgr_signal_error: ERR 3303: "
-			"Invalid signal %s(%lu) in state %s\n",
-			osm_get_sm_signal_str(signal), signal,
-			osm_get_sm_state_str(sm->state));
-}
-
-/**********************************************************************
- **********************************************************************/
 static void __osm_state_mgr_reset_node_count(IN cl_map_item_t *
 					     const p_map_item, IN void *context)
 {
@@ -1046,6 +1015,18 @@ static void do_sweep(osm_sm_t * sm)
 	ib_api_status_t status;
 	osm_remote_sm_t *p_remote_sm;
 
+	if (sm->p_subn->sm_state != IB_SMINFO_STATE_MASTER &&
+	    sm->p_subn->sm_state != IB_SMINFO_STATE_DISCOVERING)
+		return;
+
+	if (sm->p_subn->coming_out_of_standby)
+		/*
+		 * Need to force re-write of sm_base_lid to all ports
+		 * to do that we want all the ports to be considered
+		 * foriegn
+		 */
+		__osm_state_mgr_clean_known_lids(sm);
+
 	sm->master_sm_found = 0;
 
 	/*
@@ -1116,7 +1097,6 @@ _repeat_discovery:
 
 	/* discovery completed - check other sm presense */
 	if (sm->master_sm_found) {
-		sm->state = OSM_SM_STATE_STANDBY;
 		/*
 		 * Call the sm_state_mgr with signal
 		 * MASTER_OR_HIGHER_SM_DETECTED_DONE
@@ -1149,7 +1129,6 @@ _repeat_discovery:
 			__osm_state_mgr_send_handover(sm, p_remote_sm);
 			osm_sm_state_mgr_process(sm,
 						 OSM_SM_SIGNAL_HANDOVER_SENT);
-			sm->state = OSM_SM_STATE_STANDBY;
 			return;
 		} else {
 			/* We are the highest sm - check to see if there is
@@ -1305,6 +1284,8 @@ _repeat_discovery:
 
 static void do_process_mgrp_queue(osm_sm_t * sm)
 {
+	if (sm->p_subn->sm_state != IB_SMINFO_STATE_MASTER)
+		return;
 	osm_mcast_mgr_process_mgroups(&sm->mcast_mgr);
 	wait_for_pending_transactions(&sm->p_subn->p_osm->stats);
 }
@@ -1320,58 +1301,22 @@ void osm_state_mgr_process(IN osm_sm_t *sm, IN osm_signal_t signal)
 			"osm_state_mgr_process: "
 			"Received signal %s in state %s\n",
 			osm_get_sm_signal_str(signal),
-			osm_get_sm_state_str(sm->state));
-
-	switch (sm->state) {
-	case OSM_SM_STATE_IDLE:
-		switch (signal) {
-		case OSM_SIGNAL_SWEEP:
-			/*
-			 * If the osm_sm_state_mgr is in NOT-ACTIVE state -
-			 * stay in IDLE
-			 */
-			if (sm->p_subn->sm_state == IB_SMINFO_STATE_NOTACTIVE) {
-				osm_vendor_set_sm(sm->mad_ctrl.h_bind, FALSE);
-				break;
-			}
-
-			do_sweep(sm);
-			break;
+			osm_get_sm_mgr_state_str(sm->p_subn->sm_state));
 
-		case OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST:
-			do_process_mgrp_queue(sm);
-			break;
-
-		default:
-			__osm_state_mgr_signal_error(sm, signal);
-			break;
-		}
+	switch (signal) {
+	case OSM_SIGNAL_SWEEP:
+		do_sweep(sm);
 		break;
 
-	case OSM_SM_STATE_STANDBY:
-		switch (signal) {
-		case OSM_SIGNAL_EXIT_STBY:
-			/*
-			 * Need to force re-write of sm_base_lid to all ports
-			 * to do that we want all the ports to be considered
-			 * foriegn
-			 */
-			__osm_state_mgr_clean_known_lids(sm);
-			sm->state = OSM_SM_STATE_IDLE;
-			osm_sm_signal(sm, OSM_SIGNAL_SWEEP);
-			break;
-		default:
-			__osm_state_mgr_signal_error(sm, signal);
-			break;
-		}
-		/* stay with the same signal - so we can start the sweep */
+	case OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST:
+		do_process_mgrp_queue(sm);
 		break;
 
 	default:
 		CL_ASSERT(FALSE);
 		osm_log(sm->p_log, OSM_LOG_ERROR,
 			"osm_state_mgr_process: ERR 3320: "
-			"Invalid SM state %u\n", sm->state);
+			"Invalid SM signal %u\n", signal);
 		break;
 	}
 
-- 
1.5.4.rc2.60.gb2e62




More information about the general mailing list