+
+ /* how many cycles did this instr use? */
+ cycles_to_wait = vm->cycle - cycle_start;
+
+ if (cycles_to_wait == 0)
+ continue;
+
+ /* each cycle wants 10 microseconds */
+
+
+ /* how much of that did we spend already */
+ gettimeofday(&now_tv, NULL);
+ timeval_subtract(&diff_tv, &now_tv, &start_tv);
+ /* do we have time to kill? */
+ if (cycles_to_wait * MICROSECONDS_PER_CYCLE > diff_tv.tv_usec) {
+ sleep_time.tv_sec = diff_tv.tv_sec;
+ sleep_time.tv_nsec = 1000 * ( (cycles_to_wait * MICROSECONDS_PER_CYCLE) - diff_tv.tv_usec);
+ sleep_time.tv_nsec = diff_tv.tv_usec * 1000;
+
+ nanosleep(&sleep_time, NULL);
+ }