examples/ip_pipeline: reconfigure thread binding dynamically
[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         uint64_t timer_period;
231         uint32_t enabled;
232 };
233
234 struct app_thread_pipeline_data {
235         uint32_t pipeline_id;
236         void *be;
237         pipeline_be_op_run f_run;
238         pipeline_be_op_timer f_timer;
239         uint64_t timer_period;
240         uint64_t deadline;
241 };
242
243 #ifndef APP_MAX_THREAD_PIPELINES
244 #define APP_MAX_THREAD_PIPELINES                 16
245 #endif
246
247 #ifndef APP_THREAD_TIMER_PERIOD
248 #define APP_THREAD_TIMER_PERIOD                  1
249 #endif
250
251 struct app_thread_data {
252         struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
253         struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
254
255         uint32_t n_regular;
256         uint32_t n_custom;
257
258         uint64_t timer_period;
259         uint64_t thread_req_deadline;
260
261         uint64_t deadline;
262
263         struct rte_ring *msgq_in;
264         struct rte_ring *msgq_out;
265 };
266
267 struct app_eal_params {
268         /* Map lcore set to physical cpu set */
269         char *coremap;
270
271         /* Core ID that is used as master */
272         uint32_t master_lcore_present;
273         uint32_t master_lcore;
274
275         /* Number of memory channels */
276         uint32_t channels_present;
277         uint32_t channels;
278
279         /* Memory to allocate (see also --socket-mem) */
280         uint32_t memory_present;
281         uint32_t memory;
282
283         /* Force number of memory ranks (don't detect) */
284         uint32_t ranks_present;
285         uint32_t ranks;
286
287         /* Add a PCI device in black list. */
288         char *pci_blacklist;
289
290         /* Add a PCI device in white list. */
291         char *pci_whitelist;
292
293         /* Add a virtual device. */
294         char *vdev;
295
296          /* Use VMware TSC map instead of native RDTSC */
297         uint32_t vmware_tsc_map_present;
298         int vmware_tsc_map;
299
300          /* Type of this process (primary|secondary|auto) */
301         char *proc_type;
302
303          /* Set syslog facility */
304         char *syslog;
305
306         /* Set default log level */
307         uint32_t log_level_present;
308         uint32_t log_level;
309
310         /* Display version information on startup */
311         uint32_t version_present;
312         int version;
313
314         /* This help */
315         uint32_t help_present;
316         int help;
317
318          /* Use malloc instead of hugetlbfs */
319         uint32_t no_huge_present;
320         int no_huge;
321
322         /* Disable PCI */
323         uint32_t no_pci_present;
324         int no_pci;
325
326         /* Disable HPET */
327         uint32_t no_hpet_present;
328         int no_hpet;
329
330         /* No shared config (mmap'd files) */
331         uint32_t no_shconf_present;
332         int no_shconf;
333
334         /* Add driver */
335         char *add_driver;
336
337         /*  Memory to allocate on sockets (comma separated values)*/
338         char *socket_mem;
339
340         /* Directory where hugetlbfs is mounted */
341         char *huge_dir;
342
343         /* Prefix for hugepage filenames */
344         char *file_prefix;
345
346         /* Base virtual address */
347         char *base_virtaddr;
348
349         /* Create /dev/uioX (usually done by hotplug) */
350         uint32_t create_uio_dev_present;
351         int create_uio_dev;
352
353         /* Interrupt mode for VFIO (legacy|msi|msix) */
354         char *vfio_intr;
355
356         /* Support running on Xen dom0 without hugetlbfs */
357         uint32_t xen_dom0_present;
358         int xen_dom0;
359 };
360
361 #ifndef APP_APPNAME_SIZE
362 #define APP_APPNAME_SIZE                         256
363 #endif
364
365 #ifndef APP_MAX_MEMPOOLS
366 #define APP_MAX_MEMPOOLS                         8
367 #endif
368
369 #ifndef APP_MAX_LINKS
370 #define APP_MAX_LINKS                            16
371 #endif
372
373 #ifndef APP_LINK_MAX_HWQ_IN
374 #define APP_LINK_MAX_HWQ_IN                      64
375 #endif
376
377 #ifndef APP_LINK_MAX_HWQ_OUT
378 #define APP_LINK_MAX_HWQ_OUT                     64
379 #endif
380
381 #define APP_MAX_HWQ_IN                     (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
382
383 #define APP_MAX_HWQ_OUT                   (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
384
385 #ifndef APP_MAX_PKTQ_SWQ
386 #define APP_MAX_PKTQ_SWQ                         256
387 #endif
388
389 #define APP_MAX_PKTQ_TM                          APP_MAX_LINKS
390
391 #ifndef APP_MAX_PKTQ_SOURCE
392 #define APP_MAX_PKTQ_SOURCE                      16
393 #endif
394
395 #ifndef APP_MAX_PKTQ_SINK
396 #define APP_MAX_PKTQ_SINK                        16
397 #endif
398
399 #ifndef APP_MAX_MSGQ
400 #define APP_MAX_MSGQ                             64
401 #endif
402
403 #ifndef APP_MAX_PIPELINES
404 #define APP_MAX_PIPELINES                        64
405 #endif
406
407 #ifndef APP_EAL_ARGC
408 #define APP_EAL_ARGC                             32
409 #endif
410
411 #ifndef APP_MAX_PIPELINE_TYPES
412 #define APP_MAX_PIPELINE_TYPES                   64
413 #endif
414
415 #ifndef APP_MAX_THREADS
416 #define APP_MAX_THREADS                          RTE_MAX_LCORE
417 #endif
418
419 #ifndef APP_MAX_CMDS
420 #define APP_MAX_CMDS                             64
421 #endif
422
423 struct app_params {
424         /* Config */
425         char app_name[APP_APPNAME_SIZE];
426         const char *config_file;
427         const char *script_file;
428         const char *parser_file;
429         const char *output_file;
430         const char *preproc;
431         const char *preproc_args;
432         uint64_t port_mask;
433         uint32_t log_level;
434
435         struct app_eal_params eal_params;
436         struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
437         struct app_link_params link_params[APP_MAX_LINKS];
438         struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
439         struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
440         struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
441         struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
442         struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
443         struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
444         struct app_msgq_params msgq_params[APP_MAX_MSGQ];
445         struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
446
447         uint32_t n_mempools;
448         uint32_t n_links;
449         uint32_t n_pktq_hwq_in;
450         uint32_t n_pktq_hwq_out;
451         uint32_t n_pktq_swq;
452         uint32_t n_pktq_tm;
453         uint32_t n_pktq_source;
454         uint32_t n_pktq_sink;
455         uint32_t n_msgq;
456         uint32_t n_pipelines;
457
458         /* Init */
459         char *eal_argv[1 + APP_EAL_ARGC];
460         struct cpu_core_map *core_map;
461         uint64_t core_mask;
462         struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
463         struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
464         struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
465         struct rte_ring *msgq[APP_MAX_MSGQ];
466         struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
467         struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
468         struct app_thread_data thread_data[APP_MAX_THREADS];
469         cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
470
471         int eal_argc;
472         uint32_t n_pipeline_types;
473         uint32_t n_cmds;
474 };
475
476 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
477
478 #define APP_PARAM_COUNT(obj_array, n_objs)                              \
479 {                                                                       \
480         size_t i;                                                       \
481                                                                         \
482         n_objs = 0;                                                     \
483         for (i = 0; i < RTE_DIM(obj_array); i++)                        \
484                 if (APP_PARAM_VALID(&((obj_array)[i])))                 \
485                         n_objs++;                                       \
486 }
487
488 #define APP_PARAM_FIND(obj_array, key)                                  \
489 ({                                                                      \
490         ssize_t obj_idx;                                                \
491         const ssize_t obj_count = RTE_DIM(obj_array);                   \
492                                                                         \
493         for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {             \
494                 if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
495                         continue;                                       \
496                                                                         \
497                 if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
498                         break;                                          \
499         }                                                               \
500         obj_idx < obj_count ? obj_idx : -ENOENT;                        \
501 })
502
503 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj)                \
504 do {                                                                    \
505         char name[APP_PARAM_NAME_SIZE];                                 \
506         ssize_t pos;                                                    \
507                                                                         \
508         sprintf(name, prefix "%" PRIu32, id);                           \
509         pos = APP_PARAM_FIND(obj_array, name);                          \
510         obj = (pos < 0) ? NULL : &((obj_array)[pos]);                   \
511 } while (0)
512
513 #define APP_PARAM_GET_ID(obj, prefix, id)                               \
514 do                                                                      \
515         sscanf(obj->name, prefix "%" SCNu32, &id);                              \
516 while (0)                                                               \
517
518 #define APP_PARAM_ADD(obj_array, obj_name)                              \
519 ({                                                                      \
520         ssize_t obj_idx;                                                \
521         const ssize_t obj_count = RTE_DIM(obj_array);                   \
522                                                                         \
523         obj_idx = APP_PARAM_FIND(obj_array, obj_name);                  \
524         if (obj_idx < 0) {                                              \
525                 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {     \
526                         if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))  \
527                                 break;                                  \
528                 }                                                       \
529                                                                         \
530                 if (obj_idx < obj_count) {                              \
531                         (obj_array)[obj_idx].name = strdup(obj_name);   \
532                         if ((obj_array)[obj_idx].name == NULL)          \
533                                 obj_idx = -EINVAL;                      \
534                 } else                                                  \
535                         obj_idx = -ENOMEM;                              \
536         }                                                               \
537         obj_idx;                                                        \
538 })
539
540 #define APP_CHECK(exp, fmt, ...)                                        \
541 do {                                                                    \
542         if (!(exp)) {                                                   \
543                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
544                 abort();                                                \
545         }                                                               \
546 } while (0)
547
548 enum app_log_level {
549         APP_LOG_LEVEL_HIGH = 1,
550         APP_LOG_LEVEL_LOW,
551         APP_LOG_LEVELS
552 };
553
554 #define APP_LOG(app, level, fmt, ...)                                   \
555 do {                                                                    \
556         if (app->log_level >= APP_LOG_LEVEL_ ## level)                  \
557                 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__);     \
558 } while (0)
559
560 static inline uint32_t
561 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
562 {
563         uint32_t n_rxq = 0, link_id, i;
564         uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
565                 RTE_DIM(app->hwq_in_params));
566
567         APP_PARAM_GET_ID(link, "LINK", link_id);
568
569         for (i = 0; i < n_pktq_hwq_in; i++) {
570                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
571                 uint32_t rxq_link_id, rxq_queue_id;
572
573                 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
574                         &rxq_link_id, &rxq_queue_id);
575                 if (rxq_link_id == link_id)
576                         n_rxq++;
577         }
578
579         return n_rxq;
580 }
581
582 static inline uint32_t
583 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
584 {
585         uint32_t n_txq = 0, link_id, i;
586         uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
587                 RTE_DIM(app->hwq_out_params));
588
589         APP_PARAM_GET_ID(link, "LINK", link_id);
590
591         for (i = 0; i < n_pktq_hwq_out; i++) {
592                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
593                 uint32_t txq_link_id, txq_queue_id;
594
595                 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
596                         &txq_link_id, &txq_queue_id);
597                 if (txq_link_id == link_id)
598                         n_txq++;
599         }
600
601         return n_txq;
602 }
603
604 static inline uint32_t
605 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
606 {
607         uint32_t pos = rxq - app->hwq_in_params;
608         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
609                 RTE_DIM(app->pipeline_params));
610         uint32_t n_readers = 0, i;
611
612         for (i = 0; i < n_pipelines; i++) {
613                 struct app_pipeline_params *p = &app->pipeline_params[i];
614                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
615                 uint32_t j;
616
617                 for (j = 0; j < n_pktq_in; j++) {
618                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
619
620                         if ((pktq->type == APP_PKTQ_IN_HWQ) &&
621                                 (pktq->id == pos))
622                                 n_readers++;
623                 }
624         }
625
626         return n_readers;
627 }
628
629 static inline uint32_t
630 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
631 {
632         uint32_t pos = swq - app->swq_params;
633         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
634                 RTE_DIM(app->pipeline_params));
635         uint32_t n_readers = 0, i;
636
637         for (i = 0; i < n_pipelines; i++) {
638                 struct app_pipeline_params *p = &app->pipeline_params[i];
639                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
640                 uint32_t j;
641
642                 for (j = 0; j < n_pktq_in; j++) {
643                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
644
645                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
646                                 (pktq->id == pos))
647                                 n_readers++;
648                 }
649         }
650
651         return n_readers;
652 }
653
654 static inline uint32_t
655 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
656 {
657         uint32_t pos = tm - app->tm_params;
658         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
659                 RTE_DIM(app->pipeline_params));
660         uint32_t n_readers = 0, i;
661
662         for (i = 0; i < n_pipelines; i++) {
663                 struct app_pipeline_params *p = &app->pipeline_params[i];
664                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
665                 uint32_t j;
666
667                 for (j = 0; j < n_pktq_in; j++) {
668                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
669
670                         if ((pktq->type == APP_PKTQ_IN_TM) &&
671                                 (pktq->id == pos))
672                                 n_readers++;
673                 }
674         }
675
676         return n_readers;
677 }
678
679 static inline uint32_t
680 app_source_get_readers(struct app_params *app,
681 struct app_pktq_source_params *source)
682 {
683         uint32_t pos = source - app->source_params;
684         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
685                 RTE_DIM(app->pipeline_params));
686         uint32_t n_readers = 0, i;
687
688         for (i = 0; i < n_pipelines; i++) {
689                 struct app_pipeline_params *p = &app->pipeline_params[i];
690                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
691                 uint32_t j;
692
693                 for (j = 0; j < n_pktq_in; j++) {
694                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
695
696                         if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
697                                 (pktq->id == pos))
698                                 n_readers++;
699                 }
700         }
701
702         return n_readers;
703 }
704
705 static inline uint32_t
706 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
707 {
708         uint32_t pos = msgq - app->msgq_params;
709         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
710                 RTE_DIM(app->pipeline_params));
711         uint32_t n_readers = 0, i;
712
713         for (i = 0; i < n_pipelines; i++) {
714                 struct app_pipeline_params *p = &app->pipeline_params[i];
715                 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
716                 uint32_t j;
717
718                 for (j = 0; j < n_msgq_in; j++)
719                         if (p->msgq_in[j] == pos)
720                                 n_readers++;
721         }
722
723         return n_readers;
724 }
725
726 static inline uint32_t
727 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
728 {
729         uint32_t pos = txq - app->hwq_out_params;
730         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
731                 RTE_DIM(app->pipeline_params));
732         uint32_t n_writers = 0, i;
733
734         for (i = 0; i < n_pipelines; i++) {
735                 struct app_pipeline_params *p = &app->pipeline_params[i];
736                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
737                         RTE_DIM(p->pktq_out));
738                 uint32_t j;
739
740                 for (j = 0; j < n_pktq_out; j++) {
741                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
742
743                         if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
744                                 (pktq->id == pos))
745                                 n_writers++;
746                 }
747         }
748
749         return n_writers;
750 }
751
752 static inline uint32_t
753 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
754 {
755         uint32_t pos = swq - app->swq_params;
756         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
757                 RTE_DIM(app->pipeline_params));
758         uint32_t n_writers = 0, i;
759
760         for (i = 0; i < n_pipelines; i++) {
761                 struct app_pipeline_params *p = &app->pipeline_params[i];
762                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
763                         RTE_DIM(p->pktq_out));
764                 uint32_t j;
765
766                 for (j = 0; j < n_pktq_out; j++) {
767                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
768
769                         if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
770                                 (pktq->id == pos))
771                                 n_writers++;
772                 }
773         }
774
775         return n_writers;
776 }
777
778 static inline uint32_t
779 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
780 {
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_writers = 0, i;
785
786         for (i = 0; i < n_pipelines; i++) {
787                 struct app_pipeline_params *p = &app->pipeline_params[i];
788                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
789                         RTE_DIM(p->pktq_out));
790                 uint32_t j;
791
792                 for (j = 0; j < n_pktq_out; j++) {
793                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
794
795                         if ((pktq->type == APP_PKTQ_OUT_TM) &&
796                                 (pktq->id == pos))
797                                 n_writers++;
798                 }
799         }
800
801         return n_writers;
802 }
803
804 static inline uint32_t
805 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
806 {
807         uint32_t pos = sink - app->sink_params;
808         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
809                 RTE_DIM(app->pipeline_params));
810         uint32_t n_writers = 0, i;
811
812         for (i = 0; i < n_pipelines; i++) {
813                 struct app_pipeline_params *p = &app->pipeline_params[i];
814                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
815                         RTE_DIM(p->pktq_out));
816                 uint32_t j;
817
818                 for (j = 0; j < n_pktq_out; j++) {
819                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
820
821                         if ((pktq->type == APP_PKTQ_OUT_SINK) &&
822                                 (pktq->id == pos))
823                                 n_writers++;
824                 }
825         }
826
827         return n_writers;
828 }
829
830 static inline uint32_t
831 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
832 {
833         uint32_t pos = msgq - app->msgq_params;
834         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
835                 RTE_DIM(app->pipeline_params));
836         uint32_t n_writers = 0, i;
837
838         for (i = 0; i < n_pipelines; i++) {
839                 struct app_pipeline_params *p = &app->pipeline_params[i];
840                 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
841                         RTE_DIM(p->msgq_out));
842                 uint32_t j;
843
844                 for (j = 0; j < n_msgq_out; j++)
845                         if (p->msgq_out[j] == pos)
846                                 n_writers++;
847         }
848
849         return n_writers;
850 }
851
852 static inline struct app_link_params *
853 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
854 {
855         char link_name[APP_PARAM_NAME_SIZE];
856         ssize_t link_param_idx;
857         uint32_t rxq_link_id, rxq_queue_id;
858
859         sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
860                 &rxq_link_id, &rxq_queue_id);
861         sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
862         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
863         APP_CHECK((link_param_idx >= 0),
864                 "Cannot find %s for %s", link_name, p->name);
865
866         return &app->link_params[link_param_idx];
867 }
868
869 static inline struct app_link_params *
870 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
871 {
872         char link_name[APP_PARAM_NAME_SIZE];
873         ssize_t link_param_idx;
874         uint32_t txq_link_id, txq_queue_id;
875
876         sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
877                 &txq_link_id, &txq_queue_id);
878         sprintf(link_name, "LINK%" PRIu32, txq_link_id);
879         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
880         APP_CHECK((link_param_idx >= 0),
881                 "Cannot find %s for %s", link_name, p->name);
882
883         return &app->link_params[link_param_idx];
884 }
885
886 static inline struct app_link_params *
887 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
888 {
889         char link_name[APP_PARAM_NAME_SIZE];
890         uint32_t link_id;
891         ssize_t link_param_idx;
892
893         sscanf(p_tm->name, "TM%" PRIu32, &link_id);
894         sprintf(link_name, "LINK%" PRIu32, link_id);
895         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
896         APP_CHECK((link_param_idx >= 0),
897                 "Cannot find %s for %s", link_name, p_tm->name);
898
899         return &app->link_params[link_param_idx];
900 }
901
902 int app_config_init(struct app_params *app);
903
904 int app_config_args(struct app_params *app,
905         int argc, char **argv);
906
907 int app_config_preproc(struct app_params *app);
908
909 int app_config_parse(struct app_params *app,
910         const char *file_name);
911
912 int app_config_parse_tm(struct app_params *app);
913
914 void app_config_save(struct app_params *app,
915         const char *file_name);
916
917 int app_config_check(struct app_params *app);
918
919 int app_init(struct app_params *app);
920
921 int app_thread(void *arg);
922
923 int app_pipeline_type_register(struct app_params *app,
924         struct pipeline_type *ptype);
925
926 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
927         char *name);
928
929 void app_link_up_internal(struct app_params *app,
930         struct app_link_params *cp);
931
932 void app_link_down_internal(struct app_params *app,
933         struct app_link_params *cp);
934
935 #endif