4 * Copyright(c) 2016-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>
34 #include <rte_cycles.h>
35 #include <rte_crypto.h>
36 #include <rte_cryptodev.h>
38 #include "cperf_test_throughput.h"
39 #include "cperf_ops.h"
40 #include "cperf_test_common.h"
42 struct cperf_throughput_ctx {
47 struct rte_mempool *pool;
49 struct rte_cryptodev_sym_session *sess;
51 cperf_populate_ops_t populate_ops;
53 uint32_t src_buf_offset;
54 uint32_t dst_buf_offset;
56 const struct cperf_options *options;
57 const struct cperf_test_vector *test_vector;
61 cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)
65 rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess);
66 rte_cryptodev_sym_session_free(ctx->sess);
70 rte_mempool_free(ctx->pool);
77 cperf_throughput_test_constructor(struct rte_mempool *sess_mp,
78 uint8_t dev_id, uint16_t qp_id,
79 const struct cperf_options *options,
80 const struct cperf_test_vector *test_vector,
81 const struct cperf_op_fns *op_fns)
83 struct cperf_throughput_ctx *ctx = NULL;
85 ctx = rte_malloc(NULL, sizeof(struct cperf_throughput_ctx), 0);
92 ctx->populate_ops = op_fns->populate_ops;
93 ctx->options = options;
94 ctx->test_vector = test_vector;
96 /* IV goes at the end of the crypto operation */
97 uint16_t iv_offset = sizeof(struct rte_crypto_op) +
98 sizeof(struct rte_crypto_sym_op);
100 ctx->sess = op_fns->sess_create(sess_mp, dev_id, options, test_vector,
102 if (ctx->sess == NULL)
105 if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0,
106 &ctx->src_buf_offset, &ctx->dst_buf_offset,
112 cperf_throughput_test_free(ctx);
118 cperf_throughput_test_runner(void *test_ctx)
120 struct cperf_throughput_ctx *ctx = test_ctx;
121 uint16_t test_burst_size;
122 uint8_t burst_size_idx = 0;
124 static int only_once;
126 struct rte_crypto_op *ops[ctx->options->max_burst_size];
127 struct rte_crypto_op *ops_processed[ctx->options->max_burst_size];
130 uint32_t lcore = rte_lcore_id();
132 #ifdef CPERF_LINEARIZATION_ENABLE
133 struct rte_cryptodev_info dev_info;
136 /* Check if source mbufs require coalescing */
137 if (ctx->options->segment_sz < ctx->options->max_buffer_size) {
138 rte_cryptodev_info_get(ctx->dev_id, &dev_info);
139 if ((dev_info.feature_flags &
140 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) == 0)
143 #endif /* CPERF_LINEARIZATION_ENABLE */
145 ctx->lcore_id = lcore;
147 /* Warm up the host CPU before starting the test */
148 for (i = 0; i < ctx->options->total_ops; i++)
149 rte_cryptodev_enqueue_burst(ctx->dev_id, ctx->qp_id, NULL, 0);
151 /* Get first size from range or list */
152 if (ctx->options->inc_burst_size != 0)
153 test_burst_size = ctx->options->min_burst_size;
155 test_burst_size = ctx->options->burst_size_list[0];
157 uint16_t iv_offset = sizeof(struct rte_crypto_op) +
158 sizeof(struct rte_crypto_sym_op);
160 while (test_burst_size <= ctx->options->max_burst_size) {
161 uint64_t ops_enqd = 0, ops_enqd_total = 0, ops_enqd_failed = 0;
162 uint64_t ops_deqd = 0, ops_deqd_total = 0, ops_deqd_failed = 0;
164 uint64_t tsc_start, tsc_end, tsc_duration;
166 uint16_t ops_unused = 0;
168 tsc_start = rte_rdtsc_precise();
170 while (ops_enqd_total < ctx->options->total_ops) {
172 uint16_t burst_size = ((ops_enqd_total + test_burst_size)
173 <= ctx->options->total_ops) ?
175 ctx->options->total_ops -
178 uint16_t ops_needed = burst_size - ops_unused;
180 /* Allocate objects containing crypto operations and mbufs */
181 if (rte_mempool_get_bulk(ctx->pool, (void **)ops,
184 "Failed to allocate more crypto operations "
185 "from the the crypto operation pool.\n"
186 "Consider increasing the pool size "
191 /* Setup crypto op, attach mbuf etc */
192 (ctx->populate_ops)(ops, ctx->src_buf_offset,
194 ops_needed, ctx->sess,
195 ctx->options, ctx->test_vector,
199 * When ops_needed is smaller than ops_enqd, the
200 * unused ops need to be moved to the front for
203 if (unlikely(ops_enqd > ops_needed)) {
204 size_t nb_b_to_mov = ops_unused * sizeof(
205 struct rte_crypto_op *);
207 memmove(&ops[ops_needed], &ops[ops_enqd],
211 #ifdef CPERF_LINEARIZATION_ENABLE
213 /* PMD doesn't support scatter-gather and source buffer
215 * We need to linearize it before enqueuing.
217 for (i = 0; i < burst_size; i++)
218 rte_pktmbuf_linearize(ops[i]->sym->m_src);
220 #endif /* CPERF_LINEARIZATION_ENABLE */
222 /* Enqueue burst of ops on crypto device */
223 ops_enqd = rte_cryptodev_enqueue_burst(ctx->dev_id, ctx->qp_id,
225 if (ops_enqd < burst_size)
229 * Calculate number of ops not enqueued (mainly for hw
230 * accelerators whose ingress queue can fill up).
232 ops_unused = burst_size - ops_enqd;
233 ops_enqd_total += ops_enqd;
236 /* Dequeue processed burst of ops from crypto device */
237 ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id,
238 ops_processed, test_burst_size);
240 if (likely(ops_deqd)) {
241 /* Free crypto ops so they can be reused. */
242 rte_mempool_put_bulk(ctx->pool,
243 (void **)ops_processed, ops_deqd);
245 ops_deqd_total += ops_deqd;
248 * Count dequeue polls which didn't return any
249 * processed operations. This statistic is mainly
250 * relevant to hw accelerators.
257 /* Dequeue any operations still in the crypto device */
259 while (ops_deqd_total < ctx->options->total_ops) {
260 /* Sending 0 length burst to flush sw crypto device */
261 rte_cryptodev_enqueue_burst(ctx->dev_id, ctx->qp_id, NULL, 0);
264 ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id,
265 ops_processed, test_burst_size);
269 rte_mempool_put_bulk(ctx->pool,
270 (void **)ops_processed, ops_deqd);
271 ops_deqd_total += ops_deqd;
275 tsc_end = rte_rdtsc_precise();
276 tsc_duration = (tsc_end - tsc_start);
278 /* Calculate average operations processed per second */
279 double ops_per_second = ((double)ctx->options->total_ops /
280 tsc_duration) * rte_get_tsc_hz();
282 /* Calculate average throughput (Gbps) in bits per second */
283 double throughput_gbps = ((ops_per_second *
284 ctx->options->test_buffer_size * 8) / 1000000000);
286 /* Calculate average cycles per packet */
287 double cycles_per_packet = ((double)tsc_duration /
288 ctx->options->total_ops);
290 if (!ctx->options->csv) {
292 printf("%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s\n\n",
293 "lcore id", "Buf Size", "Burst Size",
294 "Enqueued", "Dequeued", "Failed Enq",
295 "Failed Deq", "MOps", "Gbps",
299 printf("%12u%12u%12u%12"PRIu64"%12"PRIu64"%12"PRIu64
300 "%12"PRIu64"%12.4f%12.4f%12.2f\n",
302 ctx->options->test_buffer_size,
308 ops_per_second/1000000,
313 printf("#lcore id,Buffer Size(B),"
314 "Burst Size,Enqueued,Dequeued,Failed Enq,"
315 "Failed Deq,Ops(Millions),Throughput(Gbps),"
319 printf("%u;%u;%u;%"PRIu64";%"PRIu64";%"PRIu64";%"PRIu64";"
322 ctx->options->test_buffer_size,
328 ops_per_second/1000000,
333 /* Get next size from range or list */
334 if (ctx->options->inc_burst_size != 0)
335 test_burst_size += ctx->options->inc_burst_size;
337 if (++burst_size_idx == ctx->options->burst_size_count)
339 test_burst_size = ctx->options->burst_size_list[burst_size_idx];
349 cperf_throughput_test_destructor(void *arg)
351 struct cperf_throughput_ctx *ctx = arg;
356 cperf_throughput_test_free(ctx);