]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - block/blk-mq-cpumap.c
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-bionic-kernel.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
fe631457
MG
17static int cpu_to_queue_index(unsigned int nr_queues, const int cpu,
18 const struct cpumask *online_mask)
320ae51f 19{
fe631457
MG
20 /*
21 * Non online CPU will be mapped to queue index 0.
22 */
23 if (!cpumask_test_cpu(cpu, online_mask))
24 return 0;
25 return cpu % nr_queues;
320ae51f
JA
26}
27
28static int get_first_sibling(unsigned int cpu)
29{
30 unsigned int ret;
31
06931e62 32 ret = cpumask_first(topology_sibling_cpumask(cpu));
320ae51f
JA
33 if (ret < nr_cpu_ids)
34 return ret;
35
36 return cpu;
37}
38
da695ba2 39int blk_mq_map_queues(struct blk_mq_tag_set *set)
320ae51f 40{
da695ba2
CH
41 unsigned int *map = set->mq_map;
42 unsigned int nr_queues = set->nr_hw_queues;
43 const struct cpumask *online_mask = cpu_online_mask;
fe631457 44 unsigned int cpu, first_sibling;
320ae51f 45
fe631457 46 for_each_possible_cpu(cpu) {
320ae51f 47 /*
fe631457
MG
48 * First do sequential mapping between CPUs and queues.
49 * In case we still have CPUs to map, and we have some number of
50 * threads per cores then map sibling threads to the same queue for
51 * performace optimizations.
320ae51f 52 */
fe631457
MG
53 if (cpu < nr_queues) {
54 map[cpu] = cpu_to_queue_index(nr_queues, cpu, online_mask);
55 } else {
56 first_sibling = get_first_sibling(cpu);
57 if (first_sibling == cpu)
58 map[cpu] = cpu_to_queue_index(nr_queues, cpu, online_mask);
59 else
60 map[cpu] = map[first_sibling];
320ae51f 61 }
320ae51f
JA
62 }
63
320ae51f
JA
64 return 0;
65}
9e5a7e22 66EXPORT_SYMBOL_GPL(blk_mq_map_queues);
320ae51f 67
f14bbe77
JA
68/*
69 * We have no quick way of doing reverse lookups. This is only used at
70 * queue init time, so runtime isn't important.
71 */
72int blk_mq_hw_queue_to_node(unsigned int *mq_map, unsigned int index)
73{
74 int i;
75
76 for_each_possible_cpu(i) {
77 if (index == mq_map[i])
bffed457 78 return local_memory_node(cpu_to_node(i));
f14bbe77
JA
79 }
80
81 return NUMA_NO_NODE;
82}