SIMulation Workbench Documentation SIMulation Workbench Documentation

Scheduler API
[SimWB RT functions]

Collaboration diagram for Scheduler API:

Functions

int ccurSched_mapShared (int init)
int ccurSched_init (const char *pgmName)
void ccurSched_syncEndInit ()
void ccurSched_asyncEndInit ()
void ccurSched_initFailed ()
void ccurSched_waitIOTasksComplete ()
int ccurSched_waitModelTasksComplete (int timeout)
int ccurSched_rtdbDataLoggingReady ()
void ccurSched_setRTDBDataLoggingReady (int ready)
int ccurSched_rtdbInitConditionsReady ()
void ccurSched_setRTDBInitConditionsReady (int ready)
void ccurSched_waitScriptInitComplete ()
int ccurSched_getInitScriptComplete ()
int ccurSched_hasInitScript ()
void ccurSched_setInitScriptComplete (int status)
void ccurSched_setHasInitScript (int has)
void ccurSched_setIOTaskIniComplete ()
void ccurSched_setModelTaskIniComplete ()
void ccurSched_ioTaskCountIncrement ()
int ccurSched_isScript ()
int ccurSched_isModel ()
void ccurSched_modelTaskCountIncrement ()
void * ccurSched_getTaskInfo (const char *pgmName)
void ccurSched_setupThread (void *pTaskInfo)
int ccurSched_waitNextFrame ()
int ccurSched_waitAsyncResume (int microSec)
int ccurSched_waitNextFrameThread (SchedTaskInfo *pTask)
const char * ccurSched_getTaskName ()
int ccurSched_asyncEndOfRun (AsyncTaskInfo *pTask)
int ccurSched_asyncStartOfRun (AsyncTaskInfo *pTask)
AsyncTaskInfo * ccurSched_asyncTaskNew (const char *pgmName)
void ccurSched_testStop (int reason)
int ccurSched_getSchedFailureCode (void)
void ccurSched_pause (void)
int ccurSched_isPaused (void)
void ccurSched_resume (void)
void ccurSched_nonRT (void)
void ccurSched_resumeRT (void)
void ccurSched_step (int nFrames)
void ccurSched_getState (char *op, char *state)
char ccurSched_stopAtEOR (void)
int ccurSched_spinningMode ()
int ccurSched_getSchedulingMode ()
void ccurSched_getAsyncQHistory (int *history)
double ccurSched_getModelFixedStep ()
int ccurSched_getTaskRate ()
int ccurSched_getNumberOfCores (void)
pid_t ccurSched_gettid (void)
SyncThreadInfo * ccurSched_getThreadInfo (pid_t tid)
void ccurSched_setMaxOverruns (int maxOverruns)
int ccurSched_getMaxOverruns ()
void ccurSched_setMaxIOShutdownTime (float maxIOShutdownTime)
float ccurSched_getMaxIOShutdownTime ()
int ccurSched_getSessionOverruns ()
void ccurSched_setSessionOverruns (int overruns)

Detailed Description

This API is used by program running on the Real-Time host to scheduler their execution via the SIMulation Workbench scheduler.

This API is used by a program running on the Real-Time host to determine how many of the SimWB tasks are currently running.

Parameters:
ignoreSelf When non-zero the PID of the calling process is ignored.
log When non-zero the PID, state and task name are written to cfgsrv.log. The state is listed as either 'running', 'gone' or 'ignored'.

Return: -1 on error (the routine could not open the shared memory segment. A system error message will
be written to the cfgsrv.log)
0 when no tasks are running
n when 'n' tasks are running


Function Documentation

int ccurSched_mapShared ( int  init  ) 

Map SimWB scheduler shared structures into the caller addressing space.
This routine is called internally by ccurSched_init(), so any user programs that calls ccurSched_init because it is loaded and displatched by the SimWB scheduler does NOT have to call this function.
This function should be called when the user program needs access to the scheduler structure but is not under the control of SimWB. For instance, a program that wants to stop a running test independently by calling ccurSched_testStop().

Parameters:
init Always set this argument to 0. A value of 1 is reserved for the SimWB scheduler to initialize the memory segments.
Returns:
0 if the call succeeded.
-1 on error . Possibly, this routine could not open shared memory segment. A system error message will be printed on the program stdout.
int ccurSched_init ( const char *  pgmName  ) 

Register myself with the SimWB scheduler.

Any programs that want to be dispatched synchronously or asynchronously by the scheduler must call this function at the beginning of its run. This lets the scheduler know that the application has started. Synchronous applications are always started by the scheduler.

Parameters:
pgmName The name of the executable. It is the name of this program as started by the scheduler.
Typically, this function is called as:

ccurSched_init(argv[1]); argv[1] is the name of the task instance without any path

Returns:
0 if the task started normally.
-1 on error . Possibly, this routine could not find pgmName in the table of tasks defined by the scheduler. This might indicate that the program was started under a different name from pgmName.
void ccurSched_syncEndInit (  ) 

Tell the scheduler that the calling synchronous program has finished initialization.

void ccurSched_asyncEndInit (  ) 

Tell the scheduler that the calling asynchronous program has finished initialization.

void ccurSched_initFailed (  ) 

Tell the scheduler that the calling program has failed initialization.
The scheduler will then abort the starting test.

void ccurSched_waitIOTasksComplete (  ) 

Wait untill all programs that are registered as I/O program have finished initializing.

int ccurSched_waitModelTasksComplete ( int  timeout  ) 

Wait until all programs that are registered as model program have finished initializing.

Parameters:
timeout in 0.1s (100000us) units. If timeout <= 0 then wait forever.
Returns:
0 on success, -1 if initializations not complete before timeout.
int ccurSched_rtdbDataLoggingReady (  ) 

Return whether all the data logging flags have been set in the RTDB.
When logging Simulink models and signals, the RTDB signals and parameters are created dynamically by the model main at initialization time. Those items can be logged by creating the loggingset.txt file in the test initial conditions. The scheduler reads this file and then set the data logging flags for the items after the models have finished initializing and then set the rtdbDataLoggingReady condition to true.
This condition is then tested by the data logging tasks logtxin, logtxout and logsend at initialization before collecting all the items that need to be logged.

Return values:
: 1 when all the data logging flags have been set.
0 when data logging is not ready.
void ccurSched_setRTDBDataLoggingReady ( int  ready  ) 

Set the rtdbDataLoggingReady flag.
This is only used by the scheduler task.

Return values:
None 
int ccurSched_rtdbInitConditionsReady (  ) 

Return whether all the initial conditions for the RTDB have been set by the scheduler.
This condition can be tested by I/O tasks or user programs to make sure the RTDB is fully initialized before proceeding.

Return values:
: 1 when the init condition file has been read and RTDB item values set.
0 when init conditions is not ready.
void ccurSched_setRTDBInitConditionsReady ( int  ready  ) 

Set the rtdbInitConditionsReady flag.
This is only used by the scheduler task.

Return values:
None 
void ccurSched_waitScriptInitComplete (  ) 

Wait untill the script program (if any) has finished initializing.

int ccurSched_getInitScriptComplete (  ) 

Return whether the initialization script status; 1 when it is done

Return values:
The initialization script status; 1 when it is done
int ccurSched_hasInitScript (  ) 

Return whether the test has an initialization script

Return values:
Whether the test has an init script ; 1 when it is does
void ccurSched_setInitScriptComplete ( int  status  ) 

Set the initialization script status; 1 when it is done The initialization script status; 1 when it is done

void ccurSched_setHasInitScript ( int  has  ) 

Set the initialization script status; 1 when it is done 1 if the test has an init script, 0 otherwise.

void ccurSched_setIOTaskIniComplete (  ) 

Let the scheduler know that the calling I/O task has finished initializing its I/O devices.
Programs that are waiting for all I/O initialization to be complete can resume execution once all I/O programs have completed initializing.

void ccurSched_setModelTaskIniComplete (  ) 

Let the scheduler know that the calling model task has finished initializing.
Programs that are waiting for all model initialization to be complete can resume execution once all model programs have completed initializing.

void ccurSched_ioTaskCountIncrement (  ) 

Tell the scheduler that the calling task is an I/O task and thus increment the number of I/O tasks that need I/O initialization time.

int ccurSched_isScript (  ) 

Return whether the calling task is a CScript.

Return values:
1 : if this is a CScript task.
0 : when this is not a CScript task.
int ccurSched_isModel (  ) 

Return whether the calling task is a model.

Return values:
1 : if this is a model task.
0 : when this is not a model task.
void ccurSched_modelTaskCountIncrement (  ) 

Tell the scheduler that the calling task is a model task and thus increment the number of model tasks that need model initialization time.

void* ccurSched_getTaskInfo ( const char *  pgmName  ) 

Return a pointer to the TaskInfo that corresponds to the task name and execution order.
This is to support multi threaded synchronous tasks.

Return values:
: The pointer to the SchedTaskInfo for the task. NULL if the task cannot be found.
void ccurSched_setupThread ( void *  pTaskInfo  ) 

Set up CPU affinity as defined in schedtasks.txt and priority as well as TID for the calling thread.
This is to support multi threaded synchronous tasks where the different threads run at different order during the simulation cycle.

Parameters:
pTaskInfo : pointer to SchedTaskInfo corresponding to the task entry in the list of synchronous tasks.
Return values:
: none
int ccurSched_waitNextFrame (  ) 

Block the calling task until resumed by the scheduler. The order of execution of the caller is independent of this routine and is established at start up time by the scheduler.

int ccurSched_waitAsyncResume ( int  microSec  ) 

Block the calling task until resumed.

Parameters:
microSec : controls the behavior of the wait/resume mechanism. The task resume mechanism depends on the value of microSec passed into the call and on its position in the execution chain .
When the task is NOT first in the execution, it is resumed bu its predecessor in the execution chain once the predecessor has completed execution.
When the task is first in the execution chain :
microSec > 0 : the routine will do a usleep(microSec) microSec ==-1 : the routine will do a pause() and will be resumed by a any signal ; typically a timer. See the asynchronous model template for an example. microSec == 0 : the routine will return immediately.
Return values:
< 0 if there is an error setting/clearing chain semaphore.
int ccurSched_waitNextFrameThread ( SchedTaskInfo *  pTask  ) 

Block the calling task until resumed by the scheduler. The order of execution of the caller is independent of this routine and is established at start up time by the scheduler and by the pointer to the SchedTaskInfo passed into the routine.

Parameters:
pTask : pointer to SchedTaskInfo corresponding to the task entry in the list of synchronous tasks.
Return values:
always 0
const char* ccurSched_getTaskName (  ) 

Return the SimWB name of the calling task.

Return values:
A pointer to the name of the task
int ccurSched_asyncEndOfRun ( AsyncTaskInfo *  pTask  ) 

Let the scheduler know that the calling asynchronous program has finished executing one cycle.
Asynchronous program are not scheduled by the SIMulation Workbench scheduler but dispatch their execution on their own. This and the next call

See also:
ccurSched_asyncEndOfRun is used to calculate execution run time.
Parameters:
pTask Pointer to asynchronous task descriptor.This pointer is obtained by a call to the ccurSched_asyncTaskNew routine.
See also:
ccurSched_asyncTaskNew.
int ccurSched_asyncStartOfRun ( AsyncTaskInfo *  pTask  ) 

Let the scheduler know that we are starting the execution of our cycle.
This and the previous call

See also:
ccurSched_asyncEndOfRun is used to calculate execution run time.
Parameters:
pTask Pointer to asynchronous task descriptor.This pointer is obtained by a call to the ccurSched_asyncTaskNew routine.
See also:
ccurSched_asyncTaskNew.
AsyncTaskInfo* ccurSched_asyncTaskNew ( const char *  pgmName  ) 

Register the calling thread as a new asynchronous process with the SIMulation Workbench scheduler.
Every separate thread of execution must register itself with a call to this routine.

Parameters:
pgmName The name of the thread registering itself. This name is used for display purpose only an dis not related to the name of the executable program started by the scheduler.
Returns:
A pointer to an asynchronous task descriptor.
void ccurSched_testStop ( int  reason  ) 

Stop the execution of the currently running test.

Parameters:
reason Integer code registering the reason the test is being stopped.
The reason should be one of
See also:
CCURSIMSCompletionCode_Scheduler specified in
simerrors.h
int ccurSched_getSchedFailureCode ( void   ) 

Return the code why the test failed to start or was aborted. This code is set by the scheduler when a test is aborted either at startup or during the run.

Returns:
integer reason code. The return is one of
See also:
CCURSIMSCompletionCode_Scheduler specified in
simerrors.h
void ccurSched_pause ( void   ) 

Pause the execution of the scheduler.
This is used internally when stepping through execution cycles.

int ccurSched_isPaused ( void   ) 

Return whether the SimWB scheduler is in the paused state.

Returns:
true if the scheduler is paused, false otherwise.
void ccurSched_resume ( void   ) 

Resume the pause execution of the scheduler.

void ccurSched_nonRT ( void   ) 

Tell the scheduler that we want to run non real-time. In non RT mode, the scheduled processes do not cause overrruns.

void ccurSched_resumeRT ( void   ) 

Tell the scheduler to return to the normal real-time running mode.

void ccurSched_step ( int  nFrames  ) 

Step the execution of the scheduler through nFrames frames of execution.

Parameters:
nFrames The number of frames to step the execution through.
void ccurSched_getState ( char *  op,
char *  state 
)

Return the current operation and state of the scheduler.

Parameters:
op pointer to a character where the current scheduler operation is returned.
state pointer to a character where the current state of the scheduler is returned.
char ccurSched_stopAtEOR ( void   ) 

Tell the scheduler to stop at the end of recording when executing in palyback mode.

int ccurSched_spinningMode (  ) 

Return whether the scheduler is in spinning mode ; i.e. the Red Line scheduler is being used instead of FBS/RCIM or software timer.

int ccurSched_getSchedulingMode (  ) 
Returns:
the scheduling mode for the currently running scheduler.
void ccurSched_getAsyncQHistory ( int *  history  ) 

Retrieve the number of entries in the asynchronous queue history list. The list always contains MAX_ASYNCQHISTORY entries. The entries are sorted in chronological order. The oldest entry is at index 0.

Parameters:
history pointer to a integer array where the values are stored. The array must be at least MAX_ASYNCQHISTORY elements long.
double ccurSched_getModelFixedStep (  ) 

Returns the fixed step for the model. The value is returned in seconds.
If the model has been defined to run with a multiplier when creating the task. The model fixed step will be the SimWB frame length / multiplier.
I.e. We have a frame rate of 1 milli second and a multiplier of 10, in this case the model fixed step would be 100 micro seconds == 0.0001 seconds

Returns:
model fixed step in seconds.
int ccurSched_getTaskRate (  ) 
Deprecated:
. Use ccurSched_getModelFixedStep() instead Returns the rate in micro seconds at which the task is running.
Returns:
Task rate in micro seconds
int ccurSched_getNumberOfCores ( void   ) 

Return the number of cpu cores in the systemr.

pid_t ccurSched_gettid ( void   ) 

Return the thread ID of the caller.

SyncThreadInfo* ccurSched_getThreadInfo ( pid_t  tid  ) 

Return the SyncThreadInfo corresponding to the thread id (tid).

Parameters:
tid The thread id for which we want the information.
Returns:
NULL id the thread id cannot be found in the SimWb scheduler list
void ccurSched_setMaxOverruns ( int  maxOverruns  ) 

Sets the maximum number of overruns allowed for the session currrently running.
Used by the SimWB scheduler to initialize the maximum of overruns.

Parameters:
maxOverruns The maximum number of overruns allowed.
Returns:
None
int ccurSched_getMaxOverruns (  ) 

Returns the maximum number of overruns allowed for the session currrently running.

Returns:
The maximum number of overruns.
void ccurSched_setMaxIOShutdownTime ( float  maxIOShutdownTime  ) 

Sets the maximum number of seconds allowed for I/O shutdown.

Parameters:
maxIOShutdownTime The maximum number of seconds for I/O shutdown .
Returns:
None
float ccurSched_getMaxIOShutdownTime (  ) 

Returns the maximum number of seconds allowed for I/O shutdown .

Returns:
The maximum number of seconds allowed for I/O shutdown.
int ccurSched_getSessionOverruns (  ) 

Returns the number of overruns that occured so far during the session run.

Returns:
The maximum number of overruns.
void ccurSched_setSessionOverruns ( int  overruns  ) 

Sets the maximum number of overruns for the session currrently running.
Used by the SimWB scheduler to initialize the number of overruns.

Parameters:
overruns The number of overruns .
Returns:
None