LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 10-11-2012, 12:38 AM   #1
bijoy
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
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?
 
Old 10-11-2012, 08:07 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,006

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
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.
 
Old 10-15-2012, 07:09 AM   #3
bijoy
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.

Last edited by bijoy; 10-19-2012 at 01:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with undefined reference to `clock_gettime' hiteurecomupf Programming 4 10-15-2010 12:12 PM
clock_gettime(CLOCK_MONOTONIC,..) fails nathan2225 Programming 7 07-21-2006 09:35 AM
clock_gettime() issue AndreiCiprian Programming 0 03-28-2006 06:04 PM
POSIX.4 clock_gettime function collinss Programming 2 09-13-2005 06:55 AM
POSIX.4 clock_gettime function collinss Linux - General 1 11-24-2003 12:12 PM


All times are GMT -5. The time now is 07:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration