tun: do not put self in waitq if doing a nonblock read
authorAmos Kong <akong@redhat.com>
Thu, 9 Jun 2011 07:27:10 +0000 (00:27 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 9 Jun 2011 07:27:10 +0000 (00:27 -0700)
Perf shows a relatively high rate (about 8%) race in
spin_lock_irqsave() when doing netperf between external host and
guest. It's mainly becuase the lock contention between the
tun_do_read() and tun_xmit_skb(), so this patch do not put self into
waitqueue to reduce this kind of race. After this patch, it drops to
4%.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c

index 2829badbae38bfa9dbe1cf5b1e85949183293500..ef68e13c042debe5f7f1c4606f8fc83ab03f0389 100644 (file)
@@ -817,7 +817,8 @@ static ssize_t tun_do_read(struct tun_struct *tun,
 
        tun_debug(KERN_INFO, tun, "tun_chr_read\n");
 
-       add_wait_queue(&tun->wq.wait, &wait);
+       if (unlikely(!noblock))
+               add_wait_queue(&tun->wq.wait, &wait);
        while (len) {
                current->state = TASK_INTERRUPTIBLE;
 
@@ -848,7 +849,8 @@ static ssize_t tun_do_read(struct tun_struct *tun,
        }
 
        current->state = TASK_RUNNING;
-       remove_wait_queue(&tun->wq.wait, &wait);
+       if (unlikely(!noblock))
+               remove_wait_queue(&tun->wq.wait, &wait);
 
        return ret;
 }
This page took 0.030607 seconds and 5 git commands to generate.