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>

+11 -1
+11 -1
Documentation/lguest/lguest.c
··· 84 84 static unsigned long guest_limit, guest_max; 85 85 /* The pipe for signal hander to write to. */ 86 86 static int timeoutpipe[2]; 87 + static unsigned int timeout_usec = 500; 87 88 88 89 /* a per-cpu variable indicating whose vcpu is currently running */ 89 90 static unsigned int __thread cpu_id; ··· 906 905 itm.it_interval.tv_sec = 0; 907 906 itm.it_interval.tv_usec = 0; 908 907 itm.it_value.tv_sec = 0; 909 - itm.it_value.tv_usec = 500; 908 + itm.it_value.tv_usec = timeout_usec; 910 909 911 910 setitimer(ITIMER_REAL, &itm, NULL); 912 911 } ··· 923 922 unsigned int head, out, in, num = 0; 924 923 int len; 925 924 struct iovec iov[vq->vring.num]; 925 + static int last_timeout_num; 926 926 927 927 /* Keep getting output buffers from the Guest until we run out. */ 928 928 while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) { ··· 941 939 /* Block further kicks and set up a timer if we saw anything. */ 942 940 if (!timeout && num) 943 941 block_vq(vq); 942 + 943 + if (timeout) { 944 + if (num < last_timeout_num) 945 + timeout_usec += 10; 946 + else if (timeout_usec > 1) 947 + timeout_usec--; 948 + last_timeout_num = num; 949 + } 944 950 } 945 951 946 952 /* This is where we handle a packet coming in from the tun device to our