Skip to content

Commit

Permalink
blk-mq/cpu-notif: Convert to new hotplug state machine
Browse files Browse the repository at this point in the history
Replace the block-mq notifier list management with the multi instance
facility in the cpu hotplug state machine.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-block@vger.kernel.org
Cc: rt@linutronix.de
Cc: Christoph Hellwing <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
KAGA-KOKO authored and axboe committed Sep 22, 2016
1 parent 5dfcfb0 commit 9467f85
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 105 deletions.
2 changes: 1 addition & 1 deletion block/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-tag.o blk-sysfs.o \
blk-flush.o blk-settings.o blk-ioc.o blk-map.o \
blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \
blk-lib.o blk-mq.o blk-mq-tag.o \
blk-mq-sysfs.o blk-mq-cpu.o blk-mq-cpumap.o ioctl.o \
blk-mq-sysfs.o blk-mq-cpumap.o ioctl.o \
genhd.o scsi_ioctl.o partition-generic.o ioprio.o \
badblocks.o partitions/

Expand Down
67 changes: 0 additions & 67 deletions block/blk-mq-cpu.c

This file was deleted.

36 changes: 13 additions & 23 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,11 +1593,13 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
* software queue to the hw queue dispatch list, and ensure that it
* gets run.
*/
static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu)
static int blk_mq_hctx_notify_dead(unsigned int cpu, struct hlist_node *node)
{
struct blk_mq_hw_ctx *hctx;
struct blk_mq_ctx *ctx;
LIST_HEAD(tmp);

hctx = hlist_entry_safe(node, struct blk_mq_hw_ctx, cpuhp_dead);
ctx = __blk_mq_get_ctx(hctx->queue, cpu);

spin_lock(&ctx->lock);
Expand All @@ -1608,30 +1610,20 @@ static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu)
spin_unlock(&ctx->lock);

if (list_empty(&tmp))
return NOTIFY_OK;
return 0;

spin_lock(&hctx->lock);
list_splice_tail_init(&tmp, &hctx->dispatch);
spin_unlock(&hctx->lock);

blk_mq_run_hw_queue(hctx, true);
return NOTIFY_OK;
return 0;
}

static int blk_mq_hctx_notify(void *data, unsigned long action,
unsigned int cpu)
static void blk_mq_remove_cpuhp(struct blk_mq_hw_ctx *hctx)
{
struct blk_mq_hw_ctx *hctx = data;

if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
return blk_mq_hctx_cpu_offline(hctx, cpu);

/*
* In case of CPU online, tags may be reallocated
* in blk_mq_map_swqueue() after mapping is updated.
*/

return NOTIFY_OK;
cpuhp_state_remove_instance_nocalls(CPUHP_BLK_MQ_DEAD,
&hctx->cpuhp_dead);
}

/* hctx->ctxs will be freed in queue's release handler */
Expand All @@ -1651,7 +1643,7 @@ static void blk_mq_exit_hctx(struct request_queue *q,
if (set->ops->exit_hctx)
set->ops->exit_hctx(hctx, hctx_idx);

blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
blk_mq_remove_cpuhp(hctx);
blk_free_flush_queue(hctx->fq);
sbitmap_free(&hctx->ctx_map);
}
Expand Down Expand Up @@ -1698,9 +1690,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
hctx->queue_num = hctx_idx;
hctx->flags = set->flags & ~BLK_MQ_F_TAG_SHARED;

blk_mq_init_cpu_notifier(&hctx->cpu_notifier,
blk_mq_hctx_notify, hctx);
blk_mq_register_cpu_notifier(&hctx->cpu_notifier);
cpuhp_state_add_instance_nocalls(CPUHP_BLK_MQ_DEAD, &hctx->cpuhp_dead);

hctx->tags = set->tags[hctx_idx];

Expand Down Expand Up @@ -1745,8 +1735,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
free_ctxs:
kfree(hctx->ctxs);
unregister_cpu_notifier:
blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);

blk_mq_remove_cpuhp(hctx);
return -1;
}

Expand Down Expand Up @@ -2399,7 +2388,8 @@ void blk_mq_enable_hotplug(void)

static int __init blk_mq_init(void)
{
blk_mq_cpu_init();
cpuhp_setup_state_multi(CPUHP_BLK_MQ_DEAD, "block/mq:dead", NULL,
blk_mq_hctx_notify_dead);

hotcpu_notifier(blk_mq_queue_reinit_notify, 0);

Expand Down
7 changes: 0 additions & 7 deletions block/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ void blk_mq_wake_waiters(struct request_queue *q);
/*
* CPU hotplug helpers
*/
struct blk_mq_cpu_notifier;
void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
int (*fn)(void *, unsigned long, unsigned int),
void *data);
void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier);
void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier);
void blk_mq_cpu_init(void);
void blk_mq_enable_hotplug(void);
void blk_mq_disable_hotplug(void);

Expand Down
8 changes: 1 addition & 7 deletions include/linux/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
struct blk_mq_tags;
struct blk_flush_queue;

struct blk_mq_cpu_notifier {
struct list_head list;
void *data;
int (*notify)(void *data, unsigned long action, unsigned int cpu);
};

struct blk_mq_hw_ctx {
struct {
spinlock_t lock;
Expand Down Expand Up @@ -53,7 +47,7 @@ struct blk_mq_hw_ctx {

struct delayed_work delay_work;

struct blk_mq_cpu_notifier cpu_notifier;
struct hlist_node cpuhp_dead;
struct kobject kobj;

unsigned long poll_considered;
Expand Down

0 comments on commit 9467f85

Please sign in to comment.