Remove muldiv64() by using period instead of frequency

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJWBVIdAAoJEPMMOL0/L748BXUP/2j+TRnsaU/gMHoL2IGP78BK
 LLLOL7yyV8ZrsrOFvyv8IW0DtpldoYsvObty/bNAr0iq+QwqwGWn9Gw4im5DtIkN
 s7e1WcxLgFHHcT1QLa70MUjjVtRrflTmcW9TVIW79PQ+HsCqnb7EmFZ96HxzH3zN
 YM93eBT6cJV3axsLwJsE82igCXsLo3raKGNb0jt8b6/XwMoR3iUb1Kgs2dJXZUJw
 TYPtHv7sJpQiLQY8Y8o4EjyyjdFuWPVeIfokgPahoOdVA1PSCx6Qh8o+FV1GZ+nF
 vmAr7Jolri6tdbMgRWtIgQQs2YSvPNIUEOYTXVu/4p287JGZPNU5790V2aIczERc
 gEPTqjI6w1AYy8/yMlO3WpfFxXWZH6ZsNBmxCmhH/mczA2dx3DzDlyI7SofQsCHW
 +81U6GSc/Ryy47C+b6m/YZNQDx3yG8rUFtY4PqCcjJwPZdSEhLEM7crC2XWJwy+0
 rg3SnVvXuE2vC/k7UHEYbnFOyVbvezUYJnigbppMilO8nfXIsyuvc7G4AT96jxbt
 4HQJT6ESGEsIToslWObJ53z3jzoAA17xp4gzkZjx7RwSofkFFIaT7jjaA/D2cxFn
 UOXZgAfde6mfg4Ak0czcBYYvm+peEjXBC+DfsBjfAcQ1dz6WSGyd3QZY0J7i9/7y
 iSNiuCE9J6Ha7XVVYzd2
 =krOI
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/vivier-misc/tags/pull-muldiv64-20150925' into staging

Remove muldiv64() by using period instead of frequency

# gpg: Signature made Fri 25 Sep 2015 14:54:37 BST using RSA key ID 3F2FBE3C
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>"
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>"
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/vivier-misc/tags/pull-muldiv64-20150925:
  net: remove muldiv64()
  bt: remove muldiv64()
  hpet: remove muldiv64()
  arm: clarify the use of muldiv64()
  openrisc: remove muldiv64()
  mips: remove muldiv64()
  pcnet: remove muldiv64()
  rtl8139: remove muldiv64()
  i6300esb: remove muldiv64()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-09-25 18:03:19 +01:00
commit 690b286fef
11 changed files with 38 additions and 48 deletions

View File

@ -595,7 +595,7 @@ static void bt_hci_inquiry_result(struct bt_hci_s *hci,
static void bt_hci_mod_timer_1280ms(QEMUTimer *timer, int period) static void bt_hci_mod_timer_1280ms(QEMUTimer *timer, int period)
{ {
timer_mod(timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timer_mod(timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
muldiv64(period << 7, get_ticks_per_sec(), 100)); (uint64_t)(period << 7) * 10000000);
} }
static void bt_hci_inquiry_start(struct bt_hci_s *hci, int length) static void bt_hci_inquiry_start(struct bt_hci_s *hci, int length)
@ -1099,7 +1099,7 @@ static int bt_hci_mode_change(struct bt_hci_s *hci, uint16_t handle,
bt_hci_event_status(hci, HCI_SUCCESS); bt_hci_event_status(hci, HCI_SUCCESS);
timer_mod(link->acl_mode_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timer_mod(link->acl_mode_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
muldiv64(interval * 625, get_ticks_per_sec(), 1000000)); ((uint64_t)interval * 625) * 1000);
bt_hci_lmp_mode_change_master(hci, link->link, mode, interval); bt_hci_lmp_mode_change_master(hci, link->link, mode, interval);
return 0; return 0;

View File

@ -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)
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)
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)
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)
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)

View File

@ -670,8 +670,7 @@ static inline hwaddr pcnet_rdra_addr(PCNetState *s, int idx)
static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_time) static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_time)
{ {
int64_t next_time = current_time + int64_t next_time = current_time +
muldiv64(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s)), (65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s))) * 30;
get_ticks_per_sec(), 33000000L);
if (next_time <= current_time) if (next_time <= current_time)
next_time = current_time + 1; next_time = current_time + 1;
return next_time; return next_time;

View File

@ -64,7 +64,7 @@
/* debug RTL8139 card */ /* debug RTL8139 card */
//#define DEBUG_RTL8139 1 //#define DEBUG_RTL8139 1
#define PCI_FREQUENCY 33000000L #define PCI_PERIOD 30 /* 30 ns period = 33.333333 Mhz frequency */
#define SET_MASKED(input, mask, curr) \ #define SET_MASKED(input, mask, curr) \
( ( (input) & ~(mask) ) | ( (curr) & (mask) ) ) ( ( (input) & ~(mask) ) | ( (curr) & (mask) ) )
@ -2834,8 +2834,7 @@ static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val)
static void rtl8139_set_next_tctr_time(RTL8139State *s) static void rtl8139_set_next_tctr_time(RTL8139State *s)
{ {
const uint64_t ns_per_period = const uint64_t ns_per_period = (uint64_t)PCI_PERIOD << 32;
muldiv64(0x100000000LL, get_ticks_per_sec(), PCI_FREQUENCY);
DPRINTF("entered rtl8139_set_next_tctr_time\n"); DPRINTF("entered rtl8139_set_next_tctr_time\n");
@ -2853,7 +2852,7 @@ static void rtl8139_set_next_tctr_time(RTL8139State *s)
if (!s->TimerInt) { if (!s->TimerInt) {
timer_del(s->timer); timer_del(s->timer);
} else { } else {
uint64_t delta = muldiv64(s->TimerInt, get_ticks_per_sec(), PCI_FREQUENCY); uint64_t delta = (uint64_t)s->TimerInt * PCI_PERIOD;
if (s->TCTR_base + delta <= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) { if (s->TCTR_base + delta <= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
delta += ns_per_period; delta += ns_per_period;
} }
@ -3127,8 +3126,8 @@ static uint32_t rtl8139_io_readl(void *opaque, uint8_t addr)
break; break;
case Timer: case Timer:
ret = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->TCTR_base, ret = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->TCTR_base) /
PCI_FREQUENCY, get_ticks_per_sec()); PCI_PERIOD;
DPRINTF("TCTR Timer read val=0x%08x\n", ret); DPRINTF("TCTR Timer read val=0x%08x\n", ret);
break; break;
@ -3222,8 +3221,7 @@ static void rtl8139_pre_save(void *opaque)
int64_t current_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int64_t current_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
/* for migration to older versions */ /* for migration to older versions */
s->TCTR = muldiv64(current_time - s->TCTR_base, PCI_FREQUENCY, s->TCTR = (current_time - s->TCTR_base) / PCI_PERIOD;
get_ticks_per_sec());
s->rtl8139_mmio_io_addr_dummy = 0; s->rtl8139_mmio_io_addr_dummy = 0;
} }

View File

@ -22,7 +22,7 @@
#include "hw/hw.h" #include "hw/hw.h"
#include "qemu/timer.h" #include "qemu/timer.h"
#define TIMER_FREQ (20 * 1000 * 1000) /* 20MHz */ #define TIMER_PERIOD 50 /* 50 ns period for 20 MHz timer */
/* The time when TTCR changes */ /* The time when TTCR changes */
static uint64_t last_clk; static uint64_t last_clk;
@ -36,8 +36,7 @@ void cpu_openrisc_count_update(OpenRISCCPU *cpu)
return; return;
} }
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
cpu->env.ttcr += (uint32_t)muldiv64(now - last_clk, TIMER_FREQ, cpu->env.ttcr += (uint32_t)((now - last_clk) / TIMER_PERIOD);
get_ticks_per_sec());
last_clk = now; last_clk = now;
} }
@ -59,7 +58,7 @@ void cpu_openrisc_timer_update(OpenRISCCPU *cpu)
} else { } else {
wait = (cpu->env.ttmr & TTMR_TP) - (cpu->env.ttcr & TTMR_TP); wait = (cpu->env.ttmr & TTMR_TP) - (cpu->env.ttcr & TTMR_TP);
} }
next = now + muldiv64(wait, get_ticks_per_sec(), TIMER_FREQ); next = now + (uint64_t)wait * TIMER_PERIOD;
timer_mod(cpu->env.timer, next); timer_mod(cpu->env.timer, next);
} }

View File

@ -126,12 +126,12 @@ static uint32_t hpet_time_after64(uint64_t a, uint64_t b)
static uint64_t ticks_to_ns(uint64_t value) static uint64_t ticks_to_ns(uint64_t value)
{ {
return (muldiv64(value, HPET_CLK_PERIOD, FS_PER_NS)); return value * HPET_CLK_PERIOD;
} }
static uint64_t ns_to_ticks(uint64_t value) static uint64_t ns_to_ticks(uint64_t value)
{ {
return (muldiv64(value, FS_PER_NS, HPET_CLK_PERIOD)); return value / HPET_CLK_PERIOD;
} }
static uint64_t hpet_fixup_reg(uint64_t new, uint64_t old, uint64_t mask) static uint64_t hpet_fixup_reg(uint64_t new, uint64_t old, uint64_t mask)
@ -758,7 +758,7 @@ static void hpet_realize(DeviceState *dev, Error **errp)
/* 64-bit main counter; LegacyReplacementRoute. */ /* 64-bit main counter; LegacyReplacementRoute. */
s->capability = 0x8086a001ULL; s->capability = 0x8086a001ULL;
s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT; s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT;
s->capability |= ((HPET_CLK_PERIOD) << 32); s->capability |= ((uint64_t)(HPET_CLK_PERIOD * FS_PER_NS) << 32);
qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2); qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2);
qdev_init_gpio_out(dev, &s->pit_enabled, 1); qdev_init_gpio_out(dev, &s->pit_enabled, 1);

View File

@ -129,14 +129,9 @@ static void i6300esb_restart_timer(I6300State *d, int stage)
else else
timeout <<= 5; timeout <<= 5;
/* Get the timeout in units of ticks_per_sec. /* Get the timeout in nanoseconds. */
*
* ticks_per_sec is typically 10^9 == 0x3B9ACA00 (30 bits), with timeout = timeout * 30; /* on a PCI bus, 1 tick is 30 ns*/
* 20 bits of user supplied preload, and 15 bits of scale, the
* multiply here can exceed 64-bits, before we divide by 33MHz, so
* we use a higher-precision intermediate result.
*/
timeout = muldiv64(timeout, get_ticks_per_sec(), 33000000);
i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout); i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout);

View File

@ -16,9 +16,9 @@
#include "qom/object.h" #include "qom/object.h"
#define HPET_BASE 0xfed00000 #define HPET_BASE 0xfed00000
#define HPET_CLK_PERIOD 10000000ULL /* 10000000 femtoseconds == 10ns*/ #define HPET_CLK_PERIOD 10 /* 10 ns*/
#define FS_PER_NS 1000000 #define FS_PER_NS 1000000 /* 1000000 femtoseconds == 1 ns */
#define HPET_MIN_TIMERS 3 #define HPET_MIN_TIMERS 3
#define HPET_MAX_TIMERS 32 #define HPET_MAX_TIMERS 32

View File

@ -69,7 +69,7 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size)
return size; return size;
} }
ts = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 1000000, get_ticks_per_sec()); ts = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL);
caplen = size > s->pcap_caplen ? s->pcap_caplen : size; caplen = size > s->pcap_caplen ? s->pcap_caplen : size;
hdr.ts.tv_sec = ts / 1000000 + s->start_ts; hdr.ts.tv_sec = ts / 1000000 + s->start_ts;

View File

@ -12,6 +12,8 @@
#include <zlib.h> /* For crc32 */ #include <zlib.h> /* For crc32 */
#include "exec/semihost.h" #include "exec/semihost.h"
#define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
static inline bool get_phys_addr(CPUARMState *env, target_ulong address, static inline bool get_phys_addr(CPUARMState *env, target_ulong address,
int access_type, ARMMMUIdx mmu_idx, int access_type, ARMMMUIdx mmu_idx,
@ -706,8 +708,8 @@ void pmccntr_sync(CPUARMState *env)
{ {
uint64_t temp_ticks; uint64_t temp_ticks;
temp_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), temp_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
get_ticks_per_sec(), 1000000); ARM_CPU_FREQ, NANOSECONDS_PER_SECOND);
if (env->cp15.c9_pmcr & PMCRD) { if (env->cp15.c9_pmcr & PMCRD) {
/* Increment once every 64 processor clock cycles */ /* Increment once every 64 processor clock cycles */
@ -745,8 +747,8 @@ static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri)
return env->cp15.c15_ccnt; return env->cp15.c15_ccnt;
} }
total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
get_ticks_per_sec(), 1000000); ARM_CPU_FREQ, NANOSECONDS_PER_SECOND);
if (env->cp15.c9_pmcr & PMCRD) { if (env->cp15.c9_pmcr & PMCRD) {
/* Increment once every 64 processor clock cycles */ /* Increment once every 64 processor clock cycles */
@ -766,8 +768,8 @@ static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri,
return; return;
} }
total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL), total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
get_ticks_per_sec(), 1000000); ARM_CPU_FREQ, NANOSECONDS_PER_SECOND);
if (env->cp15.c9_pmcr & PMCRD) { if (env->cp15.c9_pmcr & PMCRD) {
/* Increment once every 64 processor clock cycles */ /* Increment once every 64 processor clock cycles */

View File

@ -20,7 +20,7 @@ static void nop(void)
{ {
} }
#define CLK 33000000 #define CLK 33333333
static QPCIBus *pcibus; static QPCIBus *pcibus;
static QPCIDevice *dev; static QPCIDevice *dev;