mirror of
https://github.com/mii443/qemu.git
synced 2025-09-02 07:09:47 +00:00
qemu-timer: move commonly used timer code to qemu-timer-common
Move timer init functions to a new file, qemu-timer-common.c. Make other critical timer functions inlined to preserve performance in qemu-timer.c, also move muldiv64() (used by the inline functions) to qemu-timer.h. Adjust block/raw-posix.c and simpletrace.c to use get_clock() directly. Remove a similar/duplicate definition in qemu-tool.c. Adjust hw/omap_clk.c to include qemu-timer.h because muldiv64() is used there. After this change, tracing can be used also for user code and simpletrace on Win32. Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Acked-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
73
qemu-timer.c
73
qemu-timer.c
@ -64,78 +64,6 @@ int64_t qemu_icount_bias;
|
||||
static QEMUTimer *icount_rt_timer;
|
||||
static QEMUTimer *icount_vm_timer;
|
||||
|
||||
|
||||
/***********************************************************/
|
||||
/* real time host monotonic timer */
|
||||
|
||||
|
||||
static int64_t get_clock_realtime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
static int64_t clock_freq;
|
||||
|
||||
static void init_get_clock(void)
|
||||
{
|
||||
LARGE_INTEGER freq;
|
||||
int ret;
|
||||
ret = QueryPerformanceFrequency(&freq);
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "Could not calibrate ticks\n");
|
||||
exit(1);
|
||||
}
|
||||
clock_freq = freq.QuadPart;
|
||||
}
|
||||
|
||||
static int64_t get_clock(void)
|
||||
{
|
||||
LARGE_INTEGER ti;
|
||||
QueryPerformanceCounter(&ti);
|
||||
return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int use_rt_clock;
|
||||
|
||||
static void init_get_clock(void)
|
||||
{
|
||||
use_rt_clock = 0;
|
||||
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
|
||||
|| defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
|
||||
use_rt_clock = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int64_t get_clock(void)
|
||||
{
|
||||
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
|
||||
|| defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
if (use_rt_clock) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* XXX: using gettimeofday leads to problems if the date
|
||||
changes, so it should be avoided. */
|
||||
return get_clock_realtime();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
/* guest cycle counter */
|
||||
|
||||
@ -614,7 +542,6 @@ int64_t qemu_get_clock_ns(QEMUClock *clock)
|
||||
|
||||
void init_clocks(void)
|
||||
{
|
||||
init_get_clock();
|
||||
rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
|
||||
vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
|
||||
host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
|
||||
|
Reference in New Issue
Block a user