]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
scsi: hisi_sas: Pre-allocate slot DMA buffers
authorXiang Chen <chenxiang66@hisilicon.com>
Thu, 31 May 2018 12:50:48 +0000 (20:50 +0800)
committerKhalid Elmously <khalid.elmously@canonical.com>
Sun, 1 Jul 2018 23:06:50 +0000 (23:06 +0000)
BugLink: https://bugs.launchpad.net/bugs/1777727
Currently the driver spends much time allocating and freeing the slot DMA
buffer for command delivery/completion. To boost the performance,
pre-allocate the buffers for all IPTT. The downside of this approach is
that we are reallocating all buffer memory upfront, so hog memory which we
may not need.

However, the current method - DMA buffer pool - also caches all buffers and
does not free them until the pool is destroyed, so is not exactly efficient
either.

On top of this, since the slot DMA buffer is slightly bigger than a 4K
page, we need to allocate 2x4K pages per buffer (for 4K page kernel), which
is quite wasteful. For 64K page size this is not such an issue.

So, for the 4K page case, in order to make memory usage more efficient,
pre-allocating larger blocks of DMA memory for the buffers can be more
efficient.

To make DMA memory usage most efficient, we would choose a single
contiguous DMA memory block, but this could use up all the DMA memory in
the system (when CMA enabled and no IOMMU), or we may just not be able to
allocate a DMA buffer large enough when no CMA or IOMMU.

To decide the block size we use the LCM (least common multiple) of the
buffer size and the page size. We roundup(64) to ensure the LCM is not too
large, even though a little memory may be wasted per block.

So, with this, the total memory requirement is about is about 17MB for 4096
max IPTT.

Previously (for 4K pages case), it would be 32MB (for all slots
allocated).

With this change, the relative increase of IOPS for bs=4K read when
PAGE_SIZE=4K and PAGE_SIZE=64K is as follows:
    IODEPTH     4K PAGE_SIZE      64K PAGE_SIZE
    32          56%               47%
    64          53%               44%
    128         64%               43%
    256         67%               45%

Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit bbb14d21a0614deefbdf24da61606f7bd7a1263a scsi)
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/scsi/hisi_sas/hisi_sas.h
drivers/scsi/hisi_sas/hisi_sas_main.c

index 1771eafa0be7ad44cd50c5ff5b624aedbc5cd2e0..6f79343b61c6766a4c0fe4ed69ac9f4a9ec81f2f 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/clk.h>
 #include <linux/dmapool.h>
 #include <linux/iopoll.h>
+#include <linux/lcm.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
@@ -201,17 +202,18 @@ struct hisi_sas_slot {
        int     dlvry_queue_slot;
        int     cmplt_queue;
        int     cmplt_queue_slot;
-       int     idx;
        int     abort;
        int     ready;
-       void    *buf;
-       dma_addr_t buf_dma;
        void    *cmd_hdr;
        dma_addr_t cmd_hdr_dma;
        struct work_struct abort_slot;
        struct timer_list internal_abort_timer;
        bool is_internal;
        struct hisi_sas_tmf_task *tmf;
+       /* Do not reorder/change members after here */
+       void    *buf;
+       dma_addr_t buf_dma;
+       int     idx;
 };
 
 struct hisi_sas_hw {
@@ -301,7 +303,6 @@ struct hisi_hba {
 
        int     queue_count;
 
-       struct dma_pool *buffer_pool;
        struct hisi_sas_device  devices[HISI_SAS_MAX_DEVICES];
        struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES];
        dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES];
index 328303add2a53223c1c62a5f55cc3399fd535b87..55d3fa5c99a5cd954877d9e3718ec92fc15496ab 100644 (file)
@@ -241,20 +241,16 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task,
                                             task->data_dir);
        }
 
-       if (slot->buf)
-               dma_pool_free(hisi_hba->buffer_pool, slot->buf, slot->buf_dma);
 
        spin_lock_irqsave(&dq->lock, flags);
        list_del_init(&slot->entry);
        spin_unlock_irqrestore(&dq->lock, flags);
-       slot->buf = NULL;
-       slot->task = NULL;
-       slot->port = NULL;
+
+       memset(slot, 0, offsetof(struct hisi_sas_slot, buf));
+
        spin_lock_irqsave(&hisi_hba->lock, flags);
        hisi_sas_slot_index_free(hisi_hba, slot->idx);
        spin_unlock_irqrestore(&hisi_hba->lock, flags);
-
-       /* slot memory is fully zeroed when it is reused */
 }
 EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free);
 
@@ -429,21 +425,13 @@ static int hisi_sas_task_prep(struct sas_task *task,
                goto err_out_dma_unmap;
 
        slot = &hisi_hba->slot_info[slot_idx];
-       memset(slot, 0, sizeof(struct hisi_sas_slot));
-
-       slot->buf = dma_pool_alloc(hisi_hba->buffer_pool,
-                                  GFP_ATOMIC, &slot->buf_dma);
-       if (!slot->buf) {
-               rc = -ENOMEM;
-               goto err_out_tag;
-       }
 
        spin_lock_irqsave(&dq->lock, flags_dq);
        wr_q_index = hisi_hba->hw->get_free_slot(hisi_hba, dq);
        if (wr_q_index < 0) {
                spin_unlock_irqrestore(&dq->lock, flags_dq);
                rc = -EAGAIN;
-               goto err_out_buf;
+               goto err_out_tag;
        }
 
        list_add_tail(&slot->delivery, &dq->list);
@@ -452,7 +440,6 @@ static int hisi_sas_task_prep(struct sas_task *task,
        dlvry_queue = dq->id;
        dlvry_queue_slot = wr_q_index;
 
-       slot->idx = slot_idx;
        slot->n_elem = n_elem;
        slot->dlvry_queue = dlvry_queue;
        slot->dlvry_queue_slot = dlvry_queue_slot;
@@ -499,9 +486,6 @@ static int hisi_sas_task_prep(struct sas_task *task,
 
        return 0;
 
-err_out_buf:
-       dma_pool_free(hisi_hba->buffer_pool, slot->buf,
-                     slot->buf_dma);
 err_out_tag:
        spin_lock_irqsave(&hisi_hba->lock, flags);
        hisi_sas_slot_index_free(hisi_hba, slot_idx);
@@ -1723,21 +1707,13 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
        spin_unlock_irqrestore(&hisi_hba->lock, flags);
 
        slot = &hisi_hba->slot_info[slot_idx];
-       memset(slot, 0, sizeof(struct hisi_sas_slot));
-
-       slot->buf = dma_pool_alloc(hisi_hba->buffer_pool,
-                       GFP_ATOMIC, &slot->buf_dma);
-       if (!slot->buf) {
-               rc = -ENOMEM;
-               goto err_out_tag;
-       }
 
        spin_lock_irqsave(&dq->lock, flags_dq);
        wr_q_index = hisi_hba->hw->get_free_slot(hisi_hba, dq);
        if (wr_q_index < 0) {
                spin_unlock_irqrestore(&dq->lock, flags_dq);
                rc = -EAGAIN;
-               goto err_out_buf;
+               goto err_out_tag;
        }
        list_add_tail(&slot->delivery, &dq->list);
        spin_unlock_irqrestore(&dq->lock, flags_dq);
@@ -1745,7 +1721,6 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
        dlvry_queue = dq->id;
        dlvry_queue_slot = wr_q_index;
 
-       slot->idx = slot_idx;
        slot->n_elem = n_elem;
        slot->dlvry_queue = dlvry_queue;
        slot->dlvry_queue_slot = dlvry_queue_slot;
@@ -1776,9 +1751,6 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
 
        return 0;
 
-err_out_buf:
-       dma_pool_free(hisi_hba->buffer_pool, slot->buf,
-                     slot->buf_dma);
 err_out_tag:
        spin_lock_irqsave(&hisi_hba->lock, flags);
        hisi_sas_slot_index_free(hisi_hba, slot_idx);
@@ -2015,7 +1987,9 @@ EXPORT_SYMBOL_GPL(hisi_sas_init_mem);
 int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
 {
        struct device *dev = hisi_hba->dev;
-       int i, s, max_command_entries = hisi_hba->hw->max_command_entries;
+       int i, j, s, max_command_entries = hisi_hba->hw->max_command_entries;
+       int max_command_entries_ru, sz_slot_buf_ru;
+       int blk_cnt, slots_per_blk;
 
        sema_init(&hisi_hba->sem, 1);
        spin_lock_init(&hisi_hba->lock);
@@ -2062,11 +2036,6 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
                        goto err_out;
        }
 
-       s = sizeof(struct hisi_sas_slot_buf_table);
-       hisi_hba->buffer_pool = dma_pool_create("dma_buffer", dev, s, 16, 0);
-       if (!hisi_hba->buffer_pool)
-               goto err_out;
-
        s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct);
        hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma,
                                             GFP_KERNEL);
@@ -2080,6 +2049,35 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost)
        if (!hisi_hba->slot_info)
                goto err_out;
 
+       /* roundup to avoid overly large block size */
+       max_command_entries_ru = roundup(max_command_entries, 64);
+       sz_slot_buf_ru = roundup(sizeof(struct hisi_sas_slot_buf_table), 64);
+       s = lcm(max_command_entries_ru, sz_slot_buf_ru);
+       blk_cnt = (max_command_entries_ru * sz_slot_buf_ru) / s;
+       slots_per_blk = s / sz_slot_buf_ru;
+       for (i = 0; i < blk_cnt; i++) {
+               struct hisi_sas_slot_buf_table *buf;
+               dma_addr_t buf_dma;
+               int slot_index = i * slots_per_blk;
+
+               buf = dmam_alloc_coherent(dev, s, &buf_dma, GFP_KERNEL);
+               if (!buf)
+                       goto err_out;
+               memset(buf, 0, s);
+
+               for (j = 0; j < slots_per_blk; j++, slot_index++) {
+                       struct hisi_sas_slot *slot;
+
+                       slot = &hisi_hba->slot_info[slot_index];
+                       slot->buf = buf;
+                       slot->buf_dma = buf_dma;
+                       slot->idx = slot_index;
+
+                       buf++;
+                       buf_dma += sizeof(*buf);
+               }
+       }
+
        s = max_command_entries * sizeof(struct hisi_sas_iost);
        hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma,
                                             GFP_KERNEL);
@@ -2130,8 +2128,6 @@ EXPORT_SYMBOL_GPL(hisi_sas_alloc);
 
 void hisi_sas_free(struct hisi_hba *hisi_hba)
 {
-       dma_pool_destroy(hisi_hba->buffer_pool);
-
        if (hisi_hba->wq)
                destroy_workqueue(hisi_hba->wq);
 }