[net-next] net: tso: inline tso_count_descs()

Message ID 20221208024303.11191-1-linyunsheng@huawei.com
State New
Headers
Series [net-next] net: tso: inline tso_count_descs() |

Commit Message

Yunsheng Lin Dec. 8, 2022, 2:43 a.m. UTC
  tso_count_descs() is a small function doing simple calculation,
and tso_count_descs() is used in fast path, so inline it to
reduce the overhead of calls.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
 include/net/tso.h | 8 +++++++-
 net/core/tso.c    | 8 --------
 2 files changed, 7 insertions(+), 9 deletions(-)
  

Comments

Jakub Kicinski Dec. 9, 2022, 3:57 a.m. UTC | #1
On Thu, 8 Dec 2022 10:43:03 +0800 Yunsheng Lin wrote:
> tso_count_descs() is a small function doing simple calculation,
> and tso_count_descs() is used in fast path, so inline it to
> reduce the overhead of calls.

TSO frames are large, the overhead is fine.
I'm open to other opinions but I'd rather keep the code as is than
deal with the influx with similar sloppily automated changes.

> diff --git a/include/net/tso.h b/include/net/tso.h
> index 62c98a9c60f1..ab6bbf56d984 100644
> --- a/include/net/tso.h
> +++ b/include/net/tso.h
> @@ -16,7 +16,13 @@ struct tso_t {
>  	u32	tcp_seq;
>  };

no include for skbuff.h here

> -int tso_count_descs(const struct sk_buff *skb);
> +/* Calculate expected number of TX descriptors */
> +static inline int tso_count_descs(const struct sk_buff *skb)
> +{
> +	/* The Marvell Way */

these comments should be rewritten as we move
the function clearly calculates the worst case buffer count

> +	return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
> +}
  
Jakub Kicinski Dec. 9, 2022, 3:59 a.m. UTC | #2
On Thu, 8 Dec 2022 19:57:21 -0800 Jakub Kicinski wrote:
> On Thu, 8 Dec 2022 10:43:03 +0800 Yunsheng Lin wrote:
> > tso_count_descs() is a small function doing simple calculation,
> > and tso_count_descs() is used in fast path, so inline it to
> > reduce the overhead of calls.  
> 
> TSO frames are large, the overhead is fine.
> I'm open to other opinions but I'd rather keep the code as is than
> deal with the influx with similar sloppily automated changes.

Oh, wait, you're not one of the bot people. Sorry, please just address
my comments and post a v2.

There is a lot of poorly written patches coming from @huawei addresses
which are giving the company a bad name :(
  
Yunsheng Lin Dec. 9, 2022, 8:48 a.m. UTC | #3
On 2022/12/9 11:57, Jakub Kicinski wrote:
> On Thu, 8 Dec 2022 10:43:03 +0800 Yunsheng Lin wrote:
>> tso_count_descs() is a small function doing simple calculation,
>> and tso_count_descs() is used in fast path, so inline it to
>> reduce the overhead of calls.
> 
> TSO frames are large, the overhead is fine.
> I'm open to other opinions but I'd rather keep the code as is than
> deal with the influx with similar sloppily automated changes.
> 
>> diff --git a/include/net/tso.h b/include/net/tso.h
>> index 62c98a9c60f1..ab6bbf56d984 100644
>> --- a/include/net/tso.h
>> +++ b/include/net/tso.h
>> @@ -16,7 +16,13 @@ struct tso_t {
>>  	u32	tcp_seq;
>>  };
> 
> no include for skbuff.h here

Do you mean including skbuff.h explicitly in tso.h?
It seems ip.h included in tso.h has included skbuff.h.

> 
>> -int tso_count_descs(const struct sk_buff *skb);
>> +/* Calculate expected number of TX descriptors */
>> +static inline int tso_count_descs(const struct sk_buff *skb)
>> +{
>> +	/* The Marvell Way */
> 
> these comments should be rewritten as we move
> the function clearly calculates the worst case buffer count

Will change to below:
/* Calculate the worst case buffer count */

> 
>> +	return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
>> +}
> .
>
  
Yunsheng Lin Dec. 9, 2022, 8:56 a.m. UTC | #4
On 2022/12/9 11:59, Jakub Kicinski wrote:
> On Thu, 8 Dec 2022 19:57:21 -0800 Jakub Kicinski wrote:
>> On Thu, 8 Dec 2022 10:43:03 +0800 Yunsheng Lin wrote:
>>> tso_count_descs() is a small function doing simple calculation,
>>> and tso_count_descs() is used in fast path, so inline it to
>>> reduce the overhead of calls.  
>>
>> TSO frames are large, the overhead is fine.
>> I'm open to other opinions but I'd rather keep the code as is than
>> deal with the influx with similar sloppily automated changes.
> 
> Oh, wait, you're not one of the bot people. Sorry, please just address
> my comments and post a v2.
> 

Sure.
My job has shifted a little bit in huawei, and has not contributed to the
community much as used to be.
but I still look for similar pattern in the kernel when dealing with
problem, when there is some improvement to the related code, I will
contribute back:)

> .
>
  
Jakub Kicinski Dec. 9, 2022, 10:35 p.m. UTC | #5
On Fri, 9 Dec 2022 16:48:57 +0800 Yunsheng Lin wrote:
> >> diff --git a/include/net/tso.h b/include/net/tso.h
> >> index 62c98a9c60f1..ab6bbf56d984 100644
> >> --- a/include/net/tso.h
> >> +++ b/include/net/tso.h
> >> @@ -16,7 +16,13 @@ struct tso_t {
> >>  	u32	tcp_seq;
> >>  };  
> > 
> > no include for skbuff.h here  
> 
> Do you mean including skbuff.h explicitly in tso.h?
> It seems ip.h included in tso.h has included skbuff.h.

Yes, we need the definition of skb_shinfo() so let's include the header.
Let's not depend on second-order includes, it makes refactoring harder.

> >> -int tso_count_descs(const struct sk_buff *skb);
> >> +/* Calculate expected number of TX descriptors */
> >> +static inline int tso_count_descs(const struct sk_buff *skb)
> >> +{
> >> +	/* The Marvell Way */  
> > 
> > these comments should be rewritten as we move
> > the function clearly calculates the worst case buffer count  
> 
> Will change to below:
> /* Calculate the worst case buffer count */

Thanks, you can replace the comment about the function with this
comment. No need to have two comments, and mentioning descriptors
is slightly confusing because descriptor is not always equivalent
to a buffer.
  

Patch

diff --git a/include/net/tso.h b/include/net/tso.h
index 62c98a9c60f1..ab6bbf56d984 100644
--- a/include/net/tso.h
+++ b/include/net/tso.h
@@ -16,7 +16,13 @@  struct tso_t {
 	u32	tcp_seq;
 };
 
-int tso_count_descs(const struct sk_buff *skb);
+/* Calculate expected number of TX descriptors */
+static inline int tso_count_descs(const struct sk_buff *skb)
+{
+	/* The Marvell Way */
+	return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
+}
+
 void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
 		   int size, bool is_last);
 void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size);
diff --git a/net/core/tso.c b/net/core/tso.c
index 4148f6d48953..e00796e3b146 100644
--- a/net/core/tso.c
+++ b/net/core/tso.c
@@ -5,14 +5,6 @@ 
 #include <net/tso.h>
 #include <asm/unaligned.h>
 
-/* Calculate expected number of TX descriptors */
-int tso_count_descs(const struct sk_buff *skb)
-{
-	/* The Marvell Way */
-	return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
-}
-EXPORT_SYMBOL(tso_count_descs);
-
 void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
 		   int size, bool is_last)
 {