blob: 9638b25fd52124f0173e968ebdca5f1fe0b42ad9 [file] [log] [blame]
Christoph Hellwig3dcf60bc2019-04-30 14:42:43 -04001// SPDX-License-Identifier: GPL-2.0
Jens Axboe75bb4622014-05-28 10:15:41 -06002/*
3 * CPU <-> hardware queue mapping helpers
4 *
5 * Copyright (C) 2013-2014 Jens Axboe
6 */
Jens Axboe320ae512013-10-24 09:20:05 +01007#include <linux/kernel.h>
8#include <linux/threads.h>
9#include <linux/module.h>
10#include <linux/mm.h>
11#include <linux/smp.h>
12#include <linux/cpu.h>
Ming Lei6a6dcae2022-12-27 10:29:05 +080013#include <linux/group_cpus.h>
Jens Axboe320ae512013-10-24 09:20:05 +010014
Jens Axboe320ae512013-10-24 09:20:05 +010015#include "blk.h"
16#include "blk-mq.h"
17
Bart Van Asschea4e1d0b2022-08-15 10:00:43 -070018void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
Jens Axboe320ae512013-10-24 09:20:05 +010019{
Ming Lei6a6dcae2022-12-27 10:29:05 +080020 const struct cpumask *masks;
21 unsigned int queue, cpu;
Ming Lei556f36e2019-07-25 17:41:46 +080022
Ming Lei6a6dcae2022-12-27 10:29:05 +080023 masks = group_cpus_evenly(qmap->nr_queues);
24 if (!masks) {
25 for_each_possible_cpu(cpu)
26 qmap->mq_map[cpu] = qmap->queue_offset;
27 return;
Ming Lei556f36e2019-07-25 17:41:46 +080028 }
Jens Axboe320ae512013-10-24 09:20:05 +010029
Ming Lei6a6dcae2022-12-27 10:29:05 +080030 for (queue = 0; queue < qmap->nr_queues; queue++) {
31 for_each_cpu(cpu, &masks[queue])
32 qmap->mq_map[cpu] = qmap->queue_offset + queue;
Jens Axboe320ae512013-10-24 09:20:05 +010033 }
Ming Lei6a6dcae2022-12-27 10:29:05 +080034 kfree(masks);
Jens Axboe320ae512013-10-24 09:20:05 +010035}
Christoph Hellwig9e5a7e22016-11-01 08:12:47 -060036EXPORT_SYMBOL_GPL(blk_mq_map_queues);
Jens Axboe320ae512013-10-24 09:20:05 +010037
Bart Van Asschecd669f82019-05-30 17:00:53 -070038/**
39 * blk_mq_hw_queue_to_node - Look up the memory node for a hardware queue index
40 * @qmap: CPU to hardware queue map.
41 * @index: hardware queue index.
42 *
Jens Axboef14bbe72014-05-27 12:06:53 -060043 * We have no quick way of doing reverse lookups. This is only used at
44 * queue init time, so runtime isn't important.
45 */
Jens Axboeed76e322018-10-29 13:06:14 -060046int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)
Jens Axboef14bbe72014-05-27 12:06:53 -060047{
48 int i;
49
50 for_each_possible_cpu(i) {
Jens Axboeed76e322018-10-29 13:06:14 -060051 if (index == qmap->mq_map[i])
Xianting Tian576e85c2020-10-19 16:20:47 +080052 return cpu_to_node(i);
Jens Axboef14bbe72014-05-27 12:06:53 -060053 }
54
55 return NUMA_NO_NODE;
56}