Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / block / blk-mq-cpumap.c
index 09792132961991e8168c2dee283a7b0cb0b967d0..5f13f4d0bcceda747589a300170537eefb4810eb 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * CPU <-> hardware queue mapping helpers
+ *
+ * Copyright (C) 2013-2014 Jens Axboe
+ */
 #include <linux/kernel.h>
 #include <linux/threads.h>
 #include <linux/module.h>
@@ -12,7 +17,7 @@
 static int cpu_to_queue_index(unsigned int nr_cpus, unsigned int nr_queues,
                              const int cpu)
 {
-       return cpu / ((nr_cpus + nr_queues - 1) / nr_queues);
+       return cpu * nr_queues / nr_cpus;
 }
 
 static int get_first_sibling(unsigned int cpu)
@@ -80,19 +85,35 @@ int blk_mq_update_queue_map(unsigned int *map, unsigned int nr_queues)
        return 0;
 }
 
-unsigned int *blk_mq_make_queue_map(struct blk_mq_reg *reg)
+unsigned int *blk_mq_make_queue_map(struct blk_mq_tag_set *set)
 {
        unsigned int *map;
 
        /* If cpus are offline, map them to first hctx */
-       map = kzalloc_node(sizeof(*map) * num_possible_cpus(), GFP_KERNEL,
-                               reg->numa_node);
+       map = kzalloc_node(sizeof(*map) * nr_cpu_ids, GFP_KERNEL,
+                               set->numa_node);
        if (!map)
                return NULL;
 
-       if (!blk_mq_update_queue_map(map, reg->nr_hw_queues))
+       if (!blk_mq_update_queue_map(map, set->nr_hw_queues))
                return map;
 
        kfree(map);
        return NULL;
 }
+
+/*
+ * We have no quick way of doing reverse lookups. This is only used at
+ * queue init time, so runtime isn't important.
+ */
+int blk_mq_hw_queue_to_node(unsigned int *mq_map, unsigned int index)
+{
+       int i;
+
+       for_each_possible_cpu(i) {
+               if (index == mq_map[i])
+                       return cpu_to_node(i);
+       }
+
+       return NUMA_NO_NODE;
+}