op_sim_time()
Abstract
Obtains the current simulation time.
Syntax
op_sim_time ()
| Argument | Type | Description |
|---|---|---|
| no arguments |
Return Type
double
Current simulation time. This double-precision floating-point number represents the simulation time in seconds, starting with the begin simulation interrupt, at which point op_sim_time() returns a value of zero. (See special case in Details section.)
Example
Excerpt from: example model (models/std/base); process model (acb_fifo); state (svc_start); enter execs
/* get a handle on packet at head of subqueue 0 */
/* (this does not remove the packet) */
pkptr = op_subq_pk_access (0, OPC_QPOS_HEAD);
/* determine the packets length (in bits) */
pk_len = op_pk_total_size_get (pkptr);
/* determine the time required to complete */
/* service of the packet */
pk_svc_time = pk_len / service_rate;
/* schedule an interrupt for this process */
/* at the time where service ends. */
op_intrpt_schedule_self (op_sim_time () + pk_svc_time, 0);
/* the server is now busy. */
server_busy = 1;
Details
The current simulation time is a double-precision, floating-point number that indicates the time value associated with the simulation event currently being executed. Simulation time does not advance during an invocation of a process; it stands still while a single event is being processed. Simulation time advances only when one event completes (at time T) and the next event begins (at time T + dt). Because time can advance in a punctuated, irregular pattern according to this scheme, it is known as the event-driven simulation method (as opposed to the regular, time-driven simulation method).
Note: If the “sim_time_quantum“ preference has a value other than 0.0, the simulation time returned will be a multiple of the specified quantum.
This KP returns -1 if invoked at two special times (which occur before the simulation starts executing events):
- Initial invocation of the receiver group pipeline stage of radio transmitter modules
- Invocation of the init_callback procedure for a wireless domain
Purpose
Provides a mechanism to obtain the current simulation time, which is used for many applications, such as:
- computing absolute times in the future for scheduling events
- determining the time delay from some past event to the present simulation time
- printing time-tagged diagnostic information and debugging statements to the standard output device, or other open files
Errors
- No errors are trapped.
Reference
- Use the KPs op_intrpt_schedule_self(), op_intrpt_schedule_remote(), or op_intrpt_schedule_call() to schedule an interrupt for a future time
- Use the KPs op_pk_creation_time_get() or op_pk_stamp_time_get() to obtain time stamp values from packets, in order to compare them with the current simulation time
- Use the KPs op_q_wait_time() or op_q_insert_time() to obtain queueing delay information from packets stored in a queue module