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) */
431 /* Support running on Xen dom0 without hugetlbfs */
432 uint32_t xen_dom0_present;
438 #ifndef APP_APPNAME_SIZE
439 #define APP_APPNAME_SIZE 256
442 #ifndef APP_MAX_MEMPOOLS
443 #define APP_MAX_MEMPOOLS 8
446 #define APP_MAX_HWQ_IN (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
448 #define APP_MAX_HWQ_OUT (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
450 #ifndef APP_MAX_PKTQ_SWQ
451 #define APP_MAX_PKTQ_SWQ 256
454 #define APP_MAX_PKTQ_TM APP_MAX_LINKS
456 #ifndef APP_MAX_PKTQ_TAP
457 #define APP_MAX_PKTQ_TAP APP_MAX_LINKS
460 #define APP_MAX_PKTQ_KNI APP_MAX_LINKS
462 #ifndef APP_MAX_PKTQ_SOURCE
463 #define APP_MAX_PKTQ_SOURCE 64
466 #ifndef APP_MAX_PKTQ_SINK
467 #define APP_MAX_PKTQ_SINK 64
471 #define APP_MAX_MSGQ 256
475 #define APP_EAL_ARGC 64
478 #ifndef APP_MAX_PIPELINE_TYPES
479 #define APP_MAX_PIPELINE_TYPES 64
482 #ifndef APP_MAX_THREADS
483 #define APP_MAX_THREADS RTE_MAX_LCORE
487 #define APP_MAX_CMDS 64
490 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
491 #define APP_THREAD_HEADROOM_STATS_COLLECT 1
494 #define APP_CORE_MASK_SIZE \
495 (RTE_MAX_LCORE / 64 + ((RTE_MAX_LCORE % 64) ? 1 : 0))
499 char app_name[APP_APPNAME_SIZE];
500 const char *config_file;
501 const char *script_file;
502 const char *parser_file;
503 const char *output_file;
505 const char *preproc_args;
509 struct app_eal_params eal_params;
510 struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
511 struct app_link_params link_params[APP_MAX_LINKS];
512 struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
513 struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
514 struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
515 struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
516 struct app_pktq_tap_params tap_params[APP_MAX_PKTQ_TAP];
517 struct app_pktq_kni_params kni_params[APP_MAX_PKTQ_KNI];
518 struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
519 struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
520 struct app_msgq_params msgq_params[APP_MAX_MSGQ];
521 struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
525 uint32_t n_pktq_hwq_in;
526 uint32_t n_pktq_hwq_out;
531 uint32_t n_pktq_source;
532 uint32_t n_pktq_sink;
534 uint32_t n_pipelines;
537 char *eal_argv[1 + APP_EAL_ARGC];
538 struct cpu_core_map *core_map;
539 uint64_t core_mask[APP_CORE_MASK_SIZE];
540 struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
541 struct app_link_data link_data[APP_MAX_LINKS];
542 struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
543 struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
544 int tap[APP_MAX_PKTQ_TAP];
545 #ifdef RTE_LIBRTE_KNI
546 struct rte_kni *kni[APP_MAX_PKTQ_KNI];
547 #endif /* RTE_LIBRTE_KNI */
548 struct rte_ring *msgq[APP_MAX_MSGQ];
549 struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
550 struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
551 struct app_thread_data thread_data[APP_MAX_THREADS];
552 cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
555 uint32_t n_pipeline_types;
559 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
561 #define APP_PARAM_COUNT(obj_array, n_objs) \
566 for (i = 0; i < RTE_DIM(obj_array); i++) \
567 if (APP_PARAM_VALID(&((obj_array)[i]))) \
571 #define APP_PARAM_FIND(obj_array, key) \
574 const ssize_t obj_count = RTE_DIM(obj_array); \
576 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) { \
577 if (!APP_PARAM_VALID(&((obj_array)[obj_idx]))) \
580 if (strcmp(key, (obj_array)[obj_idx].name) == 0) \
583 obj_idx < obj_count ? obj_idx : -ENOENT; \
586 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj) \
588 char name[APP_PARAM_NAME_SIZE]; \
591 sprintf(name, prefix "%" PRIu32, id); \
592 pos = APP_PARAM_FIND(obj_array, name); \
593 obj = (pos < 0) ? NULL : &((obj_array)[pos]); \
596 #define APP_PARAM_GET_ID(obj, prefix, id) \
598 sscanf(obj->name, prefix "%" SCNu32, &id); \
601 #define APP_CHECK(exp, fmt, ...) \
604 fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
610 APP_LOG_LEVEL_HIGH = 1,
615 #define APP_LOG(app, level, fmt, ...) \
617 if (app->log_level >= APP_LOG_LEVEL_ ## level) \
618 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__); \
621 static inline uint32_t
622 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
624 uint32_t n_rxq = 0, link_id, i;
625 uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
626 RTE_DIM(app->hwq_in_params));
628 APP_PARAM_GET_ID(link, "LINK", link_id);
630 for (i = 0; i < n_pktq_hwq_in; i++) {
631 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
632 uint32_t rxq_link_id, rxq_queue_id;
634 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
635 &rxq_link_id, &rxq_queue_id);
636 if (rxq_link_id == link_id)
643 static inline uint32_t
644 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
646 uint32_t n_txq = 0, link_id, i;
647 uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
648 RTE_DIM(app->hwq_out_params));
650 APP_PARAM_GET_ID(link, "LINK", link_id);
652 for (i = 0; i < n_pktq_hwq_out; i++) {
653 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
654 uint32_t txq_link_id, txq_queue_id;
656 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
657 &txq_link_id, &txq_queue_id);
658 if (txq_link_id == link_id)
665 static inline uint32_t
666 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
668 uint32_t pos = rxq - app->hwq_in_params;
669 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
670 RTE_DIM(app->pipeline_params));
671 uint32_t n_readers = 0, i;
673 for (i = 0; i < n_pipelines; i++) {
674 struct app_pipeline_params *p = &app->pipeline_params[i];
675 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
678 for (j = 0; j < n_pktq_in; j++) {
679 struct app_pktq_in_params *pktq = &p->pktq_in[j];
681 if ((pktq->type == APP_PKTQ_IN_HWQ) &&
690 static inline uint32_t
691 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
693 uint32_t pos = swq - app->swq_params;
694 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
695 RTE_DIM(app->pipeline_params));
696 uint32_t n_readers = 0, i;
698 for (i = 0; i < n_pipelines; i++) {
699 struct app_pipeline_params *p = &app->pipeline_params[i];
700 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
703 for (j = 0; j < n_pktq_in; j++) {
704 struct app_pktq_in_params *pktq = &p->pktq_in[j];
706 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
715 static inline struct app_pipeline_params *
716 app_swq_get_reader(struct app_params *app,
717 struct app_pktq_swq_params *swq,
718 uint32_t *pktq_in_id)
720 struct app_pipeline_params *reader = NULL;
721 uint32_t pos = swq - app->swq_params;
722 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
723 RTE_DIM(app->pipeline_params));
724 uint32_t n_readers = 0, id = 0, i;
726 for (i = 0; i < n_pipelines; i++) {
727 struct app_pipeline_params *p = &app->pipeline_params[i];
728 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
731 for (j = 0; j < n_pktq_in; j++) {
732 struct app_pktq_in_params *pktq = &p->pktq_in[j];
734 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
750 static inline uint32_t
751 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
753 uint32_t pos = tm - app->tm_params;
754 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
755 RTE_DIM(app->pipeline_params));
756 uint32_t n_readers = 0, i;
758 for (i = 0; i < n_pipelines; i++) {
759 struct app_pipeline_params *p = &app->pipeline_params[i];
760 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
763 for (j = 0; j < n_pktq_in; j++) {
764 struct app_pktq_in_params *pktq = &p->pktq_in[j];
766 if ((pktq->type == APP_PKTQ_IN_TM) &&
775 static inline struct app_pipeline_params *
776 app_tm_get_reader(struct app_params *app,
777 struct app_pktq_tm_params *tm,
778 uint32_t *pktq_in_id)
780 struct app_pipeline_params *reader = NULL;
781 uint32_t pos = tm - app->tm_params;
782 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
783 RTE_DIM(app->pipeline_params));
784 uint32_t n_readers = 0, id = 0, i;
786 for (i = 0; i < n_pipelines; i++) {
787 struct app_pipeline_params *p = &app->pipeline_params[i];
788 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
791 for (j = 0; j < n_pktq_in; j++) {
792 struct app_pktq_in_params *pktq = &p->pktq_in[j];
794 if ((pktq->type == APP_PKTQ_IN_TM) &&
810 static inline uint32_t
811 app_tap_get_readers(struct app_params *app, struct app_pktq_tap_params *tap)
813 uint32_t pos = tap - app->tap_params;
814 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
815 RTE_DIM(app->pipeline_params));
816 uint32_t n_readers = 0, i;
818 for (i = 0; i < n_pipelines; i++) {
819 struct app_pipeline_params *p = &app->pipeline_params[i];
820 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
823 for (j = 0; j < n_pktq_in; j++) {
824 struct app_pktq_in_params *pktq = &p->pktq_in[j];
826 if ((pktq->type == APP_PKTQ_IN_TAP) &&
835 static inline struct app_pipeline_params *
836 app_tap_get_reader(struct app_params *app,
837 struct app_pktq_tap_params *tap,
838 uint32_t *pktq_in_id)
840 struct app_pipeline_params *reader = NULL;
841 uint32_t pos = tap - app->tap_params;
842 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
843 RTE_DIM(app->pipeline_params));
844 uint32_t n_readers = 0, id = 0, i;
846 for (i = 0; i < n_pipelines; i++) {
847 struct app_pipeline_params *p = &app->pipeline_params[i];
848 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
851 for (j = 0; j < n_pktq_in; j++) {
852 struct app_pktq_in_params *pktq = &p->pktq_in[j];
854 if ((pktq->type == APP_PKTQ_IN_TAP) &&
870 static inline uint32_t
871 app_kni_get_readers(struct app_params *app, struct app_pktq_kni_params *kni)
873 uint32_t pos = kni - app->kni_params;
874 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
875 RTE_DIM(app->pipeline_params));
876 uint32_t n_readers = 0, i;
878 for (i = 0; i < n_pipelines; i++) {
879 struct app_pipeline_params *p = &app->pipeline_params[i];
880 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
883 for (j = 0; j < n_pktq_in; j++) {
884 struct app_pktq_in_params *pktq = &p->pktq_in[j];
886 if ((pktq->type == APP_PKTQ_IN_KNI) &&
895 static inline struct app_pipeline_params *
896 app_kni_get_reader(struct app_params *app,
897 struct app_pktq_kni_params *kni,
898 uint32_t *pktq_in_id)
900 struct app_pipeline_params *reader = NULL;
901 uint32_t pos = kni - app->kni_params;
902 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
903 RTE_DIM(app->pipeline_params));
904 uint32_t n_readers = 0, id = 0, i;
906 for (i = 0; i < n_pipelines; i++) {
907 struct app_pipeline_params *p = &app->pipeline_params[i];
908 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
911 for (j = 0; j < n_pktq_in; j++) {
912 struct app_pktq_in_params *pktq = &p->pktq_in[j];
914 if ((pktq->type == APP_PKTQ_IN_KNI) &&
930 static inline uint32_t
931 app_source_get_readers(struct app_params *app,
932 struct app_pktq_source_params *source)
934 uint32_t pos = source - app->source_params;
935 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
936 RTE_DIM(app->pipeline_params));
937 uint32_t n_readers = 0, i;
939 for (i = 0; i < n_pipelines; i++) {
940 struct app_pipeline_params *p = &app->pipeline_params[i];
941 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
944 for (j = 0; j < n_pktq_in; j++) {
945 struct app_pktq_in_params *pktq = &p->pktq_in[j];
947 if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
956 static inline uint32_t
957 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
959 uint32_t pos = msgq - app->msgq_params;
960 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
961 RTE_DIM(app->pipeline_params));
962 uint32_t n_readers = 0, i;
964 for (i = 0; i < n_pipelines; i++) {
965 struct app_pipeline_params *p = &app->pipeline_params[i];
966 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
969 for (j = 0; j < n_msgq_in; j++)
970 if (p->msgq_in[j] == pos)
977 static inline uint32_t
978 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
980 uint32_t pos = txq - app->hwq_out_params;
981 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
982 RTE_DIM(app->pipeline_params));
983 uint32_t n_writers = 0, i;
985 for (i = 0; i < n_pipelines; i++) {
986 struct app_pipeline_params *p = &app->pipeline_params[i];
987 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
988 RTE_DIM(p->pktq_out));
991 for (j = 0; j < n_pktq_out; j++) {
992 struct app_pktq_out_params *pktq = &p->pktq_out[j];
994 if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
1003 static inline uint32_t
1004 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
1006 uint32_t pos = swq - app->swq_params;
1007 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1008 RTE_DIM(app->pipeline_params));
1009 uint32_t n_writers = 0, i;
1011 for (i = 0; i < n_pipelines; i++) {
1012 struct app_pipeline_params *p = &app->pipeline_params[i];
1013 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1014 RTE_DIM(p->pktq_out));
1017 for (j = 0; j < n_pktq_out; j++) {
1018 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1020 if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
1029 static inline struct app_pipeline_params *
1030 app_swq_get_writer(struct app_params *app,
1031 struct app_pktq_swq_params *swq,
1032 uint32_t *pktq_out_id)
1034 struct app_pipeline_params *writer = NULL;
1035 uint32_t pos = swq - app->swq_params;
1036 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1037 RTE_DIM(app->pipeline_params));
1038 uint32_t n_writers = 0, id = 0, i;
1040 for (i = 0; i < n_pipelines; i++) {
1041 struct app_pipeline_params *p = &app->pipeline_params[i];
1042 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1043 RTE_DIM(p->pktq_out));
1046 for (j = 0; j < n_pktq_out; j++) {
1047 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1049 if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
1050 (pktq->id == pos)) {
1065 static inline uint32_t
1066 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
1068 uint32_t pos = tm - app->tm_params;
1069 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1070 RTE_DIM(app->pipeline_params));
1071 uint32_t n_writers = 0, i;
1073 for (i = 0; i < n_pipelines; i++) {
1074 struct app_pipeline_params *p = &app->pipeline_params[i];
1075 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1076 RTE_DIM(p->pktq_out));
1079 for (j = 0; j < n_pktq_out; j++) {
1080 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1082 if ((pktq->type == APP_PKTQ_OUT_TM) &&
1091 static inline struct app_pipeline_params *
1092 app_tm_get_writer(struct app_params *app,
1093 struct app_pktq_tm_params *tm,
1094 uint32_t *pktq_out_id)
1096 struct app_pipeline_params *writer = NULL;
1097 uint32_t pos = tm - app->tm_params;
1098 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1099 RTE_DIM(app->pipeline_params));
1100 uint32_t n_writers = 0, id = 0, i;
1102 for (i = 0; i < n_pipelines; i++) {
1103 struct app_pipeline_params *p = &app->pipeline_params[i];
1104 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1105 RTE_DIM(p->pktq_out));
1108 for (j = 0; j < n_pktq_out; j++) {
1109 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1111 if ((pktq->type == APP_PKTQ_OUT_TM) &&
1112 (pktq->id == pos)) {
1127 static inline uint32_t
1128 app_tap_get_writers(struct app_params *app, struct app_pktq_tap_params *tap)
1130 uint32_t pos = tap - app->tap_params;
1131 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1132 RTE_DIM(app->pipeline_params));
1133 uint32_t n_writers = 0, i;
1135 for (i = 0; i < n_pipelines; i++) {
1136 struct app_pipeline_params *p = &app->pipeline_params[i];
1137 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1138 RTE_DIM(p->pktq_out));
1141 for (j = 0; j < n_pktq_out; j++) {
1142 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1144 if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1153 static inline struct app_pipeline_params *
1154 app_tap_get_writer(struct app_params *app,
1155 struct app_pktq_tap_params *tap,
1156 uint32_t *pktq_out_id)
1158 struct app_pipeline_params *writer = NULL;
1159 uint32_t pos = tap - app->tap_params;
1160 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1161 RTE_DIM(app->pipeline_params));
1162 uint32_t n_writers = 0, id = 0, i;
1164 for (i = 0; i < n_pipelines; i++) {
1165 struct app_pipeline_params *p = &app->pipeline_params[i];
1166 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1167 RTE_DIM(p->pktq_out));
1170 for (j = 0; j < n_pktq_out; j++) {
1171 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1173 if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1174 (pktq->id == pos)) {
1189 static inline uint32_t
1190 app_kni_get_writers(struct app_params *app, struct app_pktq_kni_params *kni)
1192 uint32_t pos = kni - app->kni_params;
1193 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1194 RTE_DIM(app->pipeline_params));
1195 uint32_t n_writers = 0, i;
1197 for (i = 0; i < n_pipelines; i++) {
1198 struct app_pipeline_params *p = &app->pipeline_params[i];
1199 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1200 RTE_DIM(p->pktq_out));
1203 for (j = 0; j < n_pktq_out; j++) {
1204 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1206 if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1215 static inline struct app_pipeline_params *
1216 app_kni_get_writer(struct app_params *app,
1217 struct app_pktq_kni_params *kni,
1218 uint32_t *pktq_out_id)
1220 struct app_pipeline_params *writer = NULL;
1221 uint32_t pos = kni - app->kni_params;
1222 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1223 RTE_DIM(app->pipeline_params));
1224 uint32_t n_writers = 0, id = 0, i;
1226 for (i = 0; i < n_pipelines; i++) {
1227 struct app_pipeline_params *p = &app->pipeline_params[i];
1228 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1229 RTE_DIM(p->pktq_out));
1232 for (j = 0; j < n_pktq_out; j++) {
1233 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1235 if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1236 (pktq->id == pos)) {
1251 static inline uint32_t
1252 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
1254 uint32_t pos = sink - app->sink_params;
1255 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1256 RTE_DIM(app->pipeline_params));
1257 uint32_t n_writers = 0, i;
1259 for (i = 0; i < n_pipelines; i++) {
1260 struct app_pipeline_params *p = &app->pipeline_params[i];
1261 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1262 RTE_DIM(p->pktq_out));
1265 for (j = 0; j < n_pktq_out; j++) {
1266 struct app_pktq_out_params *pktq = &p->pktq_out[j];
1268 if ((pktq->type == APP_PKTQ_OUT_SINK) &&
1277 static inline uint32_t
1278 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
1280 uint32_t pos = msgq - app->msgq_params;
1281 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1282 RTE_DIM(app->pipeline_params));
1283 uint32_t n_writers = 0, i;
1285 for (i = 0; i < n_pipelines; i++) {
1286 struct app_pipeline_params *p = &app->pipeline_params[i];
1287 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
1288 RTE_DIM(p->msgq_out));
1291 for (j = 0; j < n_msgq_out; j++)
1292 if (p->msgq_out[j] == pos)
1299 static inline struct app_link_params *
1300 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
1302 char link_name[APP_PARAM_NAME_SIZE];
1303 ssize_t link_param_idx;
1304 uint32_t rxq_link_id, rxq_queue_id;
1306 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
1307 &rxq_link_id, &rxq_queue_id);
1308 sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
1309 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1310 APP_CHECK((link_param_idx >= 0),
1311 "Cannot find %s for %s", link_name, p->name);
1313 return &app->link_params[link_param_idx];
1316 static inline struct app_link_params *
1317 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
1319 char link_name[APP_PARAM_NAME_SIZE];
1320 ssize_t link_param_idx;
1321 uint32_t txq_link_id, txq_queue_id;
1323 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
1324 &txq_link_id, &txq_queue_id);
1325 sprintf(link_name, "LINK%" PRIu32, txq_link_id);
1326 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1327 APP_CHECK((link_param_idx >= 0),
1328 "Cannot find %s for %s", link_name, p->name);
1330 return &app->link_params[link_param_idx];
1333 static inline struct app_link_params *
1334 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
1336 char link_name[APP_PARAM_NAME_SIZE];
1338 ssize_t link_param_idx;
1340 sscanf(p_tm->name, "TM%" PRIu32, &link_id);
1341 sprintf(link_name, "LINK%" PRIu32, link_id);
1342 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1343 APP_CHECK((link_param_idx >= 0),
1344 "Cannot find %s for %s", link_name, p_tm->name);
1346 return &app->link_params[link_param_idx];
1349 static inline struct app_link_params *
1350 app_get_link_for_kni(struct app_params *app, struct app_pktq_kni_params *p_kni)
1352 char link_name[APP_PARAM_NAME_SIZE];
1354 ssize_t link_param_idx;
1356 sscanf(p_kni->name, "KNI%" PRIu32, &link_id);
1357 sprintf(link_name, "LINK%" PRIu32, link_id);
1358 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1359 APP_CHECK((link_param_idx >= 0),
1360 "Cannot find %s for %s", link_name, p_kni->name);
1362 return &app->link_params[link_param_idx];
1365 static inline uint32_t
1366 app_core_is_enabled(struct app_params *app, uint32_t lcore_id)
1368 return(app->core_mask[lcore_id / 64] &
1369 (1LLU << (lcore_id % 64)));
1373 app_core_enable_in_core_mask(struct app_params *app, int lcore_id)
1375 app->core_mask[lcore_id / 64] |= 1LLU << (lcore_id % 64);
1380 app_core_build_core_mask_string(struct app_params *app, char *mask_buffer)
1384 mask_buffer[0] = '\0';
1385 for (i = (int)RTE_DIM(app->core_mask); i > 0; i--) {
1386 /* For Hex representation of bits in uint64_t */
1387 char buffer[(64 / 8) * 2 + 1];
1388 memset(buffer, 0, sizeof(buffer));
1389 snprintf(buffer, sizeof(buffer), "%016" PRIx64,
1390 app->core_mask[i-1]);
1391 strcat(mask_buffer, buffer);
1395 void app_pipeline_params_get(struct app_params *app,
1396 struct app_pipeline_params *p_in,
1397 struct pipeline_params *p_out);
1399 int app_config_init(struct app_params *app);
1401 int app_config_args(struct app_params *app,
1402 int argc, char **argv);
1404 int app_config_preproc(struct app_params *app);
1406 int app_config_parse(struct app_params *app,
1407 const char *file_name);
1409 int app_config_parse_tm(struct app_params *app);
1411 void app_config_save(struct app_params *app,
1412 const char *file_name);
1414 int app_config_check(struct app_params *app);
1416 int app_init(struct app_params *app);
1418 int app_post_init(struct app_params *app);
1420 int app_thread(void *arg);
1422 int app_pipeline_type_register(struct app_params *app,
1423 struct pipeline_type *ptype);
1425 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
1428 void app_link_up_internal(struct app_params *app,
1429 struct app_link_params *cp);
1431 void app_link_down_internal(struct app_params *app,
1432 struct app_link_params *cp);