From: Rob Nelson
This change provides a mechanism to reduce the number of MMIO doorbell
writes for the NVMe driver. When running in a virtualized environment
like QEMU, the cost of an MMIO is quite hefy here. The main idea for
the patch is provide the device two memory location locations:
1) to store the doorbell values so they can be lookup without the doorbell
MMIO write
2) to store an event index.
I believe the doorbell value is obvious, the event index not so much.
Similar to the virtio specificaiton, the virtual device can tell the
driver (guest OS) not to write MMIO unless you are writing past this
value.
FYI: doorbell values are written by the nvme driver (guest OS) and the
event index is written by the virtual device (host OS).
The patch implements a new admin command that will communicate where
these two memory locations reside. If the command fails, the nvme
driver will work as before without any optimizations.
Contributions:
Eric Northup
Frank Swiderski
Ted Tso
Keith Busch
Just to give an idea on the performance boost with the vendor
extension: Running fio [1], a stock NVMe driver I get about 200K read
IOPs with my vendor patch I get about 1000K read IOPs. This was
running with a null device i.e. the backing device simply returned
success on every read IO request.
[1] Running on a 4 core machine:
fio --time_based --name=benchmark --runtime=30
--filename=/dev/nvme0n1 --nrfiles=1 --ioengine=libaio --iodepth=32
--direct=1 --invalidate=1 --verify=0 --verify_fatal=0 --numjobs=4
--rw=randread --blocksize=4k --randrepeat=false
Signed-off-by: Rob Nelson
[mlin: port for upstream]
Signed-off-by: Ming Lin
[koike: updated for upstream]
Signed-off-by: Helen Koike
---
Changes since v2:
- Add vdb.c and vdb.h, the idea is to let the code in pci.c clean and to
make it easier to integrate with the official nvme extention when nvme
consortium publishes it
- Remove rmb (I couldn't see why they were necessary here, please let me
know if I am wrong)
- Reposition wmb
- Transform specific code in helper functions
- Coding style (checkpatch, remove unecessary goto, change if statement
logic to decrease identation)
- Rename feature to CONFIG_NVME_VDB
- Remove some PCI_VENDOR_ID_GOOGLE checks
drivers/nvme/host/Kconfig | 11
drivers/nvme/host/Makefile | 1 +
drivers/nvme/host/pci.c| 29 ++-
drivers/nvme/host/vdb.c| 125 +
drivers/nvme/host/vdb.h| 118 ++
include/linux/nvme.h | 17 ++
6 files changed, 299 insertions(+), 2 deletions(-)
create mode 100644 drivers/nvme/host/vdb.c
create mode 100644 drivers/nvme/host/vdb.h
diff --git a/drivers/nvme/host/Kconfig b/drivers/nvme/host/Kconfig
index db39d53..d3f4da9 100644
--- a/drivers/nvme/host/Kconfig
+++ b/drivers/nvme/host/Kconfig
@@ -43,3 +43,14 @@ config NVME_RDMA
from https://github.com/linux-nvme/nvme-cli.
If unsure, say N.
+
+config NVME_VDB
+ bool "NVMe Virtual Doorbell Extension for Improved Virtualization"
+ depends on NVME_CORE
+ ---help---
+ This provides support for the Virtual Doorbell Extension which
+ reduces the number of required MMIOs to ring doorbells, improving
+ performance in virtualized environments where MMIO causes a high
+ overhead.
+
+ If unsure, say N.
diff --git a/drivers/nvme/host/Makefile b/drivers/nvme/host/Makefile
index 47abcec..d4d0e3d 100644
--- a/drivers/nvme/host/Makefile
+++ b/drivers/nvme/host/Makefile
@@ -8,6 +8,7 @@ nvme-core-$(CONFIG_BLK_DEV_NVME_SCSI) += scsi.o
nvme-core-$(CONFIG_NVM)+= lightnvm.o
nvme-y += pci.o
+nvme-$(CONFIG_NVME_VDB)+= vdb.o
nvme-fabrics-y += fabrics.o
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index cf8b3d7..20bbc33 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -44,6 +44,7 @@
#include
#include "nvme.h"
+#include "vdb.h"
#define NVME_Q_DEPTH 1024
#define NVME_AQ_DEPTH 256
@@ -99,6 +100,7 @@ struct nvme_dev {
dma_addr_t cmb_dma_addr;
u64 cmb_size;
u32 cmbsz;
+ struct nvme_vdb_dev vdb_d;
struct nvme_ctrl ctrl;
struct completion ioq_wait;
};
@@ -131,6 +133,7 @@ struct nvme_queue {
u16 qid;
u8 cq_phase;
u8 cqe_seen;
+ struct nvme_vdb_queue vdb_q;
};
/*
@@ -171,6 +174,7 @@ static inline void _nvme_check_size(void)
BUILD_BUG_ON(sizeof(struct nvme_id_ns) != 4096);
BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64);
BUILD_BUG_ON(sizeof(struct nvme_smart_log) != 512);
+ BUILD_BUG_ON(sizeof(struct nvme_doorbell_memory) != 64);
}
/*
@@ -285,7 +289,7 @@ static void __nvme_submit_cmd(struct nvme_queue *nvmeq,
if (++tail == nvmeq->q_depth)
tail = 0;
- wr