Blame view

block/blk-mq-cpumap.c 1.89 KB
3dcf60bcb   Christoph Hellwig   block: add SPDX t...
1
  // SPDX-License-Identifier: GPL-2.0
75bb4625b   Jens Axboe   blk-mq: add file ...
2
3
4
5
6
  /*
   * CPU <-> hardware queue mapping helpers
   *
   * Copyright (C) 2013-2014 Jens Axboe
   */
320ae51fe   Jens Axboe   blk-mq: new multi...
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   Jens Axboe   blk-mq: initial s...
17
18
  static int cpu_to_queue_index(struct blk_mq_queue_map *qmap,
  			      unsigned int nr_queues, const int cpu)
320ae51fe   Jens Axboe   blk-mq: new multi...
19
  {
843477d4c   Jens Axboe   blk-mq: initial s...
20
  	return qmap->queue_offset + (cpu % nr_queues);
320ae51fe   Jens Axboe   blk-mq: new multi...
21
22
23
24
25
  }
  
  static int get_first_sibling(unsigned int cpu)
  {
  	unsigned int ret;
06931e622   Bartosz Golaszewski   sched/topology: R...
26
  	ret = cpumask_first(topology_sibling_cpumask(cpu));
320ae51fe   Jens Axboe   blk-mq: new multi...
27
28
29
30
31
  	if (ret < nr_cpu_ids)
  		return ret;
  
  	return cpu;
  }
ed76e329d   Jens Axboe   blk-mq: abstract ...
32
  int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
320ae51fe   Jens Axboe   blk-mq: new multi...
33
  {
ed76e329d   Jens Axboe   blk-mq: abstract ...
34
35
  	unsigned int *map = qmap->mq_map;
  	unsigned int nr_queues = qmap->nr_queues;
fe631457f   Max Gurtovoy   blk-mq: map all H...
36
  	unsigned int cpu, first_sibling;
320ae51fe   Jens Axboe   blk-mq: new multi...
37

fe631457f   Max Gurtovoy   blk-mq: map all H...
38
  	for_each_possible_cpu(cpu) {
320ae51fe   Jens Axboe   blk-mq: new multi...
39
  		/*
fe631457f   Max Gurtovoy   blk-mq: map all H...
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   Bart Van Assche   blk-mq: Fix spell...
42
43
  		 * threads per cores then map sibling threads to the same queue
  		 * for performance optimizations.
320ae51fe   Jens Axboe   blk-mq: new multi...
44
  		 */
fe631457f   Max Gurtovoy   blk-mq: map all H...
45
  		if (cpu < nr_queues) {
843477d4c   Jens Axboe   blk-mq: initial s...
46
  			map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
fe631457f   Max Gurtovoy   blk-mq: map all H...
47
48
49
  		} else {
  			first_sibling = get_first_sibling(cpu);
  			if (first_sibling == cpu)
843477d4c   Jens Axboe   blk-mq: initial s...
50
  				map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
fe631457f   Max Gurtovoy   blk-mq: map all H...
51
52
  			else
  				map[cpu] = map[first_sibling];
320ae51fe   Jens Axboe   blk-mq: new multi...
53
  		}
320ae51fe   Jens Axboe   blk-mq: new multi...
54
  	}
320ae51fe   Jens Axboe   blk-mq: new multi...
55
56
  	return 0;
  }
9e5a7e229   Christoph Hellwig   blk-mq: export bl...
57
  EXPORT_SYMBOL_GPL(blk_mq_map_queues);
320ae51fe   Jens Axboe   blk-mq: new multi...
58

cd669f88b   Bart Van Assche   blk-mq: Document ...
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   Jens Axboe   blk-mq: pass in s...
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   Jens Axboe   blk-mq: abstract ...
67
  int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
f14bbe77a   Jens Axboe   blk-mq: pass in s...
68
69
70
71
  {
  	int i;
  
  	for_each_possible_cpu(i) {
ed76e329d   Jens Axboe   blk-mq: abstract ...
72
  		if (index == qmap->mq_map[i])
bffed4571   Raghavendra K T   blk-mq: Avoid mem...
73
  			return local_memory_node(cpu_to_node(i));
f14bbe77a   Jens Axboe   blk-mq: pass in s...
74
75
76
77
  	}
  
  	return NUMA_NO_NODE;
  }