disentangle tcg and deadline calculation

Just tell main_loop_wait whether to be blocking or nonblocking, so that
there is no need to call qemu_cpus_have_work from the timer subsystem.
Instead, tcg_cpu_exec can say "we want the main loop not to block because
we have stuff to do".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Paolo Bonzini 2010-03-10 11:38:54 +01:00 committed by Anthony Liguori
parent 16b151c393
commit d6f4ade214
3 changed files with 20 additions and 11 deletions

View File

@ -983,12 +983,14 @@ void xen_init_display(int domid)
wait_more: wait_more:
i++; i++;
main_loop_wait(10); /* miliseconds */ main_loop_wait(true);
xfb = xen_be_find_xendev("vfb", domid, 0); xfb = xen_be_find_xendev("vfb", domid, 0);
xin = xen_be_find_xendev("vkbd", domid, 0); xin = xen_be_find_xendev("vkbd", domid, 0);
if (!xfb || !xin) { if (!xfb || !xin) {
if (i < 256) if (i < 256) {
usleep(10000);
goto wait_more; goto wait_more;
}
xen_be_printf(NULL, 1, "displaystate setup failed\n"); xen_be_printf(NULL, 1, "displaystate setup failed\n");
return; return;
} }

View File

@ -64,7 +64,7 @@ void cpu_synchronize_all_post_init(void);
void qemu_announce_self(void); void qemu_announce_self(void);
void main_loop_wait(int timeout); void main_loop_wait(int nonblocking);
int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable, int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
int shared); int shared);

23
vl.c
View File

@ -618,6 +618,7 @@ struct qemu_alarm_timer {
}; };
static struct qemu_alarm_timer *alarm_timer; static struct qemu_alarm_timer *alarm_timer;
static int qemu_calculate_timeout(void);
static inline int qemu_alarm_pending(void) static inline int qemu_alarm_pending(void)
{ {
@ -3596,7 +3597,7 @@ static void *kvm_cpu_thread_fn(void *arg)
return NULL; return NULL;
} }
static void tcg_cpu_exec(void); static bool tcg_cpu_exec(void);
static void *tcg_cpu_thread_fn(void *arg) static void *tcg_cpu_thread_fn(void *arg)
{ {
@ -3914,14 +3915,20 @@ static void host_main_loop_wait(int *timeout)
} }
#endif #endif
void main_loop_wait(int timeout) void main_loop_wait(int nonblocking)
{ {
IOHandlerRecord *ioh; IOHandlerRecord *ioh;
fd_set rfds, wfds, xfds; fd_set rfds, wfds, xfds;
int ret, nfds; int ret, nfds;
struct timeval tv; struct timeval tv;
int timeout;
qemu_bh_update_timeout(&timeout); if (nonblocking)
timeout = 0;
else {
timeout = qemu_calculate_timeout();
qemu_bh_update_timeout(&timeout);
}
host_main_loop_wait(&timeout); host_main_loop_wait(&timeout);
@ -4028,7 +4035,7 @@ static int qemu_cpu_exec(CPUState *env)
return ret; return ret;
} }
static void tcg_cpu_exec(void) static bool tcg_cpu_exec(void)
{ {
int ret = 0; int ret = 0;
@ -4053,6 +4060,7 @@ static void tcg_cpu_exec(void)
break; break;
} }
} }
return tcg_has_work();
} }
static int qemu_calculate_timeout(void) static int qemu_calculate_timeout(void)
@ -4062,8 +4070,6 @@ static int qemu_calculate_timeout(void)
if (!vm_running) if (!vm_running)
timeout = 5000; timeout = 5000;
else if (tcg_has_work())
timeout = 0;
else { else {
/* XXX: use timeout computed from timers */ /* XXX: use timeout computed from timers */
int64_t add; int64_t add;
@ -4123,16 +4129,17 @@ static void main_loop(void)
for (;;) { for (;;) {
do { do {
bool nonblocking = false;
#ifdef CONFIG_PROFILER #ifdef CONFIG_PROFILER
int64_t ti; int64_t ti;
#endif #endif
#ifndef CONFIG_IOTHREAD #ifndef CONFIG_IOTHREAD
tcg_cpu_exec(); nonblocking = tcg_cpu_exec();
#endif #endif
#ifdef CONFIG_PROFILER #ifdef CONFIG_PROFILER
ti = profile_getclock(); ti = profile_getclock();
#endif #endif
main_loop_wait(qemu_calculate_timeout()); main_loop_wait(nonblocking);
#ifdef CONFIG_PROFILER #ifdef CONFIG_PROFILER
dev_time += profile_getclock() - ti; dev_time += profile_getclock() - ti;
#endif #endif