[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#594742: libc6: clock_gettime(CLOCK_MONOTONIC) not monotonic

Package: libc6
Version: 2.11.2-2
Severity: normal

This program:

#include <time.h>
#include <assert.h>
#include <stdio.h>
int main()
	struct timespec last_time, current_time;
	int r;
	clockid_t id;
	assert(clock_gettime(CLOCK_MONOTONIC, &last_time) == 0);
	r = clock_getcpuclockid(0, &id);
	printf("r: %d, id: %d\n", r, id);
	while (1) {
		assert(clock_gettime(CLOCK_MONOTONIC, &current_time) == 0);
		assert(current_time.tv_sec >= last_time.tv_sec);
		assert((current_time.tv_sec > last_time.tv_sec) ||
				(current_time.tv_nsec >= last_time.tv_nsec));
		last_time = current_time;

when run:

$ gcc -std=gnu99 -lrt monotonic2.c && ./a.out
r: 0, id: -6
a.out: monotonic2.c:16: main: Assertion `(current_time.tv_sec > last_time.tv_sec) || (current_time.tv_nsec >= last_time.tv_nsec)' failed.

Shouldn't trigger an assert... The function guarantees monotonic time
increments, but apparently that promise is broken here. I am running
this on an SMP system, but the output of clock_getcpuclockid(0) is not
ENOENT, so it should really be monotonic...

The CPU is an Intel Q9450.

Credits of test program: Wouter Vermaelen.

-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages libc6 depends on:
ii  libc-bin                      2.11.2-2   Embedded GNU C Library: Binaries
ii  libgcc1                       1:4.4.4-8  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]         1.5.35     Debian configuration management sy
pn  glibc-doc                     <none>     (no description available)
ii  locales                       2.11.2-2   Embedded GNU C Library: National L

-- debconf information:
* glibc/upgrade: true
* glibc/restart-services: gdm openbsd-inetd exim4 cups cron atd

Reply to: