dmaengine: pl330: drop useless LIST_HEAD
[linux-2.6-block.git] / block / blk-mq-cpumap.c
CommitLineData
75bb4625
JA
1/*
2 * CPU <-> hardware queue mapping helpers
3 *
4 * Copyright (C) 2013-2014 Jens Axboe
5 */
320ae51f
JA
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>
12
13#include <linux/blk-mq.h>
14#include "blk.h"
15#include "blk-mq.h"
16
843477d4
JA
17static int cpu_to_queue_index(struct blk_mq_queue_map *qmap,
18 unsigned int nr_queues, const int cpu)
320ae51f 19{
843477d4 20 return qmap->queue_offset + (cpu % nr_queues);
320ae51f
JA
21}
22
23static int get_first_sibling(unsigned int cpu)
24{
25 unsigned int ret;
26
06931e62 27 ret = cpumask_first(topology_sibling_cpumask(cpu));
320ae51f
JA
28 if (ret < nr_cpu_ids)
29 return ret;
30
31 return cpu;
32}
33
ed76e329 34int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
320ae51f 35{
ed76e329
JA
36 unsigned int *map = qmap->mq_map;
37 unsigned int nr_queues = qmap->nr_queues;
fe631457 38 unsigned int cpu, first_sibling;
320ae51f 39
fe631457 40 for_each_possible_cpu(cpu) {
320ae51f 41 /*
fe631457
MG
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.
320ae51f 46 */
fe631457 47 if (cpu < nr_queues) {
843477d4 48 map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
fe631457
MG
49 } else {
50 first_sibling = get_first_sibling(cpu);
51 if (first_sibling == cpu)
843477d4 52 map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
fe631457
MG
53 else
54 map[cpu] = map[first_sibling];
320ae51f 55 }
320ae51f
JA
56 }
57
320ae51f
JA
58 return 0;
59}
9e5a7e22 60EXPORT_SYMBOL_GPL(blk_mq_map_queues);
320ae51f 61
f14bbe77
JA
62/*
63 * We have no quick way of doing reverse lookups. This is only used at
64 * queue init time, so runtime isn't important.
65 */
ed76e329 66int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
f14bbe77
JA
67{
68 int i;
69
70 for_each_possible_cpu(i) {
ed76e329 71 if (index == qmap->mq_map[i])
bffed457 72 return local_memory_node(cpu_to_node(i));
f14bbe77
JA
73 }
74
75 return NUMA_NO_NODE;
76}