4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #ifndef __INCLUDE_APP_H__
35 #define __INCLUDE_APP_H__
40 #include <rte_common.h>
41 #include <rte_mempool.h>
43 #include <rte_sched.h>
44 #include <cmdline_parse.h>
46 #include <rte_ethdev.h>
51 #include "cpu_core_map.h"
54 #define APP_PARAM_NAME_SIZE PIPELINE_NAME_SIZE
55 #define APP_LINK_PCI_BDF_SIZE 16
57 #ifndef APP_LINK_MAX_HWQ_IN
58 #define APP_LINK_MAX_HWQ_IN 128
61 #ifndef APP_LINK_MAX_HWQ_OUT
62 #define APP_LINK_MAX_HWQ_OUT 128
65 struct app_mempool_params {
71 uint32_t cpu_socket_id;
74 struct app_link_params {
77 uint32_t pmd_id; /* Generated based on port mask */
78 uint32_t arp_q; /* 0 = Disabled (packets go to default queue 0) */
79 uint32_t tcp_syn_q; /* 0 = Disabled (pkts go to default queue) */
80 uint32_t ip_local_q; /* 0 = Disabled (pkts go to default queue 0) */
81 uint32_t tcp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
82 uint32_t udp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
83 uint32_t sctp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
84 uint32_t rss_qs[APP_LINK_MAX_HWQ_IN];
86 uint64_t rss_proto_ipv4;
87 uint64_t rss_proto_ipv6;
88 uint64_t rss_proto_l2;
90 uint32_t state; /* DOWN = 0, UP = 1 */
91 uint32_t ip; /* 0 = Invalid */
92 uint32_t depth; /* Valid only when IP is valid */
93 uint64_t mac_addr; /* Read from HW */
94 char pci_bdf[APP_LINK_PCI_BDF_SIZE];
96 struct rte_eth_conf conf;
99 struct app_pktq_hwq_in_params {
102 uint32_t mempool_id; /* Position in the app->mempool_params */
106 struct rte_eth_rxconf conf;
109 struct app_pktq_hwq_out_params {
116 struct rte_eth_txconf conf;
119 struct app_pktq_swq_params {
124 uint32_t burst_write;
127 uint32_t cpu_socket_id;
133 uint32_t metadata_size;
134 uint32_t mempool_direct_id;
135 uint32_t mempool_indirect_id;
138 struct app_pktq_kni_params {
144 uint32_t hyper_th_id;
147 uint32_t mempool_id; /* Position in the app->mempool_params */
149 uint32_t burst_write;
154 #ifndef APP_FILE_NAME_SIZE
155 #define APP_FILE_NAME_SIZE 256
158 #ifndef APP_MAX_SCHED_SUBPORTS
159 #define APP_MAX_SCHED_SUBPORTS 8
162 #ifndef APP_MAX_SCHED_PIPES
163 #define APP_MAX_SCHED_PIPES 4096
166 struct app_pktq_tm_params {
169 const char *file_name;
170 struct rte_sched_port_params sched_port_params;
171 struct rte_sched_subport_params
172 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
173 struct rte_sched_pipe_params
174 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
175 int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
177 uint32_t burst_write;
180 struct app_pktq_tap_params {
184 uint32_t burst_write;
187 uint32_t mempool_id; /* Position in the app->mempool_params */
190 struct app_pktq_source_params {
193 uint32_t mempool_id; /* Position in the app->mempool_params array */
195 const char *file_name; /* Full path of PCAP file to be copied to mbufs */
196 uint32_t n_bytes_per_pkt;
199 struct app_pktq_sink_params {
202 const char *file_name; /* Full path of PCAP file to be copied to mbufs */
203 uint32_t n_pkts_to_dump;
206 struct app_msgq_params {
210 uint32_t cpu_socket_id;
213 enum app_pktq_in_type {
222 struct app_pktq_in_params {
223 enum app_pktq_in_type type;
224 uint32_t id; /* Position in the appropriate app array */
227 enum app_pktq_out_type {
236 struct app_pktq_out_params {
237 enum app_pktq_out_type type;
238 uint32_t id; /* Position in the appropriate app array */
241 #define APP_PIPELINE_TYPE_SIZE PIPELINE_TYPE_SIZE
243 #define APP_MAX_PIPELINE_PKTQ_IN PIPELINE_MAX_PORT_IN
244 #define APP_MAX_PIPELINE_PKTQ_OUT PIPELINE_MAX_PORT_OUT
245 #define APP_MAX_PIPELINE_MSGQ_IN PIPELINE_MAX_MSGQ_IN
246 #define APP_MAX_PIPELINE_MSGQ_OUT PIPELINE_MAX_MSGQ_OUT
248 #define APP_MAX_PIPELINE_ARGS PIPELINE_MAX_ARGS
250 struct app_pipeline_params {
254 char type[APP_PIPELINE_TYPE_SIZE];
258 uint32_t hyper_th_id;
260 struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
261 struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
262 uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
263 uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
270 uint32_t timer_period;
272 char *args_name[APP_MAX_PIPELINE_ARGS];
273 char *args_value[APP_MAX_PIPELINE_ARGS];
279 typedef void (*app_link_op)(struct app_params *app,
284 #ifndef APP_MAX_PIPELINES
285 #define APP_MAX_PIPELINES 64
288 struct app_link_data {
289 app_link_op f_link[APP_MAX_PIPELINES];
290 void *arg[APP_MAX_PIPELINES];
293 struct app_pipeline_data {
296 struct pipeline_type *ptype;
297 uint64_t timer_period;
301 struct app_thread_pipeline_data {
302 uint32_t pipeline_id;
304 pipeline_be_op_run f_run;
305 pipeline_be_op_timer f_timer;
306 uint64_t timer_period;
310 #ifndef APP_MAX_THREAD_PIPELINES
311 #define APP_MAX_THREAD_PIPELINES 64
314 #ifndef APP_THREAD_TIMER_PERIOD
315 #define APP_THREAD_TIMER_PERIOD 1
318 struct app_thread_data {
319 struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
320 struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
325 uint64_t timer_period;
326 uint64_t thread_req_deadline;
330 struct rte_ring *msgq_in;
331 struct rte_ring *msgq_out;
333 uint64_t headroom_time;
334 uint64_t headroom_cycles;
335 double headroom_ratio;
336 } __rte_cache_aligned;
338 #ifndef APP_MAX_LINKS
339 #define APP_MAX_LINKS 16
342 struct app_eal_params {
343 /* Map lcore set to physical cpu set */
346 /* Core ID that is used as master */
347 uint32_t master_lcore_present;
348 uint32_t master_lcore;
350 /* Number of memory channels */
351 uint32_t channels_present;
354 /* Memory to allocate (see also --socket-mem) */
355 uint32_t memory_present;
358 /* Force number of memory ranks (don't detect) */
359 uint32_t ranks_present;
362 /* Add a PCI device in black list. */
363 char *pci_blacklist[APP_MAX_LINKS];
365 /* Add a PCI device in white list. */
366 char *pci_whitelist[APP_MAX_LINKS];
368 /* Add a virtual device. */
369 char *vdev[APP_MAX_LINKS];
371 /* Use VMware TSC map instead of native RDTSC */
372 uint32_t vmware_tsc_map_present;
375 /* Type of this process (primary|secondary|auto) */
378 /* Set syslog facility */
381 /* Set default log level */
382 uint32_t log_level_present;
385 /* Display version information on startup */
386 uint32_t version_present;
390 uint32_t help_present;
393 /* Use malloc instead of hugetlbfs */
394 uint32_t no_huge_present;
398 uint32_t no_pci_present;
402 uint32_t no_hpet_present;
405 /* No shared config (mmap'd files) */
406 uint32_t no_shconf_present;
412 /* Memory to allocate on sockets (comma separated values)*/
415 /* Directory where hugetlbfs is mounted */
418 /* Prefix for hugepage filenames */
421 /* Base virtual address */
424 /* Create /dev/uioX (usually done by hotplug) */
425 uint32_t create_uio_dev_present;
428 /* Interrupt mode for VFIO (legacy|msi|msix) */
434 #ifndef APP_APPNAME_SIZE
435 #define APP_APPNAME_SIZE 256
438 #ifndef APP_MAX_MEMPOOLS
439 #define APP_MAX_MEMPOOLS 8
442 #define APP_MAX_HWQ_IN (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
444 #define APP_MAX_HWQ_OUT (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
446 #ifndef APP_MAX_PKTQ_SWQ
447 #define APP_MAX_PKTQ_SWQ 256
450 #define APP_MAX_PKTQ_TM APP_MAX_LINKS
452 #ifndef APP_MAX_PKTQ_TAP
453 #define APP_MAX_PKTQ_TAP APP_MAX_LINKS
456 #define APP_MAX_PKTQ_KNI APP_MAX_LINKS
458 #ifndef APP_MAX_PKTQ_SOURCE
459 #define APP_MAX_PKTQ_SOURCE 64
462 #ifndef APP_MAX_PKTQ_SINK
463 #define APP_MAX_PKTQ_SINK 64
467 #define APP_MAX_MSGQ 256
471 #define APP_EAL_ARGC 64
474 #ifndef APP_MAX_PIPELINE_TYPES
475 #define APP_MAX_PIPELINE_TYPES 64
478 #ifndef APP_MAX_THREADS
479 #define APP_MAX_THREADS RTE_MAX_LCORE
483 #define APP_MAX_CMDS 64
486 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
487 #define APP_THREAD_HEADROOM_STATS_COLLECT 1
490 #define APP_CORE_MASK_SIZE \
491 (RTE_MAX_LCORE / 64 + ((RTE_MAX_LCORE % 64) ? 1 : 0))
495 char app_name[APP_APPNAME_SIZE];
496 const char *config_file;
497 const char *script_file;
498 const char *parser_file;
499 const char *output_file;
501 const char *preproc_args;
505 struct app_eal_params eal_params;
506 struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
507 struct app_link_params link_params[APP_MAX_LINKS];
508 struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
509 struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
510 struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
511 struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
512 struct app_pktq_tap_params tap_params[APP_MAX_PKTQ_TAP];
513 struct app_pktq_kni_params kni_params[APP_MAX_PKTQ_KNI];
514 struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
515 struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
516 struct app_msgq_params msgq_params[APP_MAX_MSGQ];
517 struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
521 uint32_t n_pktq_hwq_in;
522 uint32_t n_pktq_hwq_out;
527 uint32_t n_pktq_source;
528 uint32_t n_pktq_sink;
530 uint32_t n_pipelines;
533 char *eal_argv[1 + APP_EAL_ARGC];
534 struct cpu_core_map *core_map;
535 uint64_t core_mask[APP_CORE_MASK_SIZE];
536 struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
537 struct app_link_data link_data[APP_MAX_LINKS];
538 struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
539 struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
540 int tap[APP_MAX_PKTQ_TAP];
541 #ifdef RTE_LIBRTE_KNI
542 struct rte_kni *kni[APP_MAX_PKTQ_KNI];
543 #endif /* RTE_LIBRTE_KNI */
544 struct rte_ring *msgq[APP_MAX_MSGQ];
545 struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
546 struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
547 struct app_thread_data thread_data[APP_MAX_THREADS];
548 cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
551 uint32_t n_pipeline_types;
555 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
557 #define APP_PARAM_COUNT(obj_array, n_objs) \
562 for (i = 0; i < RTE_DIM(obj_array); i++) \
563 if (APP_PARAM_VALID(&((obj_array)[i]))) \
567 #define APP_PARAM_FIND(obj_array, key) \
570 const ssize_t obj_count = RTE_DIM(obj_array); \
572 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) { \
573 if (!APP_PARAM_VALID(&((obj_array)[obj_idx]))) \
576 if (strcmp(key, (obj_array)[obj_idx].name) == 0) \
579 obj_idx < obj_count ? obj_idx : -ENOENT; \
582 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj) \
584 char name[APP_PARAM_NAME_SIZE]; \
587 sprintf(name, prefix "%" PRIu32, id); \
588 pos = APP_PARAM_FIND(obj_array, name); \
589 obj = (pos < 0) ? NULL : &((obj_array)[pos]); \
592 #define APP_PARAM_GET_ID(obj, prefix, id) \
594 sscanf(obj->name, prefix "%" SCNu32, &id); \
597 #define APP_CHECK(exp, fmt, ...) \
600 fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
606 APP_LOG_LEVEL_HIGH = 1,
611 #define APP_LOG(app, level, fmt, ...) \
613 if (app->log_level >= APP_LOG_LEVEL_ ## level) \
614 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__); \
617 static inline uint32_t
618 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
620 uint32_t n_rxq = 0, link_id, i;
621 uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
622 RTE_DIM(app->hwq_in_params));
624 APP_PARAM_GET_ID(link, "LINK", link_id);
626 for (i = 0; i < n_pktq_hwq_in; i++) {
627 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
628 uint32_t rxq_link_id, rxq_queue_id;
630 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
631 &rxq_link_id, &rxq_queue_id);
632 if (rxq_link_id == link_id)
639 static inline uint32_t
640 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
642 uint32_t n_txq = 0, link_id, i;
643 uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
644 RTE_DIM(app->hwq_out_params));
646 APP_PARAM_GET_ID(link, "LINK", link_id);
648 for (i = 0; i < n_pktq_hwq_out; i++) {
649 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
650 uint32_t txq_link_id, txq_queue_id;
652 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
653 &txq_link_id, &txq_queue_id);
654 if (txq_link_id == link_id)
661 static inline uint32_t
662 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
664 uint32_t pos = rxq - app->hwq_in_params;
665 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
666 RTE_DIM(app->pipeline_params));
667 uint32_t n_readers = 0, i;
669 for (i = 0; i < n_pipelines; i++) {
670 struct app_pipeline_params *p = &app->pipeline_params[i];
671 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
674 for (j = 0; j < n_pktq_in; j++) {
675 struct app_pktq_in_params *pktq = &p->pktq_in[j];
677 if ((pktq->type == APP_PKTQ_IN_HWQ) &&
686 static inline uint32_t
687 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
689 uint32_t pos = swq - app->swq_params;
690 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
691 RTE_DIM(app->pipeline_params));
692 uint32_t n_readers = 0, i;
694 for (i = 0; i < n_pipelines; i++) {
695 struct app_pipeline_params *p = &app->pipeline_params[i];
696 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
699 for (j = 0; j < n_pktq_in; j++) {
700 struct app_pktq_in_params *pktq = &p->pktq_in[j];
702 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
711 static inline struct app_pipeline_params *
712 app_swq_get_reader(struct app_params *app,
713 struct app_pktq_swq_params *swq,
714 uint32_t *pktq_in_id)
716 struct app_pipeline_params *reader = NULL;
717 uint32_t pos = swq - app->swq_params;
718 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
719 RTE_DIM(app->pipeline_params));
720 uint32_t n_readers = 0, id = 0, i;
722 for (i = 0; i < n_pipelines; i++) {
723 struct app_pipeline_params *p = &app->pipeline_params[i];
724 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
727 for (j = 0; j < n_pktq_in; j++) {
728 struct app_pktq_in_params *pktq = &p->pktq_in[j];
730 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
746 static inline uint32_t
747 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
749 uint32_t pos = tm - app->tm_params;
750 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
751 RTE_DIM(app->pipeline_params));
752 uint32_t n_readers = 0, i;
754 for (i = 0; i < n_pipelines; i++) {
755 struct app_pipeline_params *p = &app->pipeline_params[i];
756 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
759 for (j = 0; j < n_pktq_in; j++) {
760 struct app_pktq_in_params *pktq = &p->pktq_in[j];
762 if ((pktq->type == APP_PKTQ_IN_TM) &&
771 static inline struct app_pipeline_params *
772 app_tm_get_reader(struct app_params *app,
773 struct app_pktq_tm_params *tm,
774 uint32_t *pktq_in_id)
776 struct app_pipeline_params *reader = NULL;
777 uint32_t pos = tm - app->tm_params;
778 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
779 RTE_DIM(app->pipeline_params));
780 uint32_t n_readers = 0, id = 0, i;
782 for (i = 0; i < n_pipelines; i++) {
783 struct app_pipeline_params *p = &app->pipeline_params[i];
784 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
787 for (j = 0; j < n_pktq_in; j++) {
788 struct app_pktq_in_params *pktq = &p->pktq_in[j];
790 if ((pktq->type == APP_PKTQ_IN_TM) &&
806 static inline uint32_t
807 app_tap_get_readers(struct app_params *app, struct app_pktq_tap_params *tap)
809 uint32_t pos = tap - app->tap_params;
810 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
811 RTE_DIM(app->pipeline_params));
812 uint32_t n_readers = 0, i;
814 for (i = 0; i < n_pipelines; i++) {
815 struct app_pipeline_params *p = &app->pipeline_params[i];
816 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
819 for (j = 0; j < n_pktq_in; j++) {
820 struct app_pktq_in_params *pktq = &p->pktq_in[j];
822 if ((pktq->type == APP_PKTQ_IN_TAP) &&
831 static inline struct app_pipeline_params *
832 app_tap_get_reader(struct app_params *app,
833 struct app_pktq_tap_params *tap,
834 uint32_t *pktq_in_id)
836 struct app_pipeline_params *reader = NULL;
837 uint32_t pos = tap - app->tap_params;
838 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
839 RTE_DIM(app->pipeline_params));
840 uint32_t n_readers = 0, id = 0, i;
842 for (i = 0; i < n_pipelines; i++) {
843 struct app_pipeline_params *p = &app->pipeline_params[i];
844 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
847 for (j = 0; j < n_pktq_in; j++) {
848 struct app_pktq_in_params *pktq = &p->pktq_in[j];
850 if ((pktq->type == APP_PKTQ_IN_TAP) &&
866 static inline uint32_t
867 app_kni_get_readers(struct app_params *app, struct app_pktq_kni_params *kni)
869 uint32_t pos = kni - app->kni_params;
870 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
871 RTE_DIM(app->pipeline_params));
872 uint32_t n_readers = 0, i;
874 for (i = 0; i < n_pipelines; i++) {
875 struct app_pipeline_params *p = &app->pipeline_params[i];
876 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
879 for (j = 0; j < n_pktq_in; j++) {
880 struct app_pktq_in_params *pktq = &p->pktq_in[j];
882 if ((pktq->type == APP_PKTQ_IN_KNI) &&
891 static inline struct app_pipeline_params *
892 app_kni_get_reader(struct app_params *app,
893 struct app_pktq_kni_params *kni,
894 uint32_t *pktq_in_id)
896 struct app_pipeline_params *reader = NULL;
897 uint32_t pos = kni - app->kni_params;
898 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
899 RTE_DIM(app->pipeline_params));
900 uint32_t n_readers = 0, id = 0, i;
902 for (i = 0; i < n_pipelines; i++) {
903 struct app_pipeline_params *p = &app->pipeline_params[i];
904 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
907 for (j = 0; j < n_pktq_in; j++) {
908 struct app_pktq_in_params *pktq = &p->pktq_in[j];
910 if ((pktq->type == APP_PKTQ_IN_KNI) &&
926 static inline uint32_t
927 app_source_get_readers(struct app_params *app,
928 struct app_pktq_source_params *source)
930 uint32_t pos = source - app->source_params;
931 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
932 RTE_DIM(app->pipeline_params));
933 uint32_t n_readers = 0, i;
935 for (i = 0; i < n_pipelines; i++) {
936 struct app_pipeline_params *p = &app->pipeline_params[i];
937 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
940 for (j = 0; j < n_pktq_in; j++) {
941 struct app_pktq_in_params *pktq = &p->pktq_in[j];
943 if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
952 static inline uint32_t
953 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
955 uint32_t pos = msgq - app->msgq_params;
956 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
957 RTE_DIM(app->pipeline_params));
958 uint32_t n_readers = 0, i;
960 for (i = 0; i < n_pipelines; i++) {
961 struct app_pipeline_params *p = &app->pipeline_params[i];
962 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
965 for (j = 0; j < n_msgq_in; j++)
966 if (p->msgq_in[j] == pos)
973 static inline uint32_t
974 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
976 uint32_t pos = txq - app->hwq_out_params;
977 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
978 RTE_DIM(app->pipeline_params));
979 uint32_t n_writers = 0, i;
981 for (i = 0; i < n_pipelines; i++) {
982 struct app_pipeline_params *p = &app->pipeline_params[i];
983 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
984 RTE_DIM(p->pktq_out));
987 for (j = 0; j < n_pktq_out; j++) {
988 struct app_pktq_out_params *pktq = &p->pktq_out[j];
990 if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
999 static inline uint32_t
1000 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
1002 uint32_t pos = swq - app->swq_params;
1003 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1004 RTE_DIM(app->pipeline_params));
1005 uint32_t n_writers = 0, i;
1007 for (i = 0; i < n_pipelines; i++) {
1008 struct app_pipeline_params *p = &app->pipeline_params[i];
1009 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1010 RTE_DIM(p->pktq_out));
1013 for (j = 0; j < n_pktq_out; j++) {
1014 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1016 if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
1025 static inline struct app_pipeline_params *
1026 app_swq_get_writer(struct app_params *app,
1027 struct app_pktq_swq_params *swq,
1028 uint32_t *pktq_out_id)
1030 struct app_pipeline_params *writer = NULL;
1031 uint32_t pos = swq - app->swq_params;
1032 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1033 RTE_DIM(app->pipeline_params));
1034 uint32_t n_writers = 0, id = 0, i;
1036 for (i = 0; i < n_pipelines; i++) {
1037 struct app_pipeline_params *p = &app->pipeline_params[i];
1038 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1039 RTE_DIM(p->pktq_out));
1042 for (j = 0; j < n_pktq_out; j++) {
1043 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1045 if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
1046 (pktq->id == pos)) {
1061 static inline uint32_t
1062 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
1064 uint32_t pos = tm - app->tm_params;
1065 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1066 RTE_DIM(app->pipeline_params));
1067 uint32_t n_writers = 0, i;
1069 for (i = 0; i < n_pipelines; i++) {
1070 struct app_pipeline_params *p = &app->pipeline_params[i];
1071 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1072 RTE_DIM(p->pktq_out));
1075 for (j = 0; j < n_pktq_out; j++) {
1076 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1078 if ((pktq->type == APP_PKTQ_OUT_TM) &&
1087 static inline struct app_pipeline_params *
1088 app_tm_get_writer(struct app_params *app,
1089 struct app_pktq_tm_params *tm,
1090 uint32_t *pktq_out_id)
1092 struct app_pipeline_params *writer = NULL;
1093 uint32_t pos = tm - app->tm_params;
1094 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1095 RTE_DIM(app->pipeline_params));
1096 uint32_t n_writers = 0, id = 0, i;
1098 for (i = 0; i < n_pipelines; i++) {
1099 struct app_pipeline_params *p = &app->pipeline_params[i];
1100 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1101 RTE_DIM(p->pktq_out));
1104 for (j = 0; j < n_pktq_out; j++) {
1105 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1107 if ((pktq->type == APP_PKTQ_OUT_TM) &&
1108 (pktq->id == pos)) {
1123 static inline uint32_t
1124 app_tap_get_writers(struct app_params *app, struct app_pktq_tap_params *tap)
1126 uint32_t pos = tap - app->tap_params;
1127 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1128 RTE_DIM(app->pipeline_params));
1129 uint32_t n_writers = 0, i;
1131 for (i = 0; i < n_pipelines; i++) {
1132 struct app_pipeline_params *p = &app->pipeline_params[i];
1133 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1134 RTE_DIM(p->pktq_out));
1137 for (j = 0; j < n_pktq_out; j++) {
1138 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1140 if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1149 static inline struct app_pipeline_params *
1150 app_tap_get_writer(struct app_params *app,
1151 struct app_pktq_tap_params *tap,
1152 uint32_t *pktq_out_id)
1154 struct app_pipeline_params *writer = NULL;
1155 uint32_t pos = tap - app->tap_params;
1156 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1157 RTE_DIM(app->pipeline_params));
1158 uint32_t n_writers = 0, id = 0, i;
1160 for (i = 0; i < n_pipelines; i++) {
1161 struct app_pipeline_params *p = &app->pipeline_params[i];
1162 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1163 RTE_DIM(p->pktq_out));
1166 for (j = 0; j < n_pktq_out; j++) {
1167 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1169 if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1170 (pktq->id == pos)) {
1185 static inline uint32_t
1186 app_kni_get_writers(struct app_params *app, struct app_pktq_kni_params *kni)
1188 uint32_t pos = kni - app->kni_params;
1189 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1190 RTE_DIM(app->pipeline_params));
1191 uint32_t n_writers = 0, i;
1193 for (i = 0; i < n_pipelines; i++) {
1194 struct app_pipeline_params *p = &app->pipeline_params[i];
1195 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1196 RTE_DIM(p->pktq_out));
1199 for (j = 0; j < n_pktq_out; j++) {
1200 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1202 if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1211 static inline struct app_pipeline_params *
1212 app_kni_get_writer(struct app_params *app,
1213 struct app_pktq_kni_params *kni,
1214 uint32_t *pktq_out_id)
1216 struct app_pipeline_params *writer = NULL;
1217 uint32_t pos = kni - app->kni_params;
1218 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1219 RTE_DIM(app->pipeline_params));
1220 uint32_t n_writers = 0, id = 0, i;
1222 for (i = 0; i < n_pipelines; i++) {
1223 struct app_pipeline_params *p = &app->pipeline_params[i];
1224 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1225 RTE_DIM(p->pktq_out));
1228 for (j = 0; j < n_pktq_out; j++) {
1229 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1231 if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1232 (pktq->id == pos)) {
1247 static inline uint32_t
1248 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
1250 uint32_t pos = sink - app->sink_params;
1251 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1252 RTE_DIM(app->pipeline_params));
1253 uint32_t n_writers = 0, i;
1255 for (i = 0; i < n_pipelines; i++) {
1256 struct app_pipeline_params *p = &app->pipeline_params[i];
1257 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1258 RTE_DIM(p->pktq_out));
1261 for (j = 0; j < n_pktq_out; j++) {
1262 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1264 if ((pktq->type == APP_PKTQ_OUT_SINK) &&
1273 static inline uint32_t
1274 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
1276 uint32_t pos = msgq - app->msgq_params;
1277 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1278 RTE_DIM(app->pipeline_params));
1279 uint32_t n_writers = 0, i;
1281 for (i = 0; i < n_pipelines; i++) {
1282 struct app_pipeline_params *p = &app->pipeline_params[i];
1283 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
1284 RTE_DIM(p->msgq_out));
1287 for (j = 0; j < n_msgq_out; j++)
1288 if (p->msgq_out[j] == pos)
1295 static inline struct app_link_params *
1296 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
1298 char link_name[APP_PARAM_NAME_SIZE];
1299 ssize_t link_param_idx;
1300 uint32_t rxq_link_id, rxq_queue_id;
1302 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
1303 &rxq_link_id, &rxq_queue_id);
1304 sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
1305 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1306 APP_CHECK((link_param_idx >= 0),
1307 "Cannot find %s for %s", link_name, p->name);
1309 return &app->link_params[link_param_idx];
1312 static inline struct app_link_params *
1313 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
1315 char link_name[APP_PARAM_NAME_SIZE];
1316 ssize_t link_param_idx;
1317 uint32_t txq_link_id, txq_queue_id;
1319 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
1320 &txq_link_id, &txq_queue_id);
1321 sprintf(link_name, "LINK%" PRIu32, txq_link_id);
1322 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1323 APP_CHECK((link_param_idx >= 0),
1324 "Cannot find %s for %s", link_name, p->name);
1326 return &app->link_params[link_param_idx];
1329 static inline struct app_link_params *
1330 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
1332 char link_name[APP_PARAM_NAME_SIZE];
1334 ssize_t link_param_idx;
1336 sscanf(p_tm->name, "TM%" PRIu32, &link_id);
1337 sprintf(link_name, "LINK%" PRIu32, link_id);
1338 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1339 APP_CHECK((link_param_idx >= 0),
1340 "Cannot find %s for %s", link_name, p_tm->name);
1342 return &app->link_params[link_param_idx];
1345 static inline struct app_link_params *
1346 app_get_link_for_kni(struct app_params *app, struct app_pktq_kni_params *p_kni)
1348 char link_name[APP_PARAM_NAME_SIZE];
1350 ssize_t link_param_idx;
1352 sscanf(p_kni->name, "KNI%" PRIu32, &link_id);
1353 sprintf(link_name, "LINK%" PRIu32, link_id);
1354 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1355 APP_CHECK((link_param_idx >= 0),
1356 "Cannot find %s for %s", link_name, p_kni->name);
1358 return &app->link_params[link_param_idx];
1361 static inline uint32_t
1362 app_core_is_enabled(struct app_params *app, uint32_t lcore_id)
1364 return(app->core_mask[lcore_id / 64] &
1365 (1LLU << (lcore_id % 64)));
1369 app_core_enable_in_core_mask(struct app_params *app, int lcore_id)
1371 app->core_mask[lcore_id / 64] |= 1LLU << (lcore_id % 64);
1376 app_core_build_core_mask_string(struct app_params *app, char *mask_buffer)
1380 mask_buffer[0] = '\0';
1381 for (i = (int)RTE_DIM(app->core_mask); i > 0; i--) {
1382 /* For Hex representation of bits in uint64_t */
1383 char buffer[(64 / 8) * 2 + 1];
1384 memset(buffer, 0, sizeof(buffer));
1385 snprintf(buffer, sizeof(buffer), "%016" PRIx64,
1386 app->core_mask[i-1]);
1387 strcat(mask_buffer, buffer);
1391 void app_pipeline_params_get(struct app_params *app,
1392 struct app_pipeline_params *p_in,
1393 struct pipeline_params *p_out);
1395 int app_config_init(struct app_params *app);
1397 int app_config_args(struct app_params *app,
1398 int argc, char **argv);
1400 int app_config_preproc(struct app_params *app);
1402 int app_config_parse(struct app_params *app,
1403 const char *file_name);
1405 int app_config_parse_tm(struct app_params *app);
1407 void app_config_save(struct app_params *app,
1408 const char *file_name);
1410 int app_config_check(struct app_params *app);
1412 int app_init(struct app_params *app);
1414 int app_post_init(struct app_params *app);
1416 int app_thread(void *arg);
1418 int app_pipeline_type_register(struct app_params *app,
1419 struct pipeline_type *ptype);
1421 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
1424 void app_link_up_internal(struct app_params *app,
1425 struct app_link_params *cp);
1427 void app_link_down_internal(struct app_params *app,
1428 struct app_link_params *cp);