Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock functions. More...
#include <wall-clock-synchronizer.h>
Public Member Functions | |
WallClockSynchronizer () | |
virtual | ~WallClockSynchronizer () |
![]() | |
Synchronizer () | |
virtual | ~Synchronizer () |
uint64_t | EventEnd (void) |
Ask the synchronizer to return the time step between the instant remembered during EventStart and now. More... | |
void | EventStart (void) |
Ask the synchronizer to remember what time it is. More... | |
uint64_t | GetCurrentRealtime (void) |
Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units. More... | |
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). More... | |
uint64_t | GetOrigin (void) |
Retrieve the value of the origin of the simulation time in simulator timestep units. More... | |
bool | Realtime (void) |
Return true if this synchronizer is actually synchronizing to a realtime clock. More... | |
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. More... | |
void | SetOrigin (uint64_t ts) |
Establish a correspondence between a simulation time and the synchronizer real time. More... | |
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. More... | |
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. More... | |
![]() | |
Object () | |
virtual | ~Object () |
void | AggregateObject (Ptr< Object > other) |
void | Dispose (void) |
Run the DoDispose methods of this object and all the objects aggregated to it. More... | |
AggregateIterator | GetAggregateIterator (void) const |
virtual TypeId | GetInstanceTypeId (void) const |
template<typename T > | |
Ptr< T > | GetObject (void) const |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
void | Initialize (void) |
This method calls the virtual DoInitialize method on all the objects aggregated to this object. More... | |
![]() | |
SimpleRefCount () | |
Constructor. More... | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount (void) const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment. More... | |
void | Ref (void) const |
Increment the reference count. More... | |
void | Unref (void) const |
Decrement the reference count. More... | |
![]() | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
bool | GetAttributeFailSafe (std::string name, AttributeValue &attribute) const |
void | SetAttribute (std::string name, const AttributeValue &value) |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
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 Public Attributes | |
static const uint64_t | NS_PER_SEC = (uint64_t)1000000000 |
static const uint64_t | US_PER_NS = (uint64_t)1000 |
static const uint64_t | US_PER_SEC = (uint64_t)1000000 |
Protected Member Functions | |
virtual uint64_t | DoEventEnd (void) |
virtual void | DoEventStart (void) |
virtual uint64_t | DoGetCurrentRealtime (void) |
Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units. More... | |
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. More... | |
virtual bool | DoRealtime (void) |
Return true if this synchronizer is actually synchronizing to a realtime clock. More... | |
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. More... | |
virtual void | DoSetOrigin (uint64_t ns) |
Establish a correspondence between a simulation time and a wall-clock (real) time. More... | |
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. More... | |
virtual bool | DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay) |
Wait until the real time is in sync with the specified simulation time. More... | |
uint64_t | DriftCorrect (uint64_t nsNow, uint64_t nsDelay) |
uint64_t | GetNormalizedRealtime (void) |
uint64_t | GetRealtime (void) |
void | NsToTimeval (int64_t ns, struct timeval *tv) |
bool | SleepWait (uint64_t) |
bool | SpinWait (uint64_t) |
void | TimevalAdd (struct timeval *tv1, struct timeval *tv2, struct timeval *result) |
uint64_t | TimevalToNs (struct timeval *tv) |
![]() | |
Object (const Object &o) | |
virtual void | DoDispose (void) |
This method is called by Object::Dispose or by the object's destructor, whichever comes first. More... | |
virtual void | DoInitialize (void) |
This method is called only once by Object::Initialize. More... | |
virtual void | NotifyNewAggregate (void) |
This method is invoked whenever two sets of objects are aggregated together. More... | |
![]() | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
virtual void | NotifyConstructionCompleted (void) |
This method is invoked once all member attributes have been initialized. More... | |
Protected Attributes | |
SystemCondition | m_condition |
uint64_t | m_cpuTick |
uint64_t | m_jiffy |
uint64_t | m_nsEventStart |
uint64_t | m_realtimeTick |
![]() | |
uint64_t | m_realtimeOriginNano |
uint64_t | m_simOriginNano |
Additional Inherited Members | |
![]() | |
static TypeId | GetTypeId (void) |
![]() | |
static TypeId | GetTypeId (void) |
Register this type. More... | |
![]() | |
static void | Cleanup (void) |
Noop. More... | |
![]() | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
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.
Definition at line 62 of file wall-clock-synchronizer.h.
ns3::WallClockSynchronizer::WallClockSynchronizer | ( | ) |
Definition at line 31 of file wall-clock-synchronizer.cc.
References m_jiffy, NS_LOG_FUNCTION, NS_LOG_INFO, and NS_PER_SEC.
|
virtual |
Definition at line 71 of file wall-clock-synchronizer.cc.
References NS_LOG_FUNCTION.
|
protectedvirtual |
Implements ns3::Synchronizer.
Definition at line 288 of file wall-clock-synchronizer.cc.
References GetNormalizedRealtime(), m_nsEventStart, and NS_LOG_FUNCTION.
|
protectedvirtual |
Implements ns3::Synchronizer.
Definition at line 281 of file wall-clock-synchronizer.cc.
References GetNormalizedRealtime(), m_nsEventStart, and NS_LOG_FUNCTION.
|
protectedvirtual |
Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units.
Subclasses are expected to implement this method to do the actual real-time-clock-specific work of getting the current time.
Implements ns3::Synchronizer.
Definition at line 84 of file wall-clock-synchronizer.cc.
References GetNormalizedRealtime(), and NS_LOG_FUNCTION.
|
protectedvirtual |
Declaration of method used to retrieve drift between the real time clock used to synchronize the simulation and the current simulation time.
ns | Simulation timestep from the simulator normalized to nanosecond steps. |
Implements ns3::Synchronizer.
Definition at line 107 of file wall-clock-synchronizer.cc.
References GetNormalizedRealtime(), and NS_LOG_FUNCTION.
Referenced by DoSynchronize(), and DriftCorrect().
|
protectedvirtual |
Return true if this synchronizer is actually synchronizing to a realtime clock.
The simulator sometimes needs to know this.
Subclasses are expected to implement this method to tell the outside world whether or not they are synchronizing to a realtime clock.
Implements ns3::Synchronizer.
Definition at line 77 of file wall-clock-synchronizer.cc.
References NS_LOG_FUNCTION.
|
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.
Definition at line 274 of file wall-clock-synchronizer.cc.
References m_condition, NS_LOG_FUNCTION, and ns3::SystemCondition::SetCondition().
|
protectedvirtual |
Establish a correspondence between a simulation time and a wall-clock (real) time.
There are three timelines involved here: the simulation time, the (absolute) wall-clock time and the (relative) synchronizer real time. Calling this method makes a correspondence between the origin of the synchronizer time and the current wall-clock time.
This method is expected to be called at the "instant" before simulation begins. At this point, simulation time = 0, and synchronizer time is set = 0 in this method. We then associate this time with the current value of the real time clock that will be used to actually perform the synchronization.
Subclasses are expected to implement this method to do the actual real-time-clock-specific work of making the correspondence mentioned above. for example, this is where the differences between Time parameters and parameters to clock_nanosleep would be dealt with.
ns | The simulation time we need to use as the origin (normalized to nanosecond units). |
Implements ns3::Synchronizer.
Definition at line 91 of file wall-clock-synchronizer.cc.
References GetRealtime(), ns3::Synchronizer::m_realtimeOriginNano, NS_LOG_FUNCTION, and NS_LOG_INFO.
|
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.
Definition at line 265 of file wall-clock-synchronizer.cc.
References m_condition, NS_LOG_FUNCTION, ns3::SystemCondition::SetCondition(), and ns3::SystemCondition::Signal().
|
protectedvirtual |
Wait until the real time is in sync with the specified simulation time.
This is where the real work of synchronization is done. The Time passed in as a parameter is the simulation time. The job of Synchronize is to translate from simulation time to synchronizer time (in a perfect world this is the same time) and then figure out how long in real-time it needs to wait until that synchronizer / simulation time comes around.
Subclasses are expected to implement this method to do the actual real-time-clock-specific work of waiting (either busy-waiting or sleeping, or some combination) until the requested simulation time.
ns | The simulation time we need to wait for (normalized to nanosecond units). |
Implements ns3::Synchronizer.
Definition at line 147 of file wall-clock-synchronizer.cc.
References DoGetDrift(), DriftCorrect(), m_jiffy, NS_LOG_FUNCTION, NS_LOG_INFO, SleepWait(), and SpinWait().
|
protected |
Definition at line 349 of file wall-clock-synchronizer.cc.
References DoGetDrift(), and NS_LOG_FUNCTION.
Referenced by DoSynchronize().
|
protected |
Definition at line 389 of file wall-clock-synchronizer.cc.
References GetRealtime(), ns3::Synchronizer::m_realtimeOriginNano, and NS_LOG_FUNCTION.
Referenced by DoEventEnd(), DoEventStart(), DoGetCurrentRealtime(), DoGetDrift(), and SpinWait().
|
protected |
Definition at line 380 of file wall-clock-synchronizer.cc.
References NS_LOG_FUNCTION, and TimevalToNs().
Referenced by DoSetOrigin(), and GetNormalizedRealtime().
|
protected |
Definition at line 396 of file wall-clock-synchronizer.cc.
References NS_ASSERT, NS_LOG_FUNCTION, NS_PER_SEC, and US_PER_NS.
|
protected |
Definition at line 323 of file wall-clock-synchronizer.cc.
References m_condition, NS_LOG_FUNCTION, and ns3::SystemCondition::TimedWait().
Referenced by DoSynchronize().
|
protected |
Definition at line 295 of file wall-clock-synchronizer.cc.
References ns3::SystemCondition::GetCondition(), GetNormalizedRealtime(), m_condition, and NS_LOG_FUNCTION.
Referenced by DoSynchronize().
|
protected |
Definition at line 414 of file wall-clock-synchronizer.cc.
References NS_LOG_FUNCTION, and US_PER_SEC.
|
protected |
Definition at line 405 of file wall-clock-synchronizer.cc.
References NS_ASSERT, NS_LOG_FUNCTION, NS_PER_SEC, and US_PER_NS.
Referenced by GetRealtime().
|
protected |
Definition at line 191 of file wall-clock-synchronizer.h.
Referenced by DoSetCondition(), DoSignal(), SleepWait(), and SpinWait().
|
protected |
Definition at line 186 of file wall-clock-synchronizer.h.
|
protected |
Definition at line 188 of file wall-clock-synchronizer.h.
Referenced by DoSynchronize(), and WallClockSynchronizer().
|
protected |
Definition at line 189 of file wall-clock-synchronizer.h.
Referenced by DoEventEnd(), and DoEventStart().
|
protected |
Definition at line 187 of file wall-clock-synchronizer.h.
|
static |
Definition at line 70 of file wall-clock-synchronizer.h.
Referenced by NsToTimeval(), TimevalToNs(), and WallClockSynchronizer().
|
static |
Definition at line 68 of file wall-clock-synchronizer.h.
Referenced by NsToTimeval(), and TimevalToNs().
|
static |
Definition at line 69 of file wall-clock-synchronizer.h.
Referenced by TimevalAdd().