proc/sysctl: fix return error for proc_doulongvec_minmax()
[linux/fpc-iii.git] / block / blk-mq-cpumap.c
blob03a53482027150819aaf69769a5c07d0cd5b8a64
1 /*
2 * CPU <-> hardware queue mapping helpers
4 * Copyright (C) 2013-2014 Jens Axboe
5 */
6 #include <linux/kernel.h>
7 #include <linux/threads.h>
8 #include <linux/module.h>
9 #include <linux/mm.h>
10 #include <linux/smp.h>
11 #include <linux/cpu.h>
13 #include <linux/blk-mq.h>
14 #include "blk.h"
15 #include "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)
25 unsigned int ret;
27 ret = cpumask_first(topology_sibling_cpumask(cpu));
28 if (ret < nr_cpu_ids)
29 return ret;
31 return 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);
49 } else {
50 first_sibling = get_first_sibling(cpu);
51 if (first_sibling == cpu)
52 map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
53 else
54 map[cpu] = map[first_sibling];
58 return 0;
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)
68 int i;
70 for_each_possible_cpu(i) {
71 if (index == qmap->mq_map[i])
72 return local_memory_node(cpu_to_node(i));
75 return NUMA_NO_NODE;