diff mbox

tcp_input: move out condition check from tcp_data_queue()

Message ID 674DB789-9B28-4A9C-A0BF-D91023CB86F3@gmail.com
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Matvejchikov Ilya Aug. 6, 2017, 9:51 a.m. UTC
As tcp_data_queue() function is used just only twice it's better
to move out the first check and wrap it with inline. It saves a
single call in case the condition evaluated as true.

Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
---
 net/ipv4/tcp_input.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Eric Dumazet Aug. 6, 2017, 5:07 p.m. UTC | #1
On Sun, 2017-08-06 at 13:51 +0400, Ilya Matveychikov wrote:
> As tcp_data_queue() function is used just only twice it's better
> to move out the first check and wrap it with inline. It saves a
> single call in case the condition evaluated as true.
> 
> Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
> ---
>  net/ipv4/tcp_input.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 2920e0c..141a722 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -4585,16 +4585,12 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
>  
>  }
>  
> -static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
> +static void __tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>  {
>  	struct tcp_sock *tp = tcp_sk(sk);
>  	bool fragstolen = false;
>  	int eaten = -1;
>  
> -	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
> -		__kfree_skb(skb);
> -		return;
> -	}
>  	skb_dst_drop(skb);
>  	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
>  
> @@ -4703,6 +4699,14 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>  	tcp_data_queue_ofo(sk, skb);
>  }
>  
> +static inline void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
> +{
> +	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq)
> +		__kfree_skb(skb);
> +	else
> +		__tcp_data_queue(sk, skb);
> +}
> +

We wont accept such a change, because this code does not need to be
inlined in the callers, ( and btw inline in .c files are discouraged
these days )
Matvejchikov Ilya Aug. 6, 2017, 5:57 p.m. UTC | #2
> On Aug 6, 2017, at 9:07 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> 
> On Sun, 2017-08-06 at 13:51 +0400, Ilya Matveychikov wrote:
>> As tcp_data_queue() function is used just only twice it's better
>> to move out the first check and wrap it with inline. It saves a
>> single call in case the condition evaluated as true.
>> 
>> Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
>> ---
>> net/ipv4/tcp_input.c | 14 +++++++++-----
>> 1 file changed, 9 insertions(+), 5 deletions(-)
>> 
>> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
>> index 2920e0c..141a722 100644
>> --- a/net/ipv4/tcp_input.c
>> +++ b/net/ipv4/tcp_input.c
>> @@ -4585,16 +4585,12 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
>> 
>> }
>> 
>> -static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>> +static void __tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>> {
>> 	struct tcp_sock *tp = tcp_sk(sk);
>> 	bool fragstolen = false;
>> 	int eaten = -1;
>> 
>> -	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
>> -		__kfree_skb(skb);
>> -		return;
>> -	}
>> 	skb_dst_drop(skb);
>> 	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
>> 
>> @@ -4703,6 +4699,14 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>> 	tcp_data_queue_ofo(sk, skb);
>> }
>> 
>> +static inline void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
>> +{
>> +	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq)
>> +		__kfree_skb(skb);
>> +	else
>> +		__tcp_data_queue(sk, skb);
>> +}
>> +
> 
> We wont accept such a change, because this code does not need to be
> inlined in the callers, ( and btw inline in .c files are discouraged
> these days )

Not sure that I understand you point. What’s the reason for that code
not need to be inlined in the callers?
Eric Dumazet Aug. 7, 2017, 5:04 a.m. UTC | #3
On Sun, 2017-08-06 at 21:57 +0400, Ilya Matveychikov wrote:
> > On Aug 6, 2017, at 9:07 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > 
> > On Sun, 2017-08-06 at 13:51 +0400, Ilya Matveychikov wrote:
> >> As tcp_data_queue() function is used just only twice it's better
> >> to move out the first check and wrap it with inline. It saves a
> >> single call in case the condition evaluated as true.
> >>

...

> > We wont accept such a change, because this code does not need to be
> > inlined in the callers, ( and btw inline in .c files are discouraged
> > these days )
> 
> Not sure that I understand you point. What’s the reason for that code
> not need to be inlined in the callers?

You sent a patch, you have to explain why it is needed.

Your changelog is absolutely not giving a compelling reason.

TCP stack is already complex, no need to add yet another obfuscation
unless there is a strong reason.
diff mbox

Patch

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 2920e0c..141a722 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4585,16 +4585,12 @@  int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
 
 }
 
-static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
+static void __tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	bool fragstolen = false;
 	int eaten = -1;
 
-	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
-		__kfree_skb(skb);
-		return;
-	}
 	skb_dst_drop(skb);
 	__skb_pull(skb, tcp_hdr(skb)->doff * 4);
 
@@ -4703,6 +4699,14 @@  static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 	tcp_data_queue_ofo(sk, skb);
 }
 
+static inline void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
+{
+	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq)
+		__kfree_skb(skb);
+	else
+		__tcp_data_queue(sk, skb);
+}
+
 static struct sk_buff *tcp_skb_next(struct sk_buff *skb, struct sk_buff_head *list)
 {
 	if (list)