diff options
| author | Jens Axboe <axboe@kernel.dk> | 2013-10-25 06:52:25 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2013-10-25 06:56:00 -0400 |
| commit | f2298c0403b0dfcaef637eba0c02c4a06d7a25ab (patch) | |
| tree | 9228633ee420cf4b828270be589898707e777943 | |
| parent | 320ae51feed5c2f13664aa05a76bec198967e04d (diff) | |
null_blk: multi queue aware block test driver
A driver that simply completes IO it receives, it does no
transfers. Written to fascilitate testing of the blk-mq code.
It supports various module options to use either bio queueing,
rq queueing, or mq mode.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | drivers/block/Kconfig | 3 | ||||
| -rw-r--r-- | drivers/block/Makefile | 1 | ||||
| -rw-r--r-- | drivers/block/null_blk.c | 635 |
3 files changed, 639 insertions, 0 deletions
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index e07a5fd58ad7..4682546c5da7 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig | |||
| @@ -15,6 +15,9 @@ menuconfig BLK_DEV | |||
| 15 | 15 | ||
| 16 | if BLK_DEV | 16 | if BLK_DEV |
| 17 | 17 | ||
| 18 | config BLK_DEV_NULL_BLK | ||
| 19 | tristate "Null test block driver" | ||
| 20 | |||
| 18 | config BLK_DEV_FD | 21 | config BLK_DEV_FD |
| 19 | tristate "Normal floppy disk support" | 22 | tristate "Normal floppy disk support" |
| 20 | depends on ARCH_MAY_HAVE_PC_FDC | 23 | depends on ARCH_MAY_HAVE_PC_FDC |
diff --git a/drivers/block/Makefile b/drivers/block/Makefile index ca07399a8d99..03b3b4a2bd8a 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile | |||
| @@ -41,6 +41,7 @@ obj-$(CONFIG_BLK_DEV_RBD) += rbd.o | |||
| 41 | obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/ | 41 | obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/ |
| 42 | 42 | ||
| 43 | obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ | 43 | obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ |
| 44 | obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o | ||
| 44 | 45 | ||
| 45 | nvme-y := nvme-core.o nvme-scsi.o | 46 | nvme-y := nvme-core.o nvme-scsi.o |
| 46 | swim_mod-y := swim.o swim_asm.o | 47 | swim_mod-y := swim.o swim_asm.o |
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c new file mode 100644 index 000000000000..b5d842370cc9 --- /dev/null +++ b/drivers/block/null_blk.c | |||
| @@ -0,0 +1,635 @@ | |||
| 1 | #include <linux/module.h> | ||
| 2 | #include <linux/moduleparam.h> | ||
| 3 | #include <linux/sched.h> | ||
| 4 | #include <linux/fs.h> | ||
| 5 | #include <linux/blkdev.h> | ||
| 6 | #include <linux/init.h> | ||
| 7 | #include <linux/slab.h> | ||
| 8 | #include <linux/blk-mq.h> | ||
| 9 | #include <linux/hrtimer.h> | ||
| 10 | |||
| 11 | struct nullb_cmd { | ||
| 12 | struct list_head list; | ||
| 13 | struct llist_node ll_list; | ||
| 14 | struct call_single_data csd; | ||
| 15 | struct request *rq; | ||
| 16 | struct bio *bio; | ||
| 17 | unsigned int tag; | ||
| 18 | struct nullb_queue *nq; | ||
| 19 | }; | ||
| 20 | |||
| 21 | struct nullb_queue { | ||
| 22 | unsigned long *tag_map; | ||
| 23 | wait_queue_head_t wait; | ||
| 24 | unsigned int queue_depth; | ||
| 25 | |||
| 26 | struct nullb_cmd *cmds; | ||
| 27 | }; | ||
| 28 | |||
| 29 | struct nullb { | ||
| 30 | struct list_head list; | ||
| 31 | unsigned int index; | ||
| 32 | struct request_queue *q; | ||
| 33 | struct gendisk *disk; | ||
| 34 | struct hrtimer timer; | ||
| 35 | unsigned int queue_depth; | ||
| 36 | spinlock_t lock; | ||
| 37 | |||
| 38 | struct nullb_queue *queues; | ||
| 39 | unsigned int nr_queues; | ||
| 40 | }; | ||
| 41 | |||
| 42 | static LIST_HEAD(nullb_list); | ||
| 43 | static struct mutex lock; | ||
| 44 | static int null_major; | ||
| 45 | static int nullb_indexes; | ||
| 46 | |||
| 47 | struct completion_queue { | ||
| 48 | struct llist_head list; | ||
| 49 | struct hrtimer timer; | ||
| 50 | }; | ||
| 51 | |||
| 52 | /* | ||
| 53 | * These are per-cpu for now, they will need to be configured by the | ||
| 54 | * complete_queues parameter and appropriately mapped. | ||
| 55 | */ | ||
| 56 | static DEFINE_PER_CPU(struct completion_queue, completion_queues); | ||
| 57 | |||
| 58 | enum { | ||
| 59 | NULL_IRQ_NONE = 0, | ||
| 60 | NULL_IRQ_SOFTIRQ = 1, | ||
| 61 | NULL_IRQ_TIMER = 2, | ||
| 62 | |||
| 63 | NULL_Q_BIO = 0, | ||
| 64 | NULL_Q_RQ = 1, | ||
| 65 | NULL_Q_MQ = 2, | ||
| 66 | }; | ||
| 67 | |||
| 68 | static int submit_queues = 1; | ||
| 69 | module_param(submit_queues, int, S_IRUGO); | ||
| 70 | MODULE_PARM_DESC(submit_queues, "Number of submission queues"); | ||
| 71 | |||
| 72 | static int home_node = NUMA_NO_NODE; | ||
| 73 | module_param(home_node, int, S_IRUGO); | ||
| 74 | MODULE_PARM_DESC(home_node, "Home node for the device"); | ||
| 75 | |||
| 76 | static int queue_mode = NULL_Q_MQ; | ||
| 77 | module_param(queue_mode, int, S_IRUGO); | ||
| 78 | MODULE_PARM_DESC(use_mq, "Use blk-mq interface (0=bio,1=rq,2=multiqueue)"); | ||
| 79 | |||
| 80 | static int gb = 250; | ||
| 81 | module_param(gb, int, S_IRUGO); | ||
| 82 | MODULE_PARM_DESC(gb, "Size in GB"); | ||
| 83 | |||
| 84 | static int bs = 512; | ||
| 85 | module_param(bs, int, S_IRUGO); | ||
| 86 | MODULE_PARM_DESC(bs, "Block size (in bytes)"); | ||
| 87 | |||
| 88 | static int nr_devices = 2; | ||
| 89 | module_param(nr_devices, int, S_IRUGO); | ||
| 90 | MODULE_PARM_DESC(nr_devices, "Number of devices to register"); | ||
| 91 | |||
| 92 | static int irqmode = NULL_IRQ_SOFTIRQ; | ||
| 93 | module_param(irqmode, int, S_IRUGO); | ||
| 94 | MODULE_PARM_DESC(irqmode, "IRQ completion handler. 0-none, 1-softirq, 2-timer"); | ||
| 95 | |||
| 96 | static int completion_nsec = 10000; | ||
| 97 | module_param(completion_nsec, int, S_IRUGO); | ||
| 98 | MODULE_PARM_DESC(completion_nsec, "Time in ns to complete a request in hardware. Default: 10,000ns"); | ||
| 99 | |||
| 100 | static int hw_queue_depth = 64; | ||
| 101 | module_param(hw_queue_depth, int, S_IRUGO); | ||
| 102 | MODULE_PARM_DESC(hw_queue_depth, "Queue depth for each hardware queue. Default: 64"); | ||
| 103 | |||
| 104 | static bool use_per_node_hctx = true; | ||
| 105 | module_param(use_per_node_hctx, bool, S_IRUGO); | ||
| 106 | MODULE_PARM_DESC(use_per_node_hctx, "Use per-node allocation for hardware context queues. Default: true"); | ||
| 107 | |||
| 108 | static void put_tag(struct nullb_queue *nq, unsigned int tag) | ||
| 109 | { | ||
| 110 | clear_bit_unlock(tag, nq->tag_map); | ||
| 111 | |||
| 112 | if (waitqueue_active(&nq->wait)) | ||
| 113 | wake_up(&nq->wait); | ||
| 114 | } | ||
| 115 | |||
| 116 | static unsigned int get_tag(struct nullb_queue *nq) | ||
| 117 | { | ||
| 118 | unsigned int tag; | ||
| 119 | |||
| 120 | do { | ||
| 121 | tag = find_first_zero_bit(nq->tag_map, nq->queue_depth); | ||
| 122 | if (tag >= nq->queue_depth) | ||
| 123 | return -1U; | ||
| 124 | } while (test_and_set_bit_lock(tag, nq->tag_map)); | ||
| 125 | |||
| 126 | return tag; | ||
| 127 | } | ||
| 128 | |||
| 129 | static void free_cmd(struct nullb_cmd *cmd) | ||
| 130 | { | ||
| 131 | put_tag(cmd->nq, cmd->tag); | ||
| 132 | } | ||
| 133 | |||
| 134 | static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq) | ||
| 135 | { | ||
| 136 | struct nullb_cmd *cmd; | ||
| 137 | unsigned int tag; | ||
| 138 | |||
| 139 | tag = get_tag(nq); | ||
| 140 | if (tag != -1U) { | ||
| 141 | cmd = &nq->cmds[tag]; | ||
| 142 | cmd->tag = tag; | ||
| 143 | cmd->nq = nq; | ||
| 144 | return cmd; | ||
| 145 | } | ||
| 146 | |||
| 147 | return NULL; | ||
| 148 | } | ||
| 149 | |||
| 150 | static struct nullb_cmd *alloc_cmd(struct nullb_queue *nq, int can_wait) | ||
| 151 | { | ||
| 152 | struct nullb_cmd *cmd; | ||
| 153 | DEFINE_WAIT(wait); | ||
| 154 | |||
| 155 | cmd = __alloc_cmd(nq); | ||
| 156 | if (cmd || !can_wait) | ||
| 157 | return cmd; | ||
| 158 | |||
| 159 | do { | ||
| 160 | prepare_to_wait(&nq->wait, &wait, TASK_UNINTERRUPTIBLE); | ||
| 161 | cmd = __alloc_cmd(nq); | ||
| 162 | if (cmd) | ||
| 163 | break; | ||
| 164 | |||
| 165 | io_schedule(); | ||
| 166 | } while (1); | ||
| 167 | |||
| 168 | finish_wait(&nq->wait, &wait); | ||
| 169 | return cmd; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void end_cmd(struct nullb_cmd *cmd) | ||
| 173 | { | ||
| 174 | if (cmd->rq) { | ||
| 175 | if (queue_mode == NULL_Q_MQ) | ||
