2 * CPU <-> hardware queue mapping helpers
4 * Copyright (C) 2013-2014 Jens Axboe
6 #include <linux/kernel.h>
7 #include <linux/threads.h>
8 #include <linux/module.h>
10 #include <linux/smp.h>
11 #include <linux/cpu.h>
13 #include <linux/blk-mq.h>
17 static int cpu_to_queue_index(struct blk_mq_queue_map *qmap,
18 unsigned int nr_queues, const int cpu)
20 return qmap->queue_offset + (cpu % nr_queues);
23 static int get_first_sibling(unsigned int cpu)
27 ret = cpumask_first(topology_sibling_cpumask(cpu));
34 int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
36 unsigned int *map = qmap->mq_map;
37 unsigned int nr_queues = qmap->nr_queues;
38 unsigned int cpu, first_sibling;
40 for_each_possible_cpu(cpu) {
42 * First do sequential mapping between CPUs and queues.
43 * In case we still have CPUs to map, and we have some number of
44 * threads per cores then map sibling threads to the same queue for
45 * performace optimizations.
47 if (cpu < nr_queues) {
48 map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
50 first_sibling = get_first_sibling(cpu);
51 if (first_sibling == cpu)
52 map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
54 map[cpu] = map[first_sibling];
60 EXPORT_SYMBOL_GPL(blk_mq_map_queues);
63 * We have no quick way of doing reverse lookups. This is only used at
64 * queue init time, so runtime isn't important.
66 int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
70 for_each_possible_cpu(i) {
71 if (index == qmap->mq_map[i])
72 return local_memory_node(cpu_to_node(i));