<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Kumara,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In your replied mail, the line doesn’t preface with “>” and it’s hard to find your replies.<o:p></o:p></p>
<p class="MsoNormal">So I reply here. In gro_tcp4_reassemble(), I mean there is no need to switch the sequences<o:p></o:p></p>
<p class="MsoNormal">of tcp_hdr and sent_seq definition statements in the code, rather than not updating them.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Jiayu<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> kumaraparameshwaran rathinavel <kumaraparamesh92@gmail.com>
<br>
<b>Sent:</b> Friday, June 9, 2023 12:52 AM<br>
<b>To:</b> Hu, Jiayu <jiayu.hu@intel.com><br>
<b>Cc:</b> dev@dpdk.org<br>
<b>Subject:</b> Re: [PATCH v4] gro : ipv6 changes to support GRO for TCP/ipv6<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal">Hi Jiyau,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks for the quick review comments. Will address the review comments. Require clarification in one of the comments. Please find it inline.
<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Jun 8, 2023 at 9:35 AM Hu, Jiayu <<a href="mailto:jiayu.hu@intel.com">jiayu.hu@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi Kumara,<br>
<br>
Please see replies inline.<br>
<br>
In addition, you need to update the programmer guide in generic_receive_offload_lib.rst,<br>
and release note release_23_07.rst.<br>
<br>
Thanks,<br>
Jiayu<br>
<br>
> -----Original Message-----<br>
> From: Kumara Parameshwaran <<a href="mailto:kumaraparamesh92@gmail.com" target="_blank">kumaraparamesh92@gmail.com</a>><br>
> Sent: Tuesday, June 6, 2023 10:58 PM<br>
> To: Hu, Jiayu <<a href="mailto:jiayu.hu@intel.com" target="_blank">jiayu.hu@intel.com</a>><br>
> Cc: <a href="mailto:dev@dpdk.org" target="_blank">dev@dpdk.org</a>; Kumara Parameshwaran<br>
> <<a href="mailto:kumaraparamesh92@gmail.com" target="_blank">kumaraparamesh92@gmail.com</a>><br>
> Subject: [PATCH v4] gro : ipv6 changes to support GRO for TCP/ipv6<br>
> <br>
> The patch adds GRO support for TCP/ipv6 packets. This does not include the<br>
> support for vxlan, udp ipv6 packets.<br>
> <br>
> Signed-off-by: Kumara Parameshwaran <<a href="mailto:kumaraparamesh92@gmail.com" target="_blank">kumaraparamesh92@gmail.com</a>>>
<br>
> diff --git a/lib/gro/gro_tcp.c b/lib/gro/gro_tcp.c new file mode 100644 index<br>
> 0000000000..02a7d0f8c5<br>
> --- /dev/null<br>
> +++ b/lib/gro/gro_tcp.c<br>
<br>
For gro_tcp.c and gro_tcp.h, it's better to add "_internal" in the file name.<br>
<br>
> @@ -0,0 +1,128 @@<br>
> +/* SPDX-License-Identifier: BSD-3-Clause<br>
> + * Copyright(c) 2017 Intel Corporation<br>
> + */<br>
> +#include <rte_malloc.h><br>
> +#include <rte_mbuf.h><br>
> +#include <rte_ethdev.h><br>
> +<br>
> +#include "gro_tcp.h"<br>
> +<br>
> +static inline uint32_t<br>
> +find_an_empty_item(struct gro_tcp_item *items,<br>
> +     uint32_t max_item_num)<br>
> +{<br>
> +     uint32_t i;<br>
> +<br>
> +     for (i = 0; i < max_item_num; i++)<br>
> +             if (items[i].firstseg == NULL)<br>
> +                     return i;<br>
> +     return INVALID_ARRAY_INDEX;<br>
> +}<br>
> +<br>
> +uint32_t<br>
> +insert_new_tcp_item(struct rte_mbuf *pkt,<br>
> +             struct gro_tcp_item *items,<br>
> +             uint32_t *item_num,<br>
> +             uint32_t max_item_num,<br>
> +             uint64_t start_time,<br>
> +             uint32_t prev_idx,<br>
> +             uint32_t sent_seq,<br>
> +             uint16_t ip_id,<br>
> +             uint8_t is_atomic)<br>
<br>
This function can be inline.<br>
<br>
> +{<br>
> +     uint32_t item_idx;<br>
> +<br>
> +     item_idx = find_an_empty_item(items, max_item_num);<br>
> +     if (item_idx == INVALID_ARRAY_INDEX)<br>
> +             return INVALID_ARRAY_INDEX;<br>
> +<br>
> +     items[item_idx].firstseg = pkt;<br>
> +     items[item_idx].lastseg = rte_pktmbuf_lastseg(pkt);<br>
> +     items[item_idx].start_time = start_time;<br>
> +     items[item_idx].next_pkt_idx = INVALID_ARRAY_INDEX;<br>
> +     items[item_idx].sent_seq = sent_seq;<br>
> +     items[item_idx].ip_id = ip_id;<br>
> +     items[item_idx].nb_merged = 1;<br>
> +     items[item_idx].is_atomic = is_atomic;<br>
> +     (*item_num) += 1;<br>
> +<br>
> +     /* if the previous packet exists, chain them together. */<br>
> +     if (prev_idx != INVALID_ARRAY_INDEX) {<br>
> +             items[item_idx].next_pkt_idx =<br>
> +                     items[prev_idx].next_pkt_idx;<br>
> +             items[prev_idx].next_pkt_idx = item_idx;<br>
> +     }<br>
> +<br>
> +     return item_idx;<br>
> +}<br>
> +<br>
> +uint32_t<br>
> +delete_tcp_item(struct gro_tcp_item *items, uint32_t item_idx,<br>
> +             uint32_t *item_num,<br>
> +             uint32_t prev_item_idx)<br>
> +{<br>
> +     uint32_t next_idx = items[item_idx].next_pkt_idx;<br>
> +<br>
> +     /* NULL indicates an empty item */<br>
> +     items[item_idx].firstseg = NULL;<br>
> +     (*item_num) -= 1;<br>
> +     if (prev_item_idx != INVALID_ARRAY_INDEX)<br>
> +             items[prev_item_idx].next_pkt_idx = next_idx;<br>
> +<br>
> +     return next_idx;<br>
> +}<br>
<br>
This function can be inline.<br>
<br>
> +<br>
> +int32_t<br>
> +gro_process_tcp_item(struct rte_mbuf *pkt,<br>
> +     struct rte_tcp_hdr *tcp_hdr,<br>
> +     int32_t tcp_dl,<br>
> +     struct gro_tcp_item *items,<br>
> +     uint32_t item_idx,<br>
> +     uint32_t *item_num,<br>
> +     uint32_t max_item_num,<br>
> +     uint16_t ip_id,<br>
> +     uint8_t is_atomic,<br>
> +     uint64_t start_time)<br>
<br>
It is for internal use, so it's better to remove "gro_" from the function name.<br>
<br>
> +{<br>
> +     uint32_t cur_idx;<br>
> +     uint32_t prev_idx;<br>
> +     int cmp;<br>
> +     uint32_t sent_seq;<br>
> +<br>
> +     sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);<br>
> +     /*<br>
> +      * Check all packets in the flow and try to find a neighbor for<br>
> +      * the input packet.<br>
> +      */<br>
> +     cur_idx = item_idx;<br>
> +     prev_idx = cur_idx;<br>
> +     do {<br>
> +             cmp = check_seq_option(&items[cur_idx], tcp_hdr,<br>
> +                             sent_seq, ip_id, pkt->l4_len, tcp_dl, 0,<br>
> +                             is_atomic);<br>
> +             if (cmp) {<br>
> +                     if (merge_two_tcp_packets(&items[cur_idx],<br>
> +                                             pkt, cmp, sent_seq, ip_id, 0))<br>
> +                             return 1;<br>
> +                     /*<br>
> +                      * Fail to merge the two packets, as the packet<br>
> +                      * length is greater than the max value. Store<br>
> +                      * the packet into the flow.<br>
> +                      */<br>
> +                     if (insert_new_tcp_item(pkt, items, item_num,<br>
> max_item_num, start_time, cur_idx,<br>
> +                                             sent_seq, ip_id, is_atomic) ==<br>
> +                                     INVALID_ARRAY_INDEX)<br>
> +                             return -1;<br>
> +                     return 0;<br>
> +             }<br>
> +             prev_idx = cur_idx;<br>
> +             cur_idx = items[cur_idx].next_pkt_idx;<br>
> +     } while (cur_idx != INVALID_ARRAY_INDEX);<br>
> +<br>
> +     /* Fail to find a neighbor, so store the packet into the flow. */<br>
> +     if (insert_new_tcp_item(pkt, items, item_num, max_item_num,<br>
> start_time, prev_idx, sent_seq,<br>
> +                             ip_id, is_atomic) == INVALID_ARRAY_INDEX)<br>
> +             return -1;<br>
> +<br>
> +     return 0;<br>
> +}<br>
> diff --git a/lib/gro/gro_tcp.h b/lib/gro/gro_tcp.h new file mode 100644 index<br>
> 0000000000..4b5b4eda9c<br>
> --- /dev/null<br>
> +++ b/lib/gro/gro_tcp.h<br>
> @@ -0,0 +1,209 @@<br>
> +#ifndef _GRO_TCP_H_<br>
> +#define _GRO_TCP_H_<br>
> +<br>
> +#define INVALID_ARRAY_INDEX 0xffffffffUL<br>
> +<br>
> +#include <rte_tcp.h><br>
> +<br>
> +/*<br>
> + * The max length of a IPv4 packet, which includes the length of the L3<br>
> + * header, the L4 header and the data payload.<br>
> + */<br>
> +#define MAX_IP_PKT_LENGTH UINT16_MAX<br>
> +<br>
> +/* The maximum TCP header length */<br>
> +#define MAX_TCP_HLEN 60<br>
> +#define INVALID_TCP_HDRLEN(len) \<br>
> +     (((len) < sizeof(struct rte_tcp_hdr)) || ((len) > MAX_TCP_HLEN))<br>
> +<br>
> +struct gro_tcp_flow {<br>
<br>
This structure name is confusing. In the upper layer, tcp4 and tcp6 have gro_tcp4_flow<br>
and gro_tcp6_flow, which represent a flow. Inside gro_tcp4/6_flow, there are keys,<br>
represented by struct tcp4/6_flow_key. But inside struct tcp4/6_flow_key, there is<br>
struct gro_tcp_flow. Need to rename struct gro_tcp_flow, like common_tcp_flow_key.<br>
<br>
> +     struct rte_ether_addr eth_saddr;<br>
> +     struct rte_ether_addr eth_daddr;<br>
> +     uint32_t recv_ack;<br>
> +     uint16_t src_port;<br>
> +     uint16_t dst_port;<br>
> +};<br>
> +<br>
> +#define ASSIGN_TCP_FLOW_KEY(k1, k2) \<br>
<br>
Ditto. The macro needs rename, like ASSIGN_COMMON_TCP_FLOW_KEY.<br>
<br>
> +     do {\<br>
> +             rte_ether_addr_copy(&(k1->eth_saddr), &(k2->eth_saddr)); \<br>
> +             rte_ether_addr_copy(&(k1->eth_daddr), &(k2->eth_daddr));<br>
> \<br>
> +             k2->recv_ack = k1->recv_ack; \<br>
> +             k2->src_port = k1->src_port; \<br>
> +             k2->dst_port = k1->dst_port; \<br>
> +     } while (0)<br>
> +<br>
> +struct gro_tcp_item {<br>
> +     /*<br>
> +      * The first MBUF segment of the packet. If the value<br>
> +      * is NULL, it means the item is empty.<br>
> +      */<br>
> +     struct rte_mbuf *firstseg;<br>
> +     /* The last MBUF segment of the packet */<br>
> +     struct rte_mbuf *lastseg;<br>
> +     /*<br>
> +      * The time when the first packet is inserted into the table.<br>
> +      * This value won't be updated, even if the packet is merged<br>
> +      * with other packets.<br>
> +      */<br>
> +     uint64_t start_time;<br>
> +     /*<br>
> +      * next_pkt_idx is used to chain the packets that<br>
> +      * are in the same flow but can't be merged together<br>
> +      * (e.g. caused by packet reordering).<br>
> +      */<br>
> +     uint32_t next_pkt_idx;<br>
> +     /* TCP sequence number of the packet */<br>
> +     uint32_t sent_seq;<br>
> +     /* IPv4 ID of the packet */<br>
> +     uint16_t ip_id;<br>
<br>
The ip_id field is not used by tcp6. It's better to use an union to include ip_id for IPv4 and<br>
an useless member for IPv6 with some comments to avoid confusing.<br>
<br>
> +     /* the number of merged packets */<br>
> +     uint16_t nb_merged;<br>
> +     /* Indicate if IPv4 ID can be ignored */<br>
> +     uint8_t is_atomic;<br>
> +};<br>
> +<br>
> +uint32_t<br>
> +insert_new_tcp_item(struct rte_mbuf *pkt,<br>
> +             struct gro_tcp_item *items,<br>
> +             uint32_t *item_num,<br>
> +             uint32_t table_size,<br>
> +             uint64_t start_time,<br>
> +             uint32_t prev_idx,<br>
> +             uint32_t sent_seq,<br>
> +             uint16_t ip_id,<br>
> +             uint8_t is_atomic);<br>
> +<br>
> +uint32_t<br>
> +delete_tcp_item(struct gro_tcp_item *items,<br>
> +             uint32_t item_idx,<br>
> +             uint32_t *item_num,<br>
> +             uint32_t prev_item_idx);<br>
> +<br>
> +int32_t<br>
> +gro_process_tcp_item(struct rte_mbuf *pkt,<br>
> +     struct rte_tcp_hdr *tcp_hdr,<br>
> +     int32_t tcp_dl,<br>
> +     struct gro_tcp_item *items,<br>
> +     uint32_t item_idx,<br>
> +     uint32_t *item_num,<br>
> +     uint32_t table_size,<br>
> +     uint16_t ip_id,<br>
> +     uint8_t is_atomic,<br>
> +     uint64_t start_time);<br>
> +<br>
> +/*<br>
> + * Merge two TCP packets without updating checksums.<br>
> + * If cmp is larger than 0, append the new packet to the<br>
> + * original packet. Otherwise, pre-pend the new packet to<br>
> + * the original packet.<br>
> + */<br>
> +static inline int<br>
> +merge_two_tcp_packets(struct gro_tcp_item *item,<br>
> +             struct rte_mbuf *pkt,<br>
> +             int cmp,<br>
> +             uint32_t sent_seq,<br>
> +             uint16_t ip_id,<br>
> +             uint16_t l2_offset)<br>
> +{<br>
> +     struct rte_mbuf *pkt_head, *pkt_tail, *lastseg;<br>
> +     uint16_t hdr_len, l2_len;<br>
> +<br>
> +     if (cmp > 0) {<br>
> +             pkt_head = item->firstseg;<br>
> +             pkt_tail = pkt;<br>
> +     } else {<br>
> +             pkt_head = pkt;<br>
> +             pkt_tail = item->firstseg;<br>
> +     }<br>
> +<br>
> +     /* check if the IPv4 packet length is greater than the max value */<br>
> +     hdr_len = l2_offset + pkt_head->l2_len + pkt_head->l3_len +<br>
> +             pkt_head->l4_len;<br>
> +     l2_len = l2_offset > 0 ? pkt_head->outer_l2_len : pkt_head->l2_len;<br>
> +     if (unlikely(pkt_head->pkt_len - l2_len + pkt_tail->pkt_len -<br>
> +                             hdr_len > MAX_IP_PKT_LENGTH))<br>
> +             return 0;<br>
> +<br>
> +     /* remove the packet header for the tail packet */<br>
> +     rte_pktmbuf_adj(pkt_tail, hdr_len);<br>
> +<br>
> +     /* chain two packets together */<br>
> +     if (cmp > 0) {<br>
> +             item->lastseg->next = pkt;<br>
> +             item->lastseg = rte_pktmbuf_lastseg(pkt);<br>
> +             /* update IP ID to the larger value */<br>
> +             item->ip_id = ip_id;<br>
> +     } else {<br>
> +             lastseg = rte_pktmbuf_lastseg(pkt);<br>
> +             lastseg->next = item->firstseg;<br>
> +             item->firstseg = pkt;<br>
> +             /* update sent_seq to the smaller value */<br>
> +             item->sent_seq = sent_seq;<br>
> +             item->ip_id = ip_id;<br>
> +     }<br>
> +     item->nb_merged++;<br>
> +<br>
> +     /* update MBUF metadata for the merged packet */<br>
> +     pkt_head->nb_segs += pkt_tail->nb_segs;<br>
> +     pkt_head->pkt_len += pkt_tail->pkt_len;<br>
> +<br>
> +     return 1;<br>
> +}<br>
> +<br>
> +/*<br>
> + * Check if two TCP/IPv4 packets are neighbors.<br>
> + */<br>
> +static inline int<br>
> +check_seq_option(struct gro_tcp_item *item,<br>
> +             struct rte_tcp_hdr *tcph,<br>
> +             uint32_t sent_seq,<br>
> +             uint16_t ip_id,<br>
> +             uint16_t tcp_hl,<br>
> +             uint16_t tcp_dl,<br>
> +             uint16_t l2_offset,<br>
> +             uint8_t is_atomic)<br>
> +{<br>
> +     struct rte_mbuf *pkt_orig = item->firstseg;<br>
> +     char *iph_orig;<br>
> +     struct rte_tcp_hdr *tcph_orig;<br>
> +     uint16_t len, tcp_hl_orig;<br>
> +<br>
> +     iph_orig = (char *)(rte_pktmbuf_mtod(pkt_orig, char *) +<br>
> +                     l2_offset + pkt_orig->l2_len);<br>
> +     tcph_orig = (struct rte_tcp_hdr *)(iph_orig + pkt_orig->l3_len);<br>
> +     tcp_hl_orig = pkt_orig->l4_len;<br>
> +<br>
> +     /* Check if TCP option fields equal */<br>
> +     len = RTE_MAX(tcp_hl, tcp_hl_orig) - sizeof(struct rte_tcp_hdr);<br>
> +     if ((tcp_hl != tcp_hl_orig) || ((len > 0) &&<br>
> +                             (memcmp(tcph + 1, tcph_orig + 1,<br>
> +                                     len) != 0)))<br>
> +             return 0;<br>
> +<br>
> +     /* Don't merge packets whose DF bits are different */<br>
> +     if (unlikely(item->is_atomic ^ is_atomic))<br>
> +             return 0;<br>
> +<br>
> +     /* check if the two packets are neighbors */<br>
> +     len = pkt_orig->pkt_len - l2_offset - pkt_orig->l2_len -<br>
> +             pkt_orig->l3_len - tcp_hl_orig;<br>
> +     if ((sent_seq == item->sent_seq + len) && (is_atomic ||<br>
> +                             (ip_id == item->ip_id + 1)))<br>
> +             /* append the new packet */<br>
> +             return 1;<br>
> +     else if ((sent_seq + tcp_dl == item->sent_seq) && (is_atomic ||<br>
> +                             (ip_id + item->nb_merged == item->ip_id)))<br>
> +             /* pre-pend the new packet */<br>
> +             return -1;<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +static inline int<br>
> +is_same_tcp_flow(struct gro_tcp_flow *k1, struct gro_tcp_flow *k2) {<br>
> +     return (!memcmp(k1, k2, sizeof(struct gro_tcp_flow))); }<br>
<br>
I think this function needs rename, as the result of this function cannot identify if they are
<br>
same TCP flow.<br>
<br>
> +<br>
> +#endif<br>
> diff --git a/lib/gro/gro_tcp4.c b/lib/gro/gro_tcp4.c index<br>
> 0014096e63..ffc33747c4 100644<br>
> --- a/lib/gro/gro_tcp4.c<br>
> +++ b/lib/gro/gro_tcp4.c<br>
> @@ -7,6 +7,7 @@<br>
>  #include <rte_ethdev.h><br>
> <br>
>  #include "gro_tcp4.h"<br>
> +#include "gro_tcp.h"<br>
> <br>
>  void *<br>
>  gro_tcp4_tbl_create(uint16_t socket_id, @@ -30,7 +31,7 @@<br>
> gro_tcp4_tbl_create(uint16_t socket_id,<br>
>       if (tbl == NULL)<br>
>               return NULL;<br>
> <br>
> -     size = sizeof(struct gro_tcp4_item) * entries_num;<br>
> +     size = sizeof(struct gro_tcp_item) * entries_num;<br>
>       tbl->items = rte_zmalloc_socket(__func__,<br>
>                       size,<br>
>                       RTE_CACHE_LINE_SIZE,<br>
> @@ -71,18 +72,6 @@ gro_tcp4_tbl_destroy(void *tbl)<br>
>       rte_free(tcp_tbl);<br>
>  }<br>
> <br>
> -static inline uint32_t<br>
> -find_an_empty_item(struct gro_tcp4_tbl *tbl) -{<br>
> -     uint32_t i;<br>
> -     uint32_t max_item_num = tbl->max_item_num;<br>
> -<br>
> -     for (i = 0; i < max_item_num; i++)<br>
> -             if (tbl->items[i].firstseg == NULL)<br>
> -                     return i;<br>
> -     return INVALID_ARRAY_INDEX;<br>
> -}<br>
> -<br>
>  static inline uint32_t<br>
>  find_an_empty_flow(struct gro_tcp4_tbl *tbl)  { @@ -95,56 +84,6 @@<br>
> find_an_empty_flow(struct gro_tcp4_tbl *tbl)<br>
>       return INVALID_ARRAY_INDEX;<br>
>  }<br>
> <br>
> -static inline uint32_t<br>
> -insert_new_item(struct gro_tcp4_tbl *tbl,<br>
> -             struct rte_mbuf *pkt,<br>
> -             uint64_t start_time,<br>
> -             uint32_t prev_idx,<br>
> -             uint32_t sent_seq,<br>
> -             uint16_t ip_id,<br>
> -             uint8_t is_atomic)<br>
> -{<br>
> -     uint32_t item_idx;<br>
> -<br>
> -     item_idx = find_an_empty_item(tbl);<br>
> -     if (item_idx == INVALID_ARRAY_INDEX)<br>
> -             return INVALID_ARRAY_INDEX;<br>
> -<br>
> -     tbl->items[item_idx].firstseg = pkt;<br>
> -     tbl->items[item_idx].lastseg = rte_pktmbuf_lastseg(pkt);<br>
> -     tbl->items[item_idx].start_time = start_time;<br>
> -     tbl->items[item_idx].next_pkt_idx = INVALID_ARRAY_INDEX;<br>
> -     tbl->items[item_idx].sent_seq = sent_seq;<br>
> -     tbl->items[item_idx].ip_id = ip_id;<br>
> -     tbl->items[item_idx].nb_merged = 1;<br>
> -     tbl->items[item_idx].is_atomic = is_atomic;<br>
> -     tbl->item_num++;<br>
> -<br>
> -     /* if the previous packet exists, chain them together. */<br>
> -     if (prev_idx != INVALID_ARRAY_INDEX) {<br>
> -             tbl->items[item_idx].next_pkt_idx =<br>
> -                     tbl->items[prev_idx].next_pkt_idx;<br>
> -             tbl->items[prev_idx].next_pkt_idx = item_idx;<br>
> -     }<br>
> -<br>
> -     return item_idx;<br>
> -}<br>
> -<br>
> -static inline uint32_t<br>
> -delete_item(struct gro_tcp4_tbl *tbl, uint32_t item_idx,<br>
> -             uint32_t prev_item_idx)<br>
> -{<br>
> -     uint32_t next_idx = tbl->items[item_idx].next_pkt_idx;<br>
> -<br>
> -     /* NULL indicates an empty item */<br>
> -     tbl->items[item_idx].firstseg = NULL;<br>
> -     tbl->item_num--;<br>
> -     if (prev_item_idx != INVALID_ARRAY_INDEX)<br>
> -             tbl->items[prev_item_idx].next_pkt_idx = next_idx;<br>
> -<br>
> -     return next_idx;<br>
> -}<br>
> -<br>
>  static inline uint32_t<br>
>  insert_new_flow(struct gro_tcp4_tbl *tbl,<br>
>               struct tcp4_flow_key *src,<br>
> @@ -159,13 +98,10 @@ insert_new_flow(struct gro_tcp4_tbl *tbl,<br>
> <br>
>       dst = &(tbl->flows[flow_idx].key);<br>
> <br>
> -     rte_ether_addr_copy(&(src->eth_saddr), &(dst->eth_saddr));<br>
> -     rte_ether_addr_copy(&(src->eth_daddr), &(dst->eth_daddr));<br>
> +     ASSIGN_TCP_FLOW_KEY((&src->tcp_flow), (&dst->tcp_flow));<br>
> +<br>
>       dst->ip_src_addr = src->ip_src_addr;<br>
>       dst->ip_dst_addr = src->ip_dst_addr;<br>
> -     dst->recv_ack = src->recv_ack;<br>
> -     dst->src_port = src->src_port;<br>
> -     dst->dst_port = src->dst_port;<br>
> <br>
>       tbl->flows[flow_idx].start_index = item_idx;<br>
>       tbl->flow_num++;<br>
> @@ -173,21 +109,6 @@ insert_new_flow(struct gro_tcp4_tbl *tbl,<br>
>       return flow_idx;<br>
>  }<br>
> <br>
> -/*<br>
> - * update the packet length for the flushed packet.<br>
> - */<br>
> -static inline void<br>
> -update_header(struct gro_tcp4_item *item) -{<br>
> -     struct rte_ipv4_hdr *ipv4_hdr;<br>
> -     struct rte_mbuf *pkt = item->firstseg;<br>
> -<br>
> -     ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +<br>
> -                     pkt->l2_len);<br>
> -     ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -<br>
> -                     pkt->l2_len);<br>
> -}<br>
> -<br>
>  int32_t<br>
>  gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
>               struct gro_tcp4_tbl *tbl,<br>
> @@ -195,16 +116,15 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,  {<br>
>       struct rte_ether_hdr *eth_hdr;<br>
>       struct rte_ipv4_hdr *ipv4_hdr;<br>
> -     struct rte_tcp_hdr *tcp_hdr;<br>
> -     uint32_t sent_seq;<br>
>       int32_t tcp_dl;<br>
> +     struct rte_tcp_hdr *tcp_hdr;<br>
>       uint16_t ip_id, hdr_len, frag_off, ip_tlen;<br>
>       uint8_t is_atomic;<br>
> +     uint32_t sent_seq;<br>
<br>
No need to change tcp_hdr and sent_seq here.<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">The flow matching is done in the function and if the flow is not found insert_new_tcp_item is invoked from this function itself. Did you mean to move that to the process_tcp_item as well? If that is the case we should pass the start_idx
 as INVALID_ARRAY_INDEX and in process_tcp_item check if INVALID_ARRAY_INDEX do a insert_new_tcp_item and return, do not do the sequnce number checks etc.
<o:p></o:p></p>
</blockquote>
<p class="MsoNormal">> <br>
>       struct tcp4_flow_key key;<br>
> -     uint32_t cur_idx, prev_idx, item_idx;<br>
> +     uint32_t item_idx;<br>
>       uint32_t i, max_flow_num, remaining_flow_num;<br>
> -     int cmp;<br>
>       uint8_t find;<br>
> <br>
>       /*<br>
> @@ -216,7 +136,7 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
> <br>
>       eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);<br>
>       ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);<br>
> -     tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);<br>
> +     tcp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_tcp_hdr *,<br>
> +pkt->l2_len + pkt->l3_len);<br>
>       hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;<br>
> <br>
>       /*<br>
> @@ -230,7 +150,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
>       ip_tlen = rte_be_to_cpu_16(ipv4_hdr->total_length);<br>
>       if (pkt->pkt_len > (uint32_t)(ip_tlen + pkt->l2_len))<br>
>               rte_pktmbuf_trim(pkt, pkt->pkt_len - ip_tlen - pkt->l2_len);<br>
> -<br>
>       /*<br>
>        * Don't process the packet whose payload length is less than or<br>
>        * equal to 0.<br>
> @@ -239,6 +158,13 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
>       if (tcp_dl <= 0)<br>
>               return -1;<br>
> <br>
> +     rte_ether_addr_copy(&(eth_hdr->src_addr),<br>
> &(key.tcp_flow.eth_saddr));<br>
> +     rte_ether_addr_copy(&(eth_hdr->dst_addr),<br>
> &(key.tcp_flow.eth_daddr));<br>
> +     key.ip_src_addr = ipv4_hdr->src_addr;<br>
> +     key.ip_dst_addr = ipv4_hdr->dst_addr;<br>
> +     key.tcp_flow.src_port = tcp_hdr->src_port;<br>
> +     key.tcp_flow.dst_port = tcp_hdr->dst_port;<br>
> +     key.tcp_flow.recv_ack = tcp_hdr->recv_ack;<br>
>       /*<br>
>        * Save IPv4 ID for the packet whose DF bit is 0. For the packet<br>
>        * whose DF bit is 1, IPv4 ID is ignored.<br>
> @@ -246,15 +172,6 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
>       frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);<br>
>       is_atomic = (frag_off & RTE_IPV4_HDR_DF_FLAG) ==<br>
> RTE_IPV4_HDR_DF_FLAG;<br>
>       ip_id = is_atomic ? 0 : rte_be_to_cpu_16(ipv4_hdr->packet_id);<br>
> -     sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);<br>
> -<br>
> -     rte_ether_addr_copy(&(eth_hdr->src_addr), &(key.eth_saddr));<br>
> -     rte_ether_addr_copy(&(eth_hdr->dst_addr), &(key.eth_daddr));<br>
> -     key.ip_src_addr = ipv4_hdr->src_addr;<br>
> -     key.ip_dst_addr = ipv4_hdr->dst_addr;<br>
> -     key.src_port = tcp_hdr->src_port;<br>
> -     key.dst_port = tcp_hdr->dst_port;<br>
> -     key.recv_ack = tcp_hdr->recv_ack;<br>
> <br>
>       /* Search for a matched flow. */<br>
>       max_flow_num = tbl->max_flow_num;<br>
> @@ -270,63 +187,44 @@ gro_tcp4_reassemble(struct rte_mbuf *pkt,<br>
>               }<br>
>       }<br>
> <br>
> -     /*<br>
> -      * Fail to find a matched flow. Insert a new flow and store the<br>
> -      * packet into the flow.<br>
> -      */<br>
>       if (find == 0) {<br>
> -             item_idx = insert_new_item(tbl, pkt, start_time,<br>
> -                             INVALID_ARRAY_INDEX, sent_seq, ip_id,<br>
> -                             is_atomic);<br>
> +             sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);<br>
> +             item_idx = insert_new_tcp_item(pkt, tbl->items, &tbl-<br>
> >item_num, tbl->max_item_num, start_time,<br>
> +                                             INVALID_ARRAY_INDEX,<br>
> sent_seq, ip_id,<br>
> +                                             is_atomic);<br>
>               if (item_idx == INVALID_ARRAY_INDEX)<br>
>                       return -1;<br>
>               if (insert_new_flow(tbl, &key, item_idx) ==<br>
> -                             INVALID_ARRAY_INDEX) {<br>
> +                     INVALID_ARRAY_INDEX) {<br>
>                       /*<br>
>                        * Fail to insert a new flow, so delete the<br>
>                        * stored packet.<br>
> -                      */<br>
> -                     delete_item(tbl, item_idx, INVALID_ARRAY_INDEX);<br>
> +                     */<br>
> +                     delete_tcp_item(tbl->items, item_idx, &tbl-<br>
> >item_num,<br>
> +INVALID_ARRAY_INDEX);<br>
>                       return -1;<br>
>               }<br>
>               return 0;<br>
>       }<br>
> +     item_idx = tbl->flows[i].start_index;<br>
<br>
No need to update item_idx, and you can directly pass tbl->flows[i].start_index to<br>
gro_process_tcp_item(). And same in gro_tcp6_reassemble().<br>
<br>
> <br>
> -     /*<br>
> -      * Check all packets in the flow and try to find a neighbor for<br>
> -      * the input packet.<br>
> -      */<br>
> -     cur_idx = tbl->flows[i].start_index;<br>
> -     prev_idx = cur_idx;<br>
> -     do {<br>
> -             cmp = check_seq_option(&(tbl->items[cur_idx]), tcp_hdr,<br>
> -                             sent_seq, ip_id, pkt->l4_len, tcp_dl, 0,<br>
> -                             is_atomic);<br>
> -             if (cmp) {<br>
> -                     if (merge_two_tcp4_packets(&(tbl->items[cur_idx]),<br>
> -                                             pkt, cmp, sent_seq, ip_id, 0))<br>
> -                             return 1;<br>
> -                     /*<br>
> -                      * Fail to merge the two packets, as the packet<br>
> -                      * length is greater than the max value. Store<br>
> -                      * the packet into the flow.<br>
> -                      */<br>
> -                     if (insert_new_item(tbl, pkt, start_time, cur_idx,<br>
> -                                             sent_seq, ip_id, is_atomic) ==<br>
> -                                     INVALID_ARRAY_INDEX)<br>
> -                             return -1;<br>
> -                     return 0;<br>
> -             }<br>
> -             prev_idx = cur_idx;<br>
> -             cur_idx = tbl->items[cur_idx].next_pkt_idx;<br>
> -     } while (cur_idx != INVALID_ARRAY_INDEX);<br>
> +     return gro_process_tcp_item(pkt, tcp_hdr, tcp_dl, tbl->items,<br>
> item_idx,<br>
> +                                             &tbl->item_num, tbl-<br>
> >max_item_num,<br>
> +                                             ip_id, is_atomic, start_time);<br>
> +}<br>
> <br>
> -     /* Fail to find a neighbor, so store the packet into the flow. */<br>
> -     if (insert_new_item(tbl, pkt, start_time, prev_idx, sent_seq,<br>
> -                             ip_id, is_atomic) == INVALID_ARRAY_INDEX)<br>
> -             return -1;<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>