Skip to contentSkip to conversation

net: expand the data size of L3 length to 16 bits

PATCH In review Haiyue Wang 3 participants 9 messages Sep 4, 2020 – Sep 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: expand the data size of L3 length to 16 bits

The IPv6 can have large extension header, like the "Segment Routing" may have (32 + 1) * 8 = 264 bytes, the 8 bits size of L3 length can't handle this case correctly.

---
 lib/librte_net/rte_net.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_net/rte_net.h +2 -2
index 94b06d9ee..992fb088a 100644
@@ -20,11 +20,11 @@ extern "C" {
  */
 struct rte_net_hdr_lens {
 	uint8_t l2_len;
-	uint8_t l3_len;
+	uint16_t l3_len;
 	uint8_t l4_len;
 	uint8_t tunnel_len;
 	uint8_t inner_l2_len;
-	uint8_t inner_l3_len;
+	uint16_t inner_l3_len;
 	uint8_t inner_l4_len;
 };
 
Signature · 1 line
2.28.0
#1 lore raw

lib/librte_net/rte_net.h extern "C" { · line 24

Quoted 11 lines · On Fri, 4 Sep 2020 13:40:20 +0800 Haiyue Wang <[email protected]> wrote:
lib/librte_net/rte_net.h +1 -1
index 94b06d9ee..992fb088a 100644
@@ -20,11 +20,11 @@ extern "C" {
  */
 struct rte_net_hdr_lens {
 	uint8_t l2_len;
-	uint8_t l3_len;
+	uint16_t l3_len;
 	uint8_t l4_len;

Please reorder these to avoid creating a structure hole.

#2 lore raw
Quoted 10 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday, September 5, 2020 02:56
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; Olivier Matz <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v1] net: expand the data size of L3 length to 16 bits

On Fri, 4 Sep 2020 13:40:20 +0800
Haiyue Wang <[email protected]> wrote:

Quoted 13 lines

lib/librte_net/rte_net.h extern "C" { · line 24

Quoted 11 lines
lib/librte_net/rte_net.h +1 -1
index 94b06d9ee..992fb088a 100644
@@ -20,11 +20,11 @@ extern "C" {
  */
 struct rte_net_hdr_lens {
 	uint8_t l2_len;
-	uint8_t l3_len;
+	uint16_t l3_len;
 	uint8_t l4_len;

Please reorder these to avoid creating a structure hole.

Done in v2, I use the bit field like rte_mbuf, and keep the member's original order.

#3 lore raw

PATCH v2 1/1 net: adjust the header length parse size

In reply to Haiyue Wang

Align to the rte_mbuf's design about Tx header length data size for the header length parse result.

	struct {
		uint64_t   l2_len:7;             /*    88: 0  8 */
		uint64_t   l3_len:9;             /*    88: 7  8 */
		uint64_t   l4_len:8;             /*    88:16  8 */
		uint64_t   tso_segsz:16;         /*    88:24  8 */
		uint64_t   outer_l3_len:9;       /*    88:40  8 */
		uint64_t   outer_l2_len:7;       /*    88:49  8 */
	};

Now the IPv6 can support bigger extension header.

The below is the structure hole analysis result:

Before:
struct rte_net_hdr_lens {

        uint8_t                    l2_len;               /*     0     1 */
        uint8_t                    l3_len;               /*     1     1 */
        uint8_t                    l4_len;               /*     2     1 */
        uint8_t                    tunnel_len;           /*     3     1 */
        uint8_t                    inner_l2_len;         /*     4     1 */
        uint8_t                    inner_l3_len;         /*     5     1 */
        uint8_t                    inner_l4_len;         /*     6     1 */
        /* size: 7, cachelines: 1, members: 7 */
        /* last cacheline: 7 bytes */
};

Now:

struct rte_net_hdr_lens {
        uint64_t                   l2_len:7;             /*     0: 0  8 */
        uint64_t                   l3_len:9;             /*     0: 7  8 */
        uint64_t                   l4_len:8;             /*     0:16  8 */
        uint64_t                   tunnel_len:8;         /*     0:24  8 */
        uint64_t                   inner_l2_len:7;       /*     0:32  8 */
        uint64_t                   inner_l3_len:9;       /*     0:39  8 */
        uint64_t                   inner_l4_len:8;       /*     0:48  8 */

        /* size: 8, cachelines: 1, members: 7 */
        /* bit_padding: 8 bits */
        /* last cacheline: 8 bytes */
};

---
v2: use bit field to avoid creating a structure hole.

---
 lib/librte_net/rte_net.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
lib/librte_net/rte_net.h +8 -7
index 94b06d9ee..a14e3d814 100644
@@ -18,14 +18,15 @@ extern "C" {
  * Structure containing header lengths associated to a packet, filled
  * by rte_net_get_ptype().
  */
+__extension__
 struct rte_net_hdr_lens {
-	uint8_t l2_len;
-	uint8_t l3_len;
-	uint8_t l4_len;
-	uint8_t tunnel_len;
-	uint8_t inner_l2_len;
-	uint8_t inner_l3_len;
-	uint8_t inner_l4_len;
+	uint64_t l2_len:7;
+	uint64_t l3_len:9;
+	uint64_t l4_len:8;
+	uint64_t tunnel_len:8;
+	uint64_t inner_l2_len:7;
+	uint64_t inner_l3_len:9;
+	uint64_t inner_l4_len:8;
 };
 
 /**
Signature · 1 line
2.28.0
#4 lore raw

Re: [dpdk-dev] [PATCH v2] net: adjust the header length parse size

Quoted 44 lines · On Sat, 5 Sep 2020 11:06:46 +0800 Haiyue Wang <[email protected]> wrote:

Align to the rte_mbuf's design about Tx header length data size for the header length parse result.

	struct {
		uint64_t   l2_len:7;             /*    88: 0  8 */
		uint64_t   l3_len:9;             /*    88: 7  8 */
		uint64_t   l4_len:8;             /*    88:16  8 */
		uint64_t   tso_segsz:16;         /*    88:24  8 */
		uint64_t   outer_l3_len:9;       /*    88:40  8 */
		uint64_t   outer_l2_len:7;       /*    88:49  8 */
	};

Now the IPv6 can support bigger extension header.

The below is the structure hole analysis result:

Before:
struct rte_net_hdr_lens {

        uint8_t                    l2_len;               /*     0     1 */
        uint8_t                    l3_len;               /*     1     1 */
        uint8_t                    l4_len;               /*     2     1 */
        uint8_t                    tunnel_len;           /*     3     1 */
        uint8_t                    inner_l2_len;         /*     4     1 */
        uint8_t                    inner_l3_len;         /*     5     1 */
        uint8_t                    inner_l4_len;         /*     6     1 */
        /* size: 7, cachelines: 1, members: 7 */
        /* last cacheline: 7 bytes */
};

Now:

struct rte_net_hdr_lens {
        uint64_t                   l2_len:7;             /*     0: 0  8 */
        uint64_t                   l3_len:9;             /*     0: 7  8 */
        uint64_t                   l4_len:8;             /*     0:16  8 */
        uint64_t                   tunnel_len:8;         /*     0:24  8 */
        uint64_t                   inner_l2_len:7;       /*     0:32  8 */
        uint64_t                   inner_l3_len:9;       /*     0:39  8 */
        uint64_t                   inner_l4_len:8;       /*     0:48  8 */

        /* size: 8, cachelines: 1, members: 7 */
        /* bit_padding: 8 bits */
        /* last cacheline: 8 bytes */
};
Quoted 1 line

Bitfields are slow to access, compiler has to do mask/shift operations. And there is no requirement that structure be the same size.

There is no requirement that fields be ordered the same as the protocol header. Also tunnel length might get big. Why not:

struct rte_net_hdr_lens {
	uint8_t l2_len;
	uint8_t inner_l2_len;
	uint16_t l3_len;
	uint16_t inner_l3_len;
	uint16_t tunnel_len;
	uint8_t l4_len;
	uint8_t inner_l4_len;
};
#5 lore raw

Re: [dpdk-dev] [PATCH v2] net: adjust the header length parse size

Hi Stephen,

Quoted 49 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Sunday, September 6, 2020 00:56
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>; Olivier Matz <[email protected]>
Subject: Re: [PATCH v2] net: adjust the header length parse size

Quoted 39 lines · On Sat, 5 Sep 2020 11:06:46 +0800 Haiyue Wang <[email protected]> wrote:

Align to the rte_mbuf's design about Tx header length data size for the header length parse result.

	struct {
		uint64_t   l2_len:7;             /*    88: 0  8 */
		uint64_t   l3_len:9;             /*    88: 7  8 */
		uint64_t   l4_len:8;             /*    88:16  8 */
		uint64_t   tso_segsz:16;         /*    88:24  8 */
		uint64_t   outer_l3_len:9;       /*    88:40  8 */
		uint64_t   outer_l2_len:7;       /*    88:49  8 */
	};

Now the IPv6 can support bigger extension header.

The below is the structure hole analysis result:

Before:
struct rte_net_hdr_lens {

        uint8_t                    l2_len;               /*     0     1 */
        uint8_t                    l3_len;               /*     1     1 */
        uint8_t                    l4_len;               /*     2     1 */
        uint8_t                    tunnel_len;           /*     3     1 */
        uint8_t                    inner_l2_len;         /*     4     1 */
        uint8_t                    inner_l3_len;         /*     5     1 */
        uint8_t                    inner_l4_len;         /*     6     1 */
        /* size: 7, cachelines: 1, members: 7 */
        /* last cacheline: 7 bytes */
};

Now:

struct rte_net_hdr_lens {
        uint64_t                   l2_len:7;             /*     0: 0  8 */
        uint64_t                   l3_len:9;             /*     0: 7  8 */
        uint64_t                   l4_len:8;             /*     0:16  8 */
        uint64_t                   tunnel_len:8;         /*     0:24  8 */
        uint64_t                   inner_l2_len:7;       /*     0:32  8 */
        uint64_t                   inner_l3_len:9;       /*     0:39  8 */
        uint64_t                   inner_l4_len:8;       /*     0:48  8 */
Quoted 8 lines
Quoted 6 lines
        /* size: 8, cachelines: 1, members: 7 */
        /* bit_padding: 8 bits */
        /* last cacheline: 8 bytes */
};

Bitfields are slow to access, compiler has to do mask/shift operations.

Yes, you are right, I use rdtsc to trace the rte_net_get_ptype run clock about 100000 times, bitfields is near 40, but original is about 30.

Quoted 6 lines

And there is no requirement that structure be the same size.

There is no requirement that fields be ordered the same as the protocol header. Also tunnel length might get big. Why not:

Quoted 10 lines
struct rte_net_hdr_lens {
	uint8_t l2_len;
	uint8_t inner_l2_len;
	uint16_t l3_len;
	uint16_t inner_l3_len;
	uint16_t tunnel_len;
	uint8_t l4_len;
	uint8_t inner_l4_len;
};

Thanks for your comment, this is better, and in v3. ;-) The run clock is nearly the same as original type.

#6 lore raw

PATCH v3 1/1 net: adjust the header length parse size

In reply to Haiyue Wang

Enlarge the L3 and tunnel header length from 8-bit to 16-bit to handle the bigger headers. And reorder the fields to avoid creating a structure hole.

---
v2: use bit field to avoid creating a structure hole.
v3: use basic type and reorder to avoid structure hole.

---
 lib/librte_net/rte_net.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/librte_net/rte_net.h +4 -4
index 94b06d9ee..434435ffa 100644
@@ -20,11 +20,11 @@ extern "C" {
  */
 struct rte_net_hdr_lens {
 	uint8_t l2_len;
-	uint8_t l3_len;
-	uint8_t l4_len;
-	uint8_t tunnel_len;
 	uint8_t inner_l2_len;
-	uint8_t inner_l3_len;
+	uint16_t l3_len;
+	uint16_t inner_l3_len;
+	uint16_t tunnel_len;
+	uint8_t l4_len;
 	uint8_t inner_l4_len;
 };
 
Signature · 1 line
2.28.0
Acked-by on v3 1/1
#7 lore raw

Re: [dpdk-dev] [PATCH v3] net: adjust the header length parse size

Quoted 22 lines · On Mon, 7 Sep 2020 09:56:50 +0800 Haiyue Wang <[email protected]> wrote:

Enlarge the L3 and tunnel header length from 8-bit to 16-bit to handle the bigger headers. And reorder the fields to avoid creating a structure hole.

---
v2: use bit field to avoid creating a structure hole.
v3: use basic type and reorder to avoid structure hole.

---
 lib/librte_net/rte_net.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/librte_net/rte_net.h +0 -2
index 94b06d9ee..434435ffa 100644
@@ -20,11 +20,11 @@ extern "C" {
  */
 struct rte_net_hdr_lens {
 	uint8_t l2_len;
-	uint8_t l3_len;
-	uint8_t l4_len;

lib/librte_net/rte_net.h extern "C" { · line 30

Quoted 10 lines
lib/librte_net/rte_net.h +4 -2
-	uint8_t tunnel_len;
 	uint8_t inner_l2_len;
-	uint8_t inner_l3_len;
+	uint16_t l3_len;
+	uint16_t inner_l3_len;
+	uint16_t tunnel_len;
+	uint8_t l4_len;
 	uint8_t inner_l4_len;
 };
 
Applied
#8 lore raw

Re: [dpdk-dev] [PATCH v3] net: adjust the header length parse size

Quoted 29 lines · Stephen Hemminger
Quoted 26 lines · On Mon, 7 Sep 2020 09:56:50 +0800 Haiyue Wang <[email protected]> wrote:

Enlarge the L3 and tunnel header length from 8-bit to 16-bit to handle the bigger headers. And reorder the fields to avoid creating a structure hole.

---
v2: use bit field to avoid creating a structure hole.
v3: use basic type and reorder to avoid structure hole.

---
  lib/librte_net/rte_net.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
lib/librte_net/rte_net.h +1 -4
index 94b06d9ee..434435ffa 100644
@@ -20,11 +20,11 @@ extern "C" {
   */
  struct rte_net_hdr_lens {
  	uint8_t l2_len;
-	uint8_t l3_len;
-	uint8_t l4_len;
-	uint8_t tunnel_len;
  	uint8_t inner_l2_len;
-	uint8_t inner_l3_len;
+	uint16_t l3_len;
Quoted 9 lines

lib/librte_net/rte_net.h extern "C" { · line 30

Quoted 6 lines
lib/librte_net/rte_net.h +3 -0
+	uint16_t inner_l3_len;
+	uint16_t tunnel_len;
+	uint8_t l4_len;
  	uint8_t inner_l4_len;
  };
 

Applied to dpdk-next-net/main, thanks.