Skip to contentSkip to conversation

gro: move the tc_ext comparison to a helper

PATCH Superseded Jakub Kicinski 3 participants 6 messages Jun 13, 2023 – Jun 14, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 gro: move the tc_ext comparison to a helper

The double ifdefs are quite aesthetically displeasing. Use a helper function to make the code more compact. The resulting machine code looks the same (with minor movement of some basic blocks).

---
CC: [email protected]

---
 net/core/gro.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
net/core/gro.c +18 -13
index ab9a447dfba7..90889e1f3f9a 100644
@@ -305,6 +305,23 @@ void napi_gro_flush(struct napi_struct *napi, bool flush_old)
 }
 EXPORT_SYMBOL(napi_gro_flush);
 
+static void gro_list_prepare_tc_ext(const struct sk_buff *skb,
+				    const struct sk_buff *p,
+				    unsigned long *diffs)
+{
+#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
+	struct tc_skb_ext *skb_ext;
+	struct tc_skb_ext *p_ext;
+
+	skb_ext = skb_ext_find(skb, TC_SKB_EXT);
+	p_ext = skb_ext_find(p, TC_SKB_EXT);
+
+	*diffs |= (!!p_ext) ^ (!!skb_ext);
+	if (!*diffs && unlikely(skb_ext))
+		*diffs |= p_ext->chain ^ skb_ext->chain;
+#endif
+}
+
 static void gro_list_prepare(const struct list_head *head,
 			     const struct sk_buff *skb)
 {
@@ -339,23 +356,11 @@ static void gro_list_prepare(const struct list_head *head,
 		 * avoid trying too hard to skip each of them individually
 		 */
 		if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) {
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			struct tc_skb_ext *skb_ext;
-			struct tc_skb_ext *p_ext;
-#endif
-
 			diffs |= p->sk != skb->sk;
 			diffs |= skb_metadata_dst_cmp(p, skb);
 			diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb);
 
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			skb_ext = skb_ext_find(skb, TC_SKB_EXT);
-			p_ext = skb_ext_find(p, TC_SKB_EXT);
-
-			diffs |= (!!p_ext) ^ (!!skb_ext);
-			if (!diffs && unlikely(skb_ext))
-				diffs |= p_ext->chain ^ skb_ext->chain;
-#endif
+			gro_list_prepare_tc_ext(skb, p, &diffs);
 		}
 
 		NAPI_GRO_CB(p)->same_flow = !diffs;
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jakub Kicinski

The double ifdefs are quite aesthetically displeasing. Use a helper function to make the code more compact. The resulting machine code looks the same (with minor movement of some basic blocks).

Hi Jakub,

I like your patch, and I think it is a good improvement, but I find the patch description slightly confusing.

In my understanding of things this patch is doing two things:

1) Moving code into a helper
2) Eliminating a check on CONFIG_SKB_EXTENSIONS, presumably because it is selected by NET_TC_SKB_EXT.

But the patch description seems to conflate these.

In any case, code looks good.

Quoted 63 lines

---
CC: [email protected]

---
 net/core/gro.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
net/core/gro.c +18 -13
index ab9a447dfba7..90889e1f3f9a 100644
@@ -305,6 +305,23 @@ void napi_gro_flush(struct napi_struct *napi, bool flush_old)
 }
 EXPORT_SYMBOL(napi_gro_flush);
 
+static void gro_list_prepare_tc_ext(const struct sk_buff *skb,
+				    const struct sk_buff *p,
+				    unsigned long *diffs)
+{
+#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
+	struct tc_skb_ext *skb_ext;
+	struct tc_skb_ext *p_ext;
+
+	skb_ext = skb_ext_find(skb, TC_SKB_EXT);
+	p_ext = skb_ext_find(p, TC_SKB_EXT);
+
+	*diffs |= (!!p_ext) ^ (!!skb_ext);
+	if (!*diffs && unlikely(skb_ext))
+		*diffs |= p_ext->chain ^ skb_ext->chain;
+#endif
+}
+
 static void gro_list_prepare(const struct list_head *head,
 			     const struct sk_buff *skb)
 {
@@ -339,23 +356,11 @@ static void gro_list_prepare(const struct list_head *head,
 		 * avoid trying too hard to skip each of them individually
 		 */
 		if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) {
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			struct tc_skb_ext *skb_ext;
-			struct tc_skb_ext *p_ext;
-#endif
-
 			diffs |= p->sk != skb->sk;
 			diffs |= skb_metadata_dst_cmp(p, skb);
 			diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb);
 
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			skb_ext = skb_ext_find(skb, TC_SKB_EXT);
-			p_ext = skb_ext_find(p, TC_SKB_EXT);
-
-			diffs |= (!!p_ext) ^ (!!skb_ext);
-			if (!diffs && unlikely(skb_ext))
-				diffs |= p_ext->chain ^ skb_ext->chain;
-#endif
+			gro_list_prepare_tc_ext(skb, p, &diffs);
 		}
 
 		NAPI_GRO_CB(p)->same_flow = !diffs;
Signature · 1 line
2.40.1
author maintainer
#2 lore raw
Quoted 8 lines · On Wed, 14 Jun 2023 14:23:21 +0200 Simon Horman wrote:

I like your patch, and I think it is a good improvement, but I find the patch description slightly confusing.

In my understanding of things this patch is doing two things:

1) Moving code into a helper
2) Eliminating a check on CONFIG_SKB_EXTENSIONS, presumably because it is selected by NET_TC_SKB_EXT.

Ah, I thought removing the check for CONFIG_SKB_EXTENSIONS is not worth mentioning. The double ifdefs I was talking about was the fact that we need an ifdef both around the variable declarations and the comparisons themselves.

Quoted 3 lines

But the patch description seems to conflate these.

In any case, code looks good.

#3 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 14 Jun 2023 14:23:21 +0200 Simon Horman wrote:

I like your patch, and I think it is a good improvement, but I find the patch description slightly confusing.

In my understanding of things this patch is doing two things:

Quoted 8 lines
Quoted 3 lines

1) Moving code into a helper
2) Eliminating a check on CONFIG_SKB_EXTENSIONS, presumably because it is selected by NET_TC_SKB_EXT.

Ah, I thought removing the check for CONFIG_SKB_EXTENSIONS is not worth mentioning. The double ifdefs I was talking about was the fact that we need an ifdef both around the variable declarations and the comparisons themselves.

Ok, now I understand. Looks good :)

#4 lore raw
In reply to Jakub Kicinski
Quoted 17 lines · Jakub Kicinski

The double ifdefs are quite aesthetically displeasing. Use a helper function to make the code more compact. The resulting machine code looks the same (with minor movement of some basic blocks).

---
CC: [email protected]

---
 net/core/gro.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
net/core/gro.c +0 -0
index ab9a447dfba7..90889e1f3f9a 100644

net/core/gro.c void napi_gro_flush(struct napi_struct *napi, bool flush_old) · line 310

Quoted 6 lines
net/core/gro.c +3 -0
@@ -305,6 +305,23 @@ void napi_gro_flush(struct napi_struct *napi, bool flush_old)
 }
 EXPORT_SYMBOL(napi_gro_flush);
 
+static void gro_list_prepare_tc_ext(const struct sk_buff *skb,
+				    const struct sk_buff *p,
+				    unsigned long *diffs)

Isn't it more common to do something like below?

static unsigned long gro_list_prepare_tc_ext(const struct sk_buff *skb,
const struct sk_buff *p, unsigned long diffs)

Is it because the resulting machine code is bigger for the above case?

Quoted 43 lines
net/core/gro.c +15 -13
+{
+#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
+	struct tc_skb_ext *skb_ext;
+	struct tc_skb_ext *p_ext;
+
+	skb_ext = skb_ext_find(skb, TC_SKB_EXT);
+	p_ext = skb_ext_find(p, TC_SKB_EXT);
+
+	*diffs |= (!!p_ext) ^ (!!skb_ext);
+	if (!*diffs && unlikely(skb_ext))
+		*diffs |= p_ext->chain ^ skb_ext->chain;
+#endif
+}
+
 static void gro_list_prepare(const struct list_head *head,
 			     const struct sk_buff *skb)
 {
@@ -339,23 +356,11 @@ static void gro_list_prepare(const struct list_head *head,
 		 * avoid trying too hard to skip each of them individually
 		 */
 		if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) {
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			struct tc_skb_ext *skb_ext;
-			struct tc_skb_ext *p_ext;
-#endif
-
 			diffs |= p->sk != skb->sk;
 			diffs |= skb_metadata_dst_cmp(p, skb);
 			diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb);
 
-#if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
-			skb_ext = skb_ext_find(skb, TC_SKB_EXT);
-			p_ext = skb_ext_find(p, TC_SKB_EXT);
-
-			diffs |= (!!p_ext) ^ (!!skb_ext);
-			if (!diffs && unlikely(skb_ext))
-				diffs |= p_ext->chain ^ skb_ext->chain;
-#endif
+			gro_list_prepare_tc_ext(skb, p, &diffs);
 		}
 
 		NAPI_GRO_CB(p)->same_flow = !diffs;
author maintainer
#5 lore raw
Quoted 6 lines · On Wed, 14 Jun 2023 20:58:53 +0800 Yunsheng Lin wrote:

net/core/gro.c void napi_gro_flush(struct napi_struct *napi, bool flush_old) · line 310

Quoted 3 lines
net/core/gro.c +3 -0
+static void gro_list_prepare_tc_ext(const struct sk_buff *skb,
+				    const struct sk_buff *p,
+				    unsigned long *diffs)  

Isn't it more common to do something like below?

Quoted 6 lines

static unsigned long gro_list_prepare_tc_ext(const struct sk_buff *skb,
const struct sk_buff *p, unsigned long diffs)

Is it because the resulting machine code is bigger for the above case?

Not really, just laziness - the above is more typing. I guess avoiding output args is worth while, so between this and Simon's comment - let me respin.

Signature · 1 line
pw-bot: cr