ns-3
|
Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock functions. More...
#include <wall-clock-synchronizer.h>
Static Public Attributes | |
static const uint64_t | US_PER_NS = (uint64_t)1000 |
static const uint64_t | US_PER_SEC = (uint64_t)1000000 |
static const uint64_t | NS_PER_SEC = (uint64_t)1000000000 |
Protected Member Functions | |
virtual bool | DoRealtime (void) |
Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this. | |
virtual uint64_t | DoGetCurrentRealtime (void) |
Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units. | |
virtual void | DoSetOrigin (uint64_t ns) |
Establish a correspondence between a simulation time and a wall-clock (real) time. | |
virtual int64_t | DoGetDrift (uint64_t ns) |
Declaration of method used to retrieve drift between the real time clock used to synchronize the simulation and the current simulation time. | |
virtual bool | DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay) |
Wait until the real time is in sync with the specified simulation time. | |
virtual void | DoSignal (void) |
Declaration of the method used to tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time. | |
virtual void | DoSetCondition (bool cond) |
Declaration of the method used to set the condition variable that tells a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. | |
virtual void | DoEventStart (void) |
virtual uint64_t | DoEventEnd (void) |
bool | SpinWait (uint64_t) |
bool | SleepWait (uint64_t) |
uint64_t | DriftCorrect (uint64_t nsNow, uint64_t nsDelay) |
uint64_t | GetRealtime (void) |
uint64_t | GetNormalizedRealtime (void) |
void | NsToTimeval (int64_t ns, struct timeval *tv) |
uint64_t | TimevalToNs (struct timeval *tv) |
void | TimevalAdd (struct timeval *tv1, struct timeval *tv2, struct timeval *result) |
Protected Attributes | |
uint64_t | m_cpuTick |
uint64_t | m_realtimeTick |
uint64_t | m_jiffy |
uint64_t | m_nsEventStart |
SystemCondition | m_condition |
![]() | |
uint64_t | m_realtimeOriginNano |
uint64_t | m_simOriginNano |
Additional Inherited Members | |
![]() | |
bool | Realtime (void) |
Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this. | |
uint64_t | GetCurrentRealtime (void) |
Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units. | |
void | SetOrigin (uint64_t ts) |
Establish a correspondence between a simulation time and the synchronizer real time. | |
uint64_t | GetOrigin (void) |
Retrieve the value of the origin of the simulation time in simulator timestep units. | |
int64_t | GetDrift (uint64_t ts) |
Retrieve the difference between the real time clock used to synchronize the simulation and the simulation time (in simulator timestep units). | |
bool | Synchronize (uint64_t tsCurrent, uint64_t tsDelay) |
Wait until the real time is in sync with the specified simulation time or until the synchronizer is Sigalled. | |
void | Signal (void) |
Tell a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. This will cause the thread to wake and return to the simulator proper where it can get its bearings. | |
void | SetCondition (bool) |
Set the condition variable that tells a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. | |
void | EventStart (void) |
Ask the synchronizer to remember what time it is. Typically used with EventEnd to determine the real execution time of a simulation event. | |
uint64_t | EventEnd (void) |
Ask the synchronizer to return the time step between the instant remembered during EventStart and now. Used in conjunction with EventStart to determine the real execution time of a simulation event. | |
![]() | |
virtual TypeId | GetInstanceTypeId (void) const |
template<typename T > | |
Ptr< T > | GetObject (void) const |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
void | Dispose (void) |
void | AggregateObject (Ptr< Object > other) |
AggregateIterator | GetAggregateIterator (void) const |
void | Start (void) |
![]() | |
SimpleRefCount (const SimpleRefCount &o) | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
void | Ref (void) const |
void | Unref (void) const |
uint32_t | GetReferenceCount (void) const |
![]() | |
void | SetAttribute (std::string name, const AttributeValue &value) |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
void | GetAttribute (std::string name, AttributeValue &value) const |
bool | GetAttributeFailSafe (std::string name, AttributeValue &attribute) const |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
![]() | |
static TypeId | GetTypeId (void) |
This method returns the TypeId associated to ns3::Synchronizer. |
Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock functions.
Enable this synchronizer using:
DefaultValue::Bind ("Synchronizer", "WallClockSynchronizer");
before calling any simulator functions.
The simulation clock is maintained as a 64-bit integer in a unit specified by the user through the TimeStepPrecision::Set function. This means that it is not possible to specify event expiration times with anything better than this user-specified accuracy.
There are a couple of more issues at this level. Posix clocks provide access to several clocks we could use as a wall clock. We don't care about time in the sense of 0430 CEST, we care about some piece of hardware that ticks at some regular period. The most accurate posix clock in this respect is the CLOCK_PROCESS_CPUTIME_ID clock. This is a high-resolution register in the CPU. For example, on Intel machines this corresponds to the timestamp counter (TSC) register. The resolution of this counter will be on the order of nanoseconds.
Now, just because we can measure time in nanoseconds doesn't mean we can put our process to sleep to nanosecond resolution. We are eventually going to use the function clock_nanosleep () to sleep until a simulation Time specified by the caller.
MORE ON JIFFIES, SLEEP, PROCESSES, etc., as required
Nanosleep takes a struct timespec as an input so we have to deal with conversion between Time and struct timespec here. They are both interpreted as elapsed times.
|
protectedvirtual |
Declaration of the method used to set the condition variable that tells a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time.
Implements ns3::Synchronizer.
References NS_LOG_FUNCTION_NOARGS, and ns3::SystemCondition::SetCondition().
|
protectedvirtual |
Declaration of the method used to tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time.
Implements ns3::Synchronizer.
References NS_LOG_FUNCTION_NOARGS, ns3::SystemCondition::SetCondition(), and ns3::SystemCondition::Signal().