提交 683dca6b 编写于 作者: L Laurent Vivier

mips: remove muldiv64()

Originally, timers were ticks based, and it made sense to
add ticks to current time to know when to trigger an alarm.

But since commit:

74475455 change all other clock references to use nanosecond resolution accessors

All timers use nanoseconds and we need to convert ticks to nanoseconds, by
doing something like:

    y = muldiv64(x, get_ticks_per_sec(), TIMER_FREQ)

where x is the number of device ticks and y the number of system ticks.

y is used as nanoseconds in timer functions,
it works because 1 tick is 1 nanosecond.
(get_ticks_per_sec() is 10^9)

But as MIPS timer frequency is 100 MHz, we can also do:

    y = x * 10; /* 100 MHz period is 10 ns */
Signed-off-by: NLaurent Vivier <lvivier@redhat.com>
Reviewed-by: NLeon Alrae <leon.alrae@imgtec.com>
上级 c6acbe86
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "qemu/timer.h" #include "qemu/timer.h"
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
#define TIMER_FREQ 100 * 1000 * 1000 #define TIMER_PERIOD 10 /* 10 ns period for 100 Mhz frequency */
/* XXX: do not use a global */ /* XXX: do not use a global */
uint32_t cpu_mips_get_random (CPUMIPSState *env) uint32_t cpu_mips_get_random (CPUMIPSState *env)
...@@ -57,9 +57,8 @@ static void cpu_mips_timer_update(CPUMIPSState *env) ...@@ -57,9 +57,8 @@ static void cpu_mips_timer_update(CPUMIPSState *env)
uint32_t wait; uint32_t wait;
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
wait = env->CP0_Compare - env->CP0_Count - wait = env->CP0_Compare - env->CP0_Count - (uint32_t)(now / TIMER_PERIOD);
(uint32_t)muldiv64(now, TIMER_FREQ, get_ticks_per_sec()); next = now + (uint64_t)wait * TIMER_PERIOD;
next = now + muldiv64(wait, get_ticks_per_sec(), TIMER_FREQ);
timer_mod(env->timer, next); timer_mod(env->timer, next);
} }
...@@ -87,8 +86,7 @@ uint32_t cpu_mips_get_count (CPUMIPSState *env) ...@@ -87,8 +86,7 @@ uint32_t cpu_mips_get_count (CPUMIPSState *env)
cpu_mips_timer_expire(env); cpu_mips_timer_expire(env);
} }
return env->CP0_Count + return env->CP0_Count + (uint32_t)(now / TIMER_PERIOD);
(uint32_t)muldiv64(now, TIMER_FREQ, get_ticks_per_sec());
} }
} }
...@@ -103,9 +101,8 @@ void cpu_mips_store_count (CPUMIPSState *env, uint32_t count) ...@@ -103,9 +101,8 @@ void cpu_mips_store_count (CPUMIPSState *env, uint32_t count)
env->CP0_Count = count; env->CP0_Count = count;
else { else {
/* Store new count register */ /* Store new count register */
env->CP0_Count = env->CP0_Count = count -
count - (uint32_t)muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / TIMER_PERIOD);
TIMER_FREQ, get_ticks_per_sec());
/* Update timer timer */ /* Update timer timer */
cpu_mips_timer_update(env); cpu_mips_timer_update(env);
} }
...@@ -129,8 +126,8 @@ void cpu_mips_start_count(CPUMIPSState *env) ...@@ -129,8 +126,8 @@ void cpu_mips_start_count(CPUMIPSState *env)
void cpu_mips_stop_count(CPUMIPSState *env) void cpu_mips_stop_count(CPUMIPSState *env)
{ {
/* Store the current value */ /* Store the current value */
env->CP0_Count += (uint32_t)muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), env->CP0_Count += (uint32_t)(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) /
TIMER_FREQ, get_ticks_per_sec()); TIMER_PERIOD);
} }
static void mips_timer_cb (void *opaque) static void mips_timer_cb (void *opaque)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册