examples/ipsec-secgw: improve IPsec dequeue logic
authorAkhil Goyal <akhil.goyal@nxp.com>
Thu, 14 Dec 2017 07:19:23 +0000 (12:49 +0530)
committerPablo de Lara <pablo.de.lara.guarch@intel.com>
Sat, 20 Jan 2018 15:10:52 +0000 (16:10 +0100)
Since the processing of crypto operations may take time
due to hardware offload, all the packets may not be available
in the single dequeue command.
So it may happen that there is leakage of cops, and there is
nobody to dequeue the packets because dequeue of crypto ops is
done only once for a particular queue pair even if it has more
packets in flight.

This patch dequeue the packets again if the inflight packets are
more than the max packet burst.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
Acked-by: Radu Nicolau <radu.nicolau@intel.com>
examples/ipsec-secgw/ipsec.c

index d764135..b2493bb 100644 (file)
@@ -423,12 +423,10 @@ ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
        struct ipsec_sa *sa;
        struct rte_mbuf *pkt;
 
-       for (i = 0; i < ipsec_ctx->nb_qps && nb_pkts < max_pkts; i++) {
+       for (i = 0; i < ipsec_ctx->nb_qps && nb_pkts < max_pkts;) {
                struct cdev_qp *cqp;
 
-               cqp = &ipsec_ctx->tbl[ipsec_ctx->last_qp++];
-               if (ipsec_ctx->last_qp == ipsec_ctx->nb_qps)
-                       ipsec_ctx->last_qp %= ipsec_ctx->nb_qps;
+               cqp = &ipsec_ctx->tbl[ipsec_ctx->last_qp];
 
                while (cqp->ol_pkts_cnt > 0 && nb_pkts < max_pkts) {
                        pkt = cqp->ol_pkts[--cqp->ol_pkts_cnt];
@@ -443,8 +441,13 @@ ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                        pkts[nb_pkts++] = pkt;
                }
 
-               if (cqp->in_flight == 0)
+               if (cqp->in_flight == 0) {
+                       ipsec_ctx->last_qp++;
+                       if (ipsec_ctx->last_qp == ipsec_ctx->nb_qps)
+                               ipsec_ctx->last_qp %= ipsec_ctx->nb_qps;
+                       i++;
                        continue;
+               }
 
                nb_cops = rte_cryptodev_dequeue_burst(cqp->id, cqp->qp,
                                cops, max_pkts - nb_pkts);
@@ -468,6 +471,12 @@ ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                                }
                        }
                        pkts[nb_pkts++] = pkt;
+                       if (cqp->in_flight < max_pkts) {
+                               ipsec_ctx->last_qp++;
+                               if (ipsec_ctx->last_qp == ipsec_ctx->nb_qps)
+                                       ipsec_ctx->last_qp %= ipsec_ctx->nb_qps;
+                               i++;
+                       }
                }
        }