timer: rename NSEC_PER_SEC due to Mac OS X header clash
Commit e0cf11f31c
("timer: Use a single
definition of NSEC_PER_SEC for the whole codebase") renamed
NANOSECONDS_PER_SECOND to NSEC_PER_SEC.
On Mac OS X there is a <dispatch/time.h> system header which also
defines NSEC_PER_SEC. This causes compiler warnings.
Let's use the old name instead. It's longer but it doesn't clash.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1436364609-7929-1-git-send-email-stefanha@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
dcc8a3ab63
commit
13566fe3e5
@ -873,8 +873,9 @@ static int timebase_post_load(void *opaque, int version_id)
|
|||||||
*/
|
*/
|
||||||
host_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST);
|
host_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST);
|
||||||
ns_diff = MAX(0, host_ns - tb_remote->time_of_the_day_ns);
|
ns_diff = MAX(0, host_ns - tb_remote->time_of_the_day_ns);
|
||||||
migration_duration_ns = MIN(NSEC_PER_SEC, ns_diff);
|
migration_duration_ns = MIN(NANOSECONDS_PER_SECOND, ns_diff);
|
||||||
migration_duration_tb = muldiv64(migration_duration_ns, freq, NSEC_PER_SEC);
|
migration_duration_tb = muldiv64(migration_duration_ns, freq,
|
||||||
|
NANOSECONDS_PER_SECOND);
|
||||||
guest_tb = tb_remote->guest_timebase + MIN(0, migration_duration_tb);
|
guest_tb = tb_remote->guest_timebase + MIN(0, migration_duration_tb);
|
||||||
|
|
||||||
tb_off_adj = guest_tb - cpu_get_real_ticks();
|
tb_off_adj = guest_tb - cpu_get_real_ticks();
|
||||||
|
@ -51,7 +51,7 @@ void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns)
|
|||||||
assert(rtc);
|
assert(rtc);
|
||||||
|
|
||||||
guest_ns = host_ns + rtc->ns_offset;
|
guest_ns = host_ns + rtc->ns_offset;
|
||||||
guest_s = guest_ns / NSEC_PER_SEC;
|
guest_s = guest_ns / NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
if (tm) {
|
if (tm) {
|
||||||
gmtime_r(&guest_s, tm);
|
gmtime_r(&guest_s, tm);
|
||||||
@ -71,7 +71,7 @@ int spapr_rtc_import_offset(DeviceState *dev, int64_t legacy_offset)
|
|||||||
|
|
||||||
rtc = SPAPR_RTC(dev);
|
rtc = SPAPR_RTC(dev);
|
||||||
|
|
||||||
rtc->ns_offset = legacy_offset * NSEC_PER_SEC;
|
rtc->ns_offset = legacy_offset * NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
|
|
||||||
host_ns = qemu_clock_get_ns(rtc_clock);
|
host_ns = qemu_clock_get_ns(rtc_clock);
|
||||||
|
|
||||||
rtc->ns_offset = (new_s * NSEC_PER_SEC) - host_ns;
|
rtc->ns_offset = (new_s * NANOSECONDS_PER_SECOND) - host_ns;
|
||||||
|
|
||||||
rtas_st(rets, 0, RTAS_OUT_SUCCESS);
|
rtas_st(rets, 0, RTAS_OUT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ static void spapr_rtc_realize(DeviceState *dev, Error **errp)
|
|||||||
qemu_get_timedate(&tm, 0);
|
qemu_get_timedate(&tm, 0);
|
||||||
host_s = mktimegm(&tm);
|
host_s = mktimegm(&tm);
|
||||||
rtc_ns = qemu_clock_get_ns(rtc_clock);
|
rtc_ns = qemu_clock_get_ns(rtc_clock);
|
||||||
rtc->ns_offset = host_s * NSEC_PER_SEC - rtc_ns;
|
rtc->ns_offset = host_s * NANOSECONDS_PER_SECOND - rtc_ns;
|
||||||
|
|
||||||
object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date, NULL);
|
object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date, NULL);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
#define RTC_REINJECT_ON_ACK_COUNT 20
|
#define RTC_REINJECT_ON_ACK_COUNT 20
|
||||||
#define RTC_CLOCK_RATE 32768
|
#define RTC_CLOCK_RATE 32768
|
||||||
#define UIP_HOLD_LENGTH (8 * NSEC_PER_SEC / 32768)
|
#define UIP_HOLD_LENGTH (8 * NANOSECONDS_PER_SECOND / 32768)
|
||||||
|
|
||||||
#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
|
#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ static uint64_t get_guest_rtc_ns(RTCState *s)
|
|||||||
uint64_t guest_rtc;
|
uint64_t guest_rtc;
|
||||||
uint64_t guest_clock = qemu_clock_get_ns(rtc_clock);
|
uint64_t guest_clock = qemu_clock_get_ns(rtc_clock);
|
||||||
|
|
||||||
guest_rtc = s->base_rtc * NSEC_PER_SEC
|
guest_rtc = s->base_rtc * NANOSECONDS_PER_SECOND
|
||||||
+ guest_clock - s->last_update + s->offset;
|
+ guest_clock - s->last_update + s->offset;
|
||||||
return guest_rtc;
|
return guest_rtc;
|
||||||
}
|
}
|
||||||
@ -231,16 +231,17 @@ static void check_update_timer(RTCState *s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
guest_nsec = get_guest_rtc_ns(s) % NSEC_PER_SEC;
|
guest_nsec = get_guest_rtc_ns(s) % NANOSECONDS_PER_SECOND;
|
||||||
/* if UF is clear, reprogram to next second */
|
/* if UF is clear, reprogram to next second */
|
||||||
next_update_time = qemu_clock_get_ns(rtc_clock)
|
next_update_time = qemu_clock_get_ns(rtc_clock)
|
||||||
+ NSEC_PER_SEC - guest_nsec;
|
+ NANOSECONDS_PER_SECOND - guest_nsec;
|
||||||
|
|
||||||
/* Compute time of next alarm. One second is already accounted
|
/* Compute time of next alarm. One second is already accounted
|
||||||
* for in next_update_time.
|
* for in next_update_time.
|
||||||
*/
|
*/
|
||||||
next_alarm_sec = get_next_alarm(s);
|
next_alarm_sec = get_next_alarm(s);
|
||||||
s->next_alarm_time = next_update_time + (next_alarm_sec - 1) * NSEC_PER_SEC;
|
s->next_alarm_time = next_update_time +
|
||||||
|
(next_alarm_sec - 1) * NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
if (s->cmos_data[RTC_REG_C] & REG_C_UF) {
|
if (s->cmos_data[RTC_REG_C] & REG_C_UF) {
|
||||||
/* UF is set, but AF is clear. Program the timer to target
|
/* UF is set, but AF is clear. Program the timer to target
|
||||||
@ -456,7 +457,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,
|
|||||||
/* if disabling set mode, update the time */
|
/* if disabling set mode, update the time */
|
||||||
if ((s->cmos_data[RTC_REG_B] & REG_B_SET) &&
|
if ((s->cmos_data[RTC_REG_B] & REG_B_SET) &&
|
||||||
(s->cmos_data[RTC_REG_A] & 0x70) <= 0x20) {
|
(s->cmos_data[RTC_REG_A] & 0x70) <= 0x20) {
|
||||||
s->offset = get_guest_rtc_ns(s) % NSEC_PER_SEC;
|
s->offset = get_guest_rtc_ns(s) % NANOSECONDS_PER_SECOND;
|
||||||
rtc_set_time(s);
|
rtc_set_time(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -580,7 +581,7 @@ static void rtc_update_time(RTCState *s)
|
|||||||
int64_t guest_nsec;
|
int64_t guest_nsec;
|
||||||
|
|
||||||
guest_nsec = get_guest_rtc_ns(s);
|
guest_nsec = get_guest_rtc_ns(s);
|
||||||
guest_sec = guest_nsec / NSEC_PER_SEC;
|
guest_sec = guest_nsec / NANOSECONDS_PER_SECOND;
|
||||||
gmtime_r(&guest_sec, &ret);
|
gmtime_r(&guest_sec, &ret);
|
||||||
|
|
||||||
/* Is SET flag of Register B disabled? */
|
/* Is SET flag of Register B disabled? */
|
||||||
@ -608,7 +609,8 @@ static int update_in_progress(RTCState *s)
|
|||||||
|
|
||||||
guest_nsec = get_guest_rtc_ns(s);
|
guest_nsec = get_guest_rtc_ns(s);
|
||||||
/* UIP bit will be set at last 244us of every second. */
|
/* UIP bit will be set at last 244us of every second. */
|
||||||
if ((guest_nsec % NSEC_PER_SEC) >= (NSEC_PER_SEC - UIP_HOLD_LENGTH)) {
|
if ((guest_nsec % NANOSECONDS_PER_SECOND) >=
|
||||||
|
(NANOSECONDS_PER_SECOND - UIP_HOLD_LENGTH)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
|
||||||
#define FRAME_TIMER_FREQ 1000
|
#define FRAME_TIMER_FREQ 1000
|
||||||
#define FRAME_TIMER_NS (NSEC_PER_SEC / FRAME_TIMER_FREQ)
|
#define FRAME_TIMER_NS (NANOSECONDS_PER_SECOND / FRAME_TIMER_FREQ)
|
||||||
#define UFRAME_TIMER_NS (FRAME_TIMER_NS / 8)
|
#define UFRAME_TIMER_NS (FRAME_TIMER_NS / 8)
|
||||||
|
|
||||||
#define NB_MAXINTRATE 8 // Max rate at which controller issues ints
|
#define NB_MAXINTRATE 8 // Max rate at which controller issues ints
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "qemu/notify.h"
|
#include "qemu/notify.h"
|
||||||
|
|
||||||
#define NSEC_PER_SEC 1000000000LL
|
#define NANOSECONDS_PER_SECOND 1000000000LL
|
||||||
|
|
||||||
/* timers */
|
/* timers */
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ static void test_timer(void)
|
|||||||
fatal("time too big %u\n", curr);
|
fatal("time too big %u\n", curr);
|
||||||
}
|
}
|
||||||
for (cnt = 0; ; ) {
|
for (cnt = 0; ; ) {
|
||||||
clock_step(1 * NSEC_PER_SEC);
|
clock_step(1 * NANOSECONDS_PER_SECOND);
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = in_Timer();
|
curr = in_Timer();
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ static void test_timer(void)
|
|||||||
out_IntrStatus(0x4000);
|
out_IntrStatus(0x4000);
|
||||||
curr = in_Timer();
|
curr = in_Timer();
|
||||||
out_TimerInt(curr + 0.5 * CLK);
|
out_TimerInt(curr + 0.5 * CLK);
|
||||||
clock_step(1 * NSEC_PER_SEC);
|
clock_step(1 * NANOSECONDS_PER_SECOND);
|
||||||
out_Timer(0);
|
out_Timer(0);
|
||||||
if ((in_IntrStatus() & 0x4000) == 0) {
|
if ((in_IntrStatus() & 0x4000) == 0) {
|
||||||
fatal("we should have an interrupt here!\n");
|
fatal("we should have an interrupt here!\n");
|
||||||
@ -137,7 +137,7 @@ static void test_timer(void)
|
|||||||
out_IntrStatus(0x4000);
|
out_IntrStatus(0x4000);
|
||||||
curr = in_Timer();
|
curr = in_Timer();
|
||||||
out_TimerInt(curr + 0.5 * CLK);
|
out_TimerInt(curr + 0.5 * CLK);
|
||||||
clock_step(1 * NSEC_PER_SEC);
|
clock_step(1 * NANOSECONDS_PER_SECOND);
|
||||||
out_TimerInt(0);
|
out_TimerInt(0);
|
||||||
if ((in_IntrStatus() & 0x4000) == 0) {
|
if ((in_IntrStatus() & 0x4000) == 0) {
|
||||||
fatal("we should have an interrupt here!\n");
|
fatal("we should have an interrupt here!\n");
|
||||||
@ -148,7 +148,7 @@ static void test_timer(void)
|
|||||||
next = curr + 5.0 * CLK;
|
next = curr + 5.0 * CLK;
|
||||||
out_TimerInt(next);
|
out_TimerInt(next);
|
||||||
for (cnt = 0; ; ) {
|
for (cnt = 0; ; ) {
|
||||||
clock_step(1 * NSEC_PER_SEC);
|
clock_step(1 * NANOSECONDS_PER_SECOND);
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = in_Timer();
|
curr = in_Timer();
|
||||||
diff = (curr-prev) & 0xffffffffu;
|
diff = (curr-prev) & 0xffffffffu;
|
||||||
|
@ -40,19 +40,19 @@ static void test_leak_bucket(void)
|
|||||||
bkt.level = 1.5;
|
bkt.level = 1.5;
|
||||||
|
|
||||||
/* leak an op work of time */
|
/* leak an op work of time */
|
||||||
throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
|
throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
|
||||||
g_assert(bkt.avg == 150);
|
g_assert(bkt.avg == 150);
|
||||||
g_assert(bkt.max == 15);
|
g_assert(bkt.max == 15);
|
||||||
g_assert(double_cmp(bkt.level, 0.5));
|
g_assert(double_cmp(bkt.level, 0.5));
|
||||||
|
|
||||||
/* leak again emptying the bucket */
|
/* leak again emptying the bucket */
|
||||||
throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
|
throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
|
||||||
g_assert(bkt.avg == 150);
|
g_assert(bkt.avg == 150);
|
||||||
g_assert(bkt.max == 15);
|
g_assert(bkt.max == 15);
|
||||||
g_assert(double_cmp(bkt.level, 0));
|
g_assert(double_cmp(bkt.level, 0));
|
||||||
|
|
||||||
/* check that the bucket level won't go lower */
|
/* check that the bucket level won't go lower */
|
||||||
throttle_leak_bucket(&bkt, NSEC_PER_SEC / 150);
|
throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 150);
|
||||||
g_assert(bkt.avg == 150);
|
g_assert(bkt.avg == 150);
|
||||||
g_assert(bkt.max == 15);
|
g_assert(bkt.max == 15);
|
||||||
g_assert(double_cmp(bkt.level, 0));
|
g_assert(double_cmp(bkt.level, 0));
|
||||||
@ -90,7 +90,7 @@ static void test_compute_wait(void)
|
|||||||
bkt.level = 15.5;
|
bkt.level = 15.5;
|
||||||
wait = throttle_compute_wait(&bkt);
|
wait = throttle_compute_wait(&bkt);
|
||||||
/* time required to do half an operation */
|
/* time required to do half an operation */
|
||||||
result = (int64_t) NSEC_PER_SEC / 150 / 2;
|
result = (int64_t) NANOSECONDS_PER_SECOND / 150 / 2;
|
||||||
g_assert(wait == result);
|
g_assert(wait == result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,29 +40,29 @@ static QDict *qmp_get_event(const char *name)
|
|||||||
|
|
||||||
static QDict *ib700_program_and_wait(QTestState *s)
|
static QDict *ib700_program_and_wait(QTestState *s)
|
||||||
{
|
{
|
||||||
clock_step(NSEC_PER_SEC * 40);
|
clock_step(NANOSECONDS_PER_SECOND * 40);
|
||||||
qmp_check_no_event();
|
qmp_check_no_event();
|
||||||
|
|
||||||
/* 2 second limit */
|
/* 2 second limit */
|
||||||
outb(0x443, 14);
|
outb(0x443, 14);
|
||||||
|
|
||||||
/* Ping */
|
/* Ping */
|
||||||
clock_step(NSEC_PER_SEC);
|
clock_step(NANOSECONDS_PER_SECOND);
|
||||||
qmp_check_no_event();
|
qmp_check_no_event();
|
||||||
outb(0x443, 14);
|
outb(0x443, 14);
|
||||||
|
|
||||||
/* Disable */
|
/* Disable */
|
||||||
clock_step(NSEC_PER_SEC);
|
clock_step(NANOSECONDS_PER_SECOND);
|
||||||
qmp_check_no_event();
|
qmp_check_no_event();
|
||||||
outb(0x441, 1);
|
outb(0x441, 1);
|
||||||
clock_step(3 * NSEC_PER_SEC);
|
clock_step(3 * NANOSECONDS_PER_SECOND);
|
||||||
qmp_check_no_event();
|
qmp_check_no_event();
|
||||||
|
|
||||||
/* Enable and let it fire */
|
/* Enable and let it fire */
|
||||||
outb(0x443, 13);
|
outb(0x443, 13);
|
||||||
clock_step(3 * NSEC_PER_SEC);
|
clock_step(3 * NANOSECONDS_PER_SECOND);
|
||||||
qmp_check_no_event();
|
qmp_check_no_event();
|
||||||
clock_step(2 * NSEC_PER_SEC);
|
clock_step(2 * NANOSECONDS_PER_SECOND);
|
||||||
return qmp_get_event("WATCHDOG");
|
return qmp_get_event("WATCHDOG");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ void throttle_leak_bucket(LeakyBucket *bkt, int64_t delta_ns)
|
|||||||
double leak;
|
double leak;
|
||||||
|
|
||||||
/* compute how much to leak */
|
/* compute how much to leak */
|
||||||
leak = (bkt->avg * (double) delta_ns) / NSEC_PER_SEC;
|
leak = (bkt->avg * (double) delta_ns) / NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
/* make the bucket leak */
|
/* make the bucket leak */
|
||||||
bkt->level = MAX(bkt->level - leak, 0);
|
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)
|
static int64_t throttle_do_compute_wait(double limit, double extra)
|
||||||
{
|
{
|
||||||
double wait = extra * NSEC_PER_SEC;
|
double wait = extra * NANOSECONDS_PER_SECOND;
|
||||||
wait /= limit;
|
wait /= limit;
|
||||||
return wait;
|
return wait;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user