Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clock_nanosleep with clockid CLOCK_REALTIME fails with error EINVAL #2503

Closed
traversaro opened this issue Sep 17, 2017 · 3 comments
Closed

Comments

@traversaro
Copy link

  • Your Windows build number:
Microsoft Windows [Version 10.0.15063]
  • What you're doing and what's happening:
    I am calling clock_nanosleep with clockid CLOCK_REALTIME, and the call fails with error EINVAL.

A self-contained example can be found in https://gist.github.com/traversaro/c2b6941ef2ddd10e9dd6c1800483696a .
On my system, the corresponding output is:

traversaro@system:~/src/clockid_wsl_test/build$ ./clockid_wsl_test
Error macros values:
EINTR : 4
EINVAL: 22
ENOTSUP: 95
Testing CLOCK_MONOTONIC
clock_getres return value: 0 with errno 0
clock_gettime return value: 0
clock_nanosleep return value: 0
Testing CLOCK_REALTIME
clock_getres return value: 0 with errno 0
clock_gettime return value: 0
clock_nanosleep return value: 22
Testing CLOCK_PROCESS_CPUTIME_ID
clock_getres return value: -1 with errno 22
clock_gettime return value: 0
clock_nanosleep return value: 22
Testing CLOCK_THREAD_CPUTIME_ID
clock_getres return value: -1 with errno 22
clock_gettime return value: 0
clock_nanosleep return value: 22
  • What's wrong / what should be happening instead:
    The call should be successful, and sleep (at least) for the specified amount of time.

  • Strace of the failing command, if applicable:

execve("./clockid_wsl_test", ["./clockid_wsl_test"], [/* 18 vars */]) = 0
brk(NULL)                               = 0x680000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a30000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=54863, ...}) = 0
mmap(NULL, 54863, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc541a22000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \235\10\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1566440, ...}) = 0
mmap(NULL, 3675136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc541270000
mprotect(0x7fc5413e2000, 2097152, PROT_NONE) = 0
mmap(0x7fc5415e2000, 49152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x172000) = 0x7fc5415e2000
mmap(0x7fc5415ee000, 13312, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc5415ee000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540ea0000
mprotect(0x7fc541060000, 2097152, PROT_NONE) = 0
mmap(0x7fc541260000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fc541260000
mmap(0x7fc541266000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc541266000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0V\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1088952, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a20000
mmap(NULL, 3178744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540b90000
mprotect(0x7fc540c98000, 2093056, PROT_NONE) = 0
mmap(0x7fc540e97000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x107000) = 0x7fc540e97000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=89696, ...}) = 0
mmap(NULL, 2185488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540970000
mprotect(0x7fc540986000, 2093056, PROT_NONE) = 0
mmap(0x7fc540b85000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7fc540b85000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a10000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a00000
arch_prctl(ARCH_SET_FS, 0x7fc541a00740) = 0
mprotect(0x7fc541260000, 16384, PROT_READ) = 0
mprotect(0x7fc540e97000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc5419f0000
mprotect(0x7fc5415e2000, 40960, PROT_READ) = 0
mprotect(0x601000, 4096, PROT_READ)     = 0
mprotect(0x7fc541825000, 4096, PROT_READ) = 0
munmap(0x7fc541a22000, 54863)           = 0
brk(NULL)                               = 0x680000
brk(0x6b2000)                           = 0x6b2000
write(2, "Error macros values: ", 21)   = 21
write(2, "\n", 1)                       = 1
write(2, "EINTR : ", 8)                 = 8
write(2, "4", 1)                        = 1
write(2, "\n", 1)                       = 1
write(2, "EINVAL: ", 8)                 = 8
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
write(2, "ENOTSUP: ", 9)                = 9
write(2, "95", 2)                       = 2
write(2, "\n", 1)                       = 1
write(2, "Testing CLOCK_MONOTONIC ", 24) = 24
write(2, "\n", 1)                       = 1
clock_getres(CLOCK_MONOTONIC, {0, 400}) = 0
write(2, "clock_getres return value: ", 27) = 27
write(2, "0", 1)                        = 1
write(2, " with errno ", 12)            = 12
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
clock_gettime(CLOCK_MONOTONIC, {64792, 473106000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
clock_nanosleep(CLOCK_MONOTONIC, 0, {0, 100000000}, 0x7fffe836d990) = 0
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
write(2, "Testing CLOCK_REALTIME ", 23) = 23
write(2, "\n", 1)                       = 1
clock_getres(CLOCK_REALTIME, {0, 400})  = 0
write(2, "clock_getres return value: ", 27) = 27
write(2, "0", 1)                        = 1
write(2, " with errno ", 12)            = 12
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
clock_gettime(CLOCK_REALTIME, {1505639919, 799894800}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
clock_nanosleep(CLOCK_REALTIME, 0, {0, 100000000}, 0x7fffe836d990) = -1 EINVAL (Invalid argument)
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
write(2, "Testing CLOCK_PROCESS_CPUTIME_ID"..., 33) = 33
write(2, "\n", 1)                       = 1
clock_getres(CLOCK_PROCESS_CPUTIME_ID, 0x7fffe836d960) = -1 EINVAL (Invalid argument)
write(2, "clock_getres return value: ", 27) = 27
write(2, "-1", 2)                       = 2
write(2, " with errno ", 12)            = 12
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 15625000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
clock_nanosleep(0xfffffffa /* CLOCK_??? */, 0, {0, 100000000}, 0x7fffe836d990) = -1 EINVAL (Invalid argument)
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
write(2, "Testing CLOCK_THREAD_CPUTIME_ID "..., 33) = 33
write(2, "\n", 1)                       = 1
clock_getres(CLOCK_THREAD_CPUTIME_ID, 0x7fffe836d960) = -1 EINVAL (Invalid argument)
write(2, "clock_getres return value: ", 27) = 27
write(2, "-1", 2)                       = 2
write(2, " with errno ", 12)            = 12
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
clock_gettime(CLOCK_THREAD_CPUTIME_ID, {0, 15625000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1)                        = 1
write(2, "\n", 1)                       = 1
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2)                       = 2
write(2, "\n", 1)                       = 1
exit_group(0)                           = ?
+++ exited with 0 +++

There is a similar issue #2116 and User Voice idea https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/19349059-support-clock-process-thread-cputime-id-clocks related to fully support the clockid CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID , but I did not find any issue related to the full support of CLOCK_REALTIME, so I opened a new issue for this.

@traversaro traversaro changed the title clock_nanosleep with clockid CLOCK_REALTIME fails with error EINVAL. clock_nanosleep with clockid CLOCK_REALTIME fails with error EINVAL Sep 17, 2017
@pmendham
Copy link

Problem seen independently and replicated on Windows 10 Pro, Version 1709, OS Build 16299.64

This issue currently means that WSL is not POSIX compliant because CLOCK_REALTIME is mandatory.

@peci1
Copy link

peci1 commented Dec 6, 2018

ARgh, still the same problem on 1809... Took me quite some time to discover why everyting fails in my code...

@therealkenc
Copy link
Collaborator

Moving the new landing zone to #4898.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants