summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSagi Grimberg <sagi@grimberg.me>2017-07-13 04:09:43 -0400
committerDoug Ledford <dledford@redhat.com>2017-08-08 14:58:03 -0400
commit24c5dc6610e8a3764fcb885cc3284c12ff1513de (patch)
tree4e63a3a4d5cff3d270598feb0d617c146ae20a41
parent40b24403f33ed8e9401b087e25f46d002fc8f396 (diff)
block: Add rdma affinity based queue mapping helper
Like pci and virtio, we add a rdma helper for affinity spreading. This achieves optimal mq affinity assignments according to the underlying rdma device affinity maps. Reviewed-by: Jens Axboe <axboe@fb.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Max Gurtovoy <maxg@mellanox.com> Signed-off-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--block/Kconfig5
-rw-r--r--block/Makefile1
-rw-r--r--block/blk-mq-rdma.c52
-rw-r--r--include/linux/blk-mq-rdma.h10
4 files changed, 68 insertions, 0 deletions
diff --git a/block/Kconfig b/block/Kconfig
index 89cd28f8d051..3ab42bbb06d5 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -206,4 +206,9 @@ config BLK_MQ_VIRTIO
206 depends on BLOCK && VIRTIO 206 depends on BLOCK && VIRTIO
207 default y 207 default y
208 208
209config BLK_MQ_RDMA
210 bool
211 depends on BLOCK && INFINIBAND
212 default y
213
209source block/Kconfig.iosched 214source block/Kconfig.iosched
diff --git a/block/Makefile b/block/Makefile
index 2b281cf258a0..9396ebc85d24 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o
29obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o 29obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o
30obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o 30obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o
31obj-$(CONFIG_BLK_MQ_VIRTIO) += blk-mq-virtio.o 31obj-$(CONFIG_BLK_MQ_VIRTIO) += blk-mq-virtio.o
32obj-$(CONFIG_BLK_MQ_RDMA) += blk-mq-rdma.o
32obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o 33obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o
33obj-$(CONFIG_BLK_WBT) += blk-wbt.o 34obj-$(CONFIG_BLK_WBT) += blk-wbt.o
34obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o 35obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o
diff --git a/block/blk-mq-rdma.c b/block/blk-mq-rdma.c
new file mode 100644
index 000000000000..996167f1de18
--- /dev/null
+++ b/block/blk-mq-rdma.c
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 2017 Sagi Grimberg.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 */
13#include <linux/blk-mq.h>
14#include <linux/blk-mq-rdma.h>
15#include <rdma/ib_verbs.h>
16
17/**
18 * blk_mq_rdma_map_queues - provide a default queue mapping for rdma device
19 * @set: tagset to provide the mapping for
20 * @dev: rdma device associated with @set.
21 * @first_vec: first interrupt vectors to use for queues (usually 0)
22 *
23 * This function assumes the rdma device @dev has at least as many available
24 * interrupt vetors as @set has queues. It will then query it's affinity mask
25 * and built queue mapping that maps a queue to the CPUs that have irq affinity
26 * for the corresponding vector.
27 *
28 * In case either the driver passed a @dev with less vectors than
29 * @set->nr_hw_queues, or @dev does not provide an affinity mask for a
30 * vector, we fallback to the naive mapping.
31 */
32int blk_mq_rdma_map_queues(struct blk_mq_tag_set *set,
33 struct ib_device *dev, int first_vec)
34{
35 const struct cpumask *mask;
36 unsigned int queue, cpu;
37
38 for (queue = 0; queue < set->nr_hw_queues; queue++) {
39 mask = ib_get_vector_affinity(dev, first_vec + queue);
40 if (!mask)
41 goto fallback;
42
43 for_each_cpu(cpu, mask)
44 set->mq_map[cpu] = queue;
45 }
46
47 return 0;
48
49fallback:
50 return blk_mq_map_queues(set);
51}
52EXPORT_SYMBOL_GPL(blk_mq_rdma_map_queues);
diff --git a/include/linux/blk-mq-rdma.h b/include/linux/blk-mq-rdma.h
new file mode 100644
index 000000000000..b4ade198007d
--- /dev/null
+++ b/include/linux/blk-mq-rdma.h
@@ -0,0 +1,10 @@
1#ifndef _LINUX_BLK_MQ_RDMA_H
2#define _LINUX_BLK_MQ_RDMA_H
3
4struct blk_mq_tag_set;
5struct ib_device;
6
7int blk_mq_rdma_map_queues(struct blk_mq_tag_set *set,
8 struct ib_device *dev, int first_vec);
9
10#endif /* _LINUX_BLK_MQ_RDMA_H */