Skip to contentSkip to conversation

tun: don't look at current when non-blocking

PATCH In review Michael S. Tsirkin 3 participants 6 messages Oct 6, 2013 – Oct 9, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tun: don't look at current when non-blocking

We play with a wait queue even if socket is non blocking. This is an obvious waste. Besides, it will prevent calling the non blocking variant when current is not valid.

---
 drivers/net/tun.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/tun.c +5 -3
index 807815f..7cb105c 100644
@@ -1293,7 +1293,8 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 	if (unlikely(!noblock))
 		add_wait_queue(&tfile->wq.wait, &wait);
 	while (len) {
-		current->state = TASK_INTERRUPTIBLE;
+		if (unlikely(!noblock))
+			current->state = TASK_INTERRUPTIBLE;
 
 		/* Read frames from the queue */
 		if (!(skb = skb_dequeue(&tfile->socket.sk->sk_receive_queue))) {
@@ -1320,9 +1321,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 		break;
 	}
 
-	current->state = TASK_RUNNING;
-	if (unlikely(!noblock))
+	if (unlikely(!noblock)) {
+		current->state = TASK_RUNNING;
 		remove_wait_queue(&tfile->wq.wait, &wait);
+	}
 
 	return ret;
 }
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Michael S. Tsirkin

We play with a wait queue even if socket is non blocking. This is an obvious waste. Besides, it will prevent calling the non blocking variant when current is not valid.

---

Quoted 30 lines
 drivers/net/tun.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/tun.c +5 -3
index 807815f..7cb105c 100644
@@ -1293,7 +1293,8 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 	if (unlikely(!noblock))
 		add_wait_queue(&tfile->wq.wait, &wait);
 	while (len) {
-		current->state = TASK_INTERRUPTIBLE;
+		if (unlikely(!noblock))
+			current->state = TASK_INTERRUPTIBLE;
 
 		/* Read frames from the queue */
 		if (!(skb = skb_dequeue(&tfile->socket.sk->sk_receive_queue))) {
@@ -1320,9 +1321,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
 		break;
 	}
 
-	current->state = TASK_RUNNING;
-	if (unlikely(!noblock))
+	if (unlikely(!noblock)) {
+		current->state = TASK_RUNNING;
 		remove_wait_queue(&tfile->wq.wait, &wait);
+	}
 
 	return ret;
 }
#3 lore raw
Quoted 11 lines · David Miller

From: "Michael S. Tsirkin" <[email protected]>
Date: Sun, 6 Oct 2013 21:25:12 +0300

Quoted 6 lines

We play with a wait queue even if socket is non blocking. This is an obvious waste. Besides, it will prevent calling the non blocking variant when current is not valid.

Applied and queued up for -stable, thanks.
--

Michael, I believe this is just an optimization or a required patch of your following patches. So no need go for stable?

#4 lore raw
Quoted 9 lines · Jason Wang
Quoted 8 lines · David Miller

From: "Michael S. Tsirkin" <[email protected]>
Date: Sun, 6 Oct 2013 21:25:12 +0300

Quoted 5 lines

We play with a wait queue even if socket is non blocking. This is an obvious waste. Besides, it will prevent calling the non blocking variant when current is not valid.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied and queued up for -stable, thanks.
--

Michael, I believe this is just an optimization or a required patch of your following patches. So no need go for stable?

I don't think it's required for stable.

maintainer
#5 lore raw

From: "Michael S. Tsirkin" <[email protected]>
Date: Wed, 9 Oct 2013 11:13:54 +0300

Quoted 10 lines · Jason Wang
Quoted 9 lines · David Miller
Quoted 8 lines

From: "Michael S. Tsirkin" <[email protected]>
Date: Sun, 6 Oct 2013 21:25:12 +0300

Quoted 5 lines

We play with a wait queue even if socket is non blocking. This is an obvious waste. Besides, it will prevent calling the non blocking variant when current is not valid.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied and queued up for -stable, thanks.
--

Michael, I believe this is just an optimization or a required patch of your following patches. So no need go for stable?

I don't think it's required for stable.

Ok, removed from the -stable queue. Thanks.