common/qat: optimise calculation of cookie index
authorFiona Trahe <fiona.trahe@intel.com>
Wed, 11 Mar 2020 12:26:08 +0000 (13:26 +0100)
committerAkhil Goyal <akhil.goyal@oss.nxp.com>
Sun, 5 Apr 2020 16:26:04 +0000 (18:26 +0200)
Avoid costly division, use shift instead.

Signed-off-by: Fiona Trahe <fiona.trahe@intel.com>
Acked-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
drivers/common/qat/qat_qp.c
drivers/common/qat/qat_qp.h

index 9958789..b0a2064 100644 (file)
@@ -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
                }
 
index 0b95ea3..0d6896d 100644 (file)
@@ -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 */