[RFC] linux-dpdk: classification: send packets to the classifier

Message ID 1461262554-21123-1-git-send-email-zoltan.kiss@linaro.org
State New
Headers show

Commit Message

Zoltan Kiss April 21, 2016, 6:15 p.m.
This patch sends the packets to the classifier if it is used. It also contains
a slightly related fix for odp-linux. I'll split it out later into a separate
patch.

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---

Comments

Balasubramanian Manoharan April 22, 2016, 9:46 a.m. | #1
On 21 April 2016 at 23:45, Zoltan Kiss <zoltan.kiss@linaro.org> wrote:

> This patch sends the packets to the classifier if it is used. It also

> contains

> a slightly related fix for odp-linux. I'll split it out later into a

> separate

> patch.

>

> Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>

> ---

> diff --git a/platform/linux-dpdk/odp_packet_dpdk.c

> b/platform/linux-dpdk/odp_packet_dpdk.c

> index d4029a9..425cbdf 100644

> --- a/platform/linux-dpdk/odp_packet_dpdk.c

> +++ b/platform/linux-dpdk/odp_packet_dpdk.c

> @@ -27,6 +27,7 @@

>  #include <odp/api/system_info.h>

>  #include <odp_debug_internal.h>

>  #include <odp_packet_io_internal.h>

> +#include <odp_classification_internal.h>

>  #include <odp_packet_dpdk.h>

>  #include <net/if.h>

>  #include <math.h>

> @@ -347,7 +348,7 @@ static void _odp_pktio_send_completion(pktio_entry_t

> *pktio_entry)

>  static int recv_pkt_dpdk_queue(pktio_entry_t *pktio_entry, int index,

>                                odp_packet_t pkt_table[], int len)

>  {

> -       uint16_t nb_rx, i = 0;

> +       uint16_t nb_rx, i = 0, j;

>         odp_packet_t *saved_pkt_table;

>         pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;

>         uint8_t min = pkt_dpdk->min_rx_burst;

> @@ -384,6 +385,13 @@ static int recv_pkt_dpdk_queue(pktio_entry_t

> *pktio_entry, int index,

>                 odp_packet_hdr(pkt_table[i])->input =

> pktio_entry->s.handle;

>         }

>

> +       if (pktio_cls_enabled(pktio_entry)) {

> +               for (i = 0, j = 0; i < nb_rx; ++i)

> +                       if (_odp_packet_classifier(pktio_entry,

> pkt_table[i]) == -2)

>


You had already posted a fix for this issue and I believe it was concluded
that all packets will  be freed only in the called and NOT in the
classifier. So why don't you apply your earlier fix here instead of
returning two different error values ( -2 and -1 ) ?

+                               pkt_table[j++] = pkt_table[i];
> +               nb_rx = j;

> +       }

> +

>         if (odp_unlikely(min > len)) {

>                 memcpy(saved_pkt_table, pkt_table,

>                        len * sizeof(odp_packet_t));

> diff --git a/platform/linux-generic/odp_classification.c

> b/platform/linux-generic/odp_classification.c

> index f5e4673..95fd613 100644

> --- a/platform/linux-generic/odp_classification.c

> +++ b/platform/linux-generic/odp_classification.c

> @@ -743,7 +743,7 @@ int _odp_packet_classifier(pktio_entry_t *entry,

> odp_packet_t pkt)

>         /* Matching PMR and selecting the CoS for the packet*/

>         cos = pktio_select_cos(entry, pkt_addr, pkt_hdr);

>         if (cos == NULL)

> -               return -1;

> +               return -2;

>

>         if (cos->s.pool == NULL) {

>                 odp_packet_free(pkt);

> @@ -766,7 +766,12 @@ int _odp_packet_classifier(pktio_entry_t *entry,

> odp_packet_t pkt)

>

>         /* Enqueuing the Packet based on the CoS */

>         queue = cos->s.queue;

> -       return queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0);

> +       if (queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0)) {

> +               odp_packet_free(new_pkt);

> +               return -1;

> +       } else {

> +               return 0;

> +       }

>  }

>

>  int packet_classifier(odp_pktio_t pktio, odp_packet_t pkt)

> diff --git a/platform/linux-generic/pktio/loop.c

> b/platform/linux-generic/pktio/loop.c

> index 0ea6d0e..e61f1b9 100644

> --- a/platform/linux-generic/pktio/loop.c

> +++ b/platform/linux-generic/pktio/loop.c

> @@ -70,7 +70,7 @@ static int loopback_recv(pktio_entry_t *pktio_entry,

> odp_packet_t pkts[],

>                         pkt_hdr = odp_packet_hdr(pkt);

>                         packet_parse_reset(pkt_hdr);

>                         packet_parse_l2(pkt_hdr);

> -                       if (0 > _odp_packet_classifier(pktio_entry, pkt)) {

> +                       if (_odp_packet_classifier(pktio_entry, pkt) ==

> -2) {

>                                 pkts[j++] = pkt;

>                                 pktio_entry->s.stats.in_octets +=

>                                         odp_packet_len(pkts[i]);

>
Zoltan Kiss April 22, 2016, 2:45 p.m. | #2
On 22/04/16 10:46, Bala Manoharan wrote:
>
>
> On 21 April 2016 at 23:45, Zoltan Kiss <zoltan.kiss@linaro.org
> <mailto:zoltan.kiss@linaro.org>> wrote:
>
>     This patch sends the packets to the classifier if it is used. It
>     also contains
>     a slightly related fix for odp-linux. I'll split it out later into a
>     separate
>     patch.
>
>     Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org
>     <mailto:zoltan.kiss@linaro.org>>
>     ---
>     diff --git a/platform/linux-dpdk/odp_packet_dpdk.c
>     b/platform/linux-dpdk/odp_packet_dpdk.c
>     index d4029a9..425cbdf 100644
>     --- a/platform/linux-dpdk/odp_packet_dpdk.c
>     +++ b/platform/linux-dpdk/odp_packet_dpdk.c
>     @@ -27,6 +27,7 @@
>       #include <odp/api/system_info.h>
>       #include <odp_debug_internal.h>
>       #include <odp_packet_io_internal.h>
>     +#include <odp_classification_internal.h>
>       #include <odp_packet_dpdk.h>
>       #include <net/if.h>
>       #include <math.h>
>     @@ -347,7 +348,7 @@ static void
>     _odp_pktio_send_completion(pktio_entry_t *pktio_entry)
>       static int recv_pkt_dpdk_queue(pktio_entry_t *pktio_entry, int index,
>                                     odp_packet_t pkt_table[], int len)
>       {
>     -       uint16_t nb_rx, i = 0;
>     +       uint16_t nb_rx, i = 0, j;
>              odp_packet_t *saved_pkt_table;
>              pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
>              uint8_t min = pkt_dpdk->min_rx_burst;
>     @@ -384,6 +385,13 @@ static int recv_pkt_dpdk_queue(pktio_entry_t
>     *pktio_entry, int index,
>                      odp_packet_hdr(pkt_table[i])->input =
>     pktio_entry->s.handle;
>              }
>
>     +       if (pktio_cls_enabled(pktio_entry)) {
>     +               for (i = 0, j = 0; i < nb_rx; ++i)
>     +                       if (_odp_packet_classifier(pktio_entry,
>     pkt_table[i]) == -2)
>
>
> You had already posted a fix for this issue and I believe it was
> concluded that all packets will  be freed only in the called and NOT in
> the classifier. So why don't you apply your earlier fix here instead of
> returning two different error values ( -2 and -1 ) ?

You are right, I forgot to upgrade the patch file before sending out. 
I'll repost

>
>     +                               pkt_table[j++] = pkt_table[i];
>     +               nb_rx = j;
>     +       }
>     +
>              if (odp_unlikely(min > len)) {
>                      memcpy(saved_pkt_table, pkt_table,
>                             len * sizeof(odp_packet_t));
>     diff --git a/platform/linux-generic/odp_classification.c
>     b/platform/linux-generic/odp_classification.c
>     index f5e4673..95fd613 100644
>     --- a/platform/linux-generic/odp_classification.c
>     +++ b/platform/linux-generic/odp_classification.c
>     @@ -743,7 +743,7 @@ int _odp_packet_classifier(pktio_entry_t *entry,
>     odp_packet_t pkt)
>              /* Matching PMR and selecting the CoS for the packet*/
>              cos = pktio_select_cos(entry, pkt_addr, pkt_hdr);
>              if (cos == NULL)
>     -               return -1;
>     +               return -2;
>
>              if (cos->s.pool == NULL) {
>                      odp_packet_free(pkt);
>     @@ -766,7 +766,12 @@ int _odp_packet_classifier(pktio_entry_t
>     *entry, odp_packet_t pkt)
>
>              /* Enqueuing the Packet based on the CoS */
>              queue = cos->s.queue;
>     -       return queue_enq(queue,
>     odp_buf_to_hdr((odp_buffer_t)new_pkt), 0);
>     +       if (queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt),
>     0)) {
>     +               odp_packet_free(new_pkt);
>     +               return -1;
>     +       } else {
>     +               return 0;
>     +       }
>       }
>
>       int packet_classifier(odp_pktio_t pktio, odp_packet_t pkt)
>     diff --git a/platform/linux-generic/pktio/loop.c
>     b/platform/linux-generic/pktio/loop.c
>     index 0ea6d0e..e61f1b9 100644
>     --- a/platform/linux-generic/pktio/loop.c
>     +++ b/platform/linux-generic/pktio/loop.c
>     @@ -70,7 +70,7 @@ static int loopback_recv(pktio_entry_t
>     *pktio_entry, odp_packet_t pkts[],
>                              pkt_hdr = odp_packet_hdr(pkt);
>                              packet_parse_reset(pkt_hdr);
>                              packet_parse_l2(pkt_hdr);
>     -                       if (0 > _odp_packet_classifier(pktio_entry,
>     pkt)) {
>     +                       if (_odp_packet_classifier(pktio_entry, pkt)
>     == -2) {
>                                      pkts[j++] = pkt;
>                                      pktio_entry->s.stats.in_octets +=
>                                              odp_packet_len(pkts[i]);
>
>

Patch hide | download patch | download mbox

diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/odp_packet_dpdk.c
index d4029a9..425cbdf 100644
--- a/platform/linux-dpdk/odp_packet_dpdk.c
+++ b/platform/linux-dpdk/odp_packet_dpdk.c
@@ -27,6 +27,7 @@ 
 #include <odp/api/system_info.h>
 #include <odp_debug_internal.h>
 #include <odp_packet_io_internal.h>
+#include <odp_classification_internal.h>
 #include <odp_packet_dpdk.h>
 #include <net/if.h>
 #include <math.h>
@@ -347,7 +348,7 @@  static void _odp_pktio_send_completion(pktio_entry_t *pktio_entry)
 static int recv_pkt_dpdk_queue(pktio_entry_t *pktio_entry, int index,
 			       odp_packet_t pkt_table[], int len)
 {
-	uint16_t nb_rx, i = 0;
+	uint16_t nb_rx, i = 0, j;
 	odp_packet_t *saved_pkt_table;
 	pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
 	uint8_t min = pkt_dpdk->min_rx_burst;
@@ -384,6 +385,13 @@  static int recv_pkt_dpdk_queue(pktio_entry_t *pktio_entry, int index,
 		odp_packet_hdr(pkt_table[i])->input = pktio_entry->s.handle;
 	}
 
+	if (pktio_cls_enabled(pktio_entry)) {
+		for (i = 0, j = 0; i < nb_rx; ++i)
+			if (_odp_packet_classifier(pktio_entry, pkt_table[i]) == -2)
+				pkt_table[j++] = pkt_table[i];
+		nb_rx = j;
+	}
+
 	if (odp_unlikely(min > len)) {
 		memcpy(saved_pkt_table, pkt_table,
 		       len * sizeof(odp_packet_t));
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index f5e4673..95fd613 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -743,7 +743,7 @@  int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt)
 	/* Matching PMR and selecting the CoS for the packet*/
 	cos = pktio_select_cos(entry, pkt_addr, pkt_hdr);
 	if (cos == NULL)
-		return -1;
+		return -2;
 
 	if (cos->s.pool == NULL) {
 		odp_packet_free(pkt);
@@ -766,7 +766,12 @@  int _odp_packet_classifier(pktio_entry_t *entry, odp_packet_t pkt)
 
 	/* Enqueuing the Packet based on the CoS */
 	queue = cos->s.queue;
-	return queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0);
+	if (queue_enq(queue, odp_buf_to_hdr((odp_buffer_t)new_pkt), 0)) {
+		odp_packet_free(new_pkt);
+		return -1;
+	} else {
+		return 0;
+	}
 }
 
 int packet_classifier(odp_pktio_t pktio, odp_packet_t pkt)
diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index 0ea6d0e..e61f1b9 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -70,7 +70,7 @@  static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[],
 			pkt_hdr = odp_packet_hdr(pkt);
 			packet_parse_reset(pkt_hdr);
 			packet_parse_l2(pkt_hdr);
-			if (0 > _odp_packet_classifier(pktio_entry, pkt)) {
+			if (_odp_packet_classifier(pktio_entry, pkt) == -2) {
 				pkts[j++] = pkt;
 				pktio_entry->s.stats.in_octets +=
 					odp_packet_len(pkts[i]);