4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
16 * * Neither the name of Intel Corporation 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.
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.
33 #include <rte_malloc.h>
35 #include "cperf_test_common.h"
37 static struct rte_mbuf *
38 cperf_mbuf_create(struct rte_mempool *mempool,
40 const struct cperf_options *options,
41 const struct cperf_test_vector *test_vector)
43 struct rte_mbuf *mbuf;
44 uint32_t segment_sz = options->max_buffer_size / segments_nb;
45 uint32_t last_sz = options->max_buffer_size % segments_nb;
48 (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
49 test_vector->plaintext.data :
50 test_vector->ciphertext.data;
52 mbuf = rte_pktmbuf_alloc(mempool);
56 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
57 if (mbuf_data == NULL)
60 memcpy(mbuf_data, test_data, segment_sz);
61 test_data += segment_sz;
67 m = rte_pktmbuf_alloc(mempool);
71 rte_pktmbuf_chain(mbuf, m);
73 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
74 if (mbuf_data == NULL)
77 memcpy(mbuf_data, test_data, segment_sz);
78 test_data += segment_sz;
83 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, last_sz);
84 if (mbuf_data == NULL)
87 memcpy(mbuf_data, test_data, last_sz);
90 if (options->op_type != CPERF_CIPHER_ONLY) {
91 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf,
93 if (mbuf_data == NULL)
100 rte_pktmbuf_free(mbuf);
106 cperf_alloc_common_memory(const struct cperf_options *options,
107 const struct cperf_test_vector *test_vector,
108 uint8_t dev_id, size_t extra_op_priv_size,
109 struct rte_mempool **pkt_mbuf_pool_in,
110 struct rte_mempool **pkt_mbuf_pool_out,
111 struct rte_mbuf ***mbufs_in,
112 struct rte_mbuf ***mbufs_out,
113 struct rte_mempool **crypto_op_pool)
115 unsigned int mbuf_idx = 0;
116 char pool_name[32] = "";
118 snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d",
121 *pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name,
122 options->pool_sz * options->segments_nb, 0, 0,
123 RTE_PKTMBUF_HEADROOM +
124 RTE_CACHE_LINE_ROUNDUP(
125 (options->max_buffer_size / options->segments_nb) +
126 (options->max_buffer_size % options->segments_nb) +
130 if (*pkt_mbuf_pool_in == NULL)
133 /* Generate mbufs_in with plaintext populated for test */
134 *mbufs_in = (struct rte_mbuf **)rte_malloc(NULL,
135 (sizeof(struct rte_mbuf *) * options->pool_sz), 0);
137 for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
138 (*mbufs_in)[mbuf_idx] = cperf_mbuf_create(
139 *pkt_mbuf_pool_in, options->segments_nb,
140 options, test_vector);
141 if ((*mbufs_in)[mbuf_idx] == NULL)
145 *mbufs_out = (struct rte_mbuf **)rte_zmalloc(NULL,
146 (sizeof(struct rte_mbuf *) *
147 options->pool_sz), 0);
149 if (options->out_of_place == 1) {
150 snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d",
153 *pkt_mbuf_pool_out = rte_pktmbuf_pool_create(
154 pool_name, options->pool_sz, 0, 0,
155 RTE_PKTMBUF_HEADROOM +
156 RTE_CACHE_LINE_ROUNDUP(
157 options->max_buffer_size +
161 if (*pkt_mbuf_pool_out == NULL)
164 for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
165 (*mbufs_out)[mbuf_idx] = cperf_mbuf_create(
166 *pkt_mbuf_pool_out, 1,
167 options, test_vector);
168 if ((*mbufs_out)[mbuf_idx] == NULL)
173 snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d",
176 uint16_t priv_size = RTE_ALIGN_CEIL(test_vector->cipher_iv.length +
177 test_vector->auth_iv.length + test_vector->aead_iv.length +
178 extra_op_priv_size, 16) +
179 RTE_ALIGN_CEIL(options->aead_aad_sz, 16);
181 *crypto_op_pool = rte_crypto_op_pool_create(pool_name,
182 RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz,
183 512, priv_size, rte_socket_id());
184 if (*crypto_op_pool == NULL)
191 cperf_free_common_memory(const struct cperf_options *options,
192 struct rte_mempool *pkt_mbuf_pool_in,
193 struct rte_mempool *pkt_mbuf_pool_out,
194 struct rte_mbuf **mbufs_in,
195 struct rte_mbuf **mbufs_out,
196 struct rte_mempool *crypto_op_pool)
201 while (mbufs_in[i] != NULL &&
202 i < options->pool_sz)
203 rte_pktmbuf_free(mbufs_in[i++]);
210 while (mbufs_out[i] != NULL
211 && i < options->pool_sz)
212 rte_pktmbuf_free(mbufs_out[i++]);
217 if (pkt_mbuf_pool_in)
218 rte_mempool_free(pkt_mbuf_pool_in);
220 if (pkt_mbuf_pool_out)
221 rte_mempool_free(pkt_mbuf_pool_out);
224 rte_mempool_free(crypto_op_pool);