aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2008-07-29 10:58:36 -0400
committerRusty Russell <rusty@rustcorp.com.au>2008-07-28 19:58:36 -0400
commitaa1249840bfc8d62431eed5796bf99887b963ab6 (patch)
tree35cf6cd82910af52e271c5e78ad47529e6daaed6
parenta161883a29bf6100efe7b5346bec274e5023c29c (diff)
lguest: Adaptive timeout
Since the correct timeout value varies, use a heuristic which adjusts the timeout depending on how many packets we've seen. This gives slightly worse results, but doesn't need tweaking when GSO is introduced. 500 usec 19.1887 xmit 561141 recv 1 timeout 559657 Dynamic (278) 20.1974 xmit 214510 recv 5 timeout 214491 usec 278 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--Documentation/lguest/lguest.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index 018472cee151..b2bbbb7f8c57 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -84,6 +84,7 @@ static void *guest_base;
84static unsigned long guest_limit, guest_max; 84static unsigned long guest_limit, guest_max;
85/* The pipe for signal hander to write to. */ 85/* The pipe for signal hander to write to. */
86static int timeoutpipe[2]; 86static int timeoutpipe[2];
87static unsigned int timeout_usec = 500;
87 88
88/* a per-cpu variable indicating whose vcpu is currently running */ 89/* a per-cpu variable indicating whose vcpu is currently running */
89static unsigned int __thread cpu_id; 90static unsigned int __thread cpu_id;
@@ -905,7 +906,7 @@ static void block_vq(struct virtqueue *vq)
905 itm.it_interval.tv_sec = 0; 906 itm.it_interval.tv_sec = 0;
906 itm.it_interval.tv_usec = 0; 907 itm.it_interval.tv_usec = 0;
907 itm.it_value.tv_sec = 0; 908 itm.it_value.tv_sec = 0;
908 itm.it_value.tv_usec = 500; 909 itm.it_value.tv_usec = timeout_usec;
909 910
910 setitimer(ITIMER_REAL, &itm, NULL); 911 setitimer(ITIMER_REAL, &itm, NULL);
911} 912}
@@ -922,6 +923,7 @@ static void handle_net_output(int fd, struct virtqueue *vq, bool timeout)
922 unsigned int head, out, in, num = 0; 923 unsigned int head, out, in, num = 0;
923 int len; 924 int len;
924 struct iovec iov[vq->vring.num]; 925 struct iovec iov[vq->vring.num];
926 static int last_timeout_num;
925 927
926 /* Keep getting output buffers from the Guest until we run out. */ 928 /* Keep getting output buffers from the Guest until we run out. */
927 while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) { 929 while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
@@ -939,6 +941,14 @@ static void handle_net_output(int fd, struct virtqueue *vq, bool timeout)
939 /* Block further kicks and set up a timer if we saw anything. */ 941 /* Block further kicks and set up a timer if we saw anything. */
940 if (!timeout && num) 942 if (!timeout && num)
941 block_vq(vq); 943 block_vq(vq);
944
945 if (timeout) {
946 if (num < last_timeout_num)
947 timeout_usec += 10;
948 else if (timeout_usec > 1)
949 timeout_usec--;
950 last_timeout_num = num;
951 }
942} 952}
943 953
944/* This is where we handle a packet coming in from the tun device to our 954/* This is where we handle a packet coming in from the tun device to our