lguest: Debugging patch for lguest network performance
---
 Documentation/lguest/lguest.c |   28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff -r 1a0d0e0cc01f Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c	Mon Aug 25 20:46:04 2008 +1000
+++ b/Documentation/lguest/lguest.c	Tue Aug 26 00:13:58 2008 +1000
@@ -173,6 +173,8 @@ struct virtqueue
 	/* Is this blocked awaiting a timer? */
 	bool blocked;
 };
+
+static unsigned int net_xmit_notify, net_recv_notify, net_recv_notify, net_timeout;
 
 /* Remember the arguments to the program so we can "reboot" */
 static char **main_args;
@@ -810,6 +812,10 @@ struct console_abort
 	struct timeval start;
 };
 
+static int last_timeout_num;
+static u16 timeout_nums[1000];
+static int timeout_num_idx;
+
 /* This is the routine which handles console input (ie. stdin). */
 static bool handle_console_input(int fd, struct device *dev)
 {
@@ -866,6 +872,18 @@ static bool handle_console_input(int fd,
 				/* Just in case Waker is blocked in BREAK, send
 				 * unbreak now. */
 				write(fd, args, sizeof(args));
+				printf("network xmit %u recv %u timeout %u usec %u last_timeout_num %u\n",
+				       net_xmit_notify, net_recv_notify,
+				       net_timeout, timeout_usec, last_timeout_num);
+				{
+					unsigned int i;
+					for (i = 0; i < 1000; i++) {
+						printf("%u ", timeout_nums[i]);
+						if (i % 10 == 9)
+							printf("\n");
+					}
+					printf("(idx = %u)\n", timeout_num_idx);
+				}
 				exit(2);
 			}
 			abort->count = 0;
@@ -885,6 +903,8 @@ static void handle_console_output(int fd
 	unsigned int head, out, in;
 	int len;
 	struct iovec iov[vq->vring.num];
+
+	net_xmit_notify++;
 
 	/* Keep getting output buffers from the Guest until we run out. */
 	while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
@@ -925,7 +945,6 @@ static void handle_net_output(int fd, st
 	unsigned int head, out, in, num = 0;
 	int len;
 	struct iovec iov[vq->vring.num];
-	static int last_timeout_num;
 
 	/* Keep getting output buffers from the Guest until we run out. */
 	while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
@@ -948,7 +967,11 @@ static void handle_net_output(int fd, st
 	 * too small and increase it by 10 microseconds.  Otherwise, we drop it
 	 * by one microsecond every time.  It seems to work well enough. */
 	if (timeout) {
-		if (num) {
+		net_timeout++;
+		timeout_nums[timeout_num_idx++] = num;
+		if (timeout_num_idx == 1000)
+			timeout_num_idx = 0;
+		if (1) {
 			if (num < last_timeout_num)
 				timeout_usec += 10;
 			else if (timeout_usec > 1)
@@ -1011,6 +1034,7 @@ static void enable_fd(int fd, struct vir
 
 static void net_enable_fd(int fd, struct virtqueue *vq, bool timeout)
 {
+	net_recv_notify++;
 	/* We don't need to know again when Guest refills receive buffer. */
 	vq->vring.used->flags |= VRING_USED_F_NO_NOTIFY;
 	enable_fd(fd, vq, timeout);
