Kernel: Reduce the number of E1000 register reads while receiving

There is no need to read and write the receive tail pointer for every
packet. This change bumped my TCP speed from ~11MB/s to ~40MB/s which is
my network speed limit
This commit is contained in:
2026-06-28 22:13:53 +03:00
parent 8f4e15b78e
commit c0bd07174d

View File

@@ -319,14 +319,16 @@ namespace Kernel
void E1000::receive_thread() void E1000::receive_thread()
{ {
SpinLockGuard _(m_rx_lock); SpinLockGuard guard(m_rx_lock);
uint32_t rx_current = 0;
while (!m_thread_should_die) while (!m_thread_should_die)
{ {
uint32_t rx_tail = rx_current;
for (;;) for (;;)
{ {
const uint32_t rx_current = (read32(REG_RDT0) + 1) % E1000_RX_DESCRIPTOR_COUNT;
auto& descriptor = reinterpret_cast<volatile e1000_rx_desc*>(m_rx_descriptor_region->vaddr())[rx_current]; auto& descriptor = reinterpret_cast<volatile e1000_rx_desc*>(m_rx_descriptor_region->vaddr())[rx_current];
if (!(descriptor.status & 1)) if (!(descriptor.status & 1))
break; break;
@@ -344,10 +346,15 @@ namespace Kernel
m_rx_lock.lock(); m_rx_lock.lock();
descriptor.status = 0; descriptor.status = 0;
write32(REG_RDT0, rx_current);
rx_tail = rx_current;
rx_current = (rx_current + 1) % E1000_RX_DESCRIPTOR_COUNT;
} }
SpinLockAsMutex smutex(m_rx_lock, InterruptState::Enabled); if (rx_current != rx_tail)
write32(REG_RDT0, rx_tail);
SpinLockGuardAsMutex smutex(guard);
m_rx_blocker.block_indefinite(&smutex); m_rx_blocker.block_indefinite(&smutex);
} }