diff mbox series

[3/3] common/qat: optimise calculation of cookie index

Message ID 20200311122608.1262-3-adamx.dybkowski@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers show
Series [1/3] crypto/qat: improve out-of-place conditional check | expand

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Dybkowski, AdamX March 11, 2020, 12:26 p.m. UTC
From: Fiona Trahe <fiona.trahe@intel.com>

Avoid costly division, use shift instead.

Signed-off-by: Fiona Trahe <fiona.trahe@intel.com>
---
 drivers/common/qat/qat_qp.c | 9 ++++++---
 drivers/common/qat/qat_qp.h | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Kusztal, ArkadiuszX March 11, 2020, 3:44 p.m. UTC | #1
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Adam Dybkowski
> Sent: Wednesday, March 11, 2020 1:26 PM
> To: dev@dpdk.org; Trahe, Fiona <fiona.trahe@intel.com>;
> akhil.goyal@nxp.com; Dybkowski, AdamX <adamx.dybkowski@intel.com>
> Subject: [dpdk-dev] [PATCH 3/3] common/qat: optimise calculation of cookie
> index
> 
> From: Fiona Trahe <fiona.trahe@intel.com>
> 
> Avoid costly division, use shift instead.
> 
> Signed-off-by: Fiona Trahe <fiona.trahe@intel.com>
> ---
>  drivers/common/qat/qat_qp.c | 9 ++++++---  drivers/common/qat/qat_qp.h
> | 1 +
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> 2.17.1
Acked-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
diff mbox series

Patch

diff --git a/drivers/common/qat/qat_qp.c b/drivers/common/qat/qat_qp.c
index 9958789f0..b0a206434 100644
--- a/drivers/common/qat/qat_qp.c
+++ b/drivers/common/qat/qat_qp.c
@@ -430,6 +430,9 @@  qat_queue_create(struct qat_pci_device *qat_dev, struct qat_queue *queue,
 	queue->tail = 0;
 	queue->msg_size = desc_size;
 
+	/* For fast calculation of cookie index, relies on msg_size being 2^n */
+	queue->trailz = __builtin_ctz(desc_size);
+
 	/*
 	 * Write an unused pattern to the queue memory.
 	 */
@@ -623,7 +626,7 @@  qat_enqueue_op_burst(void *qp, void **ops, uint16_t nb_ops)
 
 	while (nb_ops_sent != nb_ops_possible) {
 		ret = tmp_qp->build_request(*ops, base_addr + tail,
-				tmp_qp->op_cookies[tail / queue->msg_size],
+				tmp_qp->op_cookies[tail >> queue->trailz],
 				tmp_qp->qat_dev_gen);
 		if (ret != 0) {
 			tmp_qp->stats.enqueue_err_count++;
@@ -665,12 +668,12 @@  qat_dequeue_op_burst(void *qp, void **ops, uint16_t nb_ops)
 			qat_sym_process_response(ops, resp_msg);
 		else if (tmp_qp->service_type == QAT_SERVICE_COMPRESSION)
 			qat_comp_process_response(ops, resp_msg,
-				tmp_qp->op_cookies[head / rx_queue->msg_size],
+				tmp_qp->op_cookies[head >> rx_queue->trailz],
 				&tmp_qp->stats.dequeue_err_count);
 		else if (tmp_qp->service_type == QAT_SERVICE_ASYMMETRIC) {
 #ifdef BUILD_QAT_ASYM
 			qat_asym_process_response(ops, resp_msg,
-				tmp_qp->op_cookies[head / rx_queue->msg_size]);
+				tmp_qp->op_cookies[head >> rx_queue->trailz]);
 #endif
 		}
 
diff --git a/drivers/common/qat/qat_qp.h b/drivers/common/qat/qat_qp.h
index 0b95ea3c9..0d6896d7b 100644
--- a/drivers/common/qat/qat_qp.h
+++ b/drivers/common/qat/qat_qp.h
@@ -54,6 +54,7 @@  struct qat_queue {
 	uint32_t	modulo_mask;
 	uint32_t	msg_size;
 	uint32_t	queue_size;
+	uint8_t		trailz;
 	uint8_t		hw_bundle_number;
 	uint8_t		hw_queue_number;
 	/* HW queue aka ring offset on bundle */