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>
10 #include <linux/blk-mq.h>
13 static LIST_HEAD(blk_mq_cpu_notify_list
);
14 static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock
);
16 static int blk_mq_main_cpu_notify(struct notifier_block
*self
,
17 unsigned long action
, void *hcpu
)
19 unsigned int cpu
= (unsigned long) hcpu
;
20 struct blk_mq_cpu_notifier
*notify
;
22 raw_spin_lock(&blk_mq_cpu_notify_lock
);
24 list_for_each_entry(notify
, &blk_mq_cpu_notify_list
, list
)
25 notify
->notify(notify
->data
, action
, cpu
);
27 raw_spin_unlock(&blk_mq_cpu_notify_lock
);
31 void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier
*notifier
)
33 BUG_ON(!notifier
->notify
);
35 raw_spin_lock(&blk_mq_cpu_notify_lock
);
36 list_add_tail(¬ifier
->list
, &blk_mq_cpu_notify_list
);
37 raw_spin_unlock(&blk_mq_cpu_notify_lock
);
40 void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier
*notifier
)
42 raw_spin_lock(&blk_mq_cpu_notify_lock
);
43 list_del(¬ifier
->list
);
44 raw_spin_unlock(&blk_mq_cpu_notify_lock
);
47 void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier
*notifier
,
48 void (*fn
)(void *, unsigned long, unsigned int),
51 notifier
->notify
= fn
;
52 notifier
->data
= data
;
55 void __init
blk_mq_cpu_init(void)
57 hotcpu_notifier(blk_mq_main_cpu_notify
, 0);