📄 rtapi_get_time.3rtapi
字号:
.TH rtapi_get_time "3rtapi" "2006-10-12" "EMC Documentation" "HAL".SH NAMErtapi_get_time \- get the current time.SH SYNTAX.HPlong long rtapi_get_time().HPlong long rtapi_get_clocks().SH DESCRIPTION\fBrtapi_get_time\fR returns the current time in nanoseconds. Depending on theRTOS, this may be time since boot, or time since the clock period was set, orsome other time. Its absolute value means nothing, but it is monotonicallyincreasing and can be used to schedule future events, or to time the durationof some activity. Returns a 64 bit value. The resolution of the returnedvalue may be as good as one nano-second, or as poor as several microseconds.May be called from init/cleanup code, and from within realtime tasks. Experience has shown that the implementation of this function in someRTOS/Kernel combinations is horrible. It can take up to several microseconds,which is at least 100 times longer than it should, and perhaps a thousand timeslonger. Use it only if you MUST have results in seconds instead of clocks, anduse it sparingly. In most cases, \fBrtapi_get_clocks\fR shold be used instead.\fBrtapi_get_clocks\fR returns the current time in CPU clocks. It is fast, since it just reads the TSC in the CPU instead of calling akernel or RTOS function. Of course, times measured in CPU clocksare not as convenient, but for relative measurements this worksfine. Its absolute value means nothing, but it is monotonicallyincreasing and can be used to schedule future events, or to timethe duration of some activity. (on SMP machines, the two TSC'smay get out of sync, so if a task reads the TSC, gets swapped tothe other CPU, and reads again, the value may decrease. RTAPItries to force all RT tasks to run on one CPU.)Returns a 64 bit value. The resolution of the returned value isone CPU clock, which is usually a few nanoseconds to a fraction ofa nanosecond. Note that \fIlong long\fR math may be poorly supported on some platforms,especially in kernel space. Also note that rtapi_print() will NOTprint \fIlong long\fRs. Most time measurements are relative, and shouldbe done like this:.RSdeltat = (long int)(end_time - start_time);.REwhere end_time and start_time are longlong values returned from rtapi_get_time,and deltat is an ordinary long int (32 bits). This will work for times up to asecond or so, depending on the CPU clock frequency. It is best used formillisecond and microsecond scale measurements though..SH RETURN VALUEReturns the current time in nanoseconds or CPU clocks..SH NOTESCertain versions of the Linux kernel provide a global variable \fBcpu_khz\fR.Computing .RS deltat = (end_clocks - start_clocks) / cpu_khz:.REgives the duration measured in milliseconds. Computing.RS deltat = (end_clocks - start_clocks) * 1000000 / cpu_khz:.REgives the duration measured in nanoseconds for deltas less than about 9trillion clocks (e.g., 3000 seconds at 3GHz).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -