diff mbox

[PATCHv2] example: odp_packet uncomment polling queues

Message ID 1425461175-8018-1-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit 6dcf4a8da0156c921576f15a2efd2f6f475b5db4
Headers show

Commit Message

Maxim Uvarov March 4, 2015, 9:26 a.m. UTC
odp_packet examples has polling queues commented out with if 1.
Input queue (ODP_QUEUE_TYPE_PKTIN) is not attached to scheduler
but it make sense in example show that packets can be accessed
with polling queues also.
https://bugs.linaro.org/show_bug.cgi?id=301

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 v2: fix bunch of Stuarts comments.

 example/packet/odp_pktio.c | 99 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 72 insertions(+), 27 deletions(-)

Comments

Stuart Haslam March 5, 2015, 12:41 p.m. UTC | #1
On Wed, Mar 04, 2015 at 12:26:15PM +0300, Maxim Uvarov wrote:
> odp_packet examples has polling queues commented out with if 1.
> Input queue (ODP_QUEUE_TYPE_PKTIN) is not attached to scheduler
> but it make sense in example show that packets can be accessed
> with polling queues also.
> https://bugs.linaro.org/show_bug.cgi?id=301
> 
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  v2: fix bunch of Stuarts comments.
> 
>  example/packet/odp_pktio.c | 99 +++++++++++++++++++++++++++++++++-------------
>  1 file changed, 72 insertions(+), 27 deletions(-)
> 
> diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
> index bb07726..43f94a3 100644
> --- a/example/packet/odp_pktio.c
> +++ b/example/packet/odp_pktio.c
> @@ -52,6 +52,11 @@
>   */
>  #define APPL_MODE_PKT_QUEUE    1
>  
> +/** @def APPL_MODE_PKT_SCHED
> + * @brief The application will handle packets with sheduler
> + */
> +#define APPL_MODE_PKT_SCHED    2
> +
>  /** @def PRINT_APPL_MODE(x)
>   * @brief Macro to print the current status of how the application handles
>   * packets.
> @@ -123,18 +128,30 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode)
>  	if (pktio == ODP_PKTIO_INVALID)
>  		EXAMPLE_ABORT("Error: pktio create failed for %s\n", dev);
>  
> -	/* no further setup needed for burst mode */
> -	if (mode == APPL_MODE_PKT_BURST)
> -		return pktio;
> -
> -	qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
> -	qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
> -	qparam.sched.group = ODP_SCHED_GROUP_DEFAULT;
>  	snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def",
>  		 odp_pktio_to_u64(pktio));
>  	inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0';
>  
> -	inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam);
> +	switch (mode) {
> +	case  APPL_MODE_PKT_BURST:
> +		/* no further setup needed for burst mode */
> +		return pktio;
> +	case APPL_MODE_PKT_QUEUE:
> +		inq_def = odp_queue_create(inq_name,
> +					   ODP_QUEUE_TYPE_PKTIN, NULL);
> +		break;
> +	case APPL_MODE_PKT_SCHED:
> +		qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
> +		qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
> +		qparam.sched.group = ODP_SCHED_GROUP_DEFAULT;
> +
> +		inq_def = odp_queue_create(inq_name,
> +					   ODP_QUEUE_TYPE_PKTIN, &qparam);
> +		break;
> +	default:
> +		EXAMPLE_ABORT("invalid mode %d\n", mode);
> +	}
> +
>  	if (inq_def == ODP_QUEUE_INVALID)
>  		EXAMPLE_ABORT("Error: pktio inq create failed for %s\n", dev);
>  
> @@ -162,11 +179,13 @@ static void *pktio_queue_thread(void *arg)
>  	odp_pktio_t pktio;
>  	thread_args_t *thr_args;
>  	odp_queue_t outq_def;
> +	odp_queue_t inq;
>  	odp_packet_t pkt;
>  	odp_event_t ev;
>  	unsigned long pkt_cnt = 0;
>  	unsigned long err_cnt = 0;
>  
> +

Stray blank line

>  	thr = odp_thread_id();
>  	thr_args = arg;
>  
> @@ -183,21 +202,29 @@ static void *pktio_queue_thread(void *arg)
>  	       thr, odp_pktio_to_u64(pktio), odp_pktio_to_u64(pktio),
>  	       odp_queue_to_u64(odp_pktio_inq_getdef(pktio)));
>  
> +	/* Always dequeue from the same input queue */

This comment is only valid for the APPL_MODE_PKT_QUEUE case, and you
don't need the inq for the _SCHED case. I think it would be cleaner to
do;

if (thr_args->mode == APPL_MODE_PKT_QUEUE)
	inq = odp_pktio_inq_getdef(pktio);
else
	inq = ODP_QUEUE_INVALID;

Then in the loop

if (inq != ODP_QUEUE_INVALID)
	odp_queue_deq()
else
	odp_schedule()

> +	inq = odp_pktio_inq_getdef(pktio);
> +
>  	/* Loop packets */
>  	for (;;) {
>  		odp_pktio_t pktio_tmp;
>  
> -#if 1
> -		/* Use schedule to get buf from any input queue */
> -		ev = odp_schedule(NULL, ODP_SCHED_WAIT);
> -#else
> -		/* Always dequeue from the same input queue */
> -		buf = odp_queue_deq(inq_def);
> -		if (!odp_buffer_is_valid(buf))
> -			continue;
> -#endif
> -
> -		pkt = odp_packet_from_event(ev);
> +		switch (thr_args->mode) {
> +		case APPL_MODE_PKT_QUEUE:
> +			ev = odp_queue_deq(inq);
> +			pkt = odp_packet_from_event(ev);
> +			if (!odp_packet_is_valid(pkt))
> +				continue;
> +			break;
> +		case APPL_MODE_PKT_SCHED:
> +			/* Use schedule to get buf from any input queue */
> +			ev = odp_schedule(NULL, ODP_SCHED_WAIT);
> +			pkt = odp_packet_from_event(ev);
> +			break;
> +		default:
> +			EXAMPLE_ERR("unexpected mode %d\n", thr_args->mode);
> +			return NULL;
> +		}
>  
>  		/* Drop packets with errors */
>  		if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) {
diff mbox

Patch

diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index bb07726..43f94a3 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -52,6 +52,11 @@ 
  */
 #define APPL_MODE_PKT_QUEUE    1
 
+/** @def APPL_MODE_PKT_SCHED
+ * @brief The application will handle packets with sheduler
+ */
+#define APPL_MODE_PKT_SCHED    2
+
 /** @def PRINT_APPL_MODE(x)
  * @brief Macro to print the current status of how the application handles
  * packets.
@@ -123,18 +128,30 @@  static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode)
 	if (pktio == ODP_PKTIO_INVALID)
 		EXAMPLE_ABORT("Error: pktio create failed for %s\n", dev);
 
-	/* no further setup needed for burst mode */
-	if (mode == APPL_MODE_PKT_BURST)
-		return pktio;
-
-	qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
-	qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
-	qparam.sched.group = ODP_SCHED_GROUP_DEFAULT;
 	snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def",
 		 odp_pktio_to_u64(pktio));
 	inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0';
 
-	inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam);
+	switch (mode) {
+	case  APPL_MODE_PKT_BURST:
+		/* no further setup needed for burst mode */
+		return pktio;
+	case APPL_MODE_PKT_QUEUE:
+		inq_def = odp_queue_create(inq_name,
+					   ODP_QUEUE_TYPE_PKTIN, NULL);
+		break;
+	case APPL_MODE_PKT_SCHED:
+		qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
+		qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
+		qparam.sched.group = ODP_SCHED_GROUP_DEFAULT;
+
+		inq_def = odp_queue_create(inq_name,
+					   ODP_QUEUE_TYPE_PKTIN, &qparam);
+		break;
+	default:
+		EXAMPLE_ABORT("invalid mode %d\n", mode);
+	}
+
 	if (inq_def == ODP_QUEUE_INVALID)
 		EXAMPLE_ABORT("Error: pktio inq create failed for %s\n", dev);
 
@@ -162,11 +179,13 @@  static void *pktio_queue_thread(void *arg)
 	odp_pktio_t pktio;
 	thread_args_t *thr_args;
 	odp_queue_t outq_def;
+	odp_queue_t inq;
 	odp_packet_t pkt;
 	odp_event_t ev;
 	unsigned long pkt_cnt = 0;
 	unsigned long err_cnt = 0;
 
+
 	thr = odp_thread_id();
 	thr_args = arg;
 
@@ -183,21 +202,29 @@  static void *pktio_queue_thread(void *arg)
 	       thr, odp_pktio_to_u64(pktio), odp_pktio_to_u64(pktio),
 	       odp_queue_to_u64(odp_pktio_inq_getdef(pktio)));
 
+	/* Always dequeue from the same input queue */
+	inq = odp_pktio_inq_getdef(pktio);
+
 	/* Loop packets */
 	for (;;) {
 		odp_pktio_t pktio_tmp;
 
-#if 1
-		/* Use schedule to get buf from any input queue */
-		ev = odp_schedule(NULL, ODP_SCHED_WAIT);
-#else
-		/* Always dequeue from the same input queue */
-		buf = odp_queue_deq(inq_def);
-		if (!odp_buffer_is_valid(buf))
-			continue;
-#endif
-
-		pkt = odp_packet_from_event(ev);
+		switch (thr_args->mode) {
+		case APPL_MODE_PKT_QUEUE:
+			ev = odp_queue_deq(inq);
+			pkt = odp_packet_from_event(ev);
+			if (!odp_packet_is_valid(pkt))
+				continue;
+			break;
+		case APPL_MODE_PKT_SCHED:
+			/* Use schedule to get buf from any input queue */
+			ev = odp_schedule(NULL, ODP_SCHED_WAIT);
+			pkt = odp_packet_from_event(ev);
+			break;
+		default:
+			EXAMPLE_ERR("unexpected mode %d\n", thr_args->mode);
+			return NULL;
+		}
 
 		/* Drop packets with errors */
 		if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) {
@@ -498,10 +525,10 @@  static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
 		{NULL, 0, NULL, 0}
 	};
 
-	appl_args->mode = -1; /* Invalid, must be changed by parsing */
+	appl_args->mode = APPL_MODE_PKT_SCHED;
 
 	while (1) {
-		opt = getopt_long(argc, argv, "+c:i:m:t:h",
+		opt = getopt_long(argc, argv, "+c:i:+m:t:h",
 				  longopts, &long_index);
 
 		if (opt == -1)
@@ -554,10 +581,20 @@  static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
 
 		case 'm':
 			i = atoi(optarg);
-			if (i == 0)
+			switch (i) {
+			case 0:
 				appl_args->mode = APPL_MODE_PKT_BURST;
-			else
+				break;
+			case 1:
 				appl_args->mode = APPL_MODE_PKT_QUEUE;
+				break;
+			case 2:
+				appl_args->mode = APPL_MODE_PKT_SCHED;
+				break;
+			default:
+				usage(argv[0]);
+				exit(EXIT_FAILURE);
+			}
 			break;
 		case 'h':
 			usage(argv[0]);
@@ -605,10 +642,17 @@  static void print_info(char *progname, appl_args_t *appl_args)
 		printf(" %s", appl_args->if_names[i]);
 	printf("\n"
 	       "Mode:            ");
-	if (appl_args->mode == APPL_MODE_PKT_BURST)
+	switch (appl_args->mode) {
+	case APPL_MODE_PKT_BURST:
 		PRINT_APPL_MODE(APPL_MODE_PKT_BURST);
-	else
+		break;
+	case APPL_MODE_PKT_QUEUE:
 		PRINT_APPL_MODE(APPL_MODE_PKT_QUEUE);
+		break;
+	case APPL_MODE_PKT_SCHED:
+		PRINT_APPL_MODE(APPL_MODE_PKT_SCHED);
+		break;
+	}
 	printf("\n\n");
 	fflush(NULL);
 }
@@ -626,11 +670,12 @@  static void usage(char *progname)
 	       "\n"
 	       "Mandatory OPTIONS:\n"
 	       "  -i, --interface Eth interfaces (comma-separated, no spaces)\n"
-	       "  -m, --mode      0: Burst send&receive packets (no queues)\n"
-	       "                  1: Send&receive packets through ODP queues.\n"
 	       "\n"
 	       "Optional OPTIONS\n"
 	       "  -c, --count <number> CPU count.\n"
+	       "  -m, --mode      0: Receive and send directly (no queues)\n"
+	       "                  1: Receive and send via queues.\n"
+	       "                  2: Receive via scheduler, send via queues.\n"
 	       "  -h, --help           Display help and exit.\n"
 	       " environment variables: ODP_PKTIO_DISABLE_SOCKET_MMAP\n"
 	       "                        ODP_PKTIO_DISABLE_SOCKET_MMSG\n"