Bug 709170 - clock_gettime( CLOCK_PROCESS_CPUTIME_ID, & ts ) jumps by 0.2 ms
Summary: clock_gettime( CLOCK_PROCESS_CPUTIME_ID, & ts ) jumps by 0.2 ms
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: kernel
Version: 14
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Kernel Maintainer List
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-05-30 23:00 UTC by r3obh
Modified: 2012-08-16 13:50 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-08-16 13:50:44 UTC
Type: ---


Attachments (Terms of Use)

Description r3obh 2011-05-30 23:00:48 UTC
Description of problem:
clock_gettime( CLOCK_PROCESS_CPUTIME_ID, & ts ) sometimes skips 0.2 ms, as if it was wall clock time rather than CPU time.

Version-Release number of selected component (if applicable):
glibc-2.13-1

How reproducible:
Always

Steps to Reproduce:
1. Run this with: cc test.c -lrt && ./a.out

#include <time.h>
#include <stdio.h>

double get_cpu_time( void ) {
  int ret;
  struct timespec ts;

  ret = clock_gettime( CLOCK_PROCESS_CPUTIME_ID, & ts );

  return ret ? 0 : ts.tv_nsec * 1e-9 + ts.tv_sec;
} /* end function get_cpu_time */

int main() {
  unsigned long count, lim;
  double delta, mi, ma, t1, t2, total;

  count = 0; lim = 1000;
  mi = 1e99; ma	= -1e99; total = 0;
  for ( ; ; ) {
    t1 = get_cpu_time();
    do { t2 = get_cpu_time(); } while ( t2 == t1 );
    delta = t2 - t1;
    ++ count;
    total += delta;
    if ( delta < mi ) mi = delta;
    if ( delta > ma ) ma = delta;
    if ( count >= lim ) {
      printf( "After %lu iters, min = %g ns, max = %g ns, mean = %g ns\n", count, mi * 1e9, ma * 1e9, total * 1e9 / count );
      lim *= 2;
    } /* end if */
  } /* end for */

  return 0;
} /* end function main */


Actual results:
After 1000 iters, min = 185 ns, max = 1772 ns, mean = 471.542 ns
After 2000 iters, min = 1 ns, max = 1772 ns, mean = 471.359 ns
After 4000 iters, min = 1 ns, max = 3061 ns, mean = 471.933 ns
After 8000 iters, min = 1 ns, max = 3061 ns, mean = 471.637 ns
After 16000 iters, min = 1 ns, max = 3061 ns, mean = 471.296 ns
After 32000 iters, min = 1 ns, max = 3061 ns, mean = 470.765 ns
After 64000 iters, min = 1 ns, max = 208869 ns, mean = 473.554 ns
After 128000 iters, min = 1 ns, max = 208869 ns, mean = 472.718 ns
[...]


Expected results:
Max delay in same ballpark as mean.

Additional info: Same with taskset -c 0 ./a.out

Comment 1 r3obh 2011-06-03 19:46:06 UTC
Neither mlockall() nor chrt seem to help...

Comment 2 Stanislaw Gruszka 2011-06-06 13:32:09 UTC
Perhaps you could report this issue to at kernel mailing list and cc proper scheduler and timers maintainers.

Comment 3 Chuck Ebbert 2011-06-24 10:02:08 UTC
This could be due to SMI interrupts:

 http://wiki.linuxcnc.org/emcinfo.pl?FixingSMIIssues

Comment 4 Fedora End Of Life 2012-08-16 13:50:48 UTC
This message is a notice that Fedora 14 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 14. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained.  At this time, all open bugs with a Fedora 'version'
of '14' have been closed as WONTFIX.

(Please note: Our normal process is to give advanced warning of this 
occurring, but we forgot to do that. A thousand apologies.)

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, feel free to reopen 
this bug and simply change the 'version' to a later Fedora version.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we were unable to fix it before Fedora 14 reached end of life. If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora, you are encouraged to click on 
"Clone This Bug" (top right of this page) and open it against that 
version of Fedora.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping


Note You need to log in before you can comment on or make changes to this bug.