44
55== NAME
66
7- rtapi_get_time, rtapi_get_clocks - get the current time
7+ rtapi_get_time - get the current time in ns
88
99== SYNTAX
1010
1111[source,c]
1212----
1313long long rtapi_get_time();
14- long long rtapi_get_clocks();
1514----
1615
1716== DESCRIPTION
@@ -25,55 +24,19 @@ resolution of the returned value may be as good as one nano-second, or
2524as poor as several microseconds. May be called from init/cleanup code,
2625and from within realtime tasks.
2726
28- *rtapi_get_clocks* returns the current time in CPU clocks. It is fast,
29- since it just reads the TSC in the CPU instead of calling a kernel or
30- RTOS function. Of course, times measured in CPU clocks are not as
31- convenient, but for relative measurements this works fine. Its absolute
32- value means nothing, but it is monotonically increasing and can be used
33- to schedule future events, or to time the duration of some activity. (On
34- SMP machines, the two TSC's may get out of sync, so if a task reads the
35- TSC, gets swapped to the other CPU, and reads again, the value may
36- decrease. RTAPI tries to force all RT tasks to run on one CPU.) Returns
37- a 64 bit value. The resolution of the returned value is one CPU clock,
38- which is usually a few nanoseconds to a fraction of a nanosecond. Note
39- that _long long_ math may be poorly supported on some platforms,
40- especially in kernel space. Also note that rtapi_print() will NOT print
41- __long long__s. Most time measurements are relative, and should be done
42- like this:
43-
4427[source,c]
4528----
4629deltat = (long int)(end_time - start_time);
4730----
4831
4932where end_time and start_time are longlong values returned from
5033rtapi_get_time, and deltat is an ordinary long int (32 bits). This will
51- work for times up to a second or so, depending on the CPU clock
52- frequency. It is best used for millisecond and microsecond scale
34+ work for times up to 2.1s. It is best used for millisecond and microsecond scale
5335measurements though.
5436
5537== RETURN VALUE
5638
57- Returns the current time in nanoseconds or CPU clocks.
58-
59- == NOTES
60-
61- Certain versions of the Linux kernel provide a global variable *cpu_khz*. Computing
62-
63- [source,c]
64- ----
65- deltat = (end_clocks - start_clocks) / cpu_khz:
66- ----
67-
68- gives the duration measured in milliseconds. Computing
69-
70- [source,c]
71- ----
72- deltat = (end_clocks - start_clocks) * 1000000 / cpu_khz:
73- ----
74-
75- gives the duration measured in nanoseconds for deltas less than about 9
76- trillion clocks (e.g., 3000 seconds at 3 GHz).
39+ Returns the current time in nanoseconds.
7740
7841== REALTIME CONSIDERATIONS
7942
0 commit comments