Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

9.1.3.  TLM 2.0 Quantum Keepers

TLM 2.0 provides a utility class for threads to keep track of their thread global quantum, local quantum and local time offset. This is in the tlm_utils namespace (like the convenience sockets) with a header in tlm_utils/tlm_quantumkeeper.h.

A module will instantiate one quantum keeper for each thread that uses temporal decoupling, initializing them in the constructor.

Two functions are provided to manage the thread global quantum: set_global_quantum to set the value and get_global_quantum. Typically a module constructor will get the system global quantum with a call to the singleton tlm_global_quantum and immediately use that to set the thread global quantum for each thread's quantum keeper.

One function is provided to manage the local quantum. The reset function calls compute_local_quantum to calculate the local quantum from the time stamp and the global quantum (which is done by calling the compute_local_quantum in the singleton tlm_global_quantum object) and sets the local time offset to zero.

Typically a constructor will call reset for each thread immediately after setting the thread global quantum. The compute_local_quantum in the quantum keeper is protected, so cannot be called directly (which seems to be an omission). If the value of the local quantum is needed, this can be obtained using the compute_local_quantum function in the singleton tlm_global_quantum object.

Four functions are provided to manage the local time offset. set sets the local time offset to a particular value, inc increments by a given value and get_local_time returns the current value of the local time offset. get_current_time computes the local effective time, i.e. the SystemC time stamp plus the local time offset[10]. The intention is that a thread advances model time, it will call set and inc to update the local decoupled view of time.

Two functions are provided to handle synchronization. The test need_sync returns true if the local time offset exceeds the local quantum. sync calls wait for the local time offset, synchronizing the thread with the global SystemC view of time, and allowing other threads to catch up. It then calls reset to update the local quantum and zero the local time offset. sync should always be called when need_sync is true, but may be called at any other time if required.



[10] The naming is not consistent. get_local_time should have been just get for consistency with set and inc. get_current_time would be better named get_effective_time, to match its description in the standard.

Embecosm divider strip