aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiu Ping Fan <qemulist@gmail.com>2013-08-25 10:01:21 +0800
committerJan Kiszka <jan.kiszka@siemens.com>2013-09-17 12:26:05 +0200
commita42e9c41888bc6a5446ef6bd95745c9fd023f107 (patch)
tree0a996aea98aaf4de80aa0a7622b57e772969e559
parent9b0ca6cc64d3542be35f1ca6174de2ab6af30ed0 (diff)
slirp: set mainloop timeout with more precise value
If slirp needs to emulate tcp timeout, then the timeout value for mainloop should be more precise, which is determined by slirp's fasttimo or slowtimo. Achieve this by swap the logic sequence of slirp_pollfds_fill and slirp_update_timeout. Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
-rw-r--r--main-loop.c3
-rw-r--r--slirp/libslirp.h3
-rw-r--r--slirp/slirp.c28
-rw-r--r--stubs/slirp.c6
4 files changed, 27 insertions, 13 deletions
diff --git a/main-loop.c b/main-loop.c
index 1c38ea2b93..c3c9c28fba 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -466,8 +466,7 @@ int main_loop_wait(int nonblocking)
g_array_set_size(gpollfds, 0); /* reset for new iteration */
/* XXX: separate device handlers from system ones */
#ifdef CONFIG_SLIRP
- slirp_update_timeout(&timeout);
- slirp_pollfds_fill(gpollfds);
+ slirp_pollfds_fill(gpollfds, &timeout);
#endif
qemu_iohandler_fill(gpollfds);
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index ceabff81b2..5bdcbd50f7 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -16,8 +16,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
void *opaque);
void slirp_cleanup(Slirp *slirp);
-void slirp_update_timeout(uint32_t *timeout);
-void slirp_pollfds_fill(GArray *pollfds);
+void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
void slirp_pollfds_poll(GArray *pollfds, int select_error);
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 23e60a0923..fe16367db8 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -262,14 +262,33 @@ void slirp_cleanup(Slirp *slirp)
#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
#define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
-void slirp_update_timeout(uint32_t *timeout)
+static void slirp_update_timeout(uint32_t *timeout)
{
- if (!QTAILQ_EMPTY(&slirp_instances)) {
- *timeout = MIN(TIMEOUT_DEFAULT, *timeout);
+ Slirp *slirp;
+ uint32_t t;
+
+ if (*timeout <= TIMEOUT_FAST) {
+ return;
+ }
+ *timeout = MIN(1000, *timeout);
+ t = *timeout;
+
+ /* If we have tcp timeout with slirp, then we will fill @timeout with
+ * more precise value.
+ */
+ QTAILQ_FOREACH(slirp, &slirp_instances, entry) {
+ if (slirp->time_fasttimo) {
+ *timeout = TIMEOUT_FAST;
+ return;
+ }
+ if (slirp->do_slowtimo) {
+ t = MIN(TIMEOUT_SLOW, t);
+ }
}
+ *timeout = t;
}
-void slirp_pollfds_fill(GArray *pollfds)
+void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
{
Slirp *slirp;
struct socket *so, *so_next;
@@ -439,6 +458,7 @@ void slirp_pollfds_fill(GArray *pollfds)
}
}
}
+ slirp_update_timeout(timeout);
}
void slirp_pollfds_poll(GArray *pollfds, int select_error)
diff --git a/stubs/slirp.c b/stubs/slirp.c
index f1fc833f7a..bd0ac7f27d 100644
--- a/stubs/slirp.c
+++ b/stubs/slirp.c
@@ -1,11 +1,7 @@
#include "qemu-common.h"
#include "slirp/slirp.h"
-void slirp_update_timeout(uint32_t *timeout)
-{
-}
-
-void slirp_pollfds_fill(GArray *pollfds)
+void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout)
{
}