netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: use tcp_flags in tcp_data_queue()
@ 2014-09-24 10:35 Weiping Pan
  2014-09-24 10:54 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Weiping Pan @ 2014-09-24 10:35 UTC (permalink / raw)
  To: netdev; +Cc: edumazet

Follow the idea in commit e11ecddf5128 (tcp: use TCP_SKB_CB(skb)->tcp_flags in
input path), we can use tcp_flags to avoid cache miss.

Signed-off-by: Weiping Pan <panweiping3@gmail.com>
---
 net/ipv4/tcp_input.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 13f3da4..85298c9 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4392,7 +4392,7 @@ queue_and_out:
 		tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
 		if (skb->len)
 			tcp_event_data_recv(sk, skb);
-		if (th->fin)
+		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			tcp_fin(sk);
 
 		if (!skb_queue_empty(&tp->out_of_order_queue)) {
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 10:35 [PATCH net-next] tcp: use tcp_flags in tcp_data_queue() Weiping Pan
@ 2014-09-24 10:54 ` Eric Dumazet
  2014-09-24 12:42   ` [PATCH net-next v2] " Weiping Pan
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2014-09-24 10:54 UTC (permalink / raw)
  To: Weiping Pan; +Cc: netdev, edumazet

On Wed, 2014-09-24 at 18:35 +0800, Weiping Pan wrote:
> Follow the idea in commit e11ecddf5128 (tcp: use TCP_SKB_CB(skb)->tcp_flags in
> input path), we can use tcp_flags to avoid cache miss.
> 
> Signed-off-by: Weiping Pan <panweiping3@gmail.com>
> ---
>  net/ipv4/tcp_input.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 13f3da4..85298c9 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -4392,7 +4392,7 @@ queue_and_out:
>  		tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
>  		if (skb->len)
>  			tcp_event_data_recv(sk, skb);
> -		if (th->fin)
> +		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
>  			tcp_fin(sk);
>  
>  		if (!skb_queue_empty(&tp->out_of_order_queue)) {

I thought of this, but my reasoning was that we needed th anyway, and
th->fin had the same cost.

But thinking more about this, its possible compiler can generate better
code, as tcp_hdr() will only be needed at the very beginning of the
function, and compiler no longer has to keep around th value.

Could you go one step further maybe ?

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index f3f016a15c5a..1a399737802b 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4344,7 +4344,6 @@ err:
 
 static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 {
-	const struct tcphdr *th = tcp_hdr(skb);
 	struct tcp_sock *tp = tcp_sk(sk);
 	int eaten = -1;
 	bool fragstolen = false;
@@ -4353,7 +4352,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 		goto drop;
 
 	skb_dst_drop(skb);
-	__skb_pull(skb, th->doff * 4);
+	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
 
 	TCP_ECN_accept_cwr(tp, skb);
 
@@ -4397,7 +4396,7 @@ queue_and_out:
 		tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
 		if (skb->len)
 			tcp_event_data_recv(sk, skb);
-		if (th->fin)
+		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			tcp_fin(sk);
 
 		if (!skb_queue_empty(&tp->out_of_order_queue)) {

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 10:54 ` Eric Dumazet
@ 2014-09-24 12:42   ` Weiping Pan
  2014-09-24 13:22     ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Weiping Pan @ 2014-09-24 12:42 UTC (permalink / raw)
  To: netdev; +Cc: edumazet

Follow the idea in commit e11ecddf5128 (tcp: use TCP_SKB_CB(skb)->tcp_flags in
input path), we can use tcp_flags to avoid cache miss.

v2: remove variable th

Signed-off-by: Weiping Pan <panweiping3@gmail.com>
---
 net/ipv4/tcp_input.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 13f3da4..a51663f 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4339,7 +4339,6 @@ err:
 
 static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 {
-	const struct tcphdr *th = tcp_hdr(skb);
 	struct tcp_sock *tp = tcp_sk(sk);
 	int eaten = -1;
 	bool fragstolen = false;
@@ -4348,7 +4347,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 		goto drop;
 
 	skb_dst_drop(skb);
-	__skb_pull(skb, th->doff * 4);
+	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
 
 	TCP_ECN_accept_cwr(tp, skb);
 
@@ -4392,7 +4391,7 @@ queue_and_out:
 		tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
 		if (skb->len)
 			tcp_event_data_recv(sk, skb);
-		if (th->fin)
+		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			tcp_fin(sk);
 
 		if (!skb_queue_empty(&tp->out_of_order_queue)) {
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 12:42   ` [PATCH net-next v2] " Weiping Pan
@ 2014-09-24 13:22     ` Eric Dumazet
  2014-09-24 14:17       ` [PATCH net-next v3] " Weiping Pan
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2014-09-24 13:22 UTC (permalink / raw)
  To: Weiping Pan; +Cc: netdev, edumazet

On Wed, 2014-09-24 at 20:42 +0800, Weiping Pan wrote:
> Follow the idea in commit e11ecddf5128 (tcp: use TCP_SKB_CB(skb)->tcp_flags in
> input path), we can use tcp_flags to avoid cache miss.
> 

Well, there is no cache miss here. Lets try to have precise changelogs.

We access tcp_hdr(skb)->doff right before, so the tcp header is in cpu
cache.

So this patch is a cleanup and a way to help compiler to reduce register
pressure since skb->cb[] access is fast (skb is probably in a register)

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v3] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 13:22     ` Eric Dumazet
@ 2014-09-24 14:17       ` Weiping Pan
  2014-09-26 12:38         ` Eric Dumazet
  2014-09-28 20:38         ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: Weiping Pan @ 2014-09-24 14:17 UTC (permalink / raw)
  To: netdev; +Cc: edumazet

This patch is a cleanup which follows the idea in commit e11ecddf5128 (tcp: use
TCP_SKB_CB(skb)->tcp_flags in input path),
and it may reduce register pressure since skb->cb[] access is fast,
bacause skb is probably in a register.

v2: remove variable th
v3: reword the changelog

Signed-off-by: Weiping Pan <panweiping3@gmail.com>
---
 net/ipv4/tcp_input.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 13f3da4..a51663f 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4339,7 +4339,6 @@ err:
 
 static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 {
-	const struct tcphdr *th = tcp_hdr(skb);
 	struct tcp_sock *tp = tcp_sk(sk);
 	int eaten = -1;
 	bool fragstolen = false;
@@ -4348,7 +4347,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 		goto drop;
 
 	skb_dst_drop(skb);
-	__skb_pull(skb, th->doff * 4);
+	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
 
 	TCP_ECN_accept_cwr(tp, skb);
 
@@ -4392,7 +4391,7 @@ queue_and_out:
 		tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
 		if (skb->len)
 			tcp_event_data_recv(sk, skb);
-		if (th->fin)
+		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			tcp_fin(sk);
 
 		if (!skb_queue_empty(&tp->out_of_order_queue)) {
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 14:17       ` [PATCH net-next v3] " Weiping Pan
@ 2014-09-26 12:38         ` Eric Dumazet
  2014-09-28 20:38         ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2014-09-26 12:38 UTC (permalink / raw)
  To: Weiping Pan; +Cc: netdev, edumazet

On Wed, 2014-09-24 at 22:17 +0800, Weiping Pan wrote:
> This patch is a cleanup which follows the idea in commit e11ecddf5128 (tcp: use
> TCP_SKB_CB(skb)->tcp_flags in input path),
> and it may reduce register pressure since skb->cb[] access is fast,
> bacause skb is probably in a register.
> 
> v2: remove variable th
> v3: reword the changelog
> 
> Signed-off-by: Weiping Pan <panweiping3@gmail.com>
> ---

Acked-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3] tcp: use tcp_flags in tcp_data_queue()
  2014-09-24 14:17       ` [PATCH net-next v3] " Weiping Pan
  2014-09-26 12:38         ` Eric Dumazet
@ 2014-09-28 20:38         ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2014-09-28 20:38 UTC (permalink / raw)
  To: panweiping3; +Cc: netdev, edumazet

From: Weiping Pan <panweiping3@gmail.com>
Date: Wed, 24 Sep 2014 22:17:02 +0800

> This patch is a cleanup which follows the idea in commit e11ecddf5128 (tcp: use
> TCP_SKB_CB(skb)->tcp_flags in input path),
> and it may reduce register pressure since skb->cb[] access is fast,
> bacause skb is probably in a register.
> 
> v2: remove variable th
> v3: reword the changelog
> 
> Signed-off-by: Weiping Pan <panweiping3@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-28 20:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24 10:35 [PATCH net-next] tcp: use tcp_flags in tcp_data_queue() Weiping Pan
2014-09-24 10:54 ` Eric Dumazet
2014-09-24 12:42   ` [PATCH net-next v2] " Weiping Pan
2014-09-24 13:22     ` Eric Dumazet
2014-09-24 14:17       ` [PATCH net-next v3] " Weiping Pan
2014-09-26 12:38         ` Eric Dumazet
2014-09-28 20:38         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).