Skip to content

Commit

Permalink
Merge remote-tracking branch 'stefanha/block' into staging
Browse files Browse the repository at this point in the history
# By Alex Bligh (32) and others
# Via Stefan Hajnoczi
* stefanha/block: (42 commits)
  win32-aio: drop win32_aio_flush_cb()
  aio-win32: replace incorrect AioHandler->opaque usage with ->e
  aio / timers: remove dummy_io_handler_flush from tests/test-aio.c
  aio / timers: Remove legacy interface
  aio / timers: Switch entire codebase to the new timer API
  aio / timers: Add scripts/switch-timer-api
  aio / timers: Add test harness for AioContext timers
  aio / timers: convert block_job_sleep_ns and co_sleep_ns to new API
  aio / timers: Convert rtc_clock to be a QEMUClockType
  aio / timers: Remove main_loop_timerlist
  aio / timers: Rearrange timer.h & make legacy functions call non-legacy
  aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms
  aio / timers: Remove legacy qemu_clock_deadline & qemu_timerlist_deadline
  aio / timers: Remove alarm timers
  aio / timers: Add documentation and new format calls
  aio / timers: Use all timerlists in icount warp calculations
  aio / timers: Introduce new API timer_new and friends
  aio / timers: On timer modification, qemu_notify or aio_notify
  aio / timers: Convert mainloop to use timeout
  aio / timers: Convert aio_poll to use AioContext timers' deadline
  ...

Message-id: 1377202298-22896-1-git-send-email-stefanha@redhat.com
Signed-off-by: Anthony Liguori <anthony@codemonkey.ws>
  • Loading branch information
aliguori committed Aug 26, 2013
2 parents e3f024a + b10577d commit f7ad538
Show file tree
Hide file tree
Showing 177 changed files with 2,362 additions and 1,503 deletions.
18 changes: 12 additions & 6 deletions aio-posix.c
Expand Up @@ -165,6 +165,10 @@ static bool aio_dispatch(AioContext *ctx)
g_free(tmp);
}
}

/* Run our timers */
progress |= timerlistgroup_run_timers(&ctx->tlg);

return progress;
}

Expand Down Expand Up @@ -219,9 +223,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
}

/* wait until next event */
ret = g_poll((GPollFD *)ctx->pollfds->data,
ctx->pollfds->len,
blocking ? -1 : 0);
ret = qemu_poll_ns((GPollFD *)ctx->pollfds->data,
ctx->pollfds->len,
blocking ? timerlistgroup_deadline_ns(&ctx->tlg) : 0);

/* if we have any readable fds, dispatch event */
if (ret > 0) {
Expand All @@ -232,9 +236,11 @@ bool aio_poll(AioContext *ctx, bool blocking)
node->pfd.revents = pfd->revents;
}
}
if (aio_dispatch(ctx)) {
progress = true;
}
}

/* Run dispatch even if there were no readable fds to run timers */
if (aio_dispatch(ctx)) {
progress = true;
}

return progress;
Expand Down
24 changes: 20 additions & 4 deletions aio-win32.c
Expand Up @@ -95,6 +95,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
bool progress;
int count;
int timeout;

progress = false;

Expand All @@ -108,6 +109,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
progress = true;
}

/* Run timers */
progress |= timerlistgroup_run_timers(&ctx->tlg);

/*
* Then dispatch any pending callbacks from the GSource.
*
Expand All @@ -125,7 +129,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
node->io_notify(node->e);

/* aio_notify() does not count as progress */
if (node->opaque != &ctx->notifier) {
if (node->e != &ctx->notifier) {
progress = true;
}
}
Expand Down Expand Up @@ -164,8 +168,11 @@ bool aio_poll(AioContext *ctx, bool blocking)

/* wait until next event */
while (count > 0) {
int timeout = blocking ? INFINITE : 0;
int ret = WaitForMultipleObjects(count, events, FALSE, timeout);
int ret;

timeout = blocking ?
qemu_timeout_ns_to_ms(timerlistgroup_deadline_ns(&ctx->tlg)) : 0;
ret = WaitForMultipleObjects(count, events, FALSE, timeout);

/* if we have any signaled events, dispatch event */
if ((DWORD) (ret - WAIT_OBJECT_0) >= count) {
Expand All @@ -188,7 +195,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
node->io_notify(node->e);

/* aio_notify() does not count as progress */
if (node->opaque != &ctx->notifier) {
if (node->e != &ctx->notifier) {
progress = true;
}
}
Expand All @@ -208,5 +215,14 @@ bool aio_poll(AioContext *ctx, bool blocking)
events[ret - WAIT_OBJECT_0] = events[--count];
}

if (blocking) {
/* Run the timers a second time. We do this because otherwise aio_wait
* will not note progress - and will stop a drain early - if we have
* a timer that was not ready to run entering g_poll but is ready
* after g_poll. This will only do anything if a timer has expired.
*/
progress |= timerlistgroup_run_timers(&ctx->tlg);
}

return progress;
}
12 changes: 6 additions & 6 deletions arch_init.c
Expand Up @@ -392,7 +392,7 @@ static void migration_bitmap_sync(void)
}

if (!start_time) {
start_time = qemu_get_clock_ms(rt_clock);
start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
}

trace_migration_bitmap_sync_start();
Expand All @@ -410,7 +410,7 @@ static void migration_bitmap_sync(void)
trace_migration_bitmap_sync_end(migration_dirty_pages
- num_dirty_pages_init);
num_dirty_pages_period += migration_dirty_pages - num_dirty_pages_init;
end_time = qemu_get_clock_ms(rt_clock);
end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);

/* more than 1 second = 1000 millisecons */
if (end_time > start_time + 1000) {
Expand Down Expand Up @@ -672,7 +672,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)

ram_control_before_iterate(f, RAM_CONTROL_ROUND);

t0 = qemu_get_clock_ns(rt_clock);
t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
i = 0;
while ((ret = qemu_file_rate_limit(f)) == 0) {
int bytes_sent;
Expand All @@ -691,7 +691,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
iterations
*/
if ((i & 63) == 0) {
uint64_t t1 = (qemu_get_clock_ns(rt_clock) - t0) / 1000000;
uint64_t t1 = (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - t0) / 1000000;
if (t1 > MAX_WAIT) {
DPRINTF("big wait: %" PRIu64 " milliseconds, %d iterations\n",
t1, i);
Expand Down Expand Up @@ -1217,11 +1217,11 @@ static void check_guest_throttling(void)
}

if (!t0) {
t0 = qemu_get_clock_ns(rt_clock);
t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
return;
}

t1 = qemu_get_clock_ns(rt_clock);
t1 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);

/* If it has been more than 40 ms since the last time the guest
* was throttled then do it again.
Expand Down
20 changes: 19 additions & 1 deletion async.c
Expand Up @@ -150,7 +150,10 @@ aio_ctx_prepare(GSource *source, gint *timeout)
{
AioContext *ctx = (AioContext *) source;
QEMUBH *bh;
int deadline;

/* We assume there is no timeout already supplied */
*timeout = -1;
for (bh = ctx->first_bh; bh; bh = bh->next) {
if (!bh->deleted && bh->scheduled) {
if (bh->idle) {
Expand All @@ -166,6 +169,14 @@ aio_ctx_prepare(GSource *source, gint *timeout)
}
}

deadline = qemu_timeout_ns_to_ms(timerlistgroup_deadline_ns(&ctx->tlg));
if (deadline == 0) {
*timeout = 0;
return true;
} else {
*timeout = qemu_soonest_timeout(*timeout, deadline);
}

return false;
}

Expand All @@ -180,7 +191,7 @@ aio_ctx_check(GSource *source)
return true;
}
}
return aio_pending(ctx);
return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0);
}

static gboolean
Expand All @@ -205,6 +216,7 @@ aio_ctx_finalize(GSource *source)
event_notifier_cleanup(&ctx->notifier);
qemu_mutex_destroy(&ctx->bh_lock);
g_array_free(ctx->pollfds, TRUE);
timerlistgroup_deinit(&ctx->tlg);
}

static GSourceFuncs aio_source_funcs = {
Expand Down Expand Up @@ -233,6 +245,11 @@ void aio_notify(AioContext *ctx)
event_notifier_set(&ctx->notifier);
}

static void aio_timerlist_notify(void *opaque)
{
aio_notify(opaque);
}

AioContext *aio_context_new(void)
{
AioContext *ctx;
Expand All @@ -244,6 +261,7 @@ AioContext *aio_context_new(void)
aio_set_event_notifier(ctx, &ctx->notifier,
(EventNotifierHandler *)
event_notifier_test_and_clear);
timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);

return ctx;
}
Expand Down
6 changes: 3 additions & 3 deletions audio/audio.c
Expand Up @@ -1124,10 +1124,10 @@ static int audio_is_timer_needed (void)
static void audio_reset_timer (AudioState *s)
{
if (audio_is_timer_needed ()) {
qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) + 1);
timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
}
else {
qemu_del_timer (s->ts);
timer_del (s->ts);
}
}

Expand Down Expand Up @@ -1834,7 +1834,7 @@ static void audio_init (void)
QLIST_INIT (&s->cap_head);
atexit (audio_atexit);

s->ts = qemu_new_timer_ns (vm_clock, audio_timer, s);
s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
if (!s->ts) {
hw_error("Could not create audio timer\n");
}
Expand Down
4 changes: 2 additions & 2 deletions audio/noaudio.c
Expand Up @@ -46,7 +46,7 @@ static int no_run_out (HWVoiceOut *hw, int live)
int64_t ticks;
int64_t bytes;

now = qemu_get_clock_ns (vm_clock);
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - no->old_ticks;
bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
bytes = audio_MIN (bytes, INT_MAX);
Expand Down Expand Up @@ -102,7 +102,7 @@ static int no_run_in (HWVoiceIn *hw)
int samples = 0;

if (dead) {
int64_t now = qemu_get_clock_ns (vm_clock);
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
int64_t ticks = now - no->old_ticks;
int64_t bytes =
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
Expand Down
4 changes: 2 additions & 2 deletions audio/spiceaudio.c
Expand Up @@ -81,7 +81,7 @@ static void spice_audio_fini (void *opaque)
static void rate_start (SpiceRateCtl *rate)
{
memset (rate, 0, sizeof (*rate));
rate->start_ticks = qemu_get_clock_ns (vm_clock);
rate->start_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
}

static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
Expand All @@ -91,7 +91,7 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
int64_t bytes;
int64_t samples;

now = qemu_get_clock_ns (vm_clock);
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - rate->start_ticks;
bytes = muldiv64 (ticks, info->bytes_per_second, get_ticks_per_sec ());
samples = (bytes - rate->bytes_sent) >> info->shift;
Expand Down
2 changes: 1 addition & 1 deletion audio/wavaudio.c
Expand Up @@ -52,7 +52,7 @@ static int wav_run_out (HWVoiceOut *hw, int live)
int rpos, decr, samples;
uint8_t *dst;
struct st_sample *src;
int64_t now = qemu_get_clock_ns (vm_clock);
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
int64_t ticks = now - wav->old_ticks;
int64_t bytes =
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
Expand Down
16 changes: 8 additions & 8 deletions backends/baum.c
Expand Up @@ -314,9 +314,9 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
return 0; \
if (*cur++ != ESC) { \
DPRINTF("Broken packet %#2x, tossing\n", req); \
if (qemu_timer_pending(baum->cellCount_timer)) { \
qemu_del_timer(baum->cellCount_timer); \
baum_cellCount_timer_cb(baum); \
if (timer_pending(baum->cellCount_timer)) { \
timer_del(baum->cellCount_timer); \
baum_cellCount_timer_cb(baum); \
} \
return (cur - 2 - buf); \
} \
Expand All @@ -334,7 +334,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
int i;

/* Allow 100ms to complete the DisplayData packet */
qemu_mod_timer(baum->cellCount_timer, qemu_get_clock_ns(vm_clock) +
timer_mod(baum->cellCount_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
get_ticks_per_sec() / 10);
for (i = 0; i < baum->x * baum->y ; i++) {
EAT(c);
Expand All @@ -348,7 +348,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
c = '?';
text[i] = c;
}
qemu_del_timer(baum->cellCount_timer);
timer_del(baum->cellCount_timer);

memset(zero, 0, sizeof(zero));

Expand Down Expand Up @@ -553,7 +553,7 @@ static void baum_close(struct CharDriverState *chr)
{
BaumDriverState *baum = chr->opaque;

qemu_free_timer(baum->cellCount_timer);
timer_free(baum->cellCount_timer);
if (baum->brlapi) {
brlapi__closeConnection(baum->brlapi);
g_free(baum->brlapi);
Expand Down Expand Up @@ -588,7 +588,7 @@ CharDriverState *chr_baum_init(void)
goto fail_handle;
}

baum->cellCount_timer = qemu_new_timer_ns(vm_clock, baum_cellCount_timer_cb, baum);
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);

if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
brlapi_perror("baum_init: brlapi_getDisplaySize");
Expand All @@ -614,7 +614,7 @@ CharDriverState *chr_baum_init(void)
return chr;

fail:
qemu_free_timer(baum->cellCount_timer);
timer_free(baum->cellCount_timer);
brlapi__closeConnection(handle);
fail_handle:
g_free(handle);
Expand Down

0 comments on commit f7ad538

Please sign in to comment.