examples/ip_pipeline: measure CPU utilization
[dpdk.git] / examples / ip_pipeline / app.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef __INCLUDE_APP_H__
35 #define __INCLUDE_APP_H__
36
37 #include <stdint.h>
38 #include <string.h>
39
40 #include <rte_common.h>
41 #include <rte_mempool.h>
42 #include <rte_ring.h>
43 #include <rte_sched.h>
44 #include <cmdline_parse.h>
45
46 #include <rte_ethdev.h>
47
48 #include "cpu_core_map.h"
49 #include "pipeline.h"
50
51 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
52
53 struct app_mempool_params {
54         char *name;
55         uint32_t parsed;
56         uint32_t buffer_size;
57         uint32_t pool_size;
58         uint32_t cache_size;
59         uint32_t cpu_socket_id;
60 };
61
62 struct app_link_params {
63         char *name;
64         uint32_t parsed;
65         uint32_t pmd_id; /* Generated based on port mask */
66         uint32_t arp_q; /* 0 = Disabled (packets go to default queue 0) */
67         uint32_t tcp_syn_local_q; /* 0 = Disabled (pkts go to default queue) */
68         uint32_t ip_local_q; /* 0 = Disabled (pkts go to default queue 0) */
69         uint32_t tcp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
70         uint32_t udp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
71         uint32_t sctp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
72         uint32_t state; /* DOWN = 0, UP = 1 */
73         uint32_t ip; /* 0 = Invalid */
74         uint32_t depth; /* Valid only when IP is valid */
75         uint64_t mac_addr; /* Read from HW */
76
77         struct rte_eth_conf conf;
78         uint8_t promisc;
79 };
80
81 struct app_pktq_hwq_in_params {
82         char *name;
83         uint32_t parsed;
84         uint32_t mempool_id; /* Position in the app->mempool_params */
85         uint32_t size;
86         uint32_t burst;
87
88         struct rte_eth_rxconf conf;
89 };
90
91 struct app_pktq_hwq_out_params {
92         char *name;
93         uint32_t parsed;
94         uint32_t size;
95         uint32_t burst;
96         uint32_t dropless;
97         uint64_t n_retries;
98         struct rte_eth_txconf conf;
99 };
100
101 struct app_pktq_swq_params {
102         char *name;
103         uint32_t parsed;
104         uint32_t size;
105         uint32_t burst_read;
106         uint32_t burst_write;
107         uint32_t dropless;
108         uint64_t n_retries;
109         uint32_t cpu_socket_id;
110         uint32_t ipv4_frag;
111         uint32_t ipv6_frag;
112         uint32_t ipv4_ras;
113         uint32_t ipv6_ras;
114         uint32_t mtu;
115         uint32_t metadata_size;
116         uint32_t mempool_direct_id;
117         uint32_t mempool_indirect_id;
118 };
119
120 #ifndef APP_FILE_NAME_SIZE
121 #define APP_FILE_NAME_SIZE                       256
122 #endif
123
124 #ifndef APP_MAX_SCHED_SUBPORTS
125 #define APP_MAX_SCHED_SUBPORTS                   8
126 #endif
127
128 #ifndef APP_MAX_SCHED_PIPES
129 #define APP_MAX_SCHED_PIPES                      4096
130 #endif
131
132 struct app_pktq_tm_params {
133         char *name;
134         uint32_t parsed;
135         const char *file_name;
136         struct rte_sched_port_params sched_port_params;
137         struct rte_sched_subport_params
138                 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
139         struct rte_sched_pipe_params
140                 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
141         int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
142         uint32_t burst_read;
143         uint32_t burst_write;
144 };
145
146 struct app_pktq_source_params {
147         char *name;
148         uint32_t parsed;
149         uint32_t mempool_id; /* Position in the app->mempool_params array */
150         uint32_t burst;
151 };
152
153 struct app_pktq_sink_params {
154         char *name;
155         uint8_t parsed;
156 };
157
158 struct app_msgq_params {
159         char *name;
160         uint32_t parsed;
161         uint32_t size;
162         uint32_t cpu_socket_id;
163 };
164
165 enum app_pktq_in_type {
166         APP_PKTQ_IN_HWQ,
167         APP_PKTQ_IN_SWQ,
168         APP_PKTQ_IN_TM,
169         APP_PKTQ_IN_SOURCE,
170 };
171
172 struct app_pktq_in_params {
173         enum app_pktq_in_type type;
174         uint32_t id; /* Position in the appropriate app array */
175 };
176
177 enum app_pktq_out_type {
178         APP_PKTQ_OUT_HWQ,
179         APP_PKTQ_OUT_SWQ,
180         APP_PKTQ_OUT_TM,
181         APP_PKTQ_OUT_SINK,
182 };
183
184 struct app_pktq_out_params {
185         enum app_pktq_out_type type;
186         uint32_t id; /* Position in the appropriate app array */
187 };
188
189 #ifndef APP_PIPELINE_TYPE_SIZE
190 #define APP_PIPELINE_TYPE_SIZE                   64
191 #endif
192
193 #define APP_MAX_PIPELINE_PKTQ_IN                 PIPELINE_MAX_PORT_IN
194 #define APP_MAX_PIPELINE_PKTQ_OUT                PIPELINE_MAX_PORT_OUT
195 #define APP_MAX_PIPELINE_MSGQ_IN                 PIPELINE_MAX_MSGQ_IN
196 #define APP_MAX_PIPELINE_MSGQ_OUT                PIPELINE_MAX_MSGQ_OUT
197
198 #define APP_MAX_PIPELINE_ARGS                    PIPELINE_MAX_ARGS
199
200 struct app_pipeline_params {
201         char *name;
202         uint8_t parsed;
203
204         char type[APP_PIPELINE_TYPE_SIZE];
205
206         uint32_t socket_id;
207         uint32_t core_id;
208         uint32_t hyper_th_id;
209
210         struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
211         struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
212         uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
213         uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
214
215         uint32_t n_pktq_in;
216         uint32_t n_pktq_out;
217         uint32_t n_msgq_in;
218         uint32_t n_msgq_out;
219
220         uint32_t timer_period;
221
222         char *args_name[APP_MAX_PIPELINE_ARGS];
223         char *args_value[APP_MAX_PIPELINE_ARGS];
224         uint32_t n_args;
225 };
226
227 struct app_pipeline_data {
228         void *be;
229         void *fe;
230         struct pipeline_type *ptype;
231         uint64_t timer_period;
232         uint32_t enabled;
233 };
234
235 struct app_thread_pipeline_data {
236         uint32_t pipeline_id;
237         void *be;
238         pipeline_be_op_run f_run;
239         pipeline_be_op_timer f_timer;
240         uint64_t timer_period;
241         uint64_t deadline;
242 };
243
244 #ifndef APP_MAX_THREAD_PIPELINES
245 #define APP_MAX_THREAD_PIPELINES                 16
246 #endif
247
248 #ifndef APP_THREAD_TIMER_PERIOD
249 #define APP_THREAD_TIMER_PERIOD                  1
250 #endif
251
252 struct app_thread_data {
253         struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
254         struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
255
256         uint32_t n_regular;
257         uint32_t n_custom;
258
259         uint64_t timer_period;
260         uint64_t thread_req_deadline;
261
262         uint64_t deadline;
263
264         struct rte_ring *msgq_in;
265         struct rte_ring *msgq_out;
266
267         uint64_t headroom_time;
268         uint64_t headroom_cycles;
269         double headroom_ratio;
270 };
271
272 struct app_eal_params {
273         /* Map lcore set to physical cpu set */
274         char *coremap;
275
276         /* Core ID that is used as master */
277         uint32_t master_lcore_present;
278         uint32_t master_lcore;
279
280         /* Number of memory channels */
281         uint32_t channels_present;
282         uint32_t channels;
283
284         /* Memory to allocate (see also --socket-mem) */
285         uint32_t memory_present;
286         uint32_t memory;
287
288         /* Force number of memory ranks (don't detect) */
289         uint32_t ranks_present;
290         uint32_t ranks;
291
292         /* Add a PCI device in black list. */
293         char *pci_blacklist;
294
295         /* Add a PCI device in white list. */
296         char *pci_whitelist;
297
298         /* Add a virtual device. */
299         char *vdev;
300
301          /* Use VMware TSC map instead of native RDTSC */
302         uint32_t vmware_tsc_map_present;
303         int vmware_tsc_map;
304
305          /* Type of this process (primary|secondary|auto) */
306         char *proc_type;
307
308          /* Set syslog facility */
309         char *syslog;
310
311         /* Set default log level */
312         uint32_t log_level_present;
313         uint32_t log_level;
314
315         /* Display version information on startup */
316         uint32_t version_present;
317         int version;
318
319         /* This help */
320         uint32_t help_present;
321         int help;
322
323          /* Use malloc instead of hugetlbfs */
324         uint32_t no_huge_present;
325         int no_huge;
326
327         /* Disable PCI */
328         uint32_t no_pci_present;
329         int no_pci;
330
331         /* Disable HPET */
332         uint32_t no_hpet_present;
333         int no_hpet;
334
335         /* No shared config (mmap'd files) */
336         uint32_t no_shconf_present;
337         int no_shconf;
338
339         /* Add driver */
340         char *add_driver;
341
342         /*  Memory to allocate on sockets (comma separated values)*/
343         char *socket_mem;
344
345         /* Directory where hugetlbfs is mounted */
346         char *huge_dir;
347
348         /* Prefix for hugepage filenames */
349         char *file_prefix;
350
351         /* Base virtual address */
352         char *base_virtaddr;
353
354         /* Create /dev/uioX (usually done by hotplug) */
355         uint32_t create_uio_dev_present;
356         int create_uio_dev;
357
358         /* Interrupt mode for VFIO (legacy|msi|msix) */
359         char *vfio_intr;
360
361         /* Support running on Xen dom0 without hugetlbfs */
362         uint32_t xen_dom0_present;
363         int xen_dom0;
364 };
365
366 #ifndef APP_APPNAME_SIZE
367 #define APP_APPNAME_SIZE                         256
368 #endif
369
370 #ifndef APP_MAX_MEMPOOLS
371 #define APP_MAX_MEMPOOLS                         8
372 #endif
373
374 #ifndef APP_MAX_LINKS
375 #define APP_MAX_LINKS                            16
376 #endif
377
378 #ifndef APP_LINK_MAX_HWQ_IN
379 #define APP_LINK_MAX_HWQ_IN                      64
380 #endif
381
382 #ifndef APP_LINK_MAX_HWQ_OUT
383 #define APP_LINK_MAX_HWQ_OUT                     64
384 #endif
385
386 #define APP_MAX_HWQ_IN                     (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
387
388 #define APP_MAX_HWQ_OUT                   (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
389
390 #ifndef APP_MAX_PKTQ_SWQ
391 #define APP_MAX_PKTQ_SWQ                         256
392 #endif
393
394 #define APP_MAX_PKTQ_TM                          APP_MAX_LINKS
395
396 #ifndef APP_MAX_PKTQ_SOURCE
397 #define APP_MAX_PKTQ_SOURCE                      16
398 #endif
399
400 #ifndef APP_MAX_PKTQ_SINK
401 #define APP_MAX_PKTQ_SINK                        16
402 #endif
403
404 #ifndef APP_MAX_MSGQ
405 #define APP_MAX_MSGQ                             64
406 #endif
407
408 #ifndef APP_MAX_PIPELINES
409 #define APP_MAX_PIPELINES                        64
410 #endif
411
412 #ifndef APP_EAL_ARGC
413 #define APP_EAL_ARGC                             32
414 #endif
415
416 #ifndef APP_MAX_PIPELINE_TYPES
417 #define APP_MAX_PIPELINE_TYPES                   64
418 #endif
419
420 #ifndef APP_MAX_THREADS
421 #define APP_MAX_THREADS                          RTE_MAX_LCORE
422 #endif
423
424 #ifndef APP_MAX_CMDS
425 #define APP_MAX_CMDS                             64
426 #endif
427
428 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
429 #define APP_THREAD_HEADROOM_STATS_COLLECT        1
430 #endif
431
432 struct app_params {
433         /* Config */
434         char app_name[APP_APPNAME_SIZE];
435         const char *config_file;
436         const char *script_file;
437         const char *parser_file;
438         const char *output_file;
439         const char *preproc;
440         const char *preproc_args;
441         uint64_t port_mask;
442         uint32_t log_level;
443
444         struct app_eal_params eal_params;
445         struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
446         struct app_link_params link_params[APP_MAX_LINKS];
447         struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
448         struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
449         struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
450         struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
451         struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
452         struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
453         struct app_msgq_params msgq_params[APP_MAX_MSGQ];
454         struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
455
456         uint32_t n_mempools;
457         uint32_t n_links;
458         uint32_t n_pktq_hwq_in;
459         uint32_t n_pktq_hwq_out;
460         uint32_t n_pktq_swq;
461         uint32_t n_pktq_tm;
462         uint32_t n_pktq_source;
463         uint32_t n_pktq_sink;
464         uint32_t n_msgq;
465         uint32_t n_pipelines;
466
467         /* Init */
468         char *eal_argv[1 + APP_EAL_ARGC];
469         struct cpu_core_map *core_map;
470         uint64_t core_mask;
471         struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
472         struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
473         struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
474         struct rte_ring *msgq[APP_MAX_MSGQ];
475         struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
476         struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
477         struct app_thread_data thread_data[APP_MAX_THREADS];
478         cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
479
480         int eal_argc;
481         uint32_t n_pipeline_types;
482         uint32_t n_cmds;
483 };
484
485 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
486
487 #define APP_PARAM_COUNT(obj_array, n_objs)                              \
488 {                                                                       \
489         size_t i;                                                       \
490                                                                         \
491         n_objs = 0;                                                     \
492         for (i = 0; i < RTE_DIM(obj_array); i++)                        \
493                 if (APP_PARAM_VALID(&((obj_array)[i])))                 \
494                         n_objs++;                                       \
495 }
496
497 #define APP_PARAM_FIND(obj_array, key)                                  \
498 ({                                                                      \
499         ssize_t obj_idx;                                                \
500         const ssize_t obj_count = RTE_DIM(obj_array);                   \
501                                                                         \
502         for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {             \
503                 if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
504                         continue;                                       \
505                                                                         \
506                 if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
507                         break;                                          \
508         }                                                               \
509         obj_idx < obj_count ? obj_idx : -ENOENT;                        \
510 })
511
512 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj)                \
513 do {                                                                    \
514         char name[APP_PARAM_NAME_SIZE];                                 \
515         ssize_t pos;                                                    \
516                                                                         \
517         sprintf(name, prefix "%" PRIu32, id);                           \
518         pos = APP_PARAM_FIND(obj_array, name);                          \
519         obj = (pos < 0) ? NULL : &((obj_array)[pos]);                   \
520 } while (0)
521
522 #define APP_PARAM_GET_ID(obj, prefix, id)                               \
523 do                                                                      \
524         sscanf(obj->name, prefix "%" SCNu32, &id);                              \
525 while (0)                                                               \
526
527 #define APP_PARAM_ADD(obj_array, obj_name)                              \
528 ({                                                                      \
529         ssize_t obj_idx;                                                \
530         const ssize_t obj_count = RTE_DIM(obj_array);                   \
531                                                                         \
532         obj_idx = APP_PARAM_FIND(obj_array, obj_name);                  \
533         if (obj_idx < 0) {                                              \
534                 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {     \
535                         if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))  \
536                                 break;                                  \
537                 }                                                       \
538                                                                         \
539                 if (obj_idx < obj_count) {                              \
540                         (obj_array)[obj_idx].name = strdup(obj_name);   \
541                         if ((obj_array)[obj_idx].name == NULL)          \
542                                 obj_idx = -EINVAL;                      \
543                 } else                                                  \
544                         obj_idx = -ENOMEM;                              \
545         }                                                               \
546         obj_idx;                                                        \
547 })
548
549 #define APP_CHECK(exp, fmt, ...)                                        \
550 do {                                                                    \
551         if (!(exp)) {                                                   \
552                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
553                 abort();                                                \
554         }                                                               \
555 } while (0)
556
557 enum app_log_level {
558         APP_LOG_LEVEL_HIGH = 1,
559         APP_LOG_LEVEL_LOW,
560         APP_LOG_LEVELS
561 };
562
563 #define APP_LOG(app, level, fmt, ...)                                   \
564 do {                                                                    \
565         if (app->log_level >= APP_LOG_LEVEL_ ## level)                  \
566                 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__);     \
567 } while (0)
568
569 static inline uint32_t
570 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
571 {
572         uint32_t n_rxq = 0, link_id, i;
573         uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
574                 RTE_DIM(app->hwq_in_params));
575
576         APP_PARAM_GET_ID(link, "LINK", link_id);
577
578         for (i = 0; i < n_pktq_hwq_in; i++) {
579                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
580                 uint32_t rxq_link_id, rxq_queue_id;
581
582                 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
583                         &rxq_link_id, &rxq_queue_id);
584                 if (rxq_link_id == link_id)
585                         n_rxq++;
586         }
587
588         return n_rxq;
589 }
590
591 static inline uint32_t
592 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
593 {
594         uint32_t n_txq = 0, link_id, i;
595         uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
596                 RTE_DIM(app->hwq_out_params));
597
598         APP_PARAM_GET_ID(link, "LINK", link_id);
599
600         for (i = 0; i < n_pktq_hwq_out; i++) {
601                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
602                 uint32_t txq_link_id, txq_queue_id;
603
604                 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
605                         &txq_link_id, &txq_queue_id);
606                 if (txq_link_id == link_id)
607                         n_txq++;
608         }
609
610         return n_txq;
611 }
612
613 static inline uint32_t
614 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
615 {
616         uint32_t pos = rxq - app->hwq_in_params;
617         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
618                 RTE_DIM(app->pipeline_params));
619         uint32_t n_readers = 0, i;
620
621         for (i = 0; i < n_pipelines; i++) {
622                 struct app_pipeline_params *p = &app->pipeline_params[i];
623                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
624                 uint32_t j;
625
626                 for (j = 0; j < n_pktq_in; j++) {
627                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
628
629                         if ((pktq->type == APP_PKTQ_IN_HWQ) &&
630                                 (pktq->id == pos))
631                                 n_readers++;
632                 }
633         }
634
635         return n_readers;
636 }
637
638 static inline uint32_t
639 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
640 {
641         uint32_t pos = swq - app->swq_params;
642         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
643                 RTE_DIM(app->pipeline_params));
644         uint32_t n_readers = 0, i;
645
646         for (i = 0; i < n_pipelines; i++) {
647                 struct app_pipeline_params *p = &app->pipeline_params[i];
648                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
649                 uint32_t j;
650
651                 for (j = 0; j < n_pktq_in; j++) {
652                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
653
654                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
655                                 (pktq->id == pos))
656                                 n_readers++;
657                 }
658         }
659
660         return n_readers;
661 }
662
663 static inline uint32_t
664 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
665 {
666         uint32_t pos = tm - app->tm_params;
667         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
668                 RTE_DIM(app->pipeline_params));
669         uint32_t n_readers = 0, i;
670
671         for (i = 0; i < n_pipelines; i++) {
672                 struct app_pipeline_params *p = &app->pipeline_params[i];
673                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
674                 uint32_t j;
675
676                 for (j = 0; j < n_pktq_in; j++) {
677                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
678
679                         if ((pktq->type == APP_PKTQ_IN_TM) &&
680                                 (pktq->id == pos))
681                                 n_readers++;
682                 }
683         }
684
685         return n_readers;
686 }
687
688 static inline uint32_t
689 app_source_get_readers(struct app_params *app,
690 struct app_pktq_source_params *source)
691 {
692         uint32_t pos = source - app->source_params;
693         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
694                 RTE_DIM(app->pipeline_params));
695         uint32_t n_readers = 0, i;
696
697         for (i = 0; i < n_pipelines; i++) {
698                 struct app_pipeline_params *p = &app->pipeline_params[i];
699                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
700                 uint32_t j;
701
702                 for (j = 0; j < n_pktq_in; j++) {
703                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
704
705                         if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
706                                 (pktq->id == pos))
707                                 n_readers++;
708                 }
709         }
710
711         return n_readers;
712 }
713
714 static inline uint32_t
715 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
716 {
717         uint32_t pos = msgq - app->msgq_params;
718         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
719                 RTE_DIM(app->pipeline_params));
720         uint32_t n_readers = 0, i;
721
722         for (i = 0; i < n_pipelines; i++) {
723                 struct app_pipeline_params *p = &app->pipeline_params[i];
724                 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
725                 uint32_t j;
726
727                 for (j = 0; j < n_msgq_in; j++)
728                         if (p->msgq_in[j] == pos)
729                                 n_readers++;
730         }
731
732         return n_readers;
733 }
734
735 static inline uint32_t
736 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
737 {
738         uint32_t pos = txq - app->hwq_out_params;
739         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
740                 RTE_DIM(app->pipeline_params));
741         uint32_t n_writers = 0, i;
742
743         for (i = 0; i < n_pipelines; i++) {
744                 struct app_pipeline_params *p = &app->pipeline_params[i];
745                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
746                         RTE_DIM(p->pktq_out));
747                 uint32_t j;
748
749                 for (j = 0; j < n_pktq_out; j++) {
750                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
751
752                         if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
753                                 (pktq->id == pos))
754                                 n_writers++;
755                 }
756         }
757
758         return n_writers;
759 }
760
761 static inline uint32_t
762 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
763 {
764         uint32_t pos = swq - app->swq_params;
765         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
766                 RTE_DIM(app->pipeline_params));
767         uint32_t n_writers = 0, i;
768
769         for (i = 0; i < n_pipelines; i++) {
770                 struct app_pipeline_params *p = &app->pipeline_params[i];
771                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
772                         RTE_DIM(p->pktq_out));
773                 uint32_t j;
774
775                 for (j = 0; j < n_pktq_out; j++) {
776                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
777
778                         if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
779                                 (pktq->id == pos))
780                                 n_writers++;
781                 }
782         }
783
784         return n_writers;
785 }
786
787 static inline uint32_t
788 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
789 {
790         uint32_t pos = tm - app->tm_params;
791         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
792                 RTE_DIM(app->pipeline_params));
793         uint32_t n_writers = 0, i;
794
795         for (i = 0; i < n_pipelines; i++) {
796                 struct app_pipeline_params *p = &app->pipeline_params[i];
797                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
798                         RTE_DIM(p->pktq_out));
799                 uint32_t j;
800
801                 for (j = 0; j < n_pktq_out; j++) {
802                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
803
804                         if ((pktq->type == APP_PKTQ_OUT_TM) &&
805                                 (pktq->id == pos))
806                                 n_writers++;
807                 }
808         }
809
810         return n_writers;
811 }
812
813 static inline uint32_t
814 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
815 {
816         uint32_t pos = sink - app->sink_params;
817         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
818                 RTE_DIM(app->pipeline_params));
819         uint32_t n_writers = 0, i;
820
821         for (i = 0; i < n_pipelines; i++) {
822                 struct app_pipeline_params *p = &app->pipeline_params[i];
823                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
824                         RTE_DIM(p->pktq_out));
825                 uint32_t j;
826
827                 for (j = 0; j < n_pktq_out; j++) {
828                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
829
830                         if ((pktq->type == APP_PKTQ_OUT_SINK) &&
831                                 (pktq->id == pos))
832                                 n_writers++;
833                 }
834         }
835
836         return n_writers;
837 }
838
839 static inline uint32_t
840 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
841 {
842         uint32_t pos = msgq - app->msgq_params;
843         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
844                 RTE_DIM(app->pipeline_params));
845         uint32_t n_writers = 0, i;
846
847         for (i = 0; i < n_pipelines; i++) {
848                 struct app_pipeline_params *p = &app->pipeline_params[i];
849                 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
850                         RTE_DIM(p->msgq_out));
851                 uint32_t j;
852
853                 for (j = 0; j < n_msgq_out; j++)
854                         if (p->msgq_out[j] == pos)
855                                 n_writers++;
856         }
857
858         return n_writers;
859 }
860
861 static inline struct app_link_params *
862 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
863 {
864         char link_name[APP_PARAM_NAME_SIZE];
865         ssize_t link_param_idx;
866         uint32_t rxq_link_id, rxq_queue_id;
867
868         sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
869                 &rxq_link_id, &rxq_queue_id);
870         sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
871         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
872         APP_CHECK((link_param_idx >= 0),
873                 "Cannot find %s for %s", link_name, p->name);
874
875         return &app->link_params[link_param_idx];
876 }
877
878 static inline struct app_link_params *
879 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
880 {
881         char link_name[APP_PARAM_NAME_SIZE];
882         ssize_t link_param_idx;
883         uint32_t txq_link_id, txq_queue_id;
884
885         sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
886                 &txq_link_id, &txq_queue_id);
887         sprintf(link_name, "LINK%" PRIu32, txq_link_id);
888         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
889         APP_CHECK((link_param_idx >= 0),
890                 "Cannot find %s for %s", link_name, p->name);
891
892         return &app->link_params[link_param_idx];
893 }
894
895 static inline struct app_link_params *
896 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
897 {
898         char link_name[APP_PARAM_NAME_SIZE];
899         uint32_t link_id;
900         ssize_t link_param_idx;
901
902         sscanf(p_tm->name, "TM%" PRIu32, &link_id);
903         sprintf(link_name, "LINK%" PRIu32, link_id);
904         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
905         APP_CHECK((link_param_idx >= 0),
906                 "Cannot find %s for %s", link_name, p_tm->name);
907
908         return &app->link_params[link_param_idx];
909 }
910
911 int app_config_init(struct app_params *app);
912
913 int app_config_args(struct app_params *app,
914         int argc, char **argv);
915
916 int app_config_preproc(struct app_params *app);
917
918 int app_config_parse(struct app_params *app,
919         const char *file_name);
920
921 int app_config_parse_tm(struct app_params *app);
922
923 void app_config_save(struct app_params *app,
924         const char *file_name);
925
926 int app_config_check(struct app_params *app);
927
928 int app_init(struct app_params *app);
929
930 int app_thread(void *arg);
931
932 int app_pipeline_type_register(struct app_params *app,
933         struct pipeline_type *ptype);
934
935 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
936         char *name);
937
938 void app_link_up_internal(struct app_params *app,
939         struct app_link_params *cp);
940
941 void app_link_down_internal(struct app_params *app,
942         struct app_link_params *cp);
943
944 #endif