@@ -61,11 +61,73 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues)
}
EXPORT_SYMBOL_GPL(blk_mq_num_online_queues);
+/*
+ * blk_mq_map_hk_queues - Create housekeeping CPU to hardware queue mapping
+ * @qmap: CPU to hardware queue map
+ *
+ * Create a housekeeping CPU to hardware queue mapping in @qmap. If the
+ * isolcpus feature is enabled and blk_mq_map_hk_queues returns true,
+ * @qmap contains a valid configuration honoring the managed_irq
+ * configuration. If the isolcpus feature is disabled this function
+ * returns false.
+ */
+static bool blk_mq_map_hk_queues(struct blk_mq_queue_map *qmap)
+{
+ struct cpumask *hk_masks;
+ cpumask_var_t isol_mask;
+ unsigned int queue, cpu, nr_masks;
+
+ if (!housekeeping_enabled(HK_TYPE_MANAGED_IRQ))
+ return false;
+
+ /* map housekeeping cpus to matching hardware context */
+ hk_masks = group_cpus_evenly(qmap->nr_queues, &nr_masks);
+ if (!hk_masks)
+ goto fallback;
+
+ for (queue = 0; queue < qmap->nr_queues; queue++) {
+ for_each_cpu(cpu, &hk_masks[queue % nr_masks])
+ qmap->mq_map[cpu] = qmap->queue_offset + queue;
+ }
+
+ kfree(hk_masks);
+
+ /* map isolcpus to hardware context */
+ if (!alloc_cpumask_var(&isol_mask, GFP_KERNEL))
+ goto fallback;
+
+ queue = 0;
+ cpumask_andnot(isol_mask,
+ cpu_possible_mask,
+ housekeeping_cpumask(HK_TYPE_MANAGED_IRQ));
+
+ for_each_cpu(cpu, isol_mask) {
+ qmap->mq_map[cpu] = qmap->queue_offset + queue;
+ queue = (queue + 1) % qmap->nr_queues;
+ }
+
+ free_cpumask_var(isol_mask);
+
+ return true;
+
+fallback:
+ /* map all cpus to hardware context ignoring any affinity */
+ queue = 0;
+ for_each_possible_cpu(cpu) {
+ qmap->mq_map[cpu] = qmap->queue_offset + queue;
+ queue = (queue + 1) % qmap->nr_queues;
+ }
+ return true;
+}
+
void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
{
const struct cpumask *masks;
unsigned int queue, cpu, nr_masks;
+ if (blk_mq_map_hk_queues(qmap))
+ return;
+
masks = group_cpus_evenly(qmap->nr_queues, &nr_masks);
if (!masks) {
for_each_possible_cpu(cpu)
@@ -120,6 +182,9 @@ void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
if (!dev->bus->irq_get_affinity)
goto fallback;
+ if (blk_mq_map_hk_queues(qmap))
+ return;
+
for (queue = 0; queue < qmap->nr_queues; queue++) {
mask = dev->bus->irq_get_affinity(dev, queue + offset);
if (!mask)