Skip to contentSkip to conversation

crypto/qat: improve out-of-place conditional check

PATCH In review Adam Dybkowski 2 participants 4 messages Mar 11, 2020 – Mar 25, 2020 1 message not in the archive Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 crypto/qat: improve out-of-place conditional check

From: Fiona Trahe <[email protected]>

Improve case where application set m_dst to same as m_src so really an in-place operation, though would have been treated as out-of-place. No functional change but this path can now benefit from DMA alignment.

---
 drivers/crypto/qat/qat_sym.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/qat/qat_sym.c +5 -3
index 5c9904cbf..cecced66d 100644
@@ -62,7 +62,8 @@ qat_bpicipher_preprocess(struct qat_sym_session *ctx,
 		last_block = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_src,
 				uint8_t *, last_block_offset);
 
-		if (unlikely(sym_op->m_dst != NULL))
+		if (unlikely((sym_op->m_dst != NULL)
+				&& (sym_op->m_dst != sym_op->m_src)))
 			/* out-of-place operation (OOP) */
 			dst = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_dst,
 						uint8_t *, last_block_offset);
@@ -437,7 +438,8 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
 	if (unlikely(min_ofs >= rte_pktmbuf_data_len(op->sym->m_src) && do_sgl))
 		min_ofs = 0;
 
-	if (unlikely(op->sym->m_dst != NULL)) {
+	if (unlikely((op->sym->m_dst != NULL) &&
+			(op->sym->m_dst != op->sym->m_src))) {
 		/* Out-of-place operation (OOP)
 		 * Don't align DMA start. DMA the minimum data-set
 		 * so as not to overwrite data in dest buffer
@@ -565,7 +567,7 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
 			return ret;
 		}
 
-		if (likely(op->sym->m_dst == NULL))
+		if (in_place)
 			qat_req->comn_mid.dest_data_addr =
 				qat_req->comn_mid.src_data_addr =
 				cookie->qat_sgl_src_phys_addr;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 crypto/qat: optimise check for chained mbufs

From: Fiona Trahe <[email protected]>

To detect if sgl, use nb_segs > 1, instead of checking for next pointer, as nb_segs is in first cache-line while next is in second cache-line.

---
 drivers/crypto/qat/qat_sym.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_sym.c +2 -1
index cecced66d..25b6dd5f4 100644
@@ -428,7 +428,8 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
 		min_ofs = op->sym->aead.data.offset;
 	}
 
-	if (op->sym->m_src->next || (op->sym->m_dst && op->sym->m_dst->next))
+	if (op->sym->m_src->nb_segs > 1 ||
+			(op->sym->m_dst && op->sym->m_dst->nb_segs > 1))
 		do_sgl = 1;
 
 	/* adjust for chain case */
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/3 common/qat: optimise calculation of cookie index

In reply to Adam Dybkowski

From: Fiona Trahe <[email protected]>

Avoid costly division, use shift instead.

---
 drivers/common/qat/qat_qp.c | 9 ++++++---
 drivers/common/qat/qat_qp.h | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/common/qat/qat_qp.c +6 -3
index 9958789f0..b0a206434 100644
@@ -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
 		}
 
drivers/common/qat/qat_qp.h +1 -0
index 0b95ea3c9..0d6896d7b 100644
@@ -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 */
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): BL0PR11MB3316D12948582A96E3C3365B9FFC0@BL0PR11MB3316.namprd11.prod.outlook.com

#4 lore raw
Quoted 11 lines
Quoted 11 lines

From: Fiona Trahe <[email protected]>

Improve case where application set m_dst to same as m_src so really an in- place operation, though would have been treated as out-of-place. No functional change but this path can now benefit from DMA alignment.

---
 drivers/crypto/qat/qat_sym.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 4 lines
Quoted 3 lines
drivers/crypto/qat/qat_sym.c +0 -0
index 5c9904cbf..cecced66d 100644

2.17.1

Series applied to dpdk-next-crypto

Thanks.