app/testeventdev: add perf basic functions
[dpdk.git] / app / test-eventdev / test_perf_common.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "test_perf_common.h"
34
35 int
36 perf_test_result(struct evt_test *test, struct evt_options *opt)
37 {
38         RTE_SET_USED(opt);
39         struct test_perf *t = evt_test_priv(test);
40
41         return t->result;
42 }
43
44 void
45 perf_eventdev_destroy(struct evt_test *test, struct evt_options *opt)
46 {
47         RTE_SET_USED(test);
48
49         rte_event_dev_stop(opt->dev_id);
50         rte_event_dev_close(opt->dev_id);
51 }
52
53 static inline void
54 perf_elt_init(struct rte_mempool *mp, void *arg __rte_unused,
55             void *obj, unsigned i __rte_unused)
56 {
57         memset(obj, 0, mp->elt_size);
58 }
59
60 int
61 perf_mempool_setup(struct evt_test *test, struct evt_options *opt)
62 {
63         struct test_perf *t = evt_test_priv(test);
64
65         t->pool = rte_mempool_create(test->name, /* mempool name */
66                                 opt->pool_sz, /* number of elements*/
67                                 sizeof(struct perf_elt), /* element size*/
68                                 512, /* cache size*/
69                                 0, NULL, NULL,
70                                 perf_elt_init, /* obj constructor */
71                                 NULL, opt->socket_id, 0); /* flags */
72         if (t->pool == NULL) {
73                 evt_err("failed to create mempool");
74                 return -ENOMEM;
75         }
76
77         return 0;
78 }
79
80 void
81 perf_mempool_destroy(struct evt_test *test, struct evt_options *opt)
82 {
83         RTE_SET_USED(opt);
84         struct test_perf *t = evt_test_priv(test);
85
86         rte_mempool_free(t->pool);
87 }
88
89 int
90 perf_test_setup(struct evt_test *test, struct evt_options *opt)
91 {
92         void *test_perf;
93
94         test_perf = rte_zmalloc_socket(test->name, sizeof(struct test_perf),
95                                 RTE_CACHE_LINE_SIZE, opt->socket_id);
96         if (test_perf  == NULL) {
97                 evt_err("failed to allocate test_perf memory");
98                 goto nomem;
99         }
100         test->test_priv = test_perf;
101
102         struct test_perf *t = evt_test_priv(test);
103
104         t->outstand_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores);
105         t->nb_workers = evt_nr_active_lcores(opt->wlcores);
106         t->done = false;
107         t->nb_pkts = opt->nb_pkts;
108         t->nb_flows = opt->nb_flows;
109         t->result = EVT_TEST_FAILED;
110         t->opt = opt;
111         memcpy(t->sched_type_list, opt->sched_type_list,
112                         sizeof(opt->sched_type_list));
113         return 0;
114 nomem:
115         return -ENOMEM;
116 }
117
118 void
119 perf_test_destroy(struct evt_test *test, struct evt_options *opt)
120 {
121         RTE_SET_USED(opt);
122
123         rte_free(test->test_priv);
124 }