Skip to content

Commit

Permalink
Use clock_gettime(CLOCK_VIRTUAL,...) for QEMU_CLOCK_VIRTUAL.
Browse files Browse the repository at this point in the history
This change uses clock_gettime(CLOCK_VIRTUAL,...) if it is available
for QEMU_CLOCK_VIRTUAL timers. It also backs out the 578c23d change
which cause problems booting CheriBSD.
  • Loading branch information
staceyson committed May 12, 2017
1 parent 578c23d commit abef7fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static int64_t cpu_get_clock_locked(void)

ticks = timers_state.cpu_clock_offset;
if (timers_state.cpu_ticks_enabled) {
ticks += get_clock();
ticks += get_virtual_clock();
}

return ticks;
Expand Down
18 changes: 18 additions & 0 deletions include/qemu/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,11 @@ static inline int64_t get_clock(void)
return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
}

static inline int64_t get_virtual_clock(void)
{
return get_clock();
}

#else

extern int use_rt_clock;
Expand All @@ -844,6 +849,19 @@ static inline int64_t get_clock(void)
return get_clock_realtime();
}
}

static inline int64_t get_virtual_clock(void)
{
#ifdef CLOCK_VIRTUAL
struct timespec ts;

clock_gettime(CLOCK_VIRTUAL, &ts);
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
#else
return get_clock();
#endif
}

#endif

/* icount */
Expand Down
2 changes: 1 addition & 1 deletion qemu-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
default:
case QEMU_CLOCK_VIRTUAL:
if (use_icount) {
return (cpu_get_icount() << 4) | (cpu_get_clock() & 0xful);
return cpu_get_icount();
} else {
return cpu_get_clock();
}
Expand Down

0 comments on commit abef7fd

Please sign in to comment.