Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/module.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/blkdev.h> |
| 5 | #include <linux/list.h> |
| 6 | #include <linux/llist.h> |
| 7 | #include <linux/smp.h> |
| 8 | #include <linux/cpu.h> |
| 9 | |
| 10 | #include <linux/blk-mq.h> |
| 11 | #include "blk-mq.h" |
| 12 | |
| 13 | static LIST_HEAD(blk_mq_cpu_notify_list); |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 14 | static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 15 | |
Paul Gortmaker | f618ef7 | 2013-11-14 08:26:02 -0700 | [diff] [blame] | 16 | static int blk_mq_main_cpu_notify(struct notifier_block *self, |
| 17 | unsigned long action, void *hcpu) |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 18 | { |
| 19 | unsigned int cpu = (unsigned long) hcpu; |
| 20 | struct blk_mq_cpu_notifier *notify; |
| 21 | |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 22 | raw_spin_lock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 23 | |
| 24 | list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) |
| 25 | notify->notify(notify->data, action, cpu); |
| 26 | |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 27 | raw_spin_unlock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 28 | return NOTIFY_OK; |
| 29 | } |
| 30 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 31 | void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier) |
| 32 | { |
| 33 | BUG_ON(!notifier->notify); |
| 34 | |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 35 | raw_spin_lock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 36 | list_add_tail(¬ifier->list, &blk_mq_cpu_notify_list); |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 37 | raw_spin_unlock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier) |
| 41 | { |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 42 | raw_spin_lock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 43 | list_del(¬ifier->list); |
Mike Galbraith | 2a26ebe | 2014-03-03 05:57:26 +0100 | [diff] [blame] | 44 | raw_spin_unlock(&blk_mq_cpu_notify_lock); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier, |
| 48 | void (*fn)(void *, unsigned long, unsigned int), |
| 49 | void *data) |
| 50 | { |
| 51 | notifier->notify = fn; |
| 52 | notifier->data = data; |
| 53 | } |
| 54 | |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 55 | void __init blk_mq_cpu_init(void) |
| 56 | { |
Andrew Morton | 381d3ee | 2014-01-28 09:52:01 -0700 | [diff] [blame] | 57 | hotcpu_notifier(blk_mq_main_cpu_notify, 0); |
Jens Axboe | 320ae51 | 2013-10-24 09:20:05 +0100 | [diff] [blame] | 58 | } |