1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
5 #ifndef __INCLUDE_APP_H__
6 #define __INCLUDE_APP_H__
11 #include <rte_common.h>
12 #include <rte_mempool.h>
14 #include <rte_sched.h>
15 #include <cmdline_parse.h>
17 #include <rte_ethdev.h>
22 #include "cpu_core_map.h"
25 #define APP_PARAM_NAME_SIZE PIPELINE_NAME_SIZE
26 #define APP_LINK_PCI_BDF_SIZE 16
28 #ifndef APP_LINK_MAX_HWQ_IN
29 #define APP_LINK_MAX_HWQ_IN 128
32 #ifndef APP_LINK_MAX_HWQ_OUT
33 #define APP_LINK_MAX_HWQ_OUT 128
36 struct app_mempool_params {
42 uint32_t cpu_socket_id;
45 struct app_link_params {
48 uint32_t pmd_id; /* Generated based on port mask */
49 uint32_t arp_q; /* 0 = Disabled (packets go to default queue 0) */
50 uint32_t tcp_syn_q; /* 0 = Disabled (pkts go to default queue) */
51 uint32_t ip_local_q; /* 0 = Disabled (pkts go to default queue 0) */
52 uint32_t tcp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
53 uint32_t udp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
54 uint32_t sctp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
55 uint32_t rss_qs[APP_LINK_MAX_HWQ_IN];
57 uint64_t rss_proto_ipv4;
58 uint64_t rss_proto_ipv6;
59 uint64_t rss_proto_l2;
61 uint32_t state; /* DOWN = 0, UP = 1 */
62 uint32_t ip; /* 0 = Invalid */
63 uint32_t depth; /* Valid only when IP is valid */
64 uint64_t mac_addr; /* Read from HW */
65 char pci_bdf[APP_LINK_PCI_BDF_SIZE];
67 struct rte_eth_conf conf;
70 struct app_pktq_hwq_in_params {
73 uint32_t mempool_id; /* Position in the app->mempool_params */
77 struct rte_eth_rxconf conf;
80 struct app_pktq_hwq_out_params {
87 struct rte_eth_txconf conf;
90 struct app_pktq_swq_params {
98 uint32_t cpu_socket_id;
104 uint32_t metadata_size;
105 uint32_t mempool_direct_id;
106 uint32_t mempool_indirect_id;
109 struct app_pktq_kni_params {
115 uint32_t hyper_th_id;
118 uint32_t mempool_id; /* Position in the app->mempool_params */
120 uint32_t burst_write;
125 #ifndef APP_FILE_NAME_SIZE
126 #define APP_FILE_NAME_SIZE 256
129 #ifndef APP_MAX_SCHED_SUBPORTS
130 #define APP_MAX_SCHED_SUBPORTS 8
133 #ifndef APP_MAX_SCHED_PIPES
134 #define APP_MAX_SCHED_PIPES 4096
137 struct app_pktq_tm_params {
140 const char *file_name;
141 struct rte_sched_port_params sched_port_params;
142 struct rte_sched_subport_params
143 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
144 struct rte_sched_pipe_params
145 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
146 int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
148 uint32_t burst_write;
151 struct app_pktq_tap_params {
155 uint32_t burst_write;
158 uint32_t mempool_id; /* Position in the app->mempool_params */
161 struct app_pktq_source_params {
164 uint32_t mempool_id; /* Position in the app->mempool_params array */
166 const char *file_name; /* Full path of PCAP file to be copied to mbufs */
167 uint32_t n_bytes_per_pkt;
170 struct app_pktq_sink_params {
173 const char *file_name; /* Full path of PCAP file to be copied to mbufs */
174 uint32_t n_pkts_to_dump;
177 struct app_msgq_params {
181 uint32_t cpu_socket_id;
184 enum app_pktq_in_type {
193 struct app_pktq_in_params {
194 enum app_pktq_in_type type;
195 uint32_t id; /* Position in the appropriate app array */
198 enum app_pktq_out_type {
207 struct app_pktq_out_params {
208 enum app_pktq_out_type type;
209 uint32_t id; /* Position in the appropriate app array */
212 #define APP_PIPELINE_TYPE_SIZE PIPELINE_TYPE_SIZE
214 #define APP_MAX_PIPELINE_PKTQ_IN PIPELINE_MAX_PORT_IN
215 #define APP_MAX_PIPELINE_PKTQ_OUT PIPELINE_MAX_PORT_OUT
216 #define APP_MAX_PIPELINE_MSGQ_IN PIPELINE_MAX_MSGQ_IN
217 #define APP_MAX_PIPELINE_MSGQ_OUT PIPELINE_MAX_MSGQ_OUT
219 #define APP_MAX_PIPELINE_ARGS PIPELINE_MAX_ARGS
221 struct app_pipeline_params {
225 char type[APP_PIPELINE_TYPE_SIZE];
229 uint32_t hyper_th_id;
231 struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
232 struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
233 uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
234 uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
241 uint32_t timer_period;
243 char *args_name[APP_MAX_PIPELINE_ARGS];
244 char *args_value[APP_MAX_PIPELINE_ARGS];
250 typedef void (*app_link_op)(struct app_params *app,
255 #ifndef APP_MAX_PIPELINES
256 #define APP_MAX_PIPELINES 64
259 struct app_link_data {
260 app_link_op f_link[APP_MAX_PIPELINES];
261 void *arg[APP_MAX_PIPELINES];
264 struct app_pipeline_data {
267 struct pipeline_type *ptype;
268 uint64_t timer_period;
272 struct app_thread_pipeline_data {
273 uint32_t pipeline_id;
275 pipeline_be_op_run f_run;
276 pipeline_be_op_timer f_timer;
277 uint64_t timer_period;
281 #ifndef APP_MAX_THREAD_PIPELINES
282 #define APP_MAX_THREAD_PIPELINES 64
285 #ifndef APP_THREAD_TIMER_PERIOD
286 #define APP_THREAD_TIMER_PERIOD 1
289 struct app_thread_data {
290 struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
291 struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
296 uint64_t timer_period;
297 uint64_t thread_req_deadline;
301 struct rte_ring *msgq_in;
302 struct rte_ring *msgq_out;
304 uint64_t headroom_time;
305 uint64_t headroom_cycles;
306 double headroom_ratio;
307 } __rte_cache_aligned;
309 #ifndef APP_MAX_LINKS
310 #define APP_MAX_LINKS 16
313 struct app_eal_params {
314 /* Map lcore set to physical cpu set */
317 /* Core ID that is used as master */
318 uint32_t master_lcore_present;
319 uint32_t master_lcore;
321 /* Number of memory channels */
322 uint32_t channels_present;
325 /* Memory to allocate (see also --socket-mem) */
326 uint32_t memory_present;
329 /* Force number of memory ranks (don't detect) */
330 uint32_t ranks_present;
333 /* Add a PCI device in black list. */
334 char *pci_blacklist[APP_MAX_LINKS];
336 /* Add a PCI device in white list. */
337 char *pci_whitelist[APP_MAX_LINKS];
339 /* Add a virtual device. */
340 char *vdev[APP_MAX_LINKS];
342 /* Use VMware TSC map instead of native RDTSC */
343 uint32_t vmware_tsc_map_present;
346 /* Type of this process (primary|secondary|auto) */
349 /* Set syslog facility */
352 /* Set default log level */
353 uint32_t log_level_present;
356 /* Display version information on startup */
357 uint32_t version_present;
361 uint32_t help_present;
364 /* Use malloc instead of hugetlbfs */
365 uint32_t no_huge_present;
369 uint32_t no_pci_present;
373 uint32_t no_hpet_present;
376 /* No shared config (mmap'd files) */
377 uint32_t no_shconf_present;
383 /* Memory to allocate on sockets (comma separated values)*/
386 /* Directory where hugetlbfs is mounted */
389 /* Prefix for hugepage filenames */
392 /* Base virtual address */
395 /* Create /dev/uioX (usually done by hotplug) */
396 uint32_t create_uio_dev_present;
399 /* Interrupt mode for VFIO (legacy|msi|msix) */
405 #ifndef APP_APPNAME_SIZE
406 #define APP_APPNAME_SIZE 256
409 #ifndef APP_MAX_MEMPOOLS
410 #define APP_MAX_MEMPOOLS 8
413 #define APP_MAX_HWQ_IN (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
415 #define APP_MAX_HWQ_OUT (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
417 #ifndef APP_MAX_PKTQ_SWQ
418 #define APP_MAX_PKTQ_SWQ 256
421 #define APP_MAX_PKTQ_TM APP_MAX_LINKS
423 #ifndef APP_MAX_PKTQ_TAP
424 #define APP_MAX_PKTQ_TAP APP_MAX_LINKS
427 #define APP_MAX_PKTQ_KNI APP_MAX_LINKS
429 #ifndef APP_MAX_PKTQ_SOURCE
430 #define APP_MAX_PKTQ_SOURCE 64
433 #ifndef APP_MAX_PKTQ_SINK
434 #define APP_MAX_PKTQ_SINK 64
438 #define APP_MAX_MSGQ 256
442 #define APP_EAL_ARGC 64
445 #ifndef APP_MAX_PIPELINE_TYPES
446 #define APP_MAX_PIPELINE_TYPES 64
449 #ifndef APP_MAX_THREADS
450 #define APP_MAX_THREADS RTE_MAX_LCORE
454 #define APP_MAX_CMDS 64
457 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
458 #define APP_THREAD_HEADROOM_STATS_COLLECT 1
461 #define APP_CORE_MASK_SIZE \
462 (RTE_MAX_LCORE / 64 + ((RTE_MAX_LCORE % 64) ? 1 : 0))
466 char app_name[APP_APPNAME_SIZE];
467 const char *config_file;
468 const char *script_file;
469 const char *parser_file;
470 const char *output_file;
472 const char *preproc_args;
476 struct app_eal_params eal_params;
477 struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
478 struct app_link_params link_params[APP_MAX_LINKS];
479 struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
480 struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
481 struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
482 struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
483 struct app_pktq_tap_params tap_params[APP_MAX_PKTQ_TAP];
484 struct app_pktq_kni_params kni_params[APP_MAX_PKTQ_KNI];
485 struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
486 struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
487 struct app_msgq_params msgq_params[APP_MAX_MSGQ];
488 struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
492 uint32_t n_pktq_hwq_in;
493 uint32_t n_pktq_hwq_out;
498 uint32_t n_pktq_source;
499 uint32_t n_pktq_sink;
501 uint32_t n_pipelines;
504 char *eal_argv[1 + APP_EAL_ARGC];
505 struct cpu_core_map *core_map;
506 uint64_t core_mask[APP_CORE_MASK_SIZE];
507 struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
508 struct app_link_data link_data[APP_MAX_LINKS];
509 struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
510 struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
511 int tap[APP_MAX_PKTQ_TAP];
512 #ifdef RTE_LIBRTE_KNI
513 struct rte_kni *kni[APP_MAX_PKTQ_KNI];
514 #endif /* RTE_LIBRTE_KNI */
515 struct rte_ring *msgq[APP_MAX_MSGQ];
516 struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
517 struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
518 struct app_thread_data thread_data[APP_MAX_THREADS];
519 cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
522 uint32_t n_pipeline_types;
526 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
528 #define APP_PARAM_COUNT(obj_array, n_objs) \
533 for (i = 0; i < RTE_DIM(obj_array); i++) \
534 if (APP_PARAM_VALID(&((obj_array)[i]))) \
538 #define APP_PARAM_FIND(obj_array, key) \
541 const ssize_t obj_count = RTE_DIM(obj_array); \
543 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) { \
544 if (!APP_PARAM_VALID(&((obj_array)[obj_idx]))) \
547 if (strcmp(key, (obj_array)[obj_idx].name) == 0) \
550 obj_idx < obj_count ? obj_idx : -ENOENT; \
553 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj) \
555 char name[APP_PARAM_NAME_SIZE]; \
558 sprintf(name, prefix "%" PRIu32, id); \
559 pos = APP_PARAM_FIND(obj_array, name); \
560 obj = (pos < 0) ? NULL : &((obj_array)[pos]); \
563 #define APP_PARAM_GET_ID(obj, prefix, id) \
565 sscanf(obj->name, prefix "%" SCNu32, &id); \
568 #define APP_CHECK(exp, fmt, ...) \
571 fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
577 APP_LOG_LEVEL_HIGH = 1,
582 #define APP_LOG(app, level, fmt, ...) \
584 if (app->log_level >= APP_LOG_LEVEL_ ## level) \
585 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__); \
588 static inline uint32_t
589 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
591 uint32_t n_rxq = 0, link_id, i;
592 uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
593 RTE_DIM(app->hwq_in_params));
595 APP_PARAM_GET_ID(link, "LINK", link_id);
597 for (i = 0; i < n_pktq_hwq_in; i++) {
598 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
599 uint32_t rxq_link_id, rxq_queue_id;
601 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
602 &rxq_link_id, &rxq_queue_id);
603 if (rxq_link_id == link_id)
610 static inline uint32_t
611 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
613 uint32_t n_txq = 0, link_id, i;
614 uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
615 RTE_DIM(app->hwq_out_params));
617 APP_PARAM_GET_ID(link, "LINK", link_id);
619 for (i = 0; i < n_pktq_hwq_out; i++) {
620 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
621 uint32_t txq_link_id, txq_queue_id;
623 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
624 &txq_link_id, &txq_queue_id);
625 if (txq_link_id == link_id)
632 static inline uint32_t
633 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
635 uint32_t pos = rxq - app->hwq_in_params;
636 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
637 RTE_DIM(app->pipeline_params));
638 uint32_t n_readers = 0, i;
640 for (i = 0; i < n_pipelines; i++) {
641 struct app_pipeline_params *p = &app->pipeline_params[i];
642 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
645 for (j = 0; j < n_pktq_in; j++) {
646 struct app_pktq_in_params *pktq = &p->pktq_in[j];
648 if ((pktq->type == APP_PKTQ_IN_HWQ) &&
657 static inline uint32_t
658 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
660 uint32_t pos = swq - app->swq_params;
661 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
662 RTE_DIM(app->pipeline_params));
663 uint32_t n_readers = 0, i;
665 for (i = 0; i < n_pipelines; i++) {
666 struct app_pipeline_params *p = &app->pipeline_params[i];
667 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
670 for (j = 0; j < n_pktq_in; j++) {
671 struct app_pktq_in_params *pktq = &p->pktq_in[j];
673 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
682 static inline struct app_pipeline_params *
683 app_swq_get_reader(struct app_params *app,
684 struct app_pktq_swq_params *swq,
685 uint32_t *pktq_in_id)
687 struct app_pipeline_params *reader = NULL;
688 uint32_t pos = swq - app->swq_params;
689 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
690 RTE_DIM(app->pipeline_params));
691 uint32_t n_readers = 0, id = 0, i;
693 for (i = 0; i < n_pipelines; i++) {
694 struct app_pipeline_params *p = &app->pipeline_params[i];
695 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
698 for (j = 0; j < n_pktq_in; j++) {
699 struct app_pktq_in_params *pktq = &p->pktq_in[j];
701 if ((pktq->type == APP_PKTQ_IN_SWQ) &&
717 static inline uint32_t
718 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
720 uint32_t pos = tm - app->tm_params;
721 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
722 RTE_DIM(app->pipeline_params));
723 uint32_t n_readers = 0, i;
725 for (i = 0; i < n_pipelines; i++) {
726 struct app_pipeline_params *p = &app->pipeline_params[i];
727 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
730 for (j = 0; j < n_pktq_in; j++) {
731 struct app_pktq_in_params *pktq = &p->pktq_in[j];
733 if ((pktq->type == APP_PKTQ_IN_TM) &&
742 static inline struct app_pipeline_params *
743 app_tm_get_reader(struct app_params *app,
744 struct app_pktq_tm_params *tm,
745 uint32_t *pktq_in_id)
747 struct app_pipeline_params *reader = NULL;
748 uint32_t pos = tm - app->tm_params;
749 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
750 RTE_DIM(app->pipeline_params));
751 uint32_t n_readers = 0, id = 0, i;
753 for (i = 0; i < n_pipelines; i++) {
754 struct app_pipeline_params *p = &app->pipeline_params[i];
755 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
758 for (j = 0; j < n_pktq_in; j++) {
759 struct app_pktq_in_params *pktq = &p->pktq_in[j];
761 if ((pktq->type == APP_PKTQ_IN_TM) &&
777 static inline uint32_t
778 app_tap_get_readers(struct app_params *app, struct app_pktq_tap_params *tap)
780 uint32_t pos = tap - app->tap_params;
781 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
782 RTE_DIM(app->pipeline_params));
783 uint32_t n_readers = 0, i;
785 for (i = 0; i < n_pipelines; i++) {
786 struct app_pipeline_params *p = &app->pipeline_params[i];
787 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
790 for (j = 0; j < n_pktq_in; j++) {
791 struct app_pktq_in_params *pktq = &p->pktq_in[j];
793 if ((pktq->type == APP_PKTQ_IN_TAP) &&
802 static inline struct app_pipeline_params *
803 app_tap_get_reader(struct app_params *app,
804 struct app_pktq_tap_params *tap,
805 uint32_t *pktq_in_id)
807 struct app_pipeline_params *reader = NULL;
808 uint32_t pos = tap - app->tap_params;
809 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
810 RTE_DIM(app->pipeline_params));
811 uint32_t n_readers = 0, id = 0, i;
813 for (i = 0; i < n_pipelines; i++) {
814 struct app_pipeline_params *p = &app->pipeline_params[i];
815 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
818 for (j = 0; j < n_pktq_in; j++) {
819 struct app_pktq_in_params *pktq = &p->pktq_in[j];
821 if ((pktq->type == APP_PKTQ_IN_TAP) &&
837 static inline uint32_t
838 app_kni_get_readers(struct app_params *app, struct app_pktq_kni_params *kni)
840 uint32_t pos = kni - app->kni_params;
841 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
842 RTE_DIM(app->pipeline_params));
843 uint32_t n_readers = 0, i;
845 for (i = 0; i < n_pipelines; i++) {
846 struct app_pipeline_params *p = &app->pipeline_params[i];
847 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
850 for (j = 0; j < n_pktq_in; j++) {
851 struct app_pktq_in_params *pktq = &p->pktq_in[j];
853 if ((pktq->type == APP_PKTQ_IN_KNI) &&
862 static inline struct app_pipeline_params *
863 app_kni_get_reader(struct app_params *app,
864 struct app_pktq_kni_params *kni,
865 uint32_t *pktq_in_id)
867 struct app_pipeline_params *reader = NULL;
868 uint32_t pos = kni - app->kni_params;
869 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
870 RTE_DIM(app->pipeline_params));
871 uint32_t n_readers = 0, id = 0, i;
873 for (i = 0; i < n_pipelines; i++) {
874 struct app_pipeline_params *p = &app->pipeline_params[i];
875 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
878 for (j = 0; j < n_pktq_in; j++) {
879 struct app_pktq_in_params *pktq = &p->pktq_in[j];
881 if ((pktq->type == APP_PKTQ_IN_KNI) &&
897 static inline uint32_t
898 app_source_get_readers(struct app_params *app,
899 struct app_pktq_source_params *source)
901 uint32_t pos = source - app->source_params;
902 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
903 RTE_DIM(app->pipeline_params));
904 uint32_t n_readers = 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_SOURCE) &&
923 static inline uint32_t
924 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
926 uint32_t pos = msgq - app->msgq_params;
927 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
928 RTE_DIM(app->pipeline_params));
929 uint32_t n_readers = 0, i;
931 for (i = 0; i < n_pipelines; i++) {
932 struct app_pipeline_params *p = &app->pipeline_params[i];
933 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
936 for (j = 0; j < n_msgq_in; j++)
937 if (p->msgq_in[j] == pos)
944 static inline uint32_t
945 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
947 uint32_t pos = txq - app->hwq_out_params;
948 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
949 RTE_DIM(app->pipeline_params));
950 uint32_t n_writers = 0, i;
952 for (i = 0; i < n_pipelines; i++) {
953 struct app_pipeline_params *p = &app->pipeline_params[i];
954 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
955 RTE_DIM(p->pktq_out));
958 for (j = 0; j < n_pktq_out; j++) {
959 struct app_pktq_out_params *pktq = &p->pktq_out[j];
961 if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
970 static inline uint32_t
971 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
973 uint32_t pos = swq - app->swq_params;
974 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
975 RTE_DIM(app->pipeline_params));
976 uint32_t n_writers = 0, i;
978 for (i = 0; i < n_pipelines; i++) {
979 struct app_pipeline_params *p = &app->pipeline_params[i];
980 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
981 RTE_DIM(p->pktq_out));
984 for (j = 0; j < n_pktq_out; j++) {
985 struct app_pktq_out_params *pktq = &p->pktq_out[j];
987 if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
996 static inline struct app_pipeline_params *
997 app_swq_get_writer(struct app_params *app,
998 struct app_pktq_swq_params *swq,
999 uint32_t *pktq_out_id)
1001 struct app_pipeline_params *writer = NULL;
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, id = 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) &&
1017 (pktq->id == pos)) {
1032 static inline uint32_t
1033 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
1035 uint32_t pos = tm - app->tm_params;
1036 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1037 RTE_DIM(app->pipeline_params));
1038 uint32_t n_writers = 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_TM) &&
1058 static inline struct app_pipeline_params *
1059 app_tm_get_writer(struct app_params *app,
1060 struct app_pktq_tm_params *tm,
1061 uint32_t *pktq_out_id)
1063 struct app_pipeline_params *writer = NULL;
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, id = 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) &&
1079 (pktq->id == pos)) {
1094 static inline uint32_t
1095 app_tap_get_writers(struct app_params *app, struct app_pktq_tap_params *tap)
1097 uint32_t pos = tap - app->tap_params;
1098 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1099 RTE_DIM(app->pipeline_params));
1100 uint32_t n_writers = 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_TAP) &&
1120 static inline struct app_pipeline_params *
1121 app_tap_get_writer(struct app_params *app,
1122 struct app_pktq_tap_params *tap,
1123 uint32_t *pktq_out_id)
1125 struct app_pipeline_params *writer = NULL;
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, id = 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) &&
1141 (pktq->id == pos)) {
1156 static inline uint32_t
1157 app_kni_get_writers(struct app_params *app, struct app_pktq_kni_params *kni)
1159 uint32_t pos = kni - app->kni_params;
1160 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1161 RTE_DIM(app->pipeline_params));
1162 uint32_t n_writers = 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_KNI) &&
1182 static inline struct app_pipeline_params *
1183 app_kni_get_writer(struct app_params *app,
1184 struct app_pktq_kni_params *kni,
1185 uint32_t *pktq_out_id)
1187 struct app_pipeline_params *writer = NULL;
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, id = 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) &&
1203 (pktq->id == pos)) {
1218 static inline uint32_t
1219 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
1221 uint32_t pos = sink - app->sink_params;
1222 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1223 RTE_DIM(app->pipeline_params));
1224 uint32_t n_writers = 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_SINK) &&
1244 static inline uint32_t
1245 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
1247 uint32_t pos = msgq - app->msgq_params;
1248 uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1249 RTE_DIM(app->pipeline_params));
1250 uint32_t n_writers = 0, i;
1252 for (i = 0; i < n_pipelines; i++) {
1253 struct app_pipeline_params *p = &app->pipeline_params[i];
1254 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
1255 RTE_DIM(p->msgq_out));
1258 for (j = 0; j < n_msgq_out; j++)
1259 if (p->msgq_out[j] == pos)
1266 static inline struct app_link_params *
1267 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
1269 char link_name[APP_PARAM_NAME_SIZE];
1270 ssize_t link_param_idx;
1271 uint32_t rxq_link_id, rxq_queue_id;
1273 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
1274 &rxq_link_id, &rxq_queue_id);
1275 sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
1276 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1277 APP_CHECK((link_param_idx >= 0),
1278 "Cannot find %s for %s", link_name, p->name);
1280 return &app->link_params[link_param_idx];
1283 static inline struct app_link_params *
1284 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
1286 char link_name[APP_PARAM_NAME_SIZE];
1287 ssize_t link_param_idx;
1288 uint32_t txq_link_id, txq_queue_id;
1290 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
1291 &txq_link_id, &txq_queue_id);
1292 sprintf(link_name, "LINK%" PRIu32, txq_link_id);
1293 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1294 APP_CHECK((link_param_idx >= 0),
1295 "Cannot find %s for %s", link_name, p->name);
1297 return &app->link_params[link_param_idx];
1300 static inline struct app_link_params *
1301 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
1303 char link_name[APP_PARAM_NAME_SIZE];
1305 ssize_t link_param_idx;
1307 sscanf(p_tm->name, "TM%" PRIu32, &link_id);
1308 sprintf(link_name, "LINK%" PRIu32, 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_tm->name);
1313 return &app->link_params[link_param_idx];
1316 static inline struct app_link_params *
1317 app_get_link_for_kni(struct app_params *app, struct app_pktq_kni_params *p_kni)
1319 char link_name[APP_PARAM_NAME_SIZE];
1321 ssize_t link_param_idx;
1323 sscanf(p_kni->name, "KNI%" PRIu32, &link_id);
1324 sprintf(link_name, "LINK%" PRIu32, link_id);
1325 link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1326 APP_CHECK((link_param_idx >= 0),
1327 "Cannot find %s for %s", link_name, p_kni->name);
1329 return &app->link_params[link_param_idx];
1332 static inline uint32_t
1333 app_core_is_enabled(struct app_params *app, uint32_t lcore_id)
1335 return(app->core_mask[lcore_id / 64] &
1336 (1LLU << (lcore_id % 64)));
1340 app_core_enable_in_core_mask(struct app_params *app, int lcore_id)
1342 app->core_mask[lcore_id / 64] |= 1LLU << (lcore_id % 64);
1347 app_core_build_core_mask_string(struct app_params *app, char *mask_buffer)
1351 mask_buffer[0] = '\0';
1352 for (i = (int)RTE_DIM(app->core_mask); i > 0; i--) {
1353 /* For Hex representation of bits in uint64_t */
1354 char buffer[(64 / 8) * 2 + 1];
1355 memset(buffer, 0, sizeof(buffer));
1356 snprintf(buffer, sizeof(buffer), "%016" PRIx64,
1357 app->core_mask[i-1]);
1358 strcat(mask_buffer, buffer);
1362 void app_pipeline_params_get(struct app_params *app,
1363 struct app_pipeline_params *p_in,
1364 struct pipeline_params *p_out);
1366 int app_config_init(struct app_params *app);
1368 int app_config_args(struct app_params *app,
1369 int argc, char **argv);
1371 int app_config_preproc(struct app_params *app);
1373 int app_config_parse(struct app_params *app,
1374 const char *file_name);
1376 int app_config_parse_tm(struct app_params *app);
1378 void app_config_save(struct app_params *app,
1379 const char *file_name);
1381 int app_config_check(struct app_params *app);
1383 int app_init(struct app_params *app);
1385 int app_post_init(struct app_params *app);
1387 int app_thread(void *arg);
1389 int app_pipeline_type_register(struct app_params *app,
1390 struct pipeline_type *ptype);
1392 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
1395 void app_link_up_internal(struct app_params *app,
1396 struct app_link_params *cp);
1398 void app_link_down_internal(struct app_params *app,
1399 struct app_link_params *cp);