Skip to content

Commit dcda949

Browse files
committed
qemu-timer.c: Use upstream version.
This completely modifies the implementation of timers to match upstream, the only difference is that the oddly-placed qemu_gpoll_ns() function is disabled (it's not used yet). Most of the changes here (but not all), were applied through the following sed script: s|qemu_get_clock\s*(\s*vm_clock\s*)|qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)|g s|qemu_get_clock\s*(\s*rt_clock\s*)|qemu_clock_get_ms(QEMU_CLOCK_REALTIME)|g s|qemu_get_clock_ns\s*(\s*vm_clock\s*)|qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)|g s|qemu_get_clock_ns\s*(\s*rt_clock\s*)|qemu_clock_get_ns(QEMU_CLOCK_REALTIME)|g s|qemu_get_clock_ms\s*(\s*vm_clock\s*)|qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)|g s|qemu_get_clock_ms\s*(\s*rt_clock\s*)|qemu_clock_get_ms(QEMU_CLOCK_REALTIME)|g s|qemu_get_clock_ms\s*(\s*host_clock\s*)|qemu_clock_get_ms(QEMU_CLOCK_HOST)|g s|qemu_get_clock_ms\s*(\s*SHAPER_CLOCK\s*)|qemu_clock_get_ms(SHAPER_CLOCK)|g s|qemu_mod_timer\s*(|timer_mod(|g s|qemu_del_timer\s*(|timer_del(|g s|qemu_free_timer\s*(|timer_free(|g s|qemu_new_timer_ms\s*(\s*rt_clock,|timer_new(QEMU_CLOCK_REALTIME, SCALE_MS,|g s|qemu_new_timer_ns\s*(\s*rt_clock,|timer_new(QEMU_CLOCK_REALTIME, SCALE_NS,|g s|qemu_new_timer_ms\s*(\s*vm_clock,|timer_new(QEMU_CLOCK_VIRTUAL, SCALE_MS,|g s|qemu_new_timer_ns\s*(\s*vm_clock,|timer_new(QEMU_CLOCK_VIRTUAL, SCALE_NS,|g s|qemu_new_timer_ms\s*(\s*host_clock,|timer_new(QEMU_CLOCK_HOST, SCALE_MS,|g s|qemu_new_timer_ns\s*(\s*host_clock,|timer_new(QEMU_CLOCK_HOST, SCALE_NS,|g s|qemu_new_timer_ms\s*(\s*SHAPER_CLOCK\s*,|timer_new(SHAPER_CLOCK, SCALE_MS,|g s|qemu_put_timer\s*(|timer_put(|g s|qemu_get_timer\s*(|timer_get(|g s|qemu_timer_pending\s*(|timer_pending(|g s|qemu_clock_next_deadline\s*(\s*vm_clock|qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL|g s|qemu_clock_next_deadline\s*(\s*rt_clock|qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME|g s|qemu_clock_next_deadline\s*(\s*host_clock|qemu_clock_deadline_ns_all(QEMU_CLOCK_HOST|g + Disable icount-based clock warping/adjustments. It will be re-enabled in the future after cpu emulation has been completely refactored. Change-Id: Ifbcf4a52654eed3a08dfe59b0546a75d4627f758
1 parent f018355 commit dcda949

38 files changed

+1407
-568
lines changed

android/hw-sensors.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ _hwSensorClient_free( HwSensorClient* cl )
211211
}
212212
/* remove timer, if any */
213213
if (cl->timer) {
214-
qemu_del_timer(cl->timer);
215-
qemu_free_timer(cl->timer);
214+
timer_del(cl->timer);
215+
timer_free(cl->timer);
216216
cl->timer = NULL;
217217
}
218218
AFREE(cl);
@@ -232,7 +232,7 @@ _hwSensorClient_new( HwSensors* sensors )
232232
cl->sensors = sensors;
233233
cl->enabledMask = 0;
234234
cl->delay_ms = 800;
235-
cl->timer = qemu_new_timer_ns(vm_clock, _hwSensorClient_tick, cl);
235+
cl->timer = timer_new(QEMU_CLOCK_VIRTUAL, SCALE_NS, _hwSensorClient_tick, cl);
236236

237237
cl->next = sensors->clients;
238238
sensors->clients = cl;
@@ -337,7 +337,7 @@ _hwSensorClient_tick( void* opaque )
337337
_hwSensorClient_send(cl, (uint8_t*) buffer, strlen(buffer));
338338
}
339339

340-
now_ns = qemu_get_clock_ns(vm_clock);
340+
now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
341341

342342
snprintf(buffer, sizeof buffer, "sync:%" PRId64, now_ns/1000);
343343
_hwSensorClient_send(cl, (uint8_t*)buffer, strlen(buffer));
@@ -352,7 +352,7 @@ _hwSensorClient_tick( void* opaque )
352352
delay = 20;
353353

354354
delay *= 1000000LL; /* convert to nanoseconds */
355-
qemu_mod_timer(cl->timer, now_ns + delay);
355+
timer_mod(cl->timer, now_ns + delay);
356356
}
357357

358358
/* handle incoming messages from the HAL module */
@@ -461,7 +461,7 @@ _hwSensorClient_save( QEMUFile* f, QemudClient* client, void* opaque )
461461

462462
qemu_put_be32(f, sc->delay_ms);
463463
qemu_put_be32(f, sc->enabledMask);
464-
qemu_put_timer(f, sc->timer);
464+
timer_put(f, sc->timer);
465465
}
466466

467467
/* Loads sensor-specific client data from snapshot */
@@ -472,7 +472,7 @@ _hwSensorClient_load( QEMUFile* f, QemudClient* client, void* opaque )
472472

473473
sc->delay_ms = qemu_get_be32(f);
474474
sc->enabledMask = qemu_get_be32(f);
475-
qemu_get_timer(f, sc->timer);
475+
timer_get(f, sc->timer);
476476

477477
return 0;
478478
}

android/looper-qemu.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,40 @@ qlooptimer_startRelative(void* impl, Duration timeout_ms)
3434
{
3535
QEMUTimer* tt = impl;
3636
if (timeout_ms == DURATION_INFINITE)
37-
qemu_del_timer(tt);
37+
timer_del(tt);
3838
else
39-
qemu_mod_timer(tt, qemu_get_clock_ms(host_clock) + timeout_ms);
39+
timer_mod(tt, qemu_clock_get_ms(QEMU_CLOCK_HOST) + timeout_ms);
4040
}
4141

4242
static void
4343
qlooptimer_startAbsolute(void* impl, Duration deadline_ms)
4444
{
4545
QEMUTimer* tt = impl;
4646
if (deadline_ms == DURATION_INFINITE)
47-
qemu_del_timer(tt);
47+
timer_del(tt);
4848
else
49-
qemu_mod_timer(tt, deadline_ms);
49+
timer_mod(tt, deadline_ms);
5050
}
5151

5252
static void
5353
qlooptimer_stop(void* impl)
5454
{
5555
QEMUTimer* tt = impl;
56-
qemu_del_timer(tt);
56+
timer_del(tt);
5757
}
5858

5959
static int
6060
qlooptimer_isActive(void* impl)
6161
{
6262
QEMUTimer* tt = impl;
63-
return qemu_timer_pending(tt);
63+
return timer_pending(tt);
6464
}
6565

6666
static void
6767
qlooptimer_free(void* impl)
6868
{
6969
QEMUTimer* tt = impl;
70-
qemu_free_timer(tt);
70+
timer_free(tt);
7171
}
7272

7373
static const LoopTimerClass qlooptimer_class = {
@@ -85,7 +85,7 @@ qlooper_timer_init(Looper* looper,
8585
void* opaque)
8686
{
8787
timer->clazz = (LoopTimerClass*) &qlooptimer_class;
88-
timer->impl = qemu_new_timer_ms(host_clock, callback, opaque);
88+
timer->impl = timer_new(QEMU_CLOCK_HOST, SCALE_MS, callback, opaque);
8989
}
9090

9191
/**********************************************************************
@@ -370,7 +370,7 @@ qlooper_handle_io_bh(void* opaque)
370370
static Duration
371371
qlooper_now(Looper* ll)
372372
{
373-
return qemu_get_clock_ms(host_clock);
373+
return qemu_clock_get_ms(QEMU_CLOCK_HOST);
374374
}
375375

376376
extern void qemu_system_shutdown_request(void);

android/shaper.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "qemu/timer.h"
1515
#include <stdlib.h>
1616

17-
#define SHAPER_CLOCK rt_clock
17+
#define SHAPER_CLOCK QEMU_CLOCK_REALTIME
1818
#define SHAPER_CLOCK_UNIT 1000.
1919

2020
static int
@@ -123,8 +123,8 @@ netshaper_destroy( NetShaper shaper )
123123
queued_packet_free(packet);
124124
}
125125

126-
qemu_del_timer(shaper->timer);
127-
qemu_free_timer(shaper->timer);
126+
timer_del(shaper->timer);
127+
timer_free(shaper->timer);
128128
shaper->timer = NULL;
129129
g_free(shaper);
130130
}
@@ -137,7 +137,7 @@ netshaper_expires( NetShaper shaper )
137137
QueuedPacket packet;
138138

139139
while ((packet = shaper->packets) != NULL) {
140-
int64_t now = qemu_get_clock_ms( SHAPER_CLOCK );
140+
int64_t now = qemu_clock_get_ms( SHAPER_CLOCK );
141141

142142
if (packet->expiration > now)
143143
break;
@@ -151,7 +151,7 @@ netshaper_expires( NetShaper shaper )
151151
/* reprogram timer if needed */
152152
if (shaper->packets) {
153153
shaper->block_until = shaper->packets->expiration;
154-
qemu_mod_timer( shaper->timer, shaper->block_until );
154+
timer_mod( shaper->timer, shaper->block_until );
155155
} else {
156156
shaper->block_until = -1;
157157
}
@@ -167,9 +167,9 @@ netshaper_create( int do_copy,
167167
shaper->active = 0;
168168
shaper->packets = NULL;
169169
shaper->num_packets = 0;
170-
shaper->timer = qemu_new_timer_ms( SHAPER_CLOCK,
171-
(QEMUTimerCB*) netshaper_expires,
172-
shaper );
170+
shaper->timer = timer_new( SHAPER_CLOCK, SCALE_MS,
171+
(QEMUTimerCB*) netshaper_expires,
172+
shaper );
173173
shaper->send_func = send_func;
174174
shaper->max_rate = 1e6;
175175
shaper->inv_rate = 0.;
@@ -216,7 +216,7 @@ netshaper_send_aux( NetShaper shaper,
216216
return;
217217
}
218218

219-
now = qemu_get_clock_ms( SHAPER_CLOCK );
219+
now = qemu_clock_get_ms( SHAPER_CLOCK );
220220
if (now >= shaper->block_until) {
221221
shaper->send_func( data, size, opaque );
222222
shaper->block_until = now + size*shaper->inv_rate;
@@ -246,7 +246,7 @@ netshaper_send_aux( NetShaper shaper,
246246
*pnode = packet;
247247

248248
if (packet == shaper->packets)
249-
qemu_mod_timer( shaper->timer, packet->expiration );
249+
timer_mod( shaper->timer, packet->expiration );
250250
}
251251
shaper->num_packets += 1;
252252
}
@@ -274,7 +274,7 @@ netshaper_can_send( NetShaper shaper )
274274
if (shaper->packets)
275275
return 0;
276276

277-
now = qemu_get_clock_ms( SHAPER_CLOCK );
277+
now = qemu_clock_get_ms( SHAPER_CLOCK );
278278
return (now >= shaper->block_until);
279279
}
280280

@@ -424,7 +424,7 @@ static void
424424
netdelay_expires( NetDelay delay )
425425
{
426426
Session session;
427-
int64_t now = qemu_get_clock_ms( SHAPER_CLOCK );
427+
int64_t now = qemu_clock_get_ms(SHAPER_CLOCK);
428428
int rearm = 0;
429429
int64_t rearm_time = 0;
430430

@@ -452,7 +452,7 @@ netdelay_expires( NetDelay delay )
452452
}
453453

454454
if (rearm)
455-
qemu_mod_timer( delay->timer, rearm_time );
455+
timer_mod( delay->timer, rearm_time );
456456
}
457457

458458

@@ -463,9 +463,9 @@ netdelay_create( NetShaperSendFunc send_func )
463463

464464
delay->sessions = NULL;
465465
delay->num_sessions = 0;
466-
delay->timer = qemu_new_timer_ms( SHAPER_CLOCK,
467-
(QEMUTimerCB*) netdelay_expires,
468-
delay );
466+
delay->timer = timer_new( SHAPER_CLOCK, SCALE_MS,
467+
(QEMUTimerCB*) netdelay_expires,
468+
delay );
469469
delay->active = 0;
470470
delay->min_ms = 0;
471471
delay->max_ms = 0;
@@ -553,7 +553,7 @@ netdelay_send_aux( NetDelay delay, const void* data, size_t size, void* opaqu
553553
delay->sessions = session;
554554
delay->num_sessions += 1;
555555

556-
session->expiration = qemu_get_clock_ms( SHAPER_CLOCK ) + latency;
556+
session->expiration = qemu_clock_get_ms(SHAPER_CLOCK) + latency;
557557

558558
session->src_ip = info->src_ip;
559559
session->dst_ip = info->dst_ip;

arch_init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
298298
}
299299

300300
bytes_transferred_last = bytes_transferred;
301-
bwidth = qemu_get_clock_ns(rt_clock);
301+
bwidth = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
302302

303303
while (!qemu_file_rate_limit(f)) {
304304
int bytes_sent;
@@ -310,7 +310,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
310310
}
311311
}
312312

313-
bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
313+
bwidth = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - bwidth;
314314
bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
315315

316316
/* if we haven't transferred anything this round, force expected_time to a

audio/audio.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ static void audio_timer (void *opaque)
11981198
AudioState *s = opaque;
11991199
#if 0
12001200
#define MAX_DIFFS 100
1201-
int64_t now = qemu_get_clock_ms(vm_clock);
1201+
int64_t now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL);
12021202
static int64_t last = 0;
12031203
static float diffs[MAX_DIFFS];
12041204
static int num_diffs;
@@ -1227,7 +1227,7 @@ static void audio_timer (void *opaque)
12271227
#endif
12281228

12291229
audio_run ("timer");
1230-
qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) + conf.period.ticks);
1230+
timer_mod(s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);
12311231
}
12321232

12331233

@@ -1250,10 +1250,10 @@ static void audio_reset_timer (void)
12501250
AudioState *s = &glob_audio_state;
12511251

12521252
if (audio_is_timer_needed ()) {
1253-
qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) + 1);
1253+
timer_mod(s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
12541254
}
12551255
else {
1256-
qemu_del_timer (s->ts);
1256+
timer_del(s->ts);
12571257
}
12581258
}
12591259

@@ -1964,7 +1964,7 @@ static void audio_init (void)
19641964
QLIST_INIT (&s->cap_head);
19651965
atexit (audio_atexit);
19661966

1967-
s->ts = qemu_new_timer_ns (vm_clock, audio_timer, s);
1967+
s->ts = timer_new(QEMU_CLOCK_VIRTUAL, SCALE_NS, audio_timer, s);
19681968
if (!s->ts) {
19691969
dolog ("Could not create audio timer\n");
19701970
return;

audio/noaudio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int no_run_out (HWVoiceOut *hw, int live)
4646
int64_t ticks;
4747
int64_t bytes;
4848

49-
now = qemu_get_clock (vm_clock);
49+
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
5050
ticks = now - no->old_ticks;
5151
bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
5252
bytes = audio_MIN (bytes, INT_MAX);
@@ -102,7 +102,7 @@ static int no_run_in (HWVoiceIn *hw)
102102
int samples = 0;
103103

104104
if (dead) {
105-
int64_t now = qemu_get_clock (vm_clock);
105+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
106106
int64_t ticks = now - no->old_ticks;
107107
int64_t bytes =
108108
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());

audio/wavaudio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int wav_out_run (HWVoiceOut *hw, int live)
6060
int rpos, decr, samples;
6161
uint8_t *dst;
6262
struct st_sample *src;
63-
int64_t now = qemu_get_clock (vm_clock);
63+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
6464
int64_t ticks = now - wav->old_ticks;
6565
int64_t bytes =
6666
muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
@@ -355,7 +355,7 @@ static int wav_in_run (HWVoiceIn *hw)
355355
uint8_t* src;
356356
struct st_sample* dst;
357357

358-
int64_t now = qemu_get_clock (vm_clock);
358+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
359359
int64_t ticks = now - wav->old_ticks;
360360
int64_t bytes = muldiv64(ticks, hw->info.bytes_per_second, get_ticks_per_sec());
361361

audio/winaudio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ winaudio_out_run (HWVoiceOut *hw, int live)
292292
s->write_pos += wav_bytes;
293293
if (s->write_pos == s->write_size) {
294294
#if xxDEBUG
295-
int64_t now = qemu_get_clock(vm_clock) - start_time;
295+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - start_time;
296296
int64_t diff = now - last_time;
297297

298298
D("run_out: (%7.3f:%7d):waveOutWrite buffer:%d\n",
@@ -617,7 +617,7 @@ winaudio_init(void)
617617
WinAudioState* s = &g_winaudio;
618618

619619
#if DEBUG
620-
start_time = qemu_get_clock(vm_clock);
620+
start_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
621621
last_time = 0;
622622
#endif
623623

block/raw-posix.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static int fd_open(BlockDriverState *bs)
889889
return 0;
890890
last_media_present = (s->fd >= 0);
891891
if (s->fd >= 0 &&
892-
(qemu_get_clock(rt_clock) - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
892+
(qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
893893
close(s->fd);
894894
s->fd = -1;
895895
#ifdef DEBUG_FLOPPY
@@ -898,15 +898,15 @@ static int fd_open(BlockDriverState *bs)
898898
}
899899
if (s->fd < 0) {
900900
if (s->fd_got_error &&
901-
(qemu_get_clock(rt_clock) - s->fd_error_time) < FD_OPEN_TIMEOUT) {
901+
(qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->fd_error_time) < FD_OPEN_TIMEOUT) {
902902
#ifdef DEBUG_FLOPPY
903903
printf("No floppy (open delayed)\n");
904904
#endif
905905
return -EIO;
906906
}
907907
s->fd = open(bs->filename, s->open_flags & ~O_NONBLOCK);
908908
if (s->fd < 0) {
909-
s->fd_error_time = qemu_get_clock(rt_clock);
909+
s->fd_error_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
910910
s->fd_got_error = 1;
911911
if (last_media_present)
912912
s->fd_media_changed = 1;
@@ -921,7 +921,7 @@ static int fd_open(BlockDriverState *bs)
921921
}
922922
if (!last_media_present)
923923
s->fd_media_changed = 1;
924-
s->fd_open_time = qemu_get_clock(rt_clock);
924+
s->fd_open_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
925925
s->fd_got_error = 0;
926926
return 0;
927927
}

0 commit comments

Comments
 (0)