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

Bug#374983: nanosleep fails to sleep



Package: linux-2.6
Severity: normal

The following program fails to sleep properly (on 64bit cpus != ia64):

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

int main() {
    struct timespec req = {(1L<<34), 0};
    printf("nanosleep = %d\n", nanosleep(&req, NULL));
    perror("error ");
    return 0;
}

The nanosleep syscall just returns imediatly without any error or
delay.

I believe this is caused by the conversion from struct timespec
(128bit) to ktime_t (64bit) where the upper 32bits of the seconds are
lost (leaving 0 as sleep time). [in kernel/hrtimer.c:
hrtimer_nanosleep()].

The sys_nanosleep() should probably check not only for
timespec_valid() but also guard against such an overflow.


But there is more to it:

At the time of writing a "sleep 9218114349" will sleep but a "sleep
9219114349" will just return. The value where this happens decreases
with time. The critical point seems to be a fixed wallclock time. I
think that effect is caused in 'kernel/hrtimer.c: hrtimer_start()' by

	tim = ktime_add(tim, new_base->get_time());

causing an overflow.

MfG
	Goswin

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.16-rc4-xen
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)



Reply to: