summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2015-06-12 16:01:30 +0300
committerStefan Hajnoczi <stefanha@redhat.com>2015-07-02 09:20:18 +0100
commite0cf11f31c24cfb17f44ed46c254d84c78e7f6e9 (patch)
tree5e54e4b2b5d92e382428730e38f8b21a636ea7ff
parent471fae3c98d4f44b1957eb09d51ace440c585a20 (diff)
downloadhqemu-e0cf11f31c24cfb17f44ed46c254d84c78e7f6e9.zip
hqemu-e0cf11f31c24cfb17f44ed46c254d84c78e7f6e9.tar.gz
timer: Use a single definition of NSEC_PER_SEC for the whole codebase
Signed-off-by: Alberto Garcia <berto@igalia.com> Message-id: c6e55468856ba0b8f95913c4da111cc0ef266541.1434113783.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--hw/ppc/ppc.c2
-rw-r--r--hw/ppc/spapr_rtc.c3
-rw-r--r--hw/timer/mc146818rtc.c1
-rw-r--r--hw/usb/hcd-ehci.c2
-rw-r--r--include/qemu/timer.h2
-rw-r--r--tests/rtl8139-test.c10
-rw-r--r--tests/test-throttle.c8
-rw-r--r--tests/wdt_ib700-test.c15
-rw-r--r--util/throttle.c4
9 files changed, 21 insertions, 26 deletions
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 99db56c..2a4b8e1 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -51,8 +51,6 @@
# define LOG_TB(...) do { } while (0)
#endif
-#define NSEC_PER_SEC 1000000000LL
-
static void cpu_ppc_tb_stop (CPUPPCState *env);
static void cpu_ppc_tb_start (CPUPPCState *env);
diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c
index 83eb7c1..9da3746 100644
--- a/hw/ppc/spapr_rtc.c
+++ b/hw/ppc/spapr_rtc.c
@@ -26,6 +26,7 @@
*
*/
#include "cpu.h"
+#include "qemu/timer.h"
#include "sysemu/sysemu.h"
#include "hw/ppc/spapr.h"
#include "qapi-event.h"
@@ -40,8 +41,6 @@ struct sPAPRRTCState {
int64_t ns_offset;
};
-#define NSEC_PER_SEC 1000000000LL
-
void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns)
{
sPAPRRTCState *rtc = SPAPR_RTC(dev);
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 2e3ffc8..954c34d 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -48,7 +48,6 @@
# define DPRINTF_C(format, ...) do { } while (0)
#endif
-#define NSEC_PER_SEC 1000000000LL
#define SEC_PER_MIN 60
#define MIN_PER_HOUR 60
#define SEC_PER_HOUR 3600
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index d4d7547..d7cd40b 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -32,7 +32,7 @@
#include "trace.h"
#define FRAME_TIMER_FREQ 1000
-#define FRAME_TIMER_NS (1000000000 / FRAME_TIMER_FREQ)
+#define FRAME_TIMER_NS (NSEC_PER_SEC / FRAME_TIMER_FREQ)
#define UFRAME_TIMER_NS (FRAME_TIMER_NS / 8)
#define NB_MAXINTRATE 8 // Max rate at which controller issues ints
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 5923d60..4dda20b 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -5,7 +5,7 @@
#include "qemu-common.h"
#include "qemu/notify.h"
-#define NANOSECONDS_PER_SECOND 1000000000LL
+#define NSEC_PER_SEC 1000000000LL
/* timers */
diff --git a/tests/rtl8139-test.c b/tests/rtl8139-test.c
index 4e0bf02..3bff0e3 100644
--- a/tests/rtl8139-test.c
+++ b/tests/rtl8139-test.c
@@ -12,6 +12,7 @@
#include "libqtest.h"
#include "libqos/pci-pc.h"
#include "qemu/osdep.h"
+#include "qemu/timer.h"
#include "qemu-common.h"
/* Tests only initialization so far. TODO: Replace with functional tests */
@@ -20,7 +21,6 @@ static void nop(void)
}
#define CLK 33000000
-#define NS_PER_SEC 1000000000ULL
static QPCIBus *pcibus;
static QPCIDevice *dev;
@@ -86,7 +86,7 @@ static void test_timer(void)
fatal("time too big %u\n", curr);
}
for (cnt = 0; ; ) {
- clock_step(1 * NS_PER_SEC);
+ clock_step(1 * NSEC_PER_SEC);
prev = curr;
curr = in_Timer();
@@ -125,7 +125,7 @@ static void test_timer(void)
out_IntrStatus(0x4000);
curr = in_Timer();
out_TimerInt(curr + 0.5 * CLK);
- clock_step(1 * NS_PER_SEC);
+ clock_step(1 * NSEC_PER_SEC);
out_Timer(0);
if ((in_IntrStatus() & 0x4000) == 0) {
fatal("we should have an interrupt here!\n");
@@ -137,7 +137,7 @@ static void test_timer(void)
out_IntrStatus(0x4000);
curr = in_Timer();
out_TimerInt(curr + 0.5 * CLK);
- clock_step(1 * NS_PER_SEC);
+ clock_step(1 * NSEC_PER_SEC);
out_TimerInt(0);
if ((in_IntrStatus() & 0x4000) == 0) {
fatal("we should have an interrupt here!\n");
@@ -148,7 +148,7 @@ static void test_timer(void)
next = curr + 5.0 * CLK;
out_TimerInt(next);
for (cnt = 0; ; ) {
- clock_step(1 * NS_PER_SEC);
+ clock_step(1 * NSEC_PER_SEC);
prev = curr;
curr = in_Timer();
diff = (curr-prev) & 0xffffffffu;
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index 0168445..33b6b95 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -40,19 +40,19 @@ static void test_leak_bucket(void)
bkt.level = 1.5;
/* leak an op work of time */
- throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
+ throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
g_assert(bkt.avg == 150);
g_assert(bkt.max == 15);
g_assert(double_cmp(bkt.level, 0.5));
/* leak again emptying the bucket */
- throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
+ throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
g_assert(bkt.avg == 150);
g_assert(bkt.max == 15);
g_assert(double_cmp(bkt.level, 0));
/* check that the bucket level won't go lower */
- throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
+ throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
g_assert(bkt.avg == 150);
g_assert(bkt.max == 15);
g_assert(double_cmp(bkt.level, 0));
@@ -90,7 +90,7 @@ static void test_compute_wait(void)
bkt.level = 15.5;
wait = throttle_compute_wait(&bkt);
/* time required to do half an operation */
- result = (int64_t) NANOSECONDS_PER_SECOND / 150 / 2;
+ result = (int64_t) NSEC_PER_SEC / 150 / 2;
g_assert(wait == result);
}
diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c
index 513a533..10a5472 100644
--- a/tests/wdt_ib700-test.c
+++ b/tests/wdt_ib700-test.c
@@ -11,8 +11,7 @@
#include <string.h>
#include "libqtest.h"
#include "qemu/osdep.h"
-
-#define NS_PER_SEC 1000000000ULL
+#include "qemu/timer.h"
static void qmp_check_no_event(void)
{
@@ -41,29 +40,29 @@ static QDict *qmp_get_event(const char *name)
static QDict *ib700_program_and_wait(QTestState *s)
{
- clock_step(NS_PER_SEC * 40);
+ clock_step(NSEC_PER_SEC * 40);
qmp_check_no_event();
/* 2 second limit */
outb(0x443, 14);
/* Ping */
- clock_step(NS_PER_SEC);
+ clock_step(NSEC_PER_SEC);
qmp_check_no_event();
outb(0x443, 14);
/* Disable */
- clock_step(NS_PER_SEC);
+ clock_step(NSEC_PER_SEC);
qmp_check_no_event();
outb(0x441, 1);
- clock_step(3 * NS_PER_SEC);
+ clock_step(3 * NSEC_PER_SEC);
qmp_check_no_event();
/* Enable and let it fire */
outb(0x443, 13);
- clock_step(3 * NS_PER_SEC);
+ clock_step(3 * NSEC_PER_SEC);
qmp_check_no_event();
- clock_step(2 * NS_PER_SEC);
+ clock_step(2 * NSEC_PER_SEC);
return qmp_get_event("WATCHDOG");
}
diff --git a/util/throttle.c b/util/throttle.c
index 706c131..ec70476 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -36,7 +36,7 @@ void throttle_leak_bucket(LeakyBucket *bkt, int64_t delta_ns)
double leak;
/* compute how much to leak */
- leak = (bkt->avg * (double) delta_ns) / NANOSECONDS_PER_SECOND;
+ leak = (bkt->avg * (double) delta_ns) / NSEC_PER_SEC;
/* make the bucket leak */
bkt->level = MAX(bkt->level - leak, 0);
@@ -72,7 +72,7 @@ static void throttle_do_leak(ThrottleState *ts, int64_t now)
*/
static int64_t throttle_do_compute_wait(double limit, double extra)
{
- double wait = extra * NANOSECONDS_PER_SECOND;
+ double wait = extra * NSEC_PER_SEC;
wait /= limit;
return wait;
}
OpenPOWER on IntegriCloud