Kernel: Optimize networking code

Remove buffering from network layer and rework loopback interface.
loopback now has a separate recieve thread to allow concurrent sends and
prevent deadlocks
This commit is contained in:
2026-02-27 19:08:08 +02:00
parent ff378e4538
commit 9ddf19f605
20 changed files with 563 additions and 476 deletions

View File

@@ -9,6 +9,7 @@ namespace Kernel
{
public:
static constexpr size_t buffer_size = BAN::numeric_limits<uint16_t>::max() + 1;
static constexpr size_t buffer_count = 32;
public:
static BAN::ErrorOr<BAN::RefPtr<LoopbackInterface>> create();
@@ -24,8 +25,9 @@ namespace Kernel
LoopbackInterface()
: NetworkInterface(Type::Loopback)
{}
~LoopbackInterface();
BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::ConstByteSpan) override;
BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::Span<const BAN::ConstByteSpan> payload) override;
bool can_read_impl() const override { return false; }
bool can_write_impl() const override { return false; }
@@ -33,8 +35,27 @@ namespace Kernel
bool has_hungup_impl() const override { return false; }
private:
SpinLock m_buffer_lock;
void receive_thread();
private:
struct Descriptor
{
uint8_t* addr;
uint32_t size;
uint8_t state;
};
private:
Mutex m_buffer_lock;
BAN::UniqPtr<VirtualRange> m_buffer;
uint32_t m_buffer_tail { 0 };
uint32_t m_buffer_head { 0 };
Descriptor m_descriptors[buffer_count] {};
bool m_thread_should_die { false };
BAN::Atomic<bool> m_thread_is_dead { true };
ThreadBlocker m_thread_blocker;
};
}