Skip to content

Commit

Permalink
tun: do not put self in waitq if doing a nonblock read
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Amos Kong authored and David S. Miller committed Jun 9, 2011
1 parent 6f7c156 commit 61a5ff1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 61a5ff1

Please sign in to comment.