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,
41 const struct cperf_options *options)
43 struct rte_mbuf *mbuf;
45 uint32_t remaining_bytes = options->max_buffer_size;
47 mbuf = rte_pktmbuf_alloc(mempool);
51 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
52 if (mbuf_data == NULL)
55 if (options->max_buffer_size <= segment_sz)
58 remaining_bytes -= segment_sz;
62 while (remaining_bytes) {
65 m = rte_pktmbuf_alloc(mempool);
69 rte_pktmbuf_chain(mbuf, m);
71 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
72 if (mbuf_data == NULL)
75 if (remaining_bytes <= segment_sz)
78 remaining_bytes -= segment_sz;
84 * If there was not enough room for the digest at the end
85 * of the last segment, allocate a new one
87 if (segments_nb != 0) {
89 m = rte_pktmbuf_alloc(mempool);
94 rte_pktmbuf_chain(mbuf, m);
95 mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz);
96 if (mbuf_data == NULL)
103 rte_pktmbuf_free(mbuf);
109 cperf_alloc_common_memory(const struct cperf_options *options,
110 const struct cperf_test_vector *test_vector,
111 uint8_t dev_id, size_t extra_op_priv_size,
112 struct rte_mempool **pkt_mbuf_pool_in,
113 struct rte_mempool **pkt_mbuf_pool_out,
114 struct rte_mbuf ***mbufs_in,
115 struct rte_mbuf ***mbufs_out,
116 struct rte_mempool **crypto_op_pool)
118 unsigned int mbuf_idx = 0;
119 char pool_name[32] = "";
121 snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d",
124 uint32_t max_size = options->max_buffer_size + options->digest_sz;
125 uint16_t segments_nb = (max_size % options->segment_sz) ?
126 (max_size / options->segment_sz) + 1 :
127 max_size / options->segment_sz;
129 *pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name,
130 options->pool_sz * segments_nb, 0, 0,
131 RTE_PKTMBUF_HEADROOM + options->segment_sz,
134 if (*pkt_mbuf_pool_in == NULL)
137 /* Generate mbufs_in with plaintext populated for test */
138 *mbufs_in = (struct rte_mbuf **)rte_malloc(NULL,
139 (sizeof(struct rte_mbuf *) * options->pool_sz), 0);
141 for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
142 (*mbufs_in)[mbuf_idx] = cperf_mbuf_create(
147 if ((*mbufs_in)[mbuf_idx] == NULL)
151 *mbufs_out = (struct rte_mbuf **)rte_zmalloc(NULL,
152 (sizeof(struct rte_mbuf *) *
153 options->pool_sz), 0);
155 if (options->out_of_place == 1) {
156 snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d",
159 *pkt_mbuf_pool_out = rte_pktmbuf_pool_create(
160 pool_name, options->pool_sz, 0, 0,
161 RTE_PKTMBUF_HEADROOM + max_size,
164 if (*pkt_mbuf_pool_out == NULL)
167 for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) {
168 (*mbufs_out)[mbuf_idx] = cperf_mbuf_create(
169 *pkt_mbuf_pool_out, max_size,
171 if ((*mbufs_out)[mbuf_idx] == NULL)
176 snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d",
179 uint16_t priv_size = RTE_ALIGN_CEIL(test_vector->cipher_iv.length +
180 test_vector->auth_iv.length + test_vector->aead_iv.length +
181 extra_op_priv_size, 16) +
182 RTE_ALIGN_CEIL(options->aead_aad_sz, 16);
184 *crypto_op_pool = rte_crypto_op_pool_create(pool_name,
185 RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz,
186 512, priv_size, rte_socket_id());
187 if (*crypto_op_pool == NULL)
194 cperf_free_common_memory(const struct cperf_options *options,
195 struct rte_mempool *pkt_mbuf_pool_in,
196 struct rte_mempool *pkt_mbuf_pool_out,
197 struct rte_mbuf **mbufs_in,
198 struct rte_mbuf **mbufs_out,
199 struct rte_mempool *crypto_op_pool)
204 while (mbufs_in[i] != NULL &&
205 i < options->pool_sz)
206 rte_pktmbuf_free(mbufs_in[i++]);
213 while (mbufs_out[i] != NULL
214 && i < options->pool_sz)
215 rte_pktmbuf_free(mbufs_out[i++]);
220 if (pkt_mbuf_pool_in)
221 rte_mempool_free(pkt_mbuf_pool_in);
223 if (pkt_mbuf_pool_out)
224 rte_mempool_free(pkt_mbuf_pool_out);
227 rte_mempool_free(crypto_op_pool);