1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:27:43 +00:00

NVMe: Add shadow doorbell support

Shadow doorbell feature was added in the NVMe spec to improve
the performance of virtual devices.

Typically, ringing a doorbell involves writing to an MMIO register in
QEMU, which can be expensive as there will be a trap for the VM.

Shadow doorbell mechanism was added for the VM to communicate with the
OS when it needs to do an MMIO write, thereby avoiding it when it is
not necessary.

There is no performance improvement with this support in Serenity
at the moment because of the block layer constraint of not batching
multiple IOs. Once the command batching support is added to the block
layer, shadow doorbell support can improve performance by avoiding many
MMIO writes.

Default to old MMIO mechanism if shadow doorbell is not supported.
This commit is contained in:
Pankaj Raghav 2023-08-02 12:41:31 +02:00 committed by Jelle Raaijmakers
parent 5b774f3617
commit 7138395982
5 changed files with 121 additions and 6 deletions

View file

@ -28,6 +28,8 @@ struct DoorbellRegister {
struct Doorbell {
Memory::TypedMapping<DoorbellRegister volatile> mmio_reg;
Memory::TypedMapping<DoorbellRegister> dbbuf_shadow;
Memory::TypedMapping<DoorbellRegister> dbbuf_eventidx;
};
enum class QueueType {
@ -62,9 +64,25 @@ public:
protected:
u32 process_cq();
// Updates the shadow buffer and returns if mmio is needed
bool update_shadow_buf(u16 new_value, u32* dbbuf, u32* ei)
{
u32 const old = *dbbuf;
*dbbuf = new_value;
AK::full_memory_barrier();
bool need_mmio = static_cast<u16>(new_value - *ei - 1) < static_cast<u16>(new_value - old);
return need_mmio;
}
void update_sq_doorbell()
{
m_db_regs.mmio_reg->sq_tail = m_sq_tail;
full_memory_barrier();
if (m_db_regs.dbbuf_shadow.paddr.is_null()
|| update_shadow_buf(m_sq_tail, &m_db_regs.dbbuf_shadow->sq_tail, &m_db_regs.dbbuf_eventidx->sq_tail))
m_db_regs.mmio_reg->sq_tail = m_sq_tail;
}
NVMeQueue(NonnullOwnPtr<Memory::Region> rw_dma_region, Memory::PhysicalPage const& rw_dma_page, u16 qid, u32 q_depth, OwnPtr<Memory::Region> cq_dma_region, OwnPtr<Memory::Region> sq_dma_region, Doorbell db_regs);
@ -88,7 +106,10 @@ private:
virtual void complete_current_request(u16 cmdid, u16 status) = 0;
void update_cq_doorbell()
{
m_db_regs.mmio_reg->cq_head = m_cq_head;
full_memory_barrier();
if (m_db_regs.dbbuf_shadow.paddr.is_null()
|| update_shadow_buf(m_cq_head, &m_db_regs.dbbuf_shadow->cq_head, &m_db_regs.dbbuf_eventidx->cq_head))
m_db_regs.mmio_reg->cq_head = m_cq_head;
}
protected: