LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   issue with clock_gettime (http://www.linuxquestions.org/questions/linux-kernel-70/issue-with-clock_gettime-4175431598/)

bijoy 10-11-2012 12:38 AM

issue with clock_gettime
 
Some times the clock_gettime(with CLOCK_REALTIME) call gives in non-chronological order in my ppc(Linux 2.6.21.7). Did any one come across such issues earlier? Shall i know the reason behind it?

tronayne 10-11-2012 08:07 AM

It may be related to whether you system is SMP; from the manual page
Quote:

Note for SMP systems
The CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID clocks are realized on
many platforms using timers from the CPUs (TSC on i386, AR.ITC on Itanium). These
registers may differ between CPUs and as a consequence these clocks may return
bogus results if a process is migrated to another CPU.

If the CPUs in an SMP system have different clock sources then there is no way to
maintain a correlation between the timer registers since each CPU will run at a
slightly different frequency. If that is the case then clock_getcpuclockid(0) will
return ENOENT to signify this condition. The two clocks will then only be useful
if it can be ensured that a process stays on a certain CPU.

The processors in an SMP system do not start all at exactly the same time and
therefore the timer registers are typically running at an offset. Some architec-
tures include code that attempts to limit these offsets on bootup. However, the
code cannot guarantee to accurately tune the offsets. Glibc contains no provisions
to deal with these offsets (unlike the Linux Kernel). Typically these offsets are
small and therefore the effects may be negligible in most cases.
Also, there is a good example (I think) that discusses profiling code using clock_gettime at http://www.guyrutenberg.com/2007/09/...clock_gettime/ that may provide some insight as well as other examples from Google clock_gettime example that may be useful.

Hope this helps some.

bijoy 10-15-2012 07:09 AM

The scenario is as follows,
I am having few threads with same dynamic library, which uses clock_gettime(with CLOCK_REALTIME) to get the current time stamp. In one of the thread will always shows the time with a 1 hour difference. The issue occurs some times on ppc processor restart, otherwise there is no jump in time. My system is not SMP.


eg:-
clock_gettime(CLOCK_REALTIME, &t);
rt = t.tv_sec;
localtime_r(&rt, &t1);
strftime(tmp, sizeof(tmp), "%Y/%m/%d %H:%M:%S", &t1);

output:
[Wed Sep 26 16:47:45 2012] thread 1
[Wed Sep 26 17:47:45 2012] thread 2
[Wed Sep 26 16:47:45 2012] thread 3
[Wed Sep 26 16:47:45 2012] thread 4

Is there any hope of light.


All times are GMT -5. The time now is 04:51 AM.