GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> MON / dev > mon / mv2304


Interface   Data Structures   File List   Data Fields   Globals  

MON_control.c File Reference

Control the operation of the MON CPU monitor functions. More...

#include <MON_idle.h>
#include <MON_perf.h>
#include <MON_poll.h>
#include <CDM/CDM_pubdefs.h>
#include <CPU_DB/CPU_DB_pubdefs.h>
#include <MON/MON_msgs.h>
#include <MON/MON_pubdefs.h>
#include <MON_DB/MON_DB_schema.h>
#include <MSG/MSG_pubdefs.h>
#include <PBS/INT.ih>
#include <PBS/MBA.h>
#include <PBS/MTX.ih>
#include <PBS/TASK.h>
#include <string.h>

Classes

struct  _MON_Control
 MON control information block. More...

Typedefs

typedef enum _MON_Control_State MON_Control_State
 Typedef for _MON_Control_State.
typedef struct _MON_Control MON_Control
 Typedef for _MON_Control.

Enumerations

enum  _MON_Control_State {
  MON_STATE_UNINITIALIZED = 1 << 0,
  MON_STATE_INITIALIZING = 1 << 1,
  MON_STATE_INIT_FAIL = 1 << 2,
  MON_STATE_INITIALIZED = 1 << 3,
  MON_STATE_SHUTDOWN = 1 << 4,
  MON_STATE_SHUTDOWN_FAIL = 1 << 5,
  MON_STATE_STARTING = 1 << 6,
  MON_STATE_START_FAIL = 1 << 7,
  MON_STATE_STARTED = 1 << 8,
  MON_STATE_STOPPING = 1 << 9,
  MON_STATE_STOP_FAIL = 1 << 10
}
 MON control state. More...

Functions

static unsigned int mon_create_control_block (void)
 Allocate and adopt a MON control information block.
static unsigned int mon_lock_access (MON_Control *ctl_p)
 Lock access to a MON control block.
static unsigned int mon_unlock_access (MON_Control *ctl_p, unsigned int status)
 Unlock access to a MON control block.
static unsigned int mon_change_state (MON_Control *ctl_p, unsigned int valid_states, MON_Control_State new_state)
 Change the state of the MON functions.
unsigned int MON_initialize (void)
 Initialize the MON functions.
unsigned int MON_shutdown (void)
 Shutdown the MON functions.
unsigned int MON_start (TASK_attr *idle_attr_p, TASK_attr *poll_attr_p)
 Start the MON functions.
unsigned int MON_start_with_db (void)
 Start the MON functions using the CPU_DB server.
unsigned int MON_stop (void)
 Stop the MON functions.
unsigned int MON_get_loading (MON_Load_Stats *stats_p)
 Get current CPU loading statistics.
unsigned int MON_start_perf_mon (MON_Perf_Config *cfg_p)
 Start CPU performance monitoring.
unsigned int MON_stop_perf_mon (MON_Perf_Stats *stats_p)
 Stop CPU performance monitoring.
unsigned int MON_collect_perf_stats (MON_Perf_Config *cfg_p, unsigned int time_us, MON_Perf_Stats *stats_p, MON_Perf_Cb cb, void *cb_parm)
 Collect performance monitor stats for a specified period of time.
unsigned int MON_set_watchdog (void)
 Set the hardware watchdog timer.

Variables

MON_ControlMon_control_p = NULL
 Pointer to the MON control information block.
static const MON_DB_Schema Mon_def_db
 Default MON configuration database.


Detailed Description

Control the operation of the MON CPU monitor functions.

**  CVS $Id: MON_control.c,v 1.6 2011/03/28 23:52:03 russell Exp $
**  

Control functions for the MON package.


Enumeration Type Documentation

MON control state.

Enumerator:
MON_STATE_UNINITIALIZED  The MON functions have not been initialized. Use MON_initialize() to initialize them.
MON_STATE_INITIALIZING  The MON functions are in the process of being initialized by MON_initialize().
MON_STATE_INIT_FAIL  MON_initialize() failed - use MON_shutdown() to return to MON_STATE_UNINITIALIZED.
MON_STATE_INITIALIZED  The MON functions have been initialized by MON_initialize() and are ready to be started by MON_start() or shutdown by MON_shutdown().
MON_STATE_SHUTDOWN  The MON functions are in the process of being shutdown by MON_shutdown().
MON_STATE_SHUTDOWN_FAIL  MON_shutdown() failed - use MON_shutdown() again to return to MON_STATE_UNINITIALIZED.
MON_STATE_STARTING  The MON functions are in the process of being started by MON_start().
MON_STATE_START_FAIL  MON_start() failed - use MON_stop() to return to MON_STATE_INITIALIZED.
MON_STATE_STARTED  The MON functions have been started by MON_start() and are ready to be stopped by MON_stop() or used by MON_get_loading(), MON_collect_perf_stats(), etc.
MON_STATE_STOPPING  The MON functions are in the process of being stopped by MON_stop().
MON_STATE_STOP_FAIL  MON_stop() failed - use MON_stop() again to return to MON_STATE_INITIALIZED.


Function Documentation

unsigned int mon_change_state ( MON_Control ctl_p,
unsigned int  valid_states,
MON_Control_State  new_state 
) [static]

Change the state of the MON functions.

Parameters:
ctl_p Pointer to MON control block.
valid_states Bitmask of valid current states.
new_state New state.
Returns:
MSG code.

References mon_lock_access(), mon_unlock_access(), and _MON_Control::state.

Referenced by MON_initialize(), MON_shutdown(), MON_start(), and MON_stop().

unsigned int MON_collect_perf_stats ( MON_Perf_Config cfg_p,
unsigned int  time_us,
MON_Perf_Stats stats_p,
MON_Perf_Cb  cb,
void *  cb_parm 
)

Collect performance monitor stats for a specified period of time.

This function configures and starts the CPU performance monitor facility and establishes a wake-up timer that expires after the specified amount of time. The handler for the wake-up timer stops the CPU event counters and triggers a call to the specified callback function. The callback function is executed in the context of the MON polling task. See also the MON_start_perf_mon() and MON_stop_perf_mon() functions.

Note that all event counters are cleared to zero before counting is started. This means that if the MON_EVENT_x_HOLD event is selected for a counter, its value will be set to 0 and held at that value during the collection period.

Parameters:
cfg_p Pointer to performance monitor configuration (must not be NULL).
time_us Length of time, in microseconds, to collect statistics.
stats_p Pointer to location to return statistics.
cb Function to call when the collection is complete.
cb_parm Parameter to pass to cb function.
Returns:
Zero if successful.

An error MSG code if the MON package is not in the STARTED state, the CPU is already counting events, or an error occurs.

References mon_lock_access(), MON_perf_collect(), MON_STATE_STARTED, mon_unlock_access(), _MON_Control::perf_ctl, and _MON_Control::state.

unsigned int mon_create_control_block ( void   )  [static]

Allocate and adopt a MON control information block.

Returns:
MSG code.

References MON_STATE_UNINITIALIZED, _MON_Control::mtx, and _MON_Control::state.

Referenced by MON_initialize().

unsigned int MON_get_loading ( MON_Load_Stats stats_p  ) 

Get current CPU loading statistics.

This function returns a snapshot of the CPU loading statistics for the previous minute of operation.

Parameters:
stats_p Pointer to buffer to store loading statistics (must not be NULL).
Returns:
Zero if successful.

An error MSG code if the MON package is not in the STARTED state or an error occurs.

References _MON_Control::idle_ctl, MON_idle_get_stats(), mon_lock_access(), MON_STATE_STARTED, mon_unlock_access(), and _MON_Control::state.

unsigned int MON_initialize ( void   ) 

Initialize the MON functions.

This function initializes the MON package and transitions it to the INITIALIZED state. It should be the first MON function called when using the MON package.

Returns:
Zero if successful.

An error MSG code if the MON package has already been initialized or an error occurs.

References _MON_Idle_Control::dog_seconds, _MON_Control::idle_ctl, mon_change_state(), mon_create_control_block(), MON_idle_init(), MON_perf_init(), MON_poll_init(), MON_STATE_INIT_FAIL, MON_STATE_INITIALIZED, MON_STATE_INITIALIZING, MON_STATE_UNINITIALIZED, _MON_Control::mtx, _MON_Control::perf_ctl, _MON_Control::poll_ctl, and _MON_Control::state.

unsigned int mon_lock_access ( MON_Control ctl_p  )  [static]

Lock access to a MON control block.

Parameters:
ctl_p Pointer to MON control block.
Returns:
MSG code.

References _MON_Control::mtx.

Referenced by mon_change_state(), MON_collect_perf_stats(), MON_get_loading(), MON_start_perf_mon(), and MON_stop_perf_mon().

unsigned int MON_set_watchdog ( void   ) 

Set the hardware watchdog timer.

Returns:
Zero if successful.

An error MSG code if an error occurs.

References _MON_Control::idle_ctl, MON_idle_set_watchdog(), MON_STATE_STARTED, and _MON_Control::state.

unsigned int MON_shutdown ( void   ) 

Shutdown the MON functions.

This function shuts down the MON package and transitions it back to the UNINITIALIZED state. It can be called only if the current MON state is INITIALIZED, INIT_FAIL, or SHUTDOWN_FAIL. This function should be called after MON_stop() when the MON package is no longer needed.

Returns:
Zero if successful.

An error MSG code if the MON package is in an invalid state or an error occurs.

References _MON_Control::idle_ctl, mon_change_state(), MON_idle_shutdown(), MON_perf_shutdown(), MON_poll_shutdown(), MON_STATE_INIT_FAIL, MON_STATE_INITIALIZED, MON_STATE_SHUTDOWN, MON_STATE_SHUTDOWN_FAIL, MON_STATE_UNINITIALIZED, _MON_Control::perf_ctl, _MON_Control::poll_ctl, and _MON_Control::state.

unsigned int MON_start ( TASK_attr *  idle_attr_p,
TASK_attr *  poll_attr_p 
)

Start the MON functions.

This function starts the various MON tasks and transitions MON to the STARTED state. It can be called only if the current MON state is INITIALIZED. This function should be called after MON_initialize() when using the MON package.

Parameters:
idle_attr_p IDLE task attributes. Default task attributes (with a name of 'IDLE' and a priority of 255) will be used if this value is NULL.
poll_attr_p POLL task attributes. Default task attributes (with a name of 'POLL' and a priority of 90) will be used if this value is NULL.
Returns:
Zero if successful.

An error MSG code if the MON package is not in the INITIALIZED state or an error occurs.

References _MON_Control::idle_ctl, mon_change_state(), MON_idle_start(), MON_poll_start(), MON_STATE_INITIALIZED, MON_STATE_START_FAIL, MON_STATE_STARTED, MON_STATE_STARTING, _MON_Control::poll_ctl, and _MON_Control::state.

Referenced by MON_start_with_db().

unsigned int MON_start_perf_mon ( MON_Perf_Config cfg_p  ) 

Start CPU performance monitoring.

This function configures and starts the CPU performance monitor facility, which counts various CPU events. If started with this function, the CPU will count events until MON_stop_perf_mon() is called. See also the MON_collect_perf_stats() function, which counts CPU events for a specified period of time.

Note that all event counters are cleared to zero before counting is started. This means that if the MON_EVENT_x_HOLD event is selected for a counter, its value will be set to 0 and held at that value during the collection period.

Parameters:
cfg_p Pointer to performance monitor configuration (must not be NULL).
Returns:
Zero if successful.

An error MSG code if the MON package is not in the STARTED state, the CPU is already counting events, or an error occurs.

References mon_lock_access(), MON_perf_start(), MON_STATE_STARTED, mon_unlock_access(), _MON_Control::perf_ctl, and _MON_Control::state.

unsigned int MON_start_with_db ( void   ) 

Start the MON functions using the CPU_DB server.

This function is a wrapper for MON_start. It forces MON_start to use the CPU_DB server to determine the attributes for the POLL and IDLE tasks.

Returns:
Zero if successful.

A MSG code if an error occurs.

References MON_start().

unsigned int MON_stop ( void   ) 

Stop the MON functions.

This function stops the various MON tasks and transitions MON back to the INITIALIZED state. It can be called only if the current MON state is STARTED, START_FAIL, or STOP_FAIL. This function should be called before MON_shutdown() when the MON package is no longer needed.

Returns:
Zero if successful.

An error MSG code if the MON package is in an invalid state or an error occurs.

References _MON_Control::idle_ctl, mon_change_state(), MON_idle_stop(), MON_perf_stop(), MON_poll_stop(), MON_STATE_INITIALIZED, MON_STATE_START_FAIL, MON_STATE_STARTED, MON_STATE_STOP_FAIL, MON_STATE_STOPPING, _MON_Control::perf_ctl, _MON_Control::poll_ctl, and _MON_Control::state.

unsigned int MON_stop_perf_mon ( MON_Perf_Stats stats_p  ) 

Stop CPU performance monitoring.

This function stops the CPU from counting events and returns the current counter values. If the CPU is not actively counting events, the most recent event counter values are returned.

Parameters:
stats_p Pointer to location to store monitor statistics. If this value is NULL, event counting is stopped without returning the event counter values.
Returns:
Zero if successful.

An error MSG code if the MON package is not in the STARTED state or an error occurs.

References mon_lock_access(), MON_perf_stop(), MON_STATE_STARTED, mon_unlock_access(), _MON_Control::perf_ctl, and _MON_Control::state.

unsigned int mon_unlock_access ( MON_Control ctl_p,
unsigned int  status 
) [static]

Unlock access to a MON control block.

Parameters:
ctl_p Pointer to MON control block.
status Previous status code.
Returns:
MSG code.

References _MON_Control::mtx.

Referenced by mon_change_state(), MON_collect_perf_stats(), MON_get_loading(), MON_start_perf_mon(), and MON_stop_perf_mon().


Variable Documentation

MON_DB_Schema * Mon_def_db [static]

Initial value:

    {
        10,                             
        100,                            
    }
Default MON configuration database.


Generated on Mon Mar 28 16:57:45 2011 by  doxygen 1.5.8