Next: , Previous: , Up: Multinode Model   [Contents][Index]


4.9 Handling Instruction Invocation

During system operation, nodes of multinode model execute instructions. When a node has to invoke an instruction, the node triggers event QSMM_EVT_ACTIVATE of an instruction meta-class the instruction belongs to.

When triggering event QSMM_EVT_ACTIVATE, an identifier of the node is passed to the event handler function of instruction meta-class via the argument qsmm_node. The event handler function may fetch a binary representation of parameters of the instruction class using a call to qsmm_get_eh_instr_param. The name of an instruction class set the instruction class belongs to can be obtained using a call to qsmm_get_eh_instr_class_set_name. Number idx that uniquely identifies the instruction class in the instruction class set can be fetched from the current frame of the system stack (see Working with System and User Stacks) using call

qsmm_get_stack_instr_class(qsmm,0,&idx);

While processing event QSMM_EVT_ACTIVATE, the event handler function of instruction meta-class may call nodes of multinode model using the function qsmm_node_call_default.

After performing custom actions associated with an instruction class, which change system or environment state, the event handler function may set an instruction outcome. The instruction outcome affects which state is a new state of the node after instruction invocation.

To get or set an instruction outcome, the following functions can be used.

Function: void qsmm_get_instr_outcome (qsmm_t model, int *outcome_p)

This function sets *outcome_p to an instruction outcome associated with a multinode model specified by handle model. If outcome_p is NULL, then *outcome_p will not be set.

An instruction outcome associated with a multinode model is the last instruction outcome set using a call to qsmm_set_instr_outcome while processing the instruction invocation event. If the function qsmm_set_instr_outcome is not called, and the instruction class has a positive number of outcomes, then the instruction outcome returned will be equal to -1. If the function qsmm_set_instr_outcome is not called, and the instruction class has zero number of outcomes, then the instruction outcome returned will be the outcome of the previous instruction invoked by a node since control has been transferred to the node or 0 if there is no such instruction.

Function: int qsmm_set_instr_outcome (qsmm_t model, int outcome)

This function sets the instruction outcome associated with a multinode model specified by handle model. The outcome value is set to outcome. The function performs only a preliminary check on the validity of the outcome. Final checks are performed after return from the event handler function of the corresponding instruction meta-class, and if the outcome is invalid, then error QSMM_ERR_OUTCOME will be raised by the function qsmm_node_call_default.

On success, the function returns a non-negative value. If outcome is less than -1, then negative error code QSMM_ERR_INVAL will be returned.

The number of instruction outcomes is specified using the function qsmm_set_eh_noutcome during instruction class initialization. The default number of instruction outcomes, which will be used when that function is not called, is equal to 1. The number of instruction outcomes equal to 0 has special meaning.

Before calling the event handler function of instruction meta-class to process event QSMM_EVT_ACTIVATE, an instruction outcome associated with the multinode model is set to -1 if the instruction class has a positive number of outcomes. If the instruction class has zero number of outcomes, then an instruction outcome associated with the multinode model will be set to the outcome of the previous instruction invoked by the node since control has been transferred to it or to 0 if there is no such instruction.

After calling the event handler function of instruction meta-class to process event QSMM_EVT_ACTIVATE, if an instruction outcome associated with the multinode model is equal to -1, and the number of outcomes of the instruction class is equal to 1, then outcome 0 will be used when choosing the next node state. Such default behavior allows not to call the function qsmm_set_instr_outcome at all for instruction classes that have only one possible instruction outcome.

If after calling the event handler function an instruction outcome associated with the multinode model is equal to -1, and the number of outcomes of the instruction class is not equal to 1, then error QSMM_ERR_OUTCOME will be raised by the function qsmm_node_call_default. Such check compels to set an instruction outcome using the function qsmm_set_instr_outcome if the number of outcomes of the instruction class is greater than 1.

If the instruction class has zero number of outcomes, then while processing event QSMM_EVT_ACTIVATE by the event handler function of instruction meta-class, the function qsmm_get_instr_outcome can be called to analyze the outcome of the previous instruction invoked by the node since control has been transferred to it. That outcome can be left intact or can be changed to a non-negative value less than the maximum number among the numbers of outcomes of instruction classes, which belong to an instruction class set that represents a node class of the node.

In QSMM version 1.16 there are added functions for retrieving a probability of the last state transition performed and a probability of the last instruction invoked in a state. The probabilities have the type QSMM_PROB_AGGR and are contained in corresponding cells of the state transition matrix and the action emission matrix of the node. The functions can be called during processing event QSMM_EVT_ACTIVATE by the event handler function of instruction meta-class, e.g. to compute the time when the instruction has to take effect.

Function: double qsmm_get_prob_goto (qsmm_t model)

This function returns the probability of the latest state transition performed just before the latest instruction invocation by a node of a multinode model specified by handle model. That probability has the type QSMM_PROB_AGGR and is stored in a cell of the state transition matrix of the node. The returned value is always in the range 0 to 1 (inclusive). If nodes of the model did not invoke instructions yet, then the function returns 0.

Function: double qsmm_get_prob_action (qsmm_t model)

This function returns the probability of the latest instruction invocation in a state of a node of a multinode model specified by handle model just after performing the latest state transition. That probability has the type QSMM_PROB_AGGR and is stored in a cell of the action emission matrix of the node. The returned value is always in the range 0 to 1 (inclusive). If nodes of the model did not invoke instructions yet, then the function returns 0.


Next: , Previous: , Up: Multinode Model   [Contents][Index]