From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH v4 7/8] null_blk: LightNVM support Date: Fri, 5 Jun 2015 14:54:29 +0200 Message-ID: <1433508870-28251-8-git-send-email-m@bjorling.me> References: <1433508870-28251-1-git-send-email-m@bjorling.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: javier@lightnvm.io, Stephen.Bates@pmcs.com, keith.busch@intel.com, =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: hch@infradead.org, axboe@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Return-path: In-Reply-To: <1433508870-28251-1-git-send-email-m@bjorling.me> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Initial support for LightNVM. The support can be used to benchmark performance of targets and core implementation. Signed-off-by: Matias Bj=C3=B8rling --- Documentation/block/null_blk.txt | 8 +++ drivers/block/null_blk.c | 133 +++++++++++++++++++++++++++++++= +++++++- 2 files changed, 138 insertions(+), 3 deletions(-) diff --git a/Documentation/block/null_blk.txt b/Documentation/block/nul= l_blk.txt index 2f6c6ff..a34f50a 100644 --- a/Documentation/block/null_blk.txt +++ b/Documentation/block/null_blk.txt @@ -70,3 +70,11 @@ use_per_node_hctx=3D[0/1]: Default: 0 parameter. 1: The multi-queue block layer is instantiated with a hardware dispa= tch queue for each CPU node in the system. + +IV: LightNVM specific parameters + +nvm_enable=3D[x]: Default: 0 + Enable LightNVM for null block devices. Requires blk-mq to be used. + +nvm_num_channels=3D[x]: Default: 1 + Number of LightNVM channels that is exposed to the LightNVM driver. diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c index 79972ab..1337541 100644 --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 struct nullb_cmd { struct list_head list; @@ -17,6 +18,7 @@ struct nullb_cmd { struct bio *bio; unsigned int tag; struct nullb_queue *nq; + struct nvm_rq_data nvm_rqdata; }; =20 struct nullb_queue { @@ -147,6 +149,14 @@ static bool use_per_node_hctx =3D false; module_param(use_per_node_hctx, bool, S_IRUGO); MODULE_PARM_DESC(use_per_node_hctx, "Use per-node allocation for hardw= are context queues. Default: false"); =20 +static bool nvm_enable; +module_param(nvm_enable, bool, S_IRUGO); +MODULE_PARM_DESC(nvm_enable, "Enable Open-channel SSD. Default: false"= ); + +static int nvm_num_channels =3D 1; +module_param(nvm_num_channels, int, S_IRUGO); +MODULE_PARM_DESC(nvm_num_channels, "Number of channels to be exposed f= rom the Open-Channel SSD. Default: 1"); + static void put_tag(struct nullb_queue *nq, unsigned int tag) { clear_bit_unlock(tag, nq->tag_map); @@ -273,6 +283,9 @@ static void null_softirq_done_fn(struct request *rq= ) =20 static inline void null_handle_cmd(struct nullb_cmd *cmd) { + if (nvm_enable) + nvm_unprep_rq(cmd->rq, &cmd->nvm_rqdata); + /* Complete IO by inline, softirq or timer */ switch (irqmode) { case NULL_IRQ_SOFTIRQ: @@ -351,6 +364,85 @@ static void null_request_fn(struct request_queue *= q) } } =20 +#ifdef CONFIG_NVM + +static int null_nvm_id(struct request_queue *q, struct nvm_id *id) +{ + sector_t size =3D gb * 1024 * 1024 * 1024ULL; + unsigned long per_chnl_size =3D + size / bs / nvm_num_channels; + struct nvm_id_chnl *chnl; + int i; + + id->ver_id =3D 0x1; + id->nvm_type =3D NVM_NVMT_BLK; + id->nchannels =3D nvm_num_channels; + + id->chnls =3D kmalloc_array(id->nchannels, sizeof(struct nvm_id_chnl)= , + GFP_KERNEL); + if (!id->chnls) + return -ENOMEM; + + for (i =3D 0; i < id->nchannels; i++) { + chnl =3D &id->chnls[i]; + chnl->queue_size =3D hw_queue_depth; + chnl->gran_read =3D bs; + chnl->gran_write =3D bs; + chnl->gran_erase =3D bs * 256; + chnl->oob_size =3D 0; + chnl->t_r =3D chnl->t_sqr =3D 25000; /* 25us */ + chnl->t_w =3D chnl->t_sqw =3D 500000; /* 500us */ + chnl->t_e =3D 1500000; /* 1.500us */ + chnl->io_sched =3D NVM_IOSCHED_CHANNEL; + chnl->laddr_begin =3D per_chnl_size * i; + chnl->laddr_end =3D per_chnl_size * (i + 1) - 1; + } + + return 0; +} + +static int null_nvm_get_features(struct request_queue *q, + struct nvm_get_features *gf) +{ + gf->rsp =3D 0; + gf->ext =3D 0; + + return 0; +} + +static int null_nvm_internal_rw(struct request_queue *q, + struct nvm_internal_cmd *cmd) +{ + struct request *req; + int ret; + + req =3D blk_mq_alloc_request(q, cmd->rw, GFP_KERNEL, false); + if (IS_ERR(req)) + return PTR_ERR(req); + + req->cmd_type =3D REQ_TYPE_DRV_PRIV; + req->cmd_flags |=3D REQ_FAILFAST_DRIVER; + req->__data_len =3D 0; + req->__sector =3D (sector_t) -1; + req->bio =3D req->biotail =3D NULL; + req->timeout =3D 30; + req->special =3D cmd; + + blk_execute_rq(req->q, NULL, req, 0); + ret =3D req->errors; + blk_mq_free_request(req); + return ret; +} + +static struct nvm_dev_ops null_nvm_dev_ops =3D { + .identify =3D null_nvm_id, + .get_features =3D null_nvm_get_features, + .internal_rw =3D null_nvm_internal_rw, +}; +#else +static struct nvm_dev_ops null_nvm_dev_ops; +#endif /* CONFIG_NVM */ + static int null_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { @@ -359,6 +451,22 @@ static int null_queue_rq(struct blk_mq_hw_ctx *hct= x, cmd->rq =3D bd->rq; cmd->nq =3D hctx->driver_data; =20 + if (nvm_enable) { + nvm_init_rq_data(&cmd->nvm_rqdata); + switch (nvm_prep_rq(cmd->rq, &cmd->nvm_rqdata)) { + case NVM_PREP_DONE: + return BLK_MQ_RQ_QUEUE_OK; + case NVM_PREP_REQUEUE: + blk_mq_requeue_request(bd->rq); + blk_mq_kick_requeue_list(hctx->queue); + return BLK_MQ_RQ_QUEUE_OK; + case NVM_PREP_BUSY: + return BLK_MQ_RQ_QUEUE_BUSY; + case NVM_PREP_ERROR: + return BLK_MQ_RQ_QUEUE_ERROR; + } + } + blk_mq_start_request(bd->rq); =20 null_handle_cmd(cmd); @@ -517,14 +625,21 @@ static int null_add_dev(void) goto out_free_nullb; =20 if (queue_mode =3D=3D NULL_Q_MQ) { + int cmd_size =3D sizeof(struct nullb_cmd); + + if (nvm_enable) + cmd_size +=3D sizeof(struct nvm_per_rq); + nullb->tag_set.ops =3D &null_mq_ops; nullb->tag_set.nr_hw_queues =3D submit_queues; nullb->tag_set.queue_depth =3D hw_queue_depth; nullb->tag_set.numa_node =3D home_node; - nullb->tag_set.cmd_size =3D sizeof(struct nullb_cmd); - nullb->tag_set.flags =3D BLK_MQ_F_SHOULD_MERGE; + nullb->tag_set.cmd_size =3D cmd_size; nullb->tag_set.driver_data =3D nullb; =20 + if (!nvm_enable) + nullb->tag_set.flags =3D BLK_MQ_F_SHOULD_MERGE; + rv =3D blk_mq_alloc_tag_set(&nullb->tag_set); if (rv) goto out_cleanup_queues; @@ -568,8 +683,8 @@ static int null_add_dev(void) } =20 mutex_lock(&lock); - list_add_tail(&nullb->list, &nullb_list); nullb->index =3D nullb_indexes++; + list_add_tail(&nullb->list, &nullb_list); mutex_unlock(&lock); =20 blk_queue_logical_block_size(nullb->q, bs); @@ -578,16 +693,23 @@ static int null_add_dev(void) size =3D gb * 1024 * 1024 * 1024ULL; set_capacity(disk, size >> 9); =20 + if (nvm_enable && nvm_register(nullb->q, disk, &null_nvm_dev_ops)) + goto out_cleanup_disk; + disk->flags |=3D GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO= ; disk->major =3D null_major; disk->first_minor =3D nullb->index; disk->fops =3D &null_fops; disk->private_data =3D nullb; disk->queue =3D nullb->q; + sprintf(disk->disk_name, "nullb%d", nullb->index); add_disk(disk); + nvm_attach_sysfs(disk); return 0; =20 +out_cleanup_disk: + put_disk(disk); out_cleanup_blk_queue: blk_cleanup_queue(nullb->q); out_cleanup_tags: @@ -611,6 +733,11 @@ static int __init null_init(void) bs =3D PAGE_SIZE; } =20 + if (nvm_enable && bs !=3D 4096) { + pr_warn("null_blk: only 4K sectors are supported for Open-Channel SS= Ds. bs is set to 4K.\n"); + bs =3D 4096; + } + if (queue_mode =3D=3D NULL_Q_MQ && use_per_node_hctx) { if (submit_queues < nr_online_nodes) { pr_warn("null_blk: submit_queues param is set to %u.", --=20 2.1.4