Message ID | 1424109373-29629-1-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | Superseded |
Headers | show |
On Mon, Feb 16, 2015 at 08:56:13PM +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> > --- > example/packet/odp_pktio.c | 75 +++++++++++++++++++++++++++++++++------------- > 1 file changed, 55 insertions(+), 20 deletions(-) > > diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c > index 5eec796..537bb8a 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_SHED Typo, _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. > @@ -113,13 +118,22 @@ 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) > + switch (mode) { > + case APPL_MODE_PKT_BURST: > + /* no further setup needed for burst mode */ > return pktio; > + case APPL_MODE_PKT_QUEUE: > + qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; > + qparam.sched.sync = ODP_SCHED_SYNC_NONE; > + qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; These params have no effect if we're not using the scheduler so it's confusing to configure them, it would be better just to pass NULL to odp_queue_create(). > + 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; > + break; > + } > > - 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'; > @@ -177,17 +191,20 @@ static void *pktio_queue_thread(void *arg) > 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: > + /* Always dequeue from the same input queue */ > + ev = odp_queue_deq(odp_pktio_inq_getdef(pktio)); The odp_pktio_inq_getdef() should be outside of the loop. > + 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; The patch doesn't build for me; error: ‘ev’ may be used uninitialized in this function > + } > > /* Drop packets with errors */ > if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { > @@ -544,10 +561,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_SUCCESS); EXIT_FAILURE > + } > break; > case 'h': > usage(argv[0]); > @@ -595,10 +622,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); > } > @@ -618,6 +652,7 @@ static void usage(char *progname) > " -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" > + " 2: Send&receive packets with odp_scheduler.\n" Send isn't via the scheduler, I'd reword to; 0: Receive and send directly (no queues) 1: Receive and send via queues 2: Receive via scheduler, send via queues How about also making the mode optional and have 2 be the default behaviour?
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 5eec796..537bb8a 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_SHED + * @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. @@ -113,13 +118,22 @@ 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) + switch (mode) { + case APPL_MODE_PKT_BURST: + /* no further setup needed for burst mode */ return pktio; + case APPL_MODE_PKT_QUEUE: + qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; + qparam.sched.sync = ODP_SCHED_SYNC_NONE; + qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; + 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; + break; + } - 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'; @@ -177,17 +191,20 @@ static void *pktio_queue_thread(void *arg) 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: + /* Always dequeue from the same input queue */ + ev = odp_queue_deq(odp_pktio_inq_getdef(pktio)); + 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; + } /* Drop packets with errors */ if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { @@ -544,10 +561,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_SUCCESS); + } break; case 'h': usage(argv[0]); @@ -595,10 +622,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); } @@ -618,6 +652,7 @@ static void usage(char *progname) " -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" + " 2: Send&receive packets with odp_scheduler.\n" "\n" "Optional OPTIONS\n" " -c, --count <number> CPU count.\n"
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> --- example/packet/odp_pktio.c | 75 +++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 20 deletions(-)