diff mbox series

[API-NEXT,v8,9/10] test: rewrite odp_crypto using Crypto packet API

Message ID 1499263226-5288-10-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [API-NEXT,v8,1/10] linux-generic: events subtype implementation | expand

Commit Message

Github ODP bot July 5, 2017, 2 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 64 (lumag:crypto-packet)
 ** https://github.com/Linaro/odp/pull/64
 ** Patch: https://github.com/Linaro/odp/pull/64.patch
 ** Base sha: 00a21c6dce65a30c8250db59a42a43c658e8ca1b
 ** Merge commit sha: ac9b299a7f3bee72dd9343bbfaa826217d243ea6
 **/
 test/common_plat/performance/odp_crypto.c | 169 ++++++++++++++++++------------
 1 file changed, 104 insertions(+), 65 deletions(-)
diff mbox series

Patch

diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c
index bc29a888..a129ec98 100644
--- a/test/common_plat/performance/odp_crypto.c
+++ b/test/common_plat/performance/odp_crypto.c
@@ -443,9 +443,10 @@  create_session_from_config(odp_crypto_session_t *session,
 			return -1;
 		}
 		params.compl_queue = out_queue;
-
+		params.packet_op_mode = ODP_CRYPTO_ASYNC;
 	} else {
 		params.compl_queue = ODP_QUEUE_INVALID;
+		params.packet_op_mode   = ODP_CRYPTO_SYNC;
 	}
 	if (odp_crypto_session_create(&params, session,
 				      &ses_create_rc)) {
@@ -456,6 +457,24 @@  create_session_from_config(odp_crypto_session_t *session,
 	return 0;
 }
 
+static odp_packet_t
+make_packet(odp_pool_t pkt_pool, unsigned int payload_length)
+{
+	odp_packet_t pkt;
+
+	pkt = odp_packet_alloc(pkt_pool, payload_length);
+	if (pkt == ODP_PACKET_INVALID) {
+		app_err("failed to allocate buffer\n");
+		return pkt;
+	}
+
+	void *mem = odp_packet_data(pkt);
+
+	memset(mem, 1, payload_length);
+
+	return pkt;
+}
+
 /**
  * Run measurement iterations for given config and payload size.
  * Result of run returned in 'result' out parameter.
@@ -467,15 +486,13 @@  run_measure_one(crypto_args_t *cargs,
 		unsigned int payload_length,
 		crypto_run_result_t *result)
 {
-	odp_crypto_op_param_t params;
+	odp_crypto_packet_op_param_t params;
 
 	odp_pool_t pkt_pool;
 	odp_queue_t out_queue;
-	odp_packet_t pkt;
+	odp_packet_t pkt = ODP_PACKET_INVALID;
 	int rc = 0;
 
-	odp_bool_t posted = 0;
-
 	pkt_pool = odp_pool_lookup("packet_pool");
 	if (pkt_pool == ODP_POOL_INVALID) {
 		app_err("pkt_pool not found\n");
@@ -490,16 +507,12 @@  run_measure_one(crypto_args_t *cargs,
 		}
 	}
 
-	pkt = odp_packet_alloc(pkt_pool, payload_length);
-	if (pkt == ODP_PACKET_INVALID) {
-		app_err("failed to allocate buffer\n");
-		return -1;
+	if (cargs->reuse_packet) {
+		pkt = make_packet(pkt_pool, payload_length);
+		if (ODP_PACKET_INVALID == pkt)
+			return -1;
 	}
 
-	void *mem = odp_packet_data(pkt);
-
-	memset(mem, 1, payload_length);
-
 	time_record_t start, end;
 	int packets_sent = 0;
 	int packets_received = 0;
@@ -515,77 +528,102 @@  run_measure_one(crypto_args_t *cargs,
 	params.auth_range.length = payload_length;
 	params.hash_result_offset = payload_length;
 
-	if (cargs->reuse_packet) {
-		params.pkt = pkt;
-		params.out_pkt = cargs->in_place ? pkt :
-				 ODP_PACKET_INVALID;
-	}
-
 	fill_time_record(&start);
 
 	while ((packets_sent < cargs->iteration_count) ||
 	       (packets_received <  cargs->iteration_count)) {
 		void *mem;
-		odp_crypto_op_result_t result;
 
 		if ((packets_sent < cargs->iteration_count) &&
 		    (packets_sent - packets_received <
 		     cargs->in_flight)) {
+			odp_packet_t out_pkt;
+
 			if (!cargs->reuse_packet) {
-				/*
-				 * For in place test we use just one
-				 * statically allocated buffer.
-				 * For now in place test we have to
-				 * allocate and initialize packet
-				 * every time.
-				 * Note we leaked one packet here.
-				 */
-				odp_packet_t newpkt;
-
-				newpkt = odp_packet_alloc(pkt_pool,
-							  payload_length);
-				if (newpkt == ODP_PACKET_INVALID) {
-					app_err("failed to allocate buffer\n");
+				pkt = make_packet(pkt_pool, payload_length);
+				if (ODP_PACKET_INVALID == pkt)
 					return -1;
-				}
-				mem = odp_packet_data(newpkt);
-				memset(mem, 1, payload_length);
-				params.pkt = newpkt;
-				params.out_pkt = cargs->in_place ? newpkt :
-						 ODP_PACKET_INVALID;
 			}
 
+			out_pkt = cargs->in_place ? pkt : ODP_PACKET_INVALID;
+
 			if (cargs->debug_packets) {
-				mem = odp_packet_data(params.pkt);
+				mem = odp_packet_data(pkt);
 				print_mem("Packet before encryption:",
 					  mem, payload_length);
 			}
 
-			rc = odp_crypto_operation(&params, &posted,
-						  &result);
-			if (rc)
-				app_err("failed odp_crypto_operation: rc = %d\n",
-					rc);
-			else
-				packets_sent++;
+			if (cargs->schedule || cargs->poll) {
+				rc = odp_crypto_packet_op_enq(&pkt, &out_pkt,
+							      &params, 1);
+				if (rc <= 0) {
+					app_err("failed odp_crypto_packet_op_enq: rc = %d\n",
+						rc);
+					break;
+				}
+				packets_sent += rc;
+			} else {
+				rc = odp_crypto_packet_op(&pkt, &out_pkt,
+							  &params, 1);
+				if (rc <= 0) {
+					app_err("failed odp_crypto_packet_op: rc = %d\n",
+						rc);
+					break;
+				}
+				packets_sent += rc;
+				packets_received++;
+				if (cargs->debug_packets) {
+					mem = odp_packet_data(out_pkt);
+					print_mem("Immediately encrypted "
+						   "packet",
+						  mem,
+						  payload_length +
+						  config->session.
+						   auth_digest_len);
+				}
+				if (!cargs->in_place) {
+					if (cargs->reuse_packet)
+						pkt = out_pkt;
+					else
+						odp_packet_free(out_pkt);
+				}
+			}
 		}
 
-		if (1) {
-			packets_received++;
-			if (cargs->debug_packets) {
-				mem = odp_packet_data(params.out_pkt);
-				print_mem("Immediately encrypted packet", mem,
-					  payload_length +
-					  config->session.auth_digest_len);
-			}
-			if (!cargs->in_place) {
-				if (cargs->reuse_packet) {
-					params.pkt = params.out_pkt;
-					params.out_pkt = ODP_PACKET_INVALID;
-				} else {
-					odp_packet_free(params.out_pkt);
+		if (out_queue != ODP_QUEUE_INVALID) {
+			odp_event_t ev;
+			odp_crypto_packet_result_t result;
+			odp_packet_t out_pkt;
+
+			if (cargs->schedule)
+				ev = odp_schedule(NULL,
+						  ODP_SCHED_NO_WAIT);
+			else
+				ev = odp_queue_deq(out_queue);
+
+			while (ev != ODP_EVENT_INVALID) {
+				out_pkt = odp_crypto_packet_from_event(ev);
+				odp_crypto_packet_result(&result, out_pkt);
+
+				if (cargs->debug_packets) {
+					mem = odp_packet_data(out_pkt);
+					print_mem("Receieved encrypted packet",
+						  mem,
+						  payload_length +
+						  config->
+						  session.auth_digest_len);
 				}
-			}
+				if (cargs->reuse_packet)
+					pkt = out_pkt;
+				else
+					odp_packet_free(out_pkt);
+				packets_received++;
+				if (cargs->schedule)
+					ev = odp_schedule(NULL,
+							  ODP_SCHED_NO_WAIT);
+				else
+					ev = odp_queue_deq(out_queue);
+			};
 		}
 	}
 
@@ -607,9 +645,10 @@  run_measure_one(crypto_args_t *cargs,
 					cargs->iteration_count;
 	}
 
-	odp_packet_free(pkt);
+	if (ODP_PACKET_INVALID != pkt)
+		odp_packet_free(pkt);
 
-	return rc;
+	return rc < 0 ? rc : 0;
 }
 
 /**