source: rtems/cpukit/score/include/rtems/score/timestamp.h @ d8cd045c

4.115
Last change on this file since d8cd045c was d8cd045c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/11 at 15:40:09

2011-06-17 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/types.h, score/include/rtems/score/address.h, score/include/rtems/score/apiext.h, score/include/rtems/score/bitfield.h, score/include/rtems/score/context.h, score/include/rtems/score/corebarrier.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/corerwlock.h, score/include/rtems/score/coresem.h, score/include/rtems/score/corespinlock.h, score/include/rtems/score/interr.h, score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h, score/include/rtems/score/objectmp.h, score/include/rtems/score/percpu.h, score/include/rtems/score/priority.h, score/include/rtems/score/rbtree.h, score/include/rtems/score/scheduler.h, score/include/rtems/score/smp.h, score/include/rtems/score/smplock.h, score/include/rtems/score/stack.h, score/include/rtems/score/states.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadq.h, score/include/rtems/score/threadsync.h, score/include/rtems/score/timespec.h, score/include/rtems/score/timestamp.h, score/include/rtems/score/timestamp64.h, score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h, score/include/rtems/score/watchdog.h, score/include/rtems/score/wkspace.h: Mark Score files as in Score Group to improve Doxygen output.
  • Property mode set to 100644
File size: 13.8 KB
Line 
1/**
2 *  @file  rtems/score/timestamp.h
3 *
4 *  This include file contains helpers for manipulating timestamps.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2009.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#ifndef _RTEMS_SCORE_TIMESTAMP_H
19#define _RTEMS_SCORE_TIMESTAMP_H
20
21/**
22 *  @defgroup SuperCore Timestamp
23 *
24 *  @ingroup Score
25 *
26 *  This handler encapsulates functionality related to manipulating
27 *  SuperCore Timestamps.  SuperCore Timestamps may be used to
28 *  represent time of day, uptime, or intervals.
29 *
30 *  The key attribute of the SuperCore Timestamp handler is that it
31 *  is a completely opaque handler.  There can be multiple implementations
32 *  of the required functionality and with a recompile, RTEMS can use
33 *  any implementation.  It is intended to be a simple wrapper.
34 *
35 *  This handler can be implemented as either struct timespec or
36 *  unsigned64 bit numbers.  The use of a wrapper class allows the
37 *  the implementation of timestamps to change on a per architecture
38 *  basis.  This is an important option as the performance of this
39 *  handler is critical.
40 */
41/**@{*/
42
43#include <rtems/score/timespec.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/*
50 *  NOTE: Eventually each port should select what it should use!!!
51 *
52 *  These control which implementation of SuperCore Timestamp is used.
53 *
54 *  if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
55 *     struct timespec is used
56 *  else if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
57 *     int64_t is used
58 *
59 *  When int64_t is used, then
60 *     if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
61 *        the methods are inlined
62 *     else
63 *        the methods are NOT inlined
64 *
65 *  Performance of int64_t versus struct timespec
66 *  =============================================
67 *
68 *  On PowerPC/psim, inlined int64_t saves ~50 instructions on each
69 *    _Thread_Dispatch operation which results in a context switch.
70 *    This works out to be about 10% faster dispatches and 7.5% faster
71 *    blocking semaphore obtains.  The following numbers are in instructions
72 *    and from tm02 and tm26.
73 *
74 *                         timespec  int64  inlined int64
75 *    dispatch:              446      446      400
76 *    blocking sem obtain:   627      626      581
77 *
78 *  On SPARC/sis, inlined int64_t shows the same percentage gains.
79 *    The following numbers are in microseconds and from tm02 and tm26.
80 *
81 *                         timespec  int64  inlined int64
82 *    dispatch:               59       61       53
83 *    blocking sem obtain:    98      100       92
84 *
85 *  Inlining appears to have a tendency to increase the size of
86 *    some executables.
87 *  Not inlining reduces the execution improvement but does not seem to
88 *    be an improvement on the PowerPC and SPARC. The struct timespec
89 *    and the executables with int64 not inlined are about the same size.
90 *
91 *  Once there has some analysis of which algorithm and configuration
92 *  is best suited to each target, these defines should be moved to
93 *  the appropriate score/cpu cpu.h file.  In the meantime, it is
94 *  appropriate to select an implementation here using CPU macros.
95 */
96
97#define CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC
98/*
99#define CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64
100#define CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE
101*/
102
103/*
104 *  Verify something is defined.
105 */
106#if !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC) && \
107    !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
108  #error "No SuperCore Timestamp implementation selected."
109#endif
110
111/*
112 * Verify that more than one is not defined.
113 */
114#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC) && \
115    defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
116  #error "Too many SuperCore Timestamp implementations selected."
117#endif
118
119/**
120 *   Include any implementation specific header files
121 */
122#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
123  #include <rtems/score/timestamp64.h>
124#endif
125
126/**
127 *   Define the Timestamp control type.
128 */
129#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
130  typedef struct timespec Timestamp_Control;
131#else
132  typedef Timestamp64_Control Timestamp_Control;
133#endif
134
135/**
136 *  @brief Set Timestamp to Seconds Nanosecond
137 *
138 *  This method sets the timestamp to the specified seconds and nanoseconds
139 *  value.
140 *
141 *  @param[in] _time points to the timestamp instance to validate.
142 *  @param[in] _seconds is the seconds portion of the timestamp
143 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
144 */
145#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
146  #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
147          _Timespec_Set( _time, _seconds, _nanoseconds )
148#else
149  #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
150          _Timestamp64_Set( _time, _seconds, _nanoseconds )
151#endif
152
153/**
154 *  @brief Zero Timestamp
155 *
156 *  This method sets the timestamp to zero.
157 *  value.
158 *
159 *  @param[in] _time points to the timestamp instance to zero.
160 */
161#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
162  #define _Timestamp_Set_to_zero( _time ) \
163          _Timespec_Set_to_zero( _time )
164#else
165  #define _Timestamp_Set_to_zero( _time ) \
166          _Timestamp64_Set_to_zero( _time )
167#endif
168
169/**
170 *  @brief Is Timestamp Valid
171 *
172 *  This method determines the validity of a timestamp.
173 *
174 *  @param[in] _time points to the timestamp instance to validate.
175 *
176 *  @return This method returns true if @a time is valid and
177 *          false otherwise.
178 */
179#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
180  #define _Timestamp_Is_valid( _time ) \
181          _Timespec_Is_valid( _time )
182#else
183  #define _Timestamp_Is_valid( _time ) \
184          _Timestamp64_Is_valid( _time )
185#endif
186
187/**
188 *  @brief Timestamp Less Than Operator
189 *
190 *  This method is the less than operator for timestamps.
191 *
192 *  @param[in] _lhs points to the left hand side timestamp
193 *  @param[in] _rhs points to the right hand side timestamp
194 *
195 *  @return This method returns true if @a _lhs is less than the @a _rhs and
196 *          false otherwise.
197 */
198#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
199  #define _Timestamp_Less_than( _lhs, _rhs ) \
200          _Timespec_Less_than( _lhs, _rhs )
201#else
202  #define _Timestamp_Less_than( _lhs, _rhs ) \
203          _Timestamp64_Less_than( _lhs, _rhs )
204#endif
205
206/**
207 *  @brief Timestamp Greater Than Operator
208 *
209 *  This method is the greater than operator for timestamps.
210 *
211 *  @param[in] _lhs points to the left hand side timestamp
212 *  @param[in] _rhs points to the right hand side timestamp
213 *
214 *  @return This method returns true if @a _lhs is greater than the @a _rhs and
215 *          false otherwise.
216 */
217#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
218  #define _Timestamp_Greater_than( _lhs, _rhs ) \
219          _Timespec_Greater_than( _lhs, _rhs )
220#else
221  #define _Timestamp_Greater_than( _lhs, _rhs ) \
222          _Timestamp64_Greater_than( _lhs, _rhs )
223#endif
224
225/**
226 *  @brief Timestamp equal to Operator
227 *
228 *  This method is the is equal to than operator for timestamps.
229 *
230 *  @param[in] _lhs points to the left hand side timestamp
231 *  @param[in] _rhs points to the right hand side timestamp
232 *
233 *  @return This method returns true if @a _lhs is equal to  @a _rhs and
234 *          false otherwise.
235 */
236#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
237  #define _Timestamp_Equal_to( _lhs, _rhs ) \
238          _Timespec_Equal_to( _lhs, _rhs )
239#else
240  #define _Timestamp_Equal_to( _lhs, _rhs ) \
241          _Timestamp64_Equal_to( _lhs, _rhs )
242#endif
243
244/**
245 *  @brief Add to a Timestamp
246 *
247 *  This routine adds two timestamps.  The second argument is added
248 *  to the first.
249 *
250 *  @param[in] _time points to the base time to be added to
251 *  @param[in] _add points to the timestamp to add to the first argument
252 *
253 *  @return This method returns the number of seconds @a time increased by.
254 */
255#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
256  #define _Timestamp_Add_to( _time, _add ) \
257          _Timespec_Add_to( _time, _add )
258#else
259  #define _Timestamp_Add_to( _time, _add ) \
260          _Timestamp64_Add_to( _time, _add )
261#endif
262
263/**
264 *  @brief Add to a Timestamp (At Clock Tick)
265 *
266 *  This routine adds two timestamps.  The second argument is added
267 *  to the first.
268 *
269 *  @node This routine places a special requirement on the addition
270 *        operation.  It must return the number of units that the
271 *        seconds field changed as the result of the addition.  Since this
272 *        operation is ONLY used as part of processing a clock tick,
273 *        it is generally safe to assume that only one second changed.
274 *
275 *  @param[in] _time points to the base time to be added to
276 *  @param[in] _add points to the timestamp to add to the first argument
277 *
278 *  @return This method returns the number of seconds @a time increased by.
279 */
280#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
281  #define _Timestamp_Add_to_at_tick( _time, _add ) \
282          _Timespec_Add_to( _time, _add )
283#else
284  #define _Timestamp_Add_to_at_tick( _time, _add ) \
285          _Timestamp64_Add_to_at_tick( _time, _add )
286#endif
287
288/**
289 *  @brief Convert Timestamp to Number of Ticks
290 *
291 *  This routine convert the @a time timestamp to the corresponding number
292 *  of clock ticks.
293 *
294 *  @param[in] _time points to the time to be converted
295 *
296 *  @return This method returns the number of ticks computed.
297 */
298#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
299  #define _Timestamp_To_ticks( _time ) \
300          _Timespec_To_ticks( _time )
301#else
302  #define _Timestamp_To_ticks( _time ) \
303          _Timestamp64_To_ticks( _time )
304#endif
305
306/**
307 *  @brief Convert Ticks to Timestamp
308 *
309 *  This routine converts the @a _ticks value to the corresponding
310 *  timestamp format @a _time.
311 *
312 *  @param[in] _time points to the timestamp format time result
313 *  @param[in] _ticks points to the number of ticks to be filled in
314 */
315#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
316  #define _Timestamp_From_ticks( _ticks, _time ) \
317          _Timespec_From_ticks( _ticks, _time )
318#else
319  #define _Timestamp_From_ticks( _ticks, _time ) \
320          _Timestamp64_From_ticks( _ticks, _time )
321#endif
322
323/**
324 *  @brief Subtract Two Timestamp
325 *
326 *  This routine subtracts two timestamps.  @a result is set to
327 *  @a end - @a start.
328 *
329 *  @param[in] _start points to the starting time
330 *  @param[in] _end points to the ending time
331 *  @param[in] _result points to the difference between
332 *             starting and ending time.
333 *
334 *  @return This method fills in @a _result.
335 */
336#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
337  #define _Timestamp_Subtract( _start, _end, _result ) \
338          _Timespec_Subtract( _start, _end, _result )
339#else
340  #define _Timestamp_Subtract( _start, _end, _result ) \
341          _Timestamp64_Subtract( _start, _end, _result )
342#endif
343
344/**
345 *  @brief Divide Timestamp By Integer
346 *
347 *  This routine divides a timestamp by an integer value.  The expected
348 *  use is to assist in benchmark calculations where you typically
349 *  divide a duration by a number of iterations.
350 *
351 *  @param[in] _time points to the total
352 *  @param[in] _iterations is the number of iterations
353 *  @param[in] _result points to the average time.
354 *
355 *  @return This method fills in @a result.
356 */
357#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
358  #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
359          _Timespec_Divide_by_integer(_time, _iterations, _result )
360#else
361  #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
362          _Timestamp64_Divide_by_integer( _time, _iterations, _result )
363#endif
364
365/**
366 *  @brief Divide Timestamp
367 *
368 *  This routine divides a timestamp by another timestamp.  The
369 *  intended use is for calculating percentages to three decimal points.
370 *
371 *  @param[in] _lhs points to the left hand number
372 *  @param[in] _rhs points to the right hand number
373 *  @param[in] _ival_percentage points to the integer portion of the average
374 *  @param[in] _fval_percentage points to the thousandths of percentage
375 *
376 *  @return This method fills in @a result.
377 */
378#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
379  #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
380          _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
381#else
382  #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
383          _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
384#endif
385
386/**
387 *  @brief Get Seconds Portion of Timestamp
388 *
389 *  This method returns the seconds portion of the specified timestamp
390 *
391 *  @param[in] _time points to the timestamp
392 *
393 *  @return The seconds portion of @a _time.
394 */
395#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
396  #define _Timestamp_Get_seconds( _time ) \
397          _Timespec_Get_seconds( _time )
398#else
399  #define _Timestamp_Get_seconds( _time ) \
400          _Timestamp64_Get_seconds( _time )
401#endif
402
403/**
404 *  @brief Get Nanoseconds Portion of Timestamp
405 *
406 *  This method returns the nanoseconds portion of the specified timestamp
407 *
408 *  @param[in] _time points to the timestamp
409 *
410 *  @return The nanoseconds portion of @a _time.
411 */
412#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
413  #define _Timestamp_Get_nanoseconds( _time ) \
414          _Timespec_Get_nanoseconds( _time )
415#else
416  #define _Timestamp_Get_nanoseconds( _time ) \
417          _Timestamp64_Get_nanoseconds( _time )
418#endif
419
420/**
421 *  @brief Convert Timestamp to struct timespec
422 *
423 *  This method returns the seconds portion of the specified timestamp
424 *
425 *  @param[in] _timestamp points to the timestamp
426 *  @param[in] _timespec points to the timespec
427 */
428#if defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
429  /* in this case we know they are the same type so use simple assignment */
430  #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
431          *(_timespec) = *(_timestamp)
432#else
433  #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
434          _Timestamp64_To_timespec( _timestamp, _timespec  )
435#endif
436
437#ifdef __cplusplus
438}
439#endif
440
441/**@}*/
442
443#endif
444/* end of include file */
Note: See TracBrowser for help on using the repository browser.