-
Notifications
You must be signed in to change notification settings - Fork 30
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
wall clock time goes backwards #44
Comments
I wonder if a work-around would be changing the timer source (w/ |
It seems that mips only has two choices:
|
Is there a simple and deterministic way to reproduce this? |
Unfortunately there isn't. For me, running the whole freebsd test suite usually triggers at least one event (most of the time, it won't matter since it will be within a non-time dependent test, but without the kyua hack to allow time going backwards, I've never finished a full run on vica). The failures tend to cluster (I get none sometimes and then several in the same VM other types) which leads me to believe it's somehow system load related. |
I wonder if there may be some form of wrap-around bug involving the MIPS CP0 counter?
|
The "dummy" timecounter isn't a real one. The MIPS timecounter in qemu wraps every 42 seconds. If qemu is using a host wall clock to compute the cycle counter value and the VM was starved of cycles (or stuck handling I/O, etc.) such that the counter wrapped before the "every 100ms" tc update callout fired then perhaps this could occur? It depends on how the counter is implemented in qemu I think (though 42 seconds is a fairly long time). |
Yes, it looks like Qemu is using gettimeofday() (or clock_gettime(CLOCK_MONOTONIC,...) if CLOCK_MONOTONIC is set at compile-time) to supply the MIPS CP0 Count register. Therefore, if the VM was starved of cycles I guess a roll over of the count register could be possible. Here is something to try... If the command-line option |
I've tried a number of |
578c23d fixes the "Feeding entropy" hang by using some bits from the host clock for the lower 4 bits of the counter. The upper bits are taken from the instruction counter. Now the MIPS CP0 count register should be more deterministic but still give some entropy to seed things. Using the |
With
Hitting enter causing it to continue with:
But it really is basically forever (one hung there overnight). |
I wonder if using
which seems like the worst clock to use. It seem it should at least use Of course, Linux doesn't have the In testing using |
Please give abef7fd a try. This implements the change described above. It may seem like it hangs on Please note that the |
b79c3d9 may help with this problem. According to the CheriBSD header file sys/mips/include/clock.h the MIPS Count register is incremented every two cycles. However, Qemu (hw/mips/cputimer.c) is assuming it is incremented every cycle. Therefore, this change adjusts the emulation code to more accurately emulate the hardware (which effectively increments the counter half as fast). One note about Qemu and CheriBSD from reviewing the code: Both assume the system clock is 100 Mhz (10ns period). There is an option to scale this to the actual clock in CheriBSD (TICK_USE_MALTA_RTC) but it looks like it requires some additional hardware. |
I added a simple emulated realtime clock to Qemu-CHERI (12b39ea) and a RTC driver for it to CheriBSD. I am hoping this will help with this problem. |
I'm still seeing errors. I've got a simple(ish) repro case:
This is run on a
I've seen previous cases where it that and the seconds were the same. It does appear these little slips are happening pretty often. The qemu binary is at 12b39ea. I did make an effort to reduce the test case further to a series of shell commands and never could get it to trigger. I somewhat wonder if it needs to be just slow enough to open the window and not too slow so as to mask small clock slips. |
I assume that you also added the RTC driver to CheriBSD ( 37c9a9b27b1756a7ee45 ). I am puzzled on what is causing this to go backwards a second. The timer in Qemu is implemented using a callback timer sort of based on the host clock. It attempts to make it a virtual clock but that is only the case for if the emulation is suspended or something of the like. Qemu emulation can block on a halt/wait instruction but the timer expiration should still fire an IRQ (at least I believe it does). We could try not using the virtual clock for the MIPS count/compare register emulation to see if that changes anything. Another thing we could possibly try is hacking CheriBSD to make sure the time value it returns to userland is always monotonically increasing (from the last read). If it doesn't then checking and adjusting to the realtime clock. The RTC emulation that I added to Qemu-CHERI is feed simply from the host clock. |
There driver is indeed installed and attached:
|
We've had a problem for quite a while where wall clock time goes backwards in qemu. It seems to be impossible to trigger reliably, but we're hacking around it in kyua. Unfortunately, it's causing problems with some tests. For example
/usr/tests/usr.bin/limits/limits_test cputime_hard_flag
often fails in Jenkins due to outlandish time values:I've also seen
xinstall
tests fail due to a time warp during test setup causing fails to be created out of order according to their on-disk timestamps.The text was updated successfully, but these errors were encountered: