1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * CPU <-> hardware queue mapping helpers 2 * CPU <-> hardware queue mapping helpers 4 * 3 * 5 * Copyright (C) 2013-2014 Jens Axboe 4 * Copyright (C) 2013-2014 Jens Axboe 6 */ 5 */ 7 #include <linux/kernel.h> 6 #include <linux/kernel.h> 8 #include <linux/threads.h> 7 #include <linux/threads.h> 9 #include <linux/module.h> 8 #include <linux/module.h> 10 #include <linux/mm.h> 9 #include <linux/mm.h> 11 #include <linux/smp.h> 10 #include <linux/smp.h> 12 #include <linux/cpu.h> 11 #include <linux/cpu.h> 13 #include <linux/group_cpus.h> << 14 12 >> 13 #include <linux/blk-mq.h> 15 #include "blk.h" 14 #include "blk.h" 16 #include "blk-mq.h" 15 #include "blk-mq.h" 17 16 18 void blk_mq_map_queues(struct blk_mq_queue_map !! 17 static int cpu_to_queue_index(struct blk_mq_queue_map *qmap, >> 18 unsigned int nr_queues, const int cpu) 19 { 19 { 20 const struct cpumask *masks; !! 20 return qmap->queue_offset + (cpu % nr_queues); 21 unsigned int queue, cpu; !! 21 } 22 22 23 masks = group_cpus_evenly(qmap->nr_que !! 23 static int get_first_sibling(unsigned int cpu) 24 if (!masks) { !! 24 { 25 for_each_possible_cpu(cpu) !! 25 unsigned int ret; 26 qmap->mq_map[cpu] = qm !! 26 27 return; !! 27 ret = cpumask_first(topology_sibling_cpumask(cpu)); 28 } !! 28 if (ret < nr_cpu_ids) >> 29 return ret; >> 30 >> 31 return cpu; >> 32 } 29 33 30 for (queue = 0; queue < qmap->nr_queue !! 34 int blk_mq_map_queues(struct blk_mq_queue_map *qmap) 31 for_each_cpu(cpu, &masks[queue !! 35 { 32 qmap->mq_map[cpu] = qm !! 36 unsigned int *map = qmap->mq_map; >> 37 unsigned int nr_queues = qmap->nr_queues; >> 38 unsigned int cpu, first_sibling; >> 39 >> 40 for_each_possible_cpu(cpu) { >> 41 /* >> 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. >> 46 */ >> 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]; >> 55 } 33 } 56 } 34 kfree(masks); !! 57 >> 58 return 0; 35 } 59 } 36 EXPORT_SYMBOL_GPL(blk_mq_map_queues); 60 EXPORT_SYMBOL_GPL(blk_mq_map_queues); 37 61 38 /** !! 62 /* 39 * blk_mq_hw_queue_to_node - Look up the memor << 40 * @qmap: CPU to hardware queue map. << 41 * @index: hardware queue index. << 42 * << 43 * We have no quick way of doing reverse looku 63 * We have no quick way of doing reverse lookups. This is only used at 44 * queue init time, so runtime isn't important 64 * queue init time, so runtime isn't important. 45 */ 65 */ 46 int blk_mq_hw_queue_to_node(struct blk_mq_queu 66 int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index) 47 { 67 { 48 int i; 68 int i; 49 69 50 for_each_possible_cpu(i) { 70 for_each_possible_cpu(i) { 51 if (index == qmap->mq_map[i]) 71 if (index == qmap->mq_map[i]) 52 return cpu_to_node(i); !! 72 return local_memory_node(cpu_to_node(i)); 53 } 73 } 54 74 55 return NUMA_NO_NODE; 75 return NUMA_NO_NODE; 56 } 76 } 57 77
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.