0

gettimeofday() is hardware dependent with RTC.

Can some one suggest how we can avoid the use of the same in Application Programming. How we can approach the use of System ticks ?

thanks in advance !

Manuel Selva
  • 18,554
  • 22
  • 89
  • 134
user2598064
  • 157
  • 1
  • 13
  • What about just using `time()`? Seconds aren't enough: Use `clock_gettime()` (http://man7.org/linux/man-pages/man2/clock_gettime.2.html) – alk Apr 30 '14 at 09:07
  • are you sure this api reads values from system tick. i dont think so..as there is an api provided to settime .. – user2598064 Apr 30 '14 at 09:23
  • http://www.ibm.com/developerworks/library/l-timers-list/ this is somewhat we need to follow – user2598064 Apr 30 '14 at 09:35
  • 1
    `clock_gettime()` supports different (system) clocks. You propably are after `CLOCK_BOOTTIME`, which I suspect cannot be set via `clock_settime()`. Test it. – alk Apr 30 '14 at 09:42
  • will this api work fine if i remove RTC from my system – user2598064 Apr 30 '14 at 10:07
  • Sry, that's beyond my expertise. But I could imagine: Yes – alk Apr 30 '14 at 14:49
  • 1
    Please expand on your question. What problem are you trying to solve? Maybe this SO question helps? http://stackoverflow.com/q/12392278/1401351 – Peter Apr 30 '14 at 15:11
  • hi !! peter !! i want to get system ticks .. this is sufficient to understand.. the link you provided depends on the RTC . – user2598064 Apr 30 '14 at 15:31

1 Answers1

1

To get time in ticks you might like to use times().

However is is not clear whether those ticks are measured from boot-time.

From man times:

RETURN VALUE

times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. [...]

[...]

NOTES

On Linux, the "arbitrary point in the past" from which the return value of times() is measured has varied across kernel versions. On Linux 2.4 and earlier this point is the moment the system was booted. Since Linux 2.6, this point is (2^32/HZ) - 300 (i.e., about 429 million) seconds before system boot time. This variability across kernel versions (and across UNIX implementations), combined with the fact that the returned value may overflow the range of clock_t, means that a portable application would be wise to avoid using this value. To measure changes in elapsed time, use clock_gettime(2) instead.

Reading this using clock_gettitme() with the CLOCK_BOOTTIME timer might be the more secure and more portable way to go. If this function and/or timer is available for system without RTC I'm not sure. Others are encouraged to clarfiy this.

alk
  • 69,737
  • 10
  • 105
  • 255