Blame view
block/blk-mq-cpumap.c
1.89 KB
3dcf60bcb
|
1 |
// SPDX-License-Identifier: GPL-2.0 |
75bb4625b
|
2 3 4 5 6 |
/* * CPU <-> hardware queue mapping helpers * * Copyright (C) 2013-2014 Jens Axboe */ |
320ae51fe
|
7 8 9 10 11 12 13 14 15 16 |
#include <linux/kernel.h> #include <linux/threads.h> #include <linux/module.h> #include <linux/mm.h> #include <linux/smp.h> #include <linux/cpu.h> #include <linux/blk-mq.h> #include "blk.h" #include "blk-mq.h" |
843477d4c
|
17 18 |
static int cpu_to_queue_index(struct blk_mq_queue_map *qmap, unsigned int nr_queues, const int cpu) |
320ae51fe
|
19 |
{ |
843477d4c
|
20 |
return qmap->queue_offset + (cpu % nr_queues); |
320ae51fe
|
21 22 23 24 25 |
} static int get_first_sibling(unsigned int cpu) { unsigned int ret; |
06931e622
|
26 |
ret = cpumask_first(topology_sibling_cpumask(cpu)); |
320ae51fe
|
27 28 29 30 31 |
if (ret < nr_cpu_ids) return ret; return cpu; } |
ed76e329d
|
32 |
int blk_mq_map_queues(struct blk_mq_queue_map *qmap) |
320ae51fe
|
33 |
{ |
ed76e329d
|
34 35 |
unsigned int *map = qmap->mq_map; unsigned int nr_queues = qmap->nr_queues; |
fe631457f
|
36 |
unsigned int cpu, first_sibling; |
320ae51fe
|
37 |
|
fe631457f
|
38 |
for_each_possible_cpu(cpu) { |
320ae51fe
|
39 |
/* |
fe631457f
|
40 41 |
* First do sequential mapping between CPUs and queues. * In case we still have CPUs to map, and we have some number of |
ef025d7ec
|
42 43 |
* threads per cores then map sibling threads to the same queue * for performance optimizations. |
320ae51fe
|
44 |
*/ |
fe631457f
|
45 |
if (cpu < nr_queues) { |
843477d4c
|
46 |
map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu); |
fe631457f
|
47 48 49 |
} else { first_sibling = get_first_sibling(cpu); if (first_sibling == cpu) |
843477d4c
|
50 |
map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu); |
fe631457f
|
51 52 |
else map[cpu] = map[first_sibling]; |
320ae51fe
|
53 |
} |
320ae51fe
|
54 |
} |
320ae51fe
|
55 56 |
return 0; } |
9e5a7e229
|
57 |
EXPORT_SYMBOL_GPL(blk_mq_map_queues); |
320ae51fe
|
58 |
|
cd669f88b
|
59 60 61 62 63 |
/** * blk_mq_hw_queue_to_node - Look up the memory node for a hardware queue index * @qmap: CPU to hardware queue map. * @index: hardware queue index. * |
f14bbe77a
|
64 65 66 |
* We have no quick way of doing reverse lookups. This is only used at * queue init time, so runtime isn't important. */ |
ed76e329d
|
67 |
int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index) |
f14bbe77a
|
68 69 70 71 |
{ int i; for_each_possible_cpu(i) { |
ed76e329d
|
72 |
if (index == qmap->mq_map[i]) |
bffed4571
|
73 |
return local_memory_node(cpu_to_node(i)); |
f14bbe77a
|
74 75 76 77 |
} return NUMA_NO_NODE; } |