Skip to content

Commit fe2bdef

Browse files
igawgregkh
authored andcommitted
blk-mq: introduce blk_mq_map_hw_queues
[ Upstream commit 1452e9b ] blk_mq_pci_map_queues and blk_mq_virtio_map_queues will create a CPU to hardware queue mapping based on affinity information. These two function share common code and only differ on how the affinity information is retrieved. Also, those functions are located in the block subsystem where it doesn't really fit in. They are virtio and pci subsystem specific. Thus introduce provide a generic mapping function which uses the irq_get_affinity callback from bus_type. Originally idea from Ming Lei <ming.lei@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: John Garry <john.g.garry@oracle.com> Signed-off-by: Daniel Wagner <wagi@kernel.org> Link: https://lore.kernel.org/r/20241202-refactor-blk-affinity-helpers-v6-4-27211e9c2cd5@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: a2d5a00 ("scsi: smartpqi: Use is_kdump_kernel() to check for kdump") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5ec9039 commit fe2bdef

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

block/blk-mq-cpumap.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/smp.h>
1212
#include <linux/cpu.h>
1313
#include <linux/group_cpus.h>
14+
#include <linux/device/bus.h>
1415

1516
#include "blk.h"
1617
#include "blk-mq.h"
@@ -54,3 +55,39 @@ int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
5455

5556
return NUMA_NO_NODE;
5657
}
58+
59+
/**
60+
* blk_mq_map_hw_queues - Create CPU to hardware queue mapping
61+
* @qmap: CPU to hardware queue map
62+
* @dev: The device to map queues
63+
* @offset: Queue offset to use for the device
64+
*
65+
* Create a CPU to hardware queue mapping in @qmap. The struct bus_type
66+
* irq_get_affinity callback will be used to retrieve the affinity.
67+
*/
68+
void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
69+
struct device *dev, unsigned int offset)
70+
71+
{
72+
const struct cpumask *mask;
73+
unsigned int queue, cpu;
74+
75+
if (!dev->bus->irq_get_affinity)
76+
goto fallback;
77+
78+
for (queue = 0; queue < qmap->nr_queues; queue++) {
79+
mask = dev->bus->irq_get_affinity(dev, queue + offset);
80+
if (!mask)
81+
goto fallback;
82+
83+
for_each_cpu(cpu, mask)
84+
qmap->mq_map[cpu] = qmap->queue_offset + queue;
85+
}
86+
87+
return;
88+
89+
fallback:
90+
WARN_ON_ONCE(qmap->nr_queues > 1);
91+
blk_mq_clear_mq_map(qmap);
92+
}
93+
EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);

include/linux/blk-mq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ void blk_mq_unfreeze_queue_non_owner(struct request_queue *q);
947947
void blk_freeze_queue_start_non_owner(struct request_queue *q);
948948

949949
void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
950+
void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
951+
struct device *dev, unsigned int offset);
950952
void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);
951953

952954
void blk_mq_quiesce_queue_nowait(struct request_queue *q);

0 commit comments

Comments
 (0)