Blame view

block/blk-mq-cpu.c 1.57 KB
75bb4625b   Jens Axboe   blk-mq: add file ...
1
2
3
4
5
  /*
   * CPU notifier helper code for blk-mq
   *
   * Copyright (C) 2013-2014 Jens Axboe
   */
320ae51fe   Jens Axboe   blk-mq: new multi...
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/blkdev.h>
  #include <linux/list.h>
  #include <linux/llist.h>
  #include <linux/smp.h>
  #include <linux/cpu.h>
  
  #include <linux/blk-mq.h>
  #include "blk-mq.h"
  
  static LIST_HEAD(blk_mq_cpu_notify_list);
2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
19
  static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
20

f618ef7c4   Paul Gortmaker   blk-mq: remove ne...
21
22
  static int blk_mq_main_cpu_notify(struct notifier_block *self,
  				  unsigned long action, void *hcpu)
320ae51fe   Jens Axboe   blk-mq: new multi...
23
24
25
  {
  	unsigned int cpu = (unsigned long) hcpu;
  	struct blk_mq_cpu_notifier *notify;
e814e71ba   Jens Axboe   blk-mq: allow the...
26
  	int ret = NOTIFY_OK;
320ae51fe   Jens Axboe   blk-mq: new multi...
27

2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
28
  	raw_spin_lock(&blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
29

e814e71ba   Jens Axboe   blk-mq: allow the...
30
31
32
33
34
  	list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
  		ret = notify->notify(notify->data, action, cpu);
  		if (ret != NOTIFY_OK)
  			break;
  	}
320ae51fe   Jens Axboe   blk-mq: new multi...
35

2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
36
  	raw_spin_unlock(&blk_mq_cpu_notify_lock);
e814e71ba   Jens Axboe   blk-mq: allow the...
37
  	return ret;
320ae51fe   Jens Axboe   blk-mq: new multi...
38
  }
320ae51fe   Jens Axboe   blk-mq: new multi...
39
40
41
  void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
  {
  	BUG_ON(!notifier->notify);
2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
42
  	raw_spin_lock(&blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
43
  	list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
44
  	raw_spin_unlock(&blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
45
46
47
48
  }
  
  void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
  {
2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
49
  	raw_spin_lock(&blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
50
  	list_del(&notifier->list);
2a26ebef8   Mike Galbraith   rt,blk,mq: Make b...
51
  	raw_spin_unlock(&blk_mq_cpu_notify_lock);
320ae51fe   Jens Axboe   blk-mq: new multi...
52
53
54
  }
  
  void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
e814e71ba   Jens Axboe   blk-mq: allow the...
55
  			      int (*fn)(void *, unsigned long, unsigned int),
320ae51fe   Jens Axboe   blk-mq: new multi...
56
57
58
59
60
  			      void *data)
  {
  	notifier->notify = fn;
  	notifier->data = data;
  }
320ae51fe   Jens Axboe   blk-mq: new multi...
61
62
  void __init blk_mq_cpu_init(void)
  {
381d3ee33   Andrew Morton   block/blk-mq-cpu....
63
  	hotcpu_notifier(blk_mq_main_cpu_notify, 0);
320ae51fe   Jens Axboe   blk-mq: new multi...
64
  }