source: rtems/doc/user/timespec.t @ 29e6637e

4.115
Last change on this file since 29e6637e was 66dacbfb, checked in by Joel Sherrill joel.sherrill@…>, on 08/30/12 at 23:38:50

timespec: Add documentation for struct timespec Helpers

Joel editted the documentation for clarity, grammar and technical
correctness. I also moved it in the manual and added @findex
entries. The core work was just polished.

Author: Krzysztof Mięsowicz <krzysztof.miesowicz@…>

  • Property mode set to 100644
File size: 13.5 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2012.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5
6
7@chapter Timespec Helpers
8
9@section Introduction
10
11The Timespec helpers manager provides directives to assist in manipulating
12instances of the POSIX @code{struct timespec} structure.
13
14The directives provided by the timespec helpers manager are:
15
16@itemize @bullet
17@item @code{rtems_timespec_set} - Set timespec's value
18@item @code{rtems_timespec_zero} - Zero timespec's value
19@item @code{rtems_timespec_is_valid} - Check if timespec is valid
20@item @code{rtems_timespec_add_to} - Add two timespecs
21@item @code{rtems_timespec_subtract} - Subtract two timespecs
22@item @code{rtems_timespec_divide} - Divide two timespecs
23@item @code{rtems_timespec_divide_by_integer} - Divide timespec by integer
24@item @code{rtems_timespec_less_than} - Less than operator
25@item @code{rtems_timespec_greater_than} - Greater than operator
26@item @code{rtems_timespec_equal_to} - Check if two timespecs are equal
27@item @code{rtems_timespec_get_seconds} - Obtain seconds portion of timespec
28@item @code{rtems_timespec_get_nanoseconds} - Obtain nanoseconds portion of timespec
29@item @code{rtems_timespec_to_ticks} - Convert timespec to number of ticks
30@item @code{rtems_timespec_from_ticks} - Convert ticks to timespec
31@end itemize
32
33@section Background
34
35@subsection Time Storage Conventions
36
37Time can be stored in many ways. One of them is the @code{struct timespec}
38format which is a structure that consists of the fields @code{tv_sec}
39to represent seconds and @code{tv_nsec} to represent nanoseconds.  The
40@code{struct timeval} structure is simular and consists of seconds (stored
41in @code{tv_sec}) and microseconds (stored in @code{tv_usec}). Either
42@code{struct timespec} or @code{struct timeval} can be used to represent
43elapsed time, time of executing some operations, or time of day.
44
45@section Operations
46
47@subsection Set and Obtain Timespec Value
48
49A user may write a specific time by passing the desired seconds and
50nanoseconds values and the destination @code{struct timespec} using the
51@code{rtems_timespec_set} directive.
52
53The @code{rtems_timespec_zero} directive is used to zero the seconds
54and nanoseconds portions of a @code{struct timespec} instance.
55
56Users may obtain the seconds or nanoseconds portions of a @code{struct
57timespec} instance with the @code{rtems_timespec_get_seconds} or
58@code{rtems_timespec_get_nanoseconds} methods, respectively.
59
60@subsection Timespec Math
61
62A user can perform multiple operations on @code{struct timespec}
63instances. The helpers in this manager assist in adding, subtracting, and
64performing divison on @code{struct timespec} instances.
65
66@itemize @bullet
67@item Adding two @code{struct timespec} can be done using the
68@code{rtems_timespec_add_to} directive. This directive is used mainly
69to calculate total amount of time consumed by multiple operations.
70
71@item The @code{rtems_timespec_subtract} is used to subtract two
72@code{struct timespecs} instances and determine the elapsed time between
73those two points in time.
74
75@item The @code{rtems_timespec_divide} is used to use to divide one
76@code{struct timespec} instance by another. This calculates the percentage
77with a precision to three decimal points.
78
79@item The @code{rtems_timespec_divide_by_integer} is used to divide a
80@code{struct timespec} instance by an integer. It is commonly used in
81benchmark calculations to dividing duration by the number of iterations
82performed.
83
84@end itemize
85
86@subsection Comparing struct timespec Instances
87
88A user can compare two @code{struct timespec} instances using the
89@code{rtems_timespec_less_than}, @code{rtems_timespec_greater_than}
90or @code{rtems_timespec_equal_to} routines.
91
92@subsection Conversions and Validity Check
93
94Conversion to and from clock ticks may be performed by using the
95@code{rtems_timespec_to_ticks} and @code{rtems_timespec_from_ticks}
96directives.
97
98User can also check validity of timespec with
99@code{rtems_timespec_is_valid} routine.
100
101@section Directives
102
103This section details the Timespec Helpers manager's directives.
104A subsection is dedicated to each of this manager's directives
105and describes the calling sequence, related constants, usage,
106and status codes.
107
108@page
109@subsection TIMESPEC_SET - Set struct timespec Instance
110
111@subheading CALLING SEQUENCE:
112
113@ifset is-C
114@example
115void rtems_timespec_set(
116  struct timespec *time,
117  time_t           seconds,
118  uint32_t         nanoseconds
119);
120@end example
121@findex rtems_timespec_set
122@end ifset
123
124@ifset is-Ada
125Not Currently Supported In Ada
126@end ifset
127
128@subheading STATUS CODES:
129
130NONE
131
132@subheading DESCRIPTION:
133
134This directive sets the @code{struct timespec} @code{time} value to the
135desired @code{seconds} and @code{nanoseconds} values.
136
137
138@subheading NOTES:
139
140This method does NOT check if @code{nanoseconds} is less than the
141maximum number of nanoseconds in a second.
142
143@page
144@subsection TIMESPEC_ZERO - Zero struct timespec Instance
145
146@subheading CALLING SEQUENCE:
147
148@ifset is-C
149@example
150void rtems_timespec_zero(
151  struct timespec *time
152);
153@end example
154@findex rtems_timespec_zero
155@end ifset
156
157@ifset is-Ada
158Not Currently Supported In Ada
159@end ifset
160
161@subheading STATUS CODES:
162NONE
163
164@subheading DESCRIPTION:
165
166This routine sets the contents of the @code{struct timespec} instance
167@code{time} to zero.
168
169@subheading NOTES:
170NONE
171
172@page
173@subsection TIMESPEC_IS_VALID - Check validity of a struct timespec instance
174
175@subheading CALLING SEQUENCE:
176
177@ifset is-C
178@example
179bool rtems_timespec_is_valid(
180  const struct timespec *time
181);
182@end example
183@findex rtems_timespec_is_valid
184@end ifset
185
186@ifset is-Ada
187Not Currently Supported In Ada
188@end ifset
189
190@subheading STATUS CODES:
191This method returns @code{true} if the instance is valid, and @code{false}
192otherwise.
193
194@subheading DESCRIPTION:
195
196This routine check validity of a @code{struct timespec} instance. It
197checks if the nanoseconds portion of the @code{struct timespec} instanceis
198in allowed range (less than the maximum number of nanoseconds per second).
199
200@subheading NOTES:
201
202@page
203@subsection TIMESPEC_ADD_TO - Add Two struct timespec Instances
204
205@subheading CALLING SEQUENCE:
206
207@ifset is-C
208@example
209uint32_t rtems_timespec_add_to(
210  struct timespec       *time,
211  const struct timespec *add
212);
213@end example
214@findex rtems_timespec_add_to
215@end ifset
216
217@ifset is-Ada
218Not Currently Supported In Ada
219@end ifset
220
221@subheading STATUS CODES:
222The method returns the number of seconds @code{time} increased by.
223
224@subheading DESCRIPTION:
225This routine adds two @code{struct timespec} instances. The second argument is added to the first. The parameter @code{time} is the base time to which the @code{add} parameter is added.
226
227@subheading NOTES:
228NONE
229@page
230@subsection TIMESPEC_SUBTRACT - Subtract Two struct timespec Instances
231
232@subheading CALLING SEQUENCE:
233
234@ifset is-C
235@example
236void rtems_timespec_subtract(
237  const struct timespec *start,
238  const struct timespec *end,
239  struct timespec       *result
240);
241@end example
242@findex rtems_timespec_subtract
243@end ifset
244
245@ifset is-Ada
246Not Currently Supported In Ada
247@end ifset
248
249@subheading STATUS CODES:
250NONE
251
252@subheading DESCRIPTION:
253This routine subtracts @code{start} from @code{end} saves the difference
254in @code{result}. The primary use of this directive is to calculate
255elapsed time.
256
257@subheading NOTES:
258
259It is possible to subtract when @code{end} is less than @code{start}
260and it produce negative @code{result}. When doing this you should be
261careful and remember that only the seconds portion of a @code{struct
262timespec} instance is signed, which means that nanoseconds portion is
263always increasing. Due to that when your timespec has seconds = -1 and
264nanoseconds=500,000,000 it means that result is -0.5 second, NOT the
265expected -1.5!
266
267@page
268@subsection TIMESPEC_DIVIDE - Divide Two struct timespec Instances
269
270@subheading CALLING SEQUENCE:
271
272@ifset is-C
273@example
274void rtems_timespec_divide(
275  const struct timespec *lhs,
276  const struct timespec *rhs,
277  uint32_t              *ival_percentage,
278  uint32_t              *fval_percentage
279);
280@end example
281@findex rtems_timespec_divide
282@end ifset
283
284@ifset is-Ada
285Not Currently Supported In Ada
286@end ifset
287
288@subheading STATUS CODES:
289
290NONE
291
292@subheading DESCRIPTION:
293
294This routine divides the @code{struct timespec} instance @code{lhs} by
295the @code{struct timespec} instance @code{rhs}. The result is returned
296in the @code{ival_percentage} and @code{fval_percentage}, representing
297the integer and fractional results of the division respectively.
298
299The @code{ival_percentage} is integer value of calculated percentage and @code{fval_percentage} is fractional part of calculated percentage.
300
301@subheading NOTES:
302
303The intended use is calculating percentges to three decimal points.
304
305When dividing by zero, this routine return both @code{ival_percentage}
306and @code{fval_percentage} equal zero.
307
308The division is performed using exclusively integer operations.
309
310@page
311@subsection TIMESPEC_DIVIDE_BY_INTEGER - Divide a struct timespec Instance by an Integer
312
313@subheading CALLING SEQUENCE:
314
315@ifset is-C
316@example
317int rtems_timespec_divide_by_integer(
318  const struct timespec *time,
319  uint32_t               iterations,
320  struct timespec       *result
321);
322@end example
323@findex rtems_timespec_divide_by_integer
324@end ifset
325
326@ifset is-Ada
327Not Currently Supported In Ada
328@end ifset
329
330@subheading STATUS CODES:
331
332NONE
333
334@subheading DESCRIPTION:
335This routine divides the @code{struct timespec} instance @code{time} by the integer value @code{iterations}.
336The result is saved in @code{result}.
337
338@subheading NOTES:
339
340The expected use is to assist in benchmark calculations where you
341typically divide a duration (@code{time}) by a number of iterations what
342gives average time.
343
344@page
345@subsection TIMESPEC_LESS_THAN - Less than operator
346
347@subheading CALLING SEQUENCE:
348
349@ifset is-C
350@example
351bool rtems_timespec_less_than(
352  const struct timespec *lhs,
353  const struct timespec *rhs
354);
355@end example
356@findex rtems_timespec_less_than
357@end ifset
358
359@ifset is-Ada
360Not Currently Supported In Ada
361@end ifset
362
363@subheading STATUS CODES:
364
365This method returns @code{struct true} if @code{lhs} is less than
366@code{rhs} and @code{struct false} otherwise.
367
368@subheading DESCRIPTION:
369
370This method is the less than operator for @code{struct timespec} instances. The first parameter is the left hand side and the second is the right hand side of the comparison.
371
372@subheading NOTES:
373NONE
374@page
375@subsection TIMESPEC_GREATER_THAN - Greater than operator
376
377@subheading CALLING SEQUENCE:
378
379@ifset is-C
380@example
381bool rtems_timespec_greater_than(
382  const struct timespec *_lhs,
383  const struct timespec *_rhs
384);
385@end example
386@findex rtems_timespec_greater_than
387@end ifset
388
389@ifset is-Ada
390Not Currently Supported In Ada
391@end ifset
392
393@subheading STATUS CODES:
394
395This method returns @code{struct true} if @code{lhs} is greater than
396@code{rhs} and @code{struct false} otherwise.
397
398@subheading DESCRIPTION:
399
400This method is greater than operator for @code{struct timespec} instances.
401
402@subheading NOTES:
403NONE
404
405@page
406@subsection TIMESPEC_EQUAL_TO - Check equality of timespecs
407
408@subheading CALLING SEQUENCE:
409
410@ifset is-C
411@example
412bool rtems_timespec_equal_to(
413  const struct timespec *lhs,
414  const struct timespec *rhs
415);
416@end example
417@findex rtems_timespec_equal_to
418@end ifset
419
420@ifset is-Ada
421Not Currently Supported In Ada
422@end ifset
423
424@subheading STATUS CODES:
425
426This method returns @code{struct true} if @code{lhs} is equal to
427@code{rhs} and @code{struct false} otherwise.
428
429
430@subheading DESCRIPTION:
431
432This method is equality operator for @code{struct timespec} instances.
433
434@subheading NOTES:
435NONE
436
437@page
438@subsection TIMESPEC_GET_SECONDS - Get Seconds Portion of struct timespec Instance
439
440@subheading CALLING SEQUENCE:
441
442@ifset is-C
443@example
444time_t rtems_timespec_get_seconds(
445  struct timespec *time
446);
447@end example
448@findex rtems_timespec_get_seconds
449@end ifset
450
451@ifset is-Ada
452Not Currently Supported In Ada
453@end ifset
454
455@subheading STATUS CODES:
456
457This method returns the seconds portion of the specified @code{struct
458timespec} instance.
459
460@subheading DESCRIPTION:
461
462This method returns the seconds portion of the specified @code{struct timespec} instance @code{time}.
463
464@subheading NOTES:
465NONE
466@page
467@subsection TIMESPEC_GET_NANOSECONDS - Get Nanoseconds Portion of the struct timespec Instance
468
469@subheading CALLING SEQUENCE:
470
471@ifset is-C
472@example
473uint32_t rtems_timespec_get_nanoseconds(
474  struct timespec *_time
475);
476@end example
477@findex rtems_timespec_get_nanoseconds
478@end ifset
479
480@ifset is-Ada
481Not Currently Supported In Ada
482@end ifset
483
484@subheading STATUS CODES:
485
486This method returns the nanoseconds portion of the specified @code{struct
487timespec} instance.
488
489@subheading DESCRIPTION:
490This method returns the nanoseconds portion of the specified timespec
491which is pointed by @code{_time}.
492
493@subheading NOTES:
494
495@page
496@subsection TIMESPEC_TO_TICKS - Convert struct timespec Instance to Ticks
497
498@subheading CALLING SEQUENCE:
499
500@ifset is-C
501@example
502uint32_t rtems_timespec_to_ticks(
503  const struct timespec *time
504);
505@end example
506@findex rtems_timespec_to_ticks
507@end ifset
508
509@ifset is-Ada
510Not Currently Supported In Ada
511@end ifset
512
513@subheading STATUS CODES:
514
515This directive returns the number of ticks computed.
516
517@subheading DESCRIPTION:
518
519This directive converts the @code{time} timespec to the corresponding number of clock ticks.
520
521@subheading NOTES:
522NONE
523
524@page
525@subsection TIMESPEC_FROM_TICKS - Convert Ticks to struct timespec Representation
526
527@subheading CALLING SEQUENCE:
528
529@ifset is-C
530@example
531void rtems_timespec_from_ticks(
532  uint32_t         ticks,
533  struct timespec *time
534);
535@end example
536@findex rtems_timespec_from_ticks
537@end ifset
538
539@ifset is-Ada
540Not Currently Supported In Ada
541@end ifset
542
543@subheading STATUS CODES:
544
545NONE
546
547@subheading DESCRIPTION:
548
549This routine converts the @code{ticks} to the corresponding @code{struct timespec} representation and stores it in @code{time}.
550
551@subheading NOTES:
552NONE
553
Note: See TracBrowser for help on using the repository browser.