Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / block / blk-mq-cpu.c
1 /*
2  * CPU notifier helper code for blk-mq
3  *
4  * Copyright (C) 2013-2014 Jens Axboe
5  */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/blkdev.h>
10 #include <linux/list.h>
11 #include <linux/llist.h>
12 #include <linux/smp.h>
13 #include <linux/cpu.h>
14
15 #include <linux/blk-mq.h>
16 #include "blk-mq.h"
17
18 static LIST_HEAD(blk_mq_cpu_notify_list);
19 static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
20
21 static int blk_mq_main_cpu_notify(struct notifier_block *self,
22                                   unsigned long action, void *hcpu)
23 {
24         unsigned int cpu = (unsigned long) hcpu;
25         struct blk_mq_cpu_notifier *notify;
26         int ret = NOTIFY_OK;
27
28         if (action != CPU_POST_DEAD)
29                 return NOTIFY_OK;
30
31         spin_lock(&blk_mq_cpu_notify_lock);
32
33         list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
34                 ret = notify->notify(notify->data, action, cpu);
35                 if (ret != NOTIFY_OK)
36                         break;
37         }
38
39         spin_unlock(&blk_mq_cpu_notify_lock);
40         return ret;
41 }
42
43 void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
44 {
45         BUG_ON(!notifier->notify);
46
47         spin_lock(&blk_mq_cpu_notify_lock);
48         list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
49         spin_unlock(&blk_mq_cpu_notify_lock);
50 }
51
52 void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
53 {
54         spin_lock(&blk_mq_cpu_notify_lock);
55         list_del(&notifier->list);
56         spin_unlock(&blk_mq_cpu_notify_lock);
57 }
58
59 void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
60                               int (*fn)(void *, unsigned long, unsigned int),
61                               void *data)
62 {
63         notifier->notify = fn;
64         notifier->data = data;
65 }
66
67 void __init blk_mq_cpu_init(void)
68 {
69         hotcpu_notifier(blk_mq_main_cpu_notify, 0);
70 }