Compare commits

...

2 Commits

Author SHA1 Message Date
Bananymous e77de1804f Kernel: Fix some race conditions in TCP stack
Remove race condition if two acks are to be sent one after another.

Always unblock semaphore once TCP thread has done something. This
allows better chance of TCP sending to succeed.

There are multiple places in the networking code that would require
thread-safe entering to blocking mode. I should add some API for this
so that a lot of race conditions could be removed.
2024-05-21 01:53:45 +03:00
Bananymous e00b92225d Kernel: Fix E1000 interrupt handling condition
I had written the ICR register check backwards which lead to interrupt
handling only when it was not needed, and no handling when it was
needed. This somehow still worked, just much slower often requiring tcp
resends from the server.
2024-05-21 01:52:19 +03:00
2 changed files with 3 additions and 4 deletions

View File

@ -290,7 +290,7 @@ namespace Kernel
void E1000::handle_irq()
{
if (read32(REG_ICR) & ICR_RxQ0)
if (!(read32(REG_ICR) & ICR_RxQ0))
return;
SpinLockGuard _(m_lock);

View File

@ -438,10 +438,8 @@ namespace Kernel
{
LockGuard _(m_mutex);
if (m_should_ack)
if (m_should_ack.compare_exchange(true, false))
{
m_should_ack = false;
ASSERT(m_connection_info.has_value());
auto* target_address = reinterpret_cast<const sockaddr*>(&m_connection_info->address);
auto target_address_len = m_connection_info->address_len;
@ -510,6 +508,7 @@ namespace Kernel
}
}
m_semaphore.unblock();
m_semaphore.block_with_wake_time(current_ms + retransmit_timeout_ms);
}