Added new parameter "-q/--queues"

Signed-off-by: Nikita Kalyazin <[email protected]>
Reviewed-by: Ilya Maximets <[email protected]>
---
 example/generator/odp_generator.c | 63 ++++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 18 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index 085902b..ad61bb7 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -24,7 +24,8 @@
 #include <odp/helper/icmp.h>
 
 #define MAX_WORKERS            32              /**< max number of works */
-#define SHM_PKT_POOL_SIZE      (512*2048)      /**< pkt pool size */
+#define MAX_QUEUES             32              /**< max number of queues */
+#define SHM_PKT_POOL_SIZE      (32 * 512 * 2048) /**< pkt pool size */
 #define SHM_PKT_POOL_BUF_SIZE  1856            /**< pkt pool buf size */
 #define DEFAULT_PKT_INTERVAL   1000             /**< interval btw each pkt */
 
@@ -43,6 +44,7 @@
  */
 typedef struct {
        int cpu_count;          /**< system CPU count */
+       int num_queues;         /**< number of queues */
        const char *mask;       /**< CPU mask */
        int if_count;           /**< Number of interfaces to be used */
        char **if_names;        /**< Array of pointers to interface names */
@@ -74,6 +76,7 @@ static struct {
  */
 typedef struct {
        char *pktio_dev;        /**< Interface name to use */
+       uint32_t queue_idx;     /**< Queue index to use */
        odp_pool_t pool;        /**< Pool for packet IO */
        odp_timer_pool_t tp;    /**< Timer pool handle */
        odp_queue_t tq;         /**< Queue for timeouts */
@@ -321,14 +324,16 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool)
  * @return The handle of the created pktio object.
  * @warning This routine aborts if the create is unsuccessful.
  */
-static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool)
+static odp_pktio_t create_pktio(const char *dev, int num_queues,
+                               odp_pool_t pool)
 {
        odp_queue_param_t qparam;
        char inq_name[ODP_QUEUE_NAME_LEN];
        odp_pktio_t pktio;
        int ret;
-       odp_queue_t inq_def;
+       odp_queue_t inqs_def[MAX_QUEUES];
        odp_pktio_param_t pktio_param;
+       int i;
 
        memset(&pktio_param, 0, sizeof(pktio_param));
        pktio_param.in_mode = ODP_PKTIN_MODE_SCHED;
@@ -347,15 +352,25 @@ static odp_pktio_t create_pktio(const char *dev, 
odp_pool_t pool)
        qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
        qparam.sched.sync  = ODP_SCHED_SYNC_ATOMIC;
        qparam.sched.group = ODP_SCHED_GROUP_ALL;
-       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);
-       if (inq_def == ODP_QUEUE_INVALID)
-               EXAMPLE_ABORT("Error: pktio inq create failed for %s\n", dev);
+       for (i = 0; i < num_queues; i++) {
+               snprintf(inq_name, sizeof(inq_name),
+                        "%" PRIu64 "-%d-pktio_inq_def",
+                        odp_pktio_to_u64(pktio), i);
+               inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0';
+
+               inqs_def[i] = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN,
+                                             &qparam);
+               if (inqs_def[i] == ODP_QUEUE_INVALID)
+                       EXAMPLE_ABORT("Error: pktio inq create failed for %s 
(%d)\n",
+                                     dev, i);
+       }
 
-       ret = odp_pktio_inq_setdef(pktio, inq_def);
+       ret = odp_pktio_configure(pktio, num_queues, num_queues);
+       if (ret != 0)
+               EXAMPLE_ABORT("Error: unable to configure %s\n", dev);
+
+       ret = odp_pktio_inqs_setdef(pktio, inqs_def);
        if (ret != 0)
                EXAMPLE_ABORT("Error: default input-Q setup for %s\n", dev);
 
@@ -366,9 +381,11 @@ static odp_pktio_t create_pktio(const char *dev, 
odp_pool_t pool)
        printf("  created pktio:%02" PRIu64
               ", dev:%s, queue mode (ATOMIC queues)\n"
               "          default pktio%02" PRIu64
-              "-INPUT queue:%" PRIu64 "\n",
+              "-INPUT queues:%" PRIu64 "-%" PRIu64 "\n",
               odp_pktio_to_u64(pktio), dev,
-              odp_pktio_to_u64(pktio), odp_queue_to_u64(inq_def));
+              odp_pktio_to_u64(pktio),
+              odp_queue_to_u64(inqs_def[0]),
+              odp_queue_to_u64(inqs_def[num_queues - 1]));
 
        return pktio;
 }
@@ -384,7 +401,7 @@ static void *gen_send_thread(void *arg)
        int thr;
        odp_pktio_t pktio;
        thread_args_t *thr_args;
-       odp_queue_t outq_def;
+       odp_queue_t outqs_def[MAX_QUEUES];
        odp_packet_t pkt;
 
        thr = odp_thread_id();
@@ -397,8 +414,7 @@ static void *gen_send_thread(void *arg)
                return NULL;
        }
 
-       outq_def = odp_pktio_outq_getdef(pktio);
-       if (outq_def == ODP_QUEUE_INVALID) {
+       if (odp_pktio_outqs_getdef(pktio, outqs_def)) {
                EXAMPLE_ERR("  [%02i] Error: def output-Q query\n", thr);
                return NULL;
        }
@@ -419,7 +435,8 @@ static void *gen_send_thread(void *arg)
                        return NULL;
                }
 
-               err = odp_queue_enq(outq_def, odp_packet_to_event(pkt));
+               err = odp_queue_enq(outqs_def[thr_args->queue_idx],
+                                   odp_packet_to_event(pkt));
                if (err != 0) {
                        EXAMPLE_ERR("  [%02i] send pkt err!\n", thr);
                        odp_packet_free(pkt);
@@ -755,7 +772,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
        for (i = 0; i < args->appl.if_count; ++i)
-               create_pktio(args->appl.if_names[i], pool);
+               create_pktio(args->appl.if_names[i], args->appl.num_queues,
+                            pool);
 
        /* Create and init worker threads */
        memset(thread_tbl, 0, sizeof(thread_tbl));
@@ -813,13 +831,16 @@ int main(int argc, char *argv[])
                        void *(*thr_run_func) (void *);
                        int if_idx;
                        odp_queue_t tq;
+                       uint32_t queue_idx;
 
                        if_idx = i % args->appl.if_count;
+                       queue_idx = i / args->appl.if_count;
 
                        args->thread[i].pktio_dev = args->appl.if_names[if_idx];
                        tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL);
                        if (tq == ODP_QUEUE_INVALID)
                                abort();
+                       args->thread[i].queue_idx = queue_idx;
                        args->thread[i].pool = pool;
                        args->thread[i].tp = tp;
                        args->thread[i].tq = tq;
@@ -886,6 +907,7 @@ static void parse_args(int argc, char *argv[], appl_args_t 
*appl_args)
        static struct option longopts[] = {
                {"interface", required_argument, NULL, 'I'},
                {"workers", required_argument, NULL, 'w'},
+               {"queues", required_argument, NULL, 'q'},
                {"cpumask", required_argument, NULL, 'c'},
                {"srcmac", required_argument, NULL, 'a'},
                {"dstmac", required_argument, NULL, 'b'},
@@ -904,9 +926,10 @@ static void parse_args(int argc, char *argv[], appl_args_t 
*appl_args)
        appl_args->number = -1;
        appl_args->payload = 56;
        appl_args->timeout = -1;
+       appl_args->num_queues = 1;
 
        while (1) {
-               opt = getopt_long(argc, argv, "+I:a:b:s:d:p:i:m:n:t:w:c:h",
+               opt = getopt_long(argc, argv, "+I:a:b:s:d:p:i:m:n:t:w:c:h:q:",
                                  longopts, &long_index);
                if (opt == -1)
                        break;  /* No more options */
@@ -915,6 +938,9 @@ static void parse_args(int argc, char *argv[], appl_args_t 
*appl_args)
                case 'w':
                        appl_args->cpu_count = atoi(optarg);
                        break;
+               case 'q':
+                       appl_args->num_queues = atoi(optarg);
+                       break;
                case 'c':
                        appl_args->mask = optarg;
                        odp_cpumask_from_str(&cpumask_args, args->appl.mask);
@@ -1124,6 +1150,7 @@ static void usage(char *progname)
               "                 default is 1000ms. 0 for flood mode\n"
               "  -w, --workers specify number of workers need to be assigned 
to application\n"
               "                 default is to assign all\n"
+              "  -q, --queues the number of queues to open in pktio\n"
               "  -n, --count the number of packets to be send\n"
               "  -c, --cpumask to set on cores\n"
               "\n", NO_PATH(progname), NO_PATH(progname)
-- 
2.5.3

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to