mirror of
https://github.com/CTCaer/switch-l4t-kernel-4.9.git
synced 2024-11-26 21:31:18 +00:00
blk-mq: Create hctx for each present CPU
Currently we only create hctx for online CPUs, which can lead to a lot of churn due to frequent soft offline / online operations. Instead allocate one for each present CPU to avoid this and dramatically simplify the code. Bug 2090405 Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jens Axboe <axboe@kernel.dk> Cc: Keith Busch <keith.busch@intel.com> Cc: linux-block@vger.kernel.org Cc: linux-nvme@lists.infradead.org Link: http://lkml.kernel.org/r/20170626102058.10200-3-hch@lst.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de> (cherry-picked from commit 4b855ad37194f7bdbb200ce7a1c7051fecb56a08 in dev-kernel-4.14) (vigneshr, resolved merge conflicts) Change-Id: I88b3f6d8122caebc7e3cdd1f0c3ffa9fc60141f7 Signed-off-by: Vignesh Radhakrishnan <vigneshr@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1740887 Reviewed-by: Alexander Van Brunt <avanbrunt@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
parent
b32b6b3a7d
commit
67a095c6fe
124
block/blk-mq.c
124
block/blk-mq.c
@ -31,9 +31,6 @@
|
||||
#include "blk-mq.h"
|
||||
#include "blk-mq-tag.h"
|
||||
|
||||
static DEFINE_MUTEX(all_q_mutex);
|
||||
static LIST_HEAD(all_q_list);
|
||||
|
||||
/*
|
||||
* Check if any of the ctx's have pending work in this hardware queue
|
||||
*/
|
||||
@ -1723,8 +1720,8 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,
|
||||
INIT_LIST_HEAD(&__ctx->rq_list);
|
||||
__ctx->queue = q;
|
||||
|
||||
/* If the cpu isn't online, the cpu is mapped to first hctx */
|
||||
if (!cpu_online(i))
|
||||
/* If the cpu isn't present, the cpu is mapped to first hctx */
|
||||
if (!cpu_present(i))
|
||||
continue;
|
||||
|
||||
hctx = blk_mq_map_queue(q, i);
|
||||
@ -1738,8 +1735,7 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,
|
||||
}
|
||||
}
|
||||
|
||||
static void blk_mq_map_swqueue(struct request_queue *q,
|
||||
const struct cpumask *online_mask)
|
||||
static void blk_mq_map_swqueue(struct request_queue *q)
|
||||
{
|
||||
unsigned int i;
|
||||
struct blk_mq_hw_ctx *hctx;
|
||||
@ -1757,12 +1753,11 @@ static void blk_mq_map_swqueue(struct request_queue *q,
|
||||
}
|
||||
|
||||
/*
|
||||
* Map software to hardware queues
|
||||
* Map software to hardware queues.
|
||||
*
|
||||
* If the cpu isn't present, the cpu is mapped to first hctx.
|
||||
*/
|
||||
for_each_possible_cpu(i) {
|
||||
/* If the cpu isn't online, the cpu is mapped to first hctx */
|
||||
if (!cpumask_test_cpu(i, online_mask))
|
||||
continue;
|
||||
for_each_present_cpu(i) {
|
||||
|
||||
ctx = per_cpu_ptr(q->queue_ctx, i);
|
||||
hctx = blk_mq_map_queue(q, i);
|
||||
@ -2029,15 +2024,8 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
|
||||
|
||||
blk_mq_init_cpu_queues(q, set->nr_hw_queues);
|
||||
|
||||
get_online_cpus();
|
||||
mutex_lock(&all_q_mutex);
|
||||
|
||||
list_add_tail(&q->all_q_node, &all_q_list);
|
||||
blk_mq_add_queue_tag_set(set, q);
|
||||
blk_mq_map_swqueue(q, cpu_online_mask);
|
||||
|
||||
mutex_unlock(&all_q_mutex);
|
||||
put_online_cpus();
|
||||
blk_mq_map_swqueue(q);
|
||||
|
||||
return q;
|
||||
|
||||
@ -2055,10 +2043,6 @@ void blk_mq_free_queue(struct request_queue *q)
|
||||
{
|
||||
struct blk_mq_tag_set *set = q->tag_set;
|
||||
|
||||
mutex_lock(&all_q_mutex);
|
||||
list_del_init(&q->all_q_node);
|
||||
mutex_unlock(&all_q_mutex);
|
||||
|
||||
blk_mq_del_queue_tag_set(q);
|
||||
|
||||
blk_mq_exit_hw_queues(q, set, set->nr_hw_queues);
|
||||
@ -2066,8 +2050,7 @@ void blk_mq_free_queue(struct request_queue *q)
|
||||
}
|
||||
|
||||
/* Basically redo blk_mq_init_queue with queue frozen */
|
||||
static void blk_mq_queue_reinit(struct request_queue *q,
|
||||
const struct cpumask *online_mask)
|
||||
static void blk_mq_queue_reinit(struct request_queue *q)
|
||||
{
|
||||
WARN_ON_ONCE(!atomic_read(&q->mq_freeze_depth));
|
||||
|
||||
@ -2079,82 +2062,11 @@ static void blk_mq_queue_reinit(struct request_queue *q,
|
||||
* involves free and re-allocate memory, worthy doing?)
|
||||
*/
|
||||
|
||||
blk_mq_map_swqueue(q, online_mask);
|
||||
blk_mq_map_swqueue(q);
|
||||
|
||||
blk_mq_sysfs_register(q);
|
||||
}
|
||||
|
||||
/*
|
||||
* New online cpumask which is going to be set in this hotplug event.
|
||||
* Declare this cpumasks as global as cpu-hotplug operation is invoked
|
||||
* one-by-one and dynamically allocating this could result in a failure.
|
||||
*/
|
||||
static struct cpumask cpuhp_online_new;
|
||||
|
||||
static void blk_mq_queue_reinit_work(void)
|
||||
{
|
||||
struct request_queue *q;
|
||||
|
||||
mutex_lock(&all_q_mutex);
|
||||
/*
|
||||
* We need to freeze and reinit all existing queues. Freezing
|
||||
* involves synchronous wait for an RCU grace period and doing it
|
||||
* one by one may take a long time. Start freezing all queues in
|
||||
* one swoop and then wait for the completions so that freezing can
|
||||
* take place in parallel.
|
||||
*/
|
||||
list_for_each_entry(q, &all_q_list, all_q_node)
|
||||
blk_mq_freeze_queue_start(q);
|
||||
list_for_each_entry(q, &all_q_list, all_q_node) {
|
||||
blk_mq_freeze_queue_wait(q);
|
||||
|
||||
/*
|
||||
* timeout handler can't touch hw queue during the
|
||||
* reinitialization
|
||||
*/
|
||||
del_timer_sync(&q->timeout);
|
||||
}
|
||||
|
||||
list_for_each_entry(q, &all_q_list, all_q_node)
|
||||
blk_mq_queue_reinit(q, &cpuhp_online_new);
|
||||
|
||||
list_for_each_entry(q, &all_q_list, all_q_node)
|
||||
blk_mq_unfreeze_queue(q);
|
||||
|
||||
mutex_unlock(&all_q_mutex);
|
||||
}
|
||||
|
||||
static int blk_mq_queue_reinit_dead(unsigned int cpu)
|
||||
{
|
||||
cpumask_copy(&cpuhp_online_new, cpu_online_mask);
|
||||
blk_mq_queue_reinit_work();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Before hotadded cpu starts handling requests, new mappings must be
|
||||
* established. Otherwise, these requests in hw queue might never be
|
||||
* dispatched.
|
||||
*
|
||||
* For example, there is a single hw queue (hctx) and two CPU queues (ctx0
|
||||
* for CPU0, and ctx1 for CPU1).
|
||||
*
|
||||
* Now CPU1 is just onlined and a request is inserted into ctx1->rq_list
|
||||
* and set bit0 in pending bitmap as ctx1->index_hw is still zero.
|
||||
*
|
||||
* And then while running hw queue, flush_busy_ctxs() finds bit0 is set in
|
||||
* pending bitmap and tries to retrieve requests in hctx->ctxs[0]->rq_list.
|
||||
* But htx->ctxs[0] is a pointer to ctx0, so the request in ctx1->rq_list
|
||||
* is ignored.
|
||||
*/
|
||||
static int blk_mq_queue_reinit_prepare(unsigned int cpu)
|
||||
{
|
||||
cpumask_copy(&cpuhp_online_new, cpu_online_mask);
|
||||
cpumask_set_cpu(cpu, &cpuhp_online_new);
|
||||
blk_mq_queue_reinit_work();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set)
|
||||
{
|
||||
int i;
|
||||
@ -2351,7 +2263,7 @@ void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues)
|
||||
else
|
||||
blk_queue_make_request(q, blk_sq_make_request);
|
||||
|
||||
blk_mq_queue_reinit(q, cpu_online_mask);
|
||||
blk_mq_queue_reinit(q);
|
||||
}
|
||||
|
||||
list_for_each_entry(q, &set->tag_list, tag_set_list)
|
||||
@ -2359,24 +2271,10 @@ void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues);
|
||||
|
||||
void blk_mq_disable_hotplug(void)
|
||||
{
|
||||
mutex_lock(&all_q_mutex);
|
||||
}
|
||||
|
||||
void blk_mq_enable_hotplug(void)
|
||||
{
|
||||
mutex_unlock(&all_q_mutex);
|
||||
}
|
||||
|
||||
static int __init blk_mq_init(void)
|
||||
{
|
||||
cpuhp_setup_state_multi(CPUHP_BLK_MQ_DEAD, "block/mq:dead", NULL,
|
||||
blk_mq_hctx_notify_dead);
|
||||
|
||||
cpuhp_setup_state_nocalls(CPUHP_BLK_MQ_PREPARE, "block/mq:prepare",
|
||||
blk_mq_queue_reinit_prepare,
|
||||
blk_mq_queue_reinit_dead);
|
||||
return 0;
|
||||
}
|
||||
subsys_initcall(blk_mq_init);
|
||||
|
@ -29,11 +29,6 @@ void blk_mq_free_queue(struct request_queue *q);
|
||||
int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr);
|
||||
void blk_mq_wake_waiters(struct request_queue *q);
|
||||
|
||||
/*
|
||||
* CPU hotplug helpers
|
||||
*/
|
||||
void blk_mq_enable_hotplug(void);
|
||||
void blk_mq_disable_hotplug(void);
|
||||
|
||||
/*
|
||||
* CPU -> queue mappings
|
||||
|
@ -47,7 +47,6 @@ enum cpuhp_state {
|
||||
CPUHP_NOTIFY_PREPARE,
|
||||
CPUHP_ARM_SHMOBILE_SCU_PREPARE,
|
||||
CPUHP_SH_SH3X_PREPARE,
|
||||
CPUHP_BLK_MQ_PREPARE,
|
||||
CPUHP_TIMERS_PREPARE,
|
||||
CPUHP_NOTF_ERR_INJ_PREPARE,
|
||||
CPUHP_MIPS_SOC_PREPARE,
|
||||
|
Loading…
Reference in New Issue
Block a user