Jon and I have encountered a strange issue when using VirtualBox with 64
bits Linux hosts: the monotonic counter is not monotonic, with both 32 and
64 bits Linux guest systems.

The attached program (compile with "gcc -O2 -o t t.c -lrt") gives an error
when executed onto the guest system with the following configurations:

   - Host: 64 bits Linux 2.6.29 x86_64 + VirtualBox 3.0.2, Guest: 32 bits
   Linux 2.6.32 i686
   - Host: 64 bits Linux 2.6.32 x86_64 + VirtualBox 3.1.4, Guest: 32 bits
   Linux 2.6.32 x86_64

The monotonic timer jumps backwards in time, causing a critical error in
Factor.

I've implemented the following stupid hack that can be pulled from "git://
git.rfc1149.net/factor.git for-slava":

--- a/vm/run.cpp
+++ b/vm/run.cpp
@@ -16,7 +16,8 @@ void factor_vm::primitive_system_micros()
 void factor_vm::primitive_nano_count()
 {
        u64 nanos = nano_count();
-       if(nanos < last_nano_count) critical_error("Monotonic counter
decreased",0);
+       if(nanos < last_nano_count)
+         nanos = last_nano_count + 1;
        last_nano_count = nanos;
        ctx->push(from_unsigned_8(nanos));
 }

This does not seem to cause any trouble for Factor itself as the correction
is a one-time shot every time the problem occurs, and lets us use Factor in
VirtualBox with a 64 bits host. This should not change anything for systems
functioning correctly (the test program does not exhibit the bogus behaviour
when executed directly onto the host system).

  Sam
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to