app/eventdev: add pipeline opt dump and check functions
[dpdk.git] / app / test-eventdev / test_pipeline_common.c
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright 2017 Cavium, Inc.
4  */
5
6 #include "test_pipeline_common.h"
7
8 int
9 pipeline_test_result(struct evt_test *test, struct evt_options *opt)
10 {
11         RTE_SET_USED(opt);
12         int i;
13         uint64_t total = 0;
14         struct test_pipeline *t = evt_test_priv(test);
15
16         printf("Packet distribution across worker cores :\n");
17         for (i = 0; i < t->nb_workers; i++)
18                 total += t->worker[i].processed_pkts;
19         for (i = 0; i < t->nb_workers; i++)
20                 printf("Worker %d packets: "CLGRN"%"PRIx64" "CLNRM"percentage:"
21                                 CLGRN" %3.2f\n"CLNRM, i,
22                                 t->worker[i].processed_pkts,
23                                 (((double)t->worker[i].processed_pkts)/total)
24                                 * 100);
25         return t->result;
26 }
27
28 void
29 pipeline_opt_dump(struct evt_options *opt, uint8_t nb_queues)
30 {
31         evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores));
32         evt_dump_worker_lcores(opt);
33         evt_dump_nb_stages(opt);
34         evt_dump("nb_evdev_ports", "%d", pipeline_nb_event_ports(opt));
35         evt_dump("nb_evdev_queues", "%d", nb_queues);
36         evt_dump_queue_priority(opt);
37         evt_dump_sched_type_list(opt);
38         evt_dump_producer_type(opt);
39 }
40
41 int
42 pipeline_opt_check(struct evt_options *opt, uint64_t nb_queues)
43 {
44         unsigned int lcores;
45         /*
46          * N worker + 1 master
47          */
48         lcores = 2;
49
50         if (!rte_eth_dev_count()) {
51                 evt_err("test needs minimum 1 ethernet dev");
52                 return -1;
53         }
54
55         if (rte_lcore_count() < lcores) {
56                 evt_err("test need minimum %d lcores", lcores);
57                 return -1;
58         }
59
60         /* Validate worker lcores */
61         if (evt_lcores_has_overlap(opt->wlcores, rte_get_master_lcore())) {
62                 evt_err("worker lcores overlaps with master lcore");
63                 return -1;
64         }
65         if (evt_has_disabled_lcore(opt->wlcores)) {
66                 evt_err("one or more workers lcores are not enabled");
67                 return -1;
68         }
69         if (!evt_has_active_lcore(opt->wlcores)) {
70                 evt_err("minimum one worker is required");
71                 return -1;
72         }
73
74         if (nb_queues > EVT_MAX_QUEUES) {
75                 evt_err("number of queues exceeds %d", EVT_MAX_QUEUES);
76                 return -1;
77         }
78         if (pipeline_nb_event_ports(opt) > EVT_MAX_PORTS) {
79                 evt_err("number of ports exceeds %d", EVT_MAX_PORTS);
80                 return -1;
81         }
82
83         if (evt_has_invalid_stage(opt))
84                 return -1;
85
86         if (evt_has_invalid_sched_type(opt))
87                 return -1;
88
89         return 0;
90 }
91
92 int
93 pipeline_mempool_setup(struct evt_test *test, struct evt_options *opt)
94 {
95         struct test_pipeline *t = evt_test_priv(test);
96
97         t->pool = rte_pktmbuf_pool_create(test->name, /* mempool name */
98                         opt->pool_sz, /* number of elements*/
99                         512, /* cache size*/
100                         0,
101                         RTE_MBUF_DEFAULT_BUF_SIZE,
102                         opt->socket_id); /* flags */
103
104         if (t->pool == NULL) {
105                 evt_err("failed to create mempool");
106                 return -ENOMEM;
107         }
108
109         return 0;
110 }
111
112 void
113 pipeline_mempool_destroy(struct evt_test *test, struct evt_options *opt)
114 {
115         RTE_SET_USED(opt);
116         struct test_pipeline *t = evt_test_priv(test);
117
118         rte_mempool_free(t->pool);
119 }
120
121 int
122 pipeline_test_setup(struct evt_test *test, struct evt_options *opt)
123 {
124         void *test_pipeline;
125
126         test_pipeline = rte_zmalloc_socket(test->name,
127                         sizeof(struct test_pipeline), RTE_CACHE_LINE_SIZE,
128                         opt->socket_id);
129         if (test_pipeline  == NULL) {
130                 evt_err("failed to allocate test_pipeline memory");
131                 goto nomem;
132         }
133         test->test_priv = test_pipeline;
134
135         struct test_pipeline *t = evt_test_priv(test);
136
137         t->nb_workers = evt_nr_active_lcores(opt->wlcores);
138         t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->wlcores);
139         t->done = false;
140         t->nb_flows = opt->nb_flows;
141         t->result = EVT_TEST_FAILED;
142         t->opt = opt;
143         opt->prod_type = EVT_PROD_TYPE_ETH_RX_ADPTR;
144         memcpy(t->sched_type_list, opt->sched_type_list,
145                         sizeof(opt->sched_type_list));
146         return 0;
147 nomem:
148         return -ENOMEM;
149 }
150
151 void
152 pipeline_test_destroy(struct evt_test *test, struct evt_options *opt)
153 {
154         RTE_SET_USED(opt);
155
156         rte_free(test->test_priv);
157 }