Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,23 @@ static bool blk_mq_hctx_empty_cpumask(struct blk_mq_hw_ctx *hctx)
return hctx->next_cpu >= nr_cpu_ids;
}

static inline int blk_mq_hctx_unbound_cpu(void)
{
guard(rcu)();

if (cpu_is_isolated(raw_smp_processor_id())) {
int cpu;

guard(preempt)();
cpu = cpumask_any_and_distribute(housekeeping_cpumask(HK_TYPE_DOMAIN),
cpu_online_mask);
if (cpu < nr_cpu_ids)
return cpu;
}

return WORK_CPU_UNBOUND;
}

/*
* It'd be great if the workqueue API had a way to pass
* in a mask and had some smarts for more clever placement.
Expand All @@ -2263,9 +2280,17 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
bool tried = false;
int next_cpu = hctx->next_cpu;

/* Switch to unbound if no allowable CPUs in this hctx */
if (hctx->queue->nr_hw_queues == 1 || blk_mq_hctx_empty_cpumask(hctx))
if (hctx->queue->nr_hw_queues == 1) {
#ifdef CONFIG_CPU_ISOLATION
if (static_branch_unlikely(&housekeeping_overridden))
return blk_mq_hctx_unbound_cpu();
#endif
return WORK_CPU_UNBOUND;
}

/* Switch to unbound if no allowable CPUs in this hctx */
if (blk_mq_hctx_empty_cpumask(hctx))
return blk_mq_hctx_unbound_cpu();

if (--hctx->next_cpu_batch <= 0) {
select_cpu:
Expand All @@ -2292,7 +2317,7 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
*/
hctx->next_cpu = next_cpu;
hctx->next_cpu_batch = 1;
return WORK_CPU_UNBOUND;
return blk_mq_hctx_unbound_cpu();
}

hctx->next_cpu = next_cpu;
Expand Down
Loading