OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 University of Washington | 3 * Copyright (c) 2008 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 */ | 17 */ |
18 | 18 |
19 #ifndef WALL_CLOCK_CLOCK_SYNCHRONIZER_H | 19 #ifndef WALL_CLOCK_CLOCK_SYNCHRONIZER_H |
20 #define WALL_CLOCK_CLOCK_SYNCHRONIZER_H | 20 #define WALL_CLOCK_CLOCK_SYNCHRONIZER_H |
21 | 21 |
22 #include "system-condition.h" | 22 #include "system-condition.h" |
23 #include "synchronizer.h" | 23 #include "synchronizer.h" |
24 | 24 |
| 25 #include "ns3/ns3-module.h" |
| 26 #define NS3_MODULE NS3_CORE_MODULE |
| 27 #include "ns3/ns3-export.h" |
| 28 |
25 /** | 29 /** |
26 * @file | 30 * @file |
27 * @ingroup realtime | 31 * @ingroup realtime |
28 * ns3::WallClockSynchronizer declaration. | 32 * ns3::WallClockSynchronizer declaration. |
29 */ | 33 */ |
30 | 34 |
31 namespace ns3 { | 35 namespace ns3 { |
32 | 36 |
33 /** | 37 /** |
34 * @ingroup realtime | 38 * @ingroup realtime |
(...skipping 25 matching lines...) Expand all Loading... |
60 * to use the function @c clock_nanosleep() to sleep until a simulation Time | 64 * to use the function @c clock_nanosleep() to sleep until a simulation Time |
61 * specified by the caller.· | 65 * specified by the caller.· |
62 * | 66 * |
63 * @todo Add more on jiffies, sleep, processes, etc. | 67 * @todo Add more on jiffies, sleep, processes, etc. |
64 * | 68 * |
65 * @internal | 69 * @internal |
66 * Nanosleep takes a <tt>struct timeval</tt> as an input so we have to | 70 * Nanosleep takes a <tt>struct timeval</tt> as an input so we have to |
67 * deal with conversion between Time and @c timeval here. | 71 * deal with conversion between Time and @c timeval here. |
68 * They are both interpreted as elapsed times. | 72 * They are both interpreted as elapsed times. |
69 */ | 73 */ |
70 class WallClockSynchronizer : public Synchronizer | 74 class NS3_EXPORT WallClockSynchronizer : public Synchronizer |
71 { | 75 { |
72 public: | 76 public: |
73 /** | 77 /** |
74 * Get the registered TypeId for this class. | 78 * Get the registered TypeId for this class. |
75 * @returns The TypeId. | 79 * @returns The TypeId. |
76 */ | 80 */ |
77 static TypeId GetTypeId (void); | 81 static TypeId GetTypeId (void); |
78 | 82 |
79 /** Constructor. */ | 83 /** Constructor. */ |
80 WallClockSynchronizer (); | 84 WallClockSynchronizer (); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 * Signal(). In either case, we are done waiting. If the timeout happened, | 125 * Signal(). In either case, we are done waiting. If the timeout happened, |
122 * we return @c true; if a Signal happened we return @c false. | 126 * we return @c true; if a Signal happened we return @c false. |
123 * | 127 * |
124 * @param [in] ns The target normalized real time we should wait for. | 128 * @param [in] ns The target normalized real time we should wait for. |
125 * @returns @c true if we reached the target time, | 129 * @returns @c true if we reached the target time, |
126 * @c false if we returned because the condition was set. | 130 * @c false if we returned because the condition was set. |
127 */ | 131 */ |
128 bool SleepWait (uint64_t ns); | 132 bool SleepWait (uint64_t ns); |
129 | 133 |
130 // Inherited from Synchronizer | 134 // Inherited from Synchronizer |
| 135 /** |
| 136 * @brief Establish a correspondence between a simulation time and a· |
| 137 * wall-clock (real) time. |
| 138 * |
| 139 * @internal |
| 140 * |
| 141 * There are three timelines involved here: the simulation time, the· |
| 142 * (absolute) wall-clock time and the (relative) synchronizer real time. |
| 143 * Calling this method makes a correspondence between the origin of the |
| 144 * synchronizer time and the current wall-clock time. |
| 145 * |
| 146 * This method is expected to be called at the "instant" before simulation |
| 147 * begins. At this point, simulation time = 0, and synchronizer time is |
| 148 * set = 0 in this method. We then associate this time with the current |
| 149 * value of the real time clock that will be used to actually perform the |
| 150 * synchronization. |
| 151 * |
| 152 * Subclasses are expected to implement this method to do the actual· |
| 153 * real-time-clock-specific work of making the correspondence mentioned above. |
| 154 * for example, this is where the differences between Time parameters and |
| 155 * parameters to clock_nanosleep would be dealt with.· |
| 156 * |
| 157 * @param ns The simulation time we need to use as the origin (normalized to |
| 158 * nanosecond units). |
| 159 */ |
131 virtual void DoSetOrigin (uint64_t ns); | 160 virtual void DoSetOrigin (uint64_t ns); |
132 virtual bool DoRealtime (void); | 161 virtual bool DoRealtime (void); |
| 162 |
| 163 /** |
| 164 * @brief Retrieve the value of the origin of the underlying normalized wall |
| 165 * clock time in nanosecond units. |
| 166 * |
| 167 * @internal |
| 168 * |
| 169 * Subclasses are expected to implement this method to do the actual |
| 170 * real-time-clock-specific work of getting the current time. |
| 171 * |
| 172 * @returns The normalized wall clock time (in nanosecond units). |
| 173 * @see TimeStepPrecision::Get |
| 174 * @see Synchronizer::SetOrigin |
| 175 */ |
133 virtual uint64_t DoGetCurrentRealtime (void); | 176 virtual uint64_t DoGetCurrentRealtime (void); |
| 177 /** |
| 178 * @brief Wait until the real time is in sync with the specified simulation |
| 179 * time. |
| 180 * |
| 181 * @internal |
| 182 * |
| 183 * This is where the real work of synchronization is done. The Time passed |
| 184 * in as a parameter is the simulation time. The job of Synchronize is to |
| 185 * translate from simulation time to synchronizer time (in a perfect world |
| 186 * this is the same time) and then figure out how long in real-time it needs |
| 187 * to wait until that synchronizer / simulation time comes around. |
| 188 * |
| 189 * Subclasses are expected to implement this method to do the actual |
| 190 * real-time-clock-specific work of waiting (either busy-waiting or sleeping, |
| 191 * or some combination) until the requested simulation time. |
| 192 * |
| 193 * @param ns The simulation time we need to wait for (normalized to nanosecond |
| 194 * units). |
| 195 * @see TimeStepPrecision::Get |
| 196 */ |
134 virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay); | 197 virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay); |
135 virtual void DoSignal (void); | 198 virtual void DoSignal (void); |
136 virtual void DoSetCondition (bool cond); | 199 virtual void DoSetCondition (bool cond); |
| 200 /** |
| 201 * @brief Declaration of method used to retrieve drift between the real time |
| 202 * clock used to synchronize the simulation and the current simulation time. |
| 203 * |
| 204 * @internal |
| 205 * |
| 206 * @param ns Simulation timestep from the simulator normalized to nanosecond· |
| 207 * steps. |
| 208 * @returns Drift in nanosecond units. |
| 209 * @see TimeStepPrecision::Get |
| 210 * @see Synchronizer::SetOrigin |
| 211 * @see Synchronizer::GetDrift |
| 212 */ |
137 virtual int64_t DoGetDrift (uint64_t ns); | 213 virtual int64_t DoGetDrift (uint64_t ns); |
138 virtual void DoEventStart (void); | 214 virtual void DoEventStart (void); |
139 virtual uint64_t DoEventEnd (void); | 215 virtual uint64_t DoEventEnd (void); |
140 | 216 |
141 /** | 217 /** |
142 * @brief Compute a correction to the nominal delay to account for | 218 * @brief Compute a correction to the nominal delay to account for |
143 * realtime drift since the last DoSynchronize. | 219 * realtime drift since the last DoSynchronize. |
144 * | 220 * |
145 * @param [in] nsNow The current simulation time (in nanosecond units). | 221 * @param [in] nsNow The current simulation time (in nanosecond units). |
146 * @param [in] nsDelay The simulation time we need to wait for (normalized to· | 222 * @param [in] nsDelay The simulation time we need to wait for (normalized to· |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 /** Time recorded by DoEventStart. */ | 270 /** Time recorded by DoEventStart. */ |
195 uint64_t m_nsEventStart; | 271 uint64_t m_nsEventStart; |
196 | 272 |
197 /** Thread synchronizer. */ | 273 /** Thread synchronizer. */ |
198 SystemCondition m_condition; | 274 SystemCondition m_condition; |
199 }; | 275 }; |
200 | 276 |
201 } // namespace ns3 | 277 } // namespace ns3 |
202 | 278 |
203 #endif /* WALL_CLOCK_SYNCHRONIZER_H */ | 279 #endif /* WALL_CLOCK_SYNCHRONIZER_H */ |
OLD | NEW |