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 issues #357
Comments
Relevant MSR bits are in this document for the clock implementation are in : https://www.kernel.org/doc/Documentation/virtual/kvm/msr.txt |
As I understand it, the differences between CLOCK_REALTIME and CLOCK_MONOTONIC is that the CLOCK_REALTIME value can be changed by setting the system clock via ntp etc. CLOCK_MONOTONIC is not affect by any change via ntp |
The implementation currently ignores CLOCK_MONOTONIC and treats all clk_id fields passed to clock_gettime as CLOCK_REALTIME which is incorrect. Changes to just return zeros CLOCK_MONOTONIC gives acceptable results for short running programs but will cause programs that need a monotonic clock for time stamping objects to be incorrect. It would return the same time stamp during the execution of the program no matter how long. I have a simple fix that just returns zeros for CLOCK_MONOTONIC but a more complete implementation is needed |
The current now() implementation is implemented specifically for KVM. There's a monotonic clock source that I can use within KVM. Not all cloud virtualization infrastructure uses KVM, like with Microsoft, but start with a KVM specific version for now |
MSR_KVM_SYSTEM_TIME_NEW: 0x4b564d01 Looks there's a monotonic clock in the KVM paravirtualization API that can be useful here for implementing a monotonic clock |
billh@dungeon:~/project$ ./main#375 Monotonic Time = Fri Mar 13 17:58:19 1970 Monotonic Time = Fri Mar 13 17:58:21 1970 Monotonic Time = Fri Mar 13 17:58:23 1970 Monotonic Time = Fri Mar 13 17:58:25 1970 billh@dungeon:~/project$ ops run main#375 Monotonic Time = Fri Feb 15 21:42:01 2019 Monotonic Time = Fri Feb 15 21:42:03 2019 |
6227901 seconds = 72.0821875 days billh@dungeon:~/project$ uptime Current (mono) = 1550266921 second Monotonic time should return the the number of seconds that have elapsed since the machine started up and not the Unix time |
|
Updated program above to generate the test output |
|
Above log is how monotonic time should proceed. |
the other issue in this tkt is that if you notice that usleep calls nanosleep(2) underneath - so it basically skips it when ran in nanos |
Yeah, in following discussions. It looks like the test program originally assumes that the second elapsed as boot is the same as monotonic time. Not sure if the patch I submitted should be merged or not but it now currently worse as the above program expects it to work |
The now() function returns the wall clock time, so it will be subject to discontinuities if the system time is changed (when support for changing the system time is actually implemented), and for this reason it should not be used as time source in clock_gettime() in case the requested clock is a monotonic clock. This commit uses uptime() as time source in such cases. Closes #357.
nanosleep() works fine actually. When inserting printf() calls before and after a call to sleep(), it might appear not to be working because the strings being sent to the standard output are buffered, so you will see the content printed by all printf() calls only after sleep() returns. To set the standard output as unbuffered, you can call |
The now() function returns the wall clock time, so it will be subject to discontinuities if the system time is changed (when support for changing the system time is actually implemented), and for this reason it should not be used as time source in clock_gettime() in case the requested clock is a monotonic clock. This commit uses uptime() as time source in such cases. In addition, the CLOCK_PROCESS_CPUTIME_ID clock type is now implemented as well. Closes #357.
The now() function returns the wall clock time, so it will be subject to discontinuities if the system time is changed (when support for changing the system time is actually implemented), and for this reason it should not be used as time source in clock_gettime() in case the requested clock is a monotonic clock. This commit uses uptime() as time source in such cases. In addition, the CLOCK_PROCESS_CPUTIME_ID clock type is now implemented as well. Closes #357.
taken form #354
and if you look @ http://man7.org/linux/man-pages/man3/sleep.3.html you can see it uses nanosleep which uses... http://man7.org/linux/man-pages/man2/nanosleep.2.html
&&&.... https://golang.org/src/time/time.go
The text was updated successfully, but these errors were encountered: