2022-12-08 02:56:59

by Yunsheng Lin

[permalink] [raw]
Subject: [PATCH net-next] net: tso: inline tso_count_descs()

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 <[email protected]>
---
include/net/tso.h | 8 +++++++-
net/core/tso.c | 8 --------
2 files changed, 7 insertions(+), 9 deletions(-)

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)
{
--
2.33.0


2022-12-09 04:09:50

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next] net: tso: inline tso_count_descs()

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;
> +}

2022-12-09 04:33:14

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next] net: tso: inline tso_count_descs()

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 :(

2022-12-09 09:13:34

by Yunsheng Lin

[permalink] [raw]
Subject: Re: [PATCH net-next] net: tso: inline tso_count_descs()

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:)

> .
>

2022-12-09 09:15:47

by Yunsheng Lin

[permalink] [raw]
Subject: Re: [PATCH net-next] net: tso: inline tso_count_descs()

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;
>> +}
> .
>

2022-12-09 22:48:59

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH net-next] net: tso: inline tso_count_descs()

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.