Commit | Line | Data |
---|---|---|
3dcf60bc | 1 | // SPDX-License-Identifier: GPL-2.0 |
75bb4625 JA |
2 | /* |
3 | * CPU <-> hardware queue mapping helpers | |
4 | * | |
5 | * Copyright (C) 2013-2014 Jens Axboe | |
6 | */ | |
320ae51f JA |
7 | #include <linux/kernel.h> |
8 | #include <linux/threads.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/mm.h> | |
11 | #include <linux/smp.h> | |
12 | #include <linux/cpu.h> | |
6a6dcae8 | 13 | #include <linux/group_cpus.h> |
320ae51f JA |
14 | |
15 | #include <linux/blk-mq.h> | |
16 | #include "blk.h" | |
17 | #include "blk-mq.h" | |
18 | ||
a4e1d0b7 | 19 | void blk_mq_map_queues(struct blk_mq_queue_map *qmap) |
320ae51f | 20 | { |
6a6dcae8 ML |
21 | const struct cpumask *masks; |
22 | unsigned int queue, cpu; | |
23 | ||
24 | masks = group_cpus_evenly(qmap->nr_queues); | |
25 | if (!masks) { | |
26 | for_each_possible_cpu(cpu) | |
27 | qmap->mq_map[cpu] = qmap->queue_offset; | |
28 | return; | |
556f36e9 | 29 | } |
320ae51f | 30 | |
6a6dcae8 ML |
31 | for (queue = 0; queue < qmap->nr_queues; queue++) { |
32 | for_each_cpu(cpu, &masks[queue]) | |
33 | qmap->mq_map[cpu] = qmap->queue_offset + queue; | |
320ae51f | 34 | } |
6a6dcae8 | 35 | kfree(masks); |
320ae51f | 36 | } |
9e5a7e22 | 37 | EXPORT_SYMBOL_GPL(blk_mq_map_queues); |
320ae51f | 38 | |
cd669f88 BVA |
39 | /** |
40 | * blk_mq_hw_queue_to_node - Look up the memory node for a hardware queue index | |
41 | * @qmap: CPU to hardware queue map. | |
42 | * @index: hardware queue index. | |
43 | * | |
f14bbe77 JA |
44 | * We have no quick way of doing reverse lookups. This is only used at |
45 | * queue init time, so runtime isn't important. | |
46 | */ | |
ed76e329 | 47 | int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index) |
f14bbe77 JA |
48 | { |
49 | int i; | |
50 | ||
51 | for_each_possible_cpu(i) { | |
ed76e329 | 52 | if (index == qmap->mq_map[i]) |
576e85c5 | 53 | return cpu_to_node(i); |
f14bbe77 JA |
54 | } |
55 | ||
56 | return NUMA_NO_NODE; | |
57 | } |