Skip to content

Runtime + Network Stack - #5

Closed
supernomad wants to merge 166 commits into
mainfrom
runtime_v2
Closed

supernomad wants to merge 166 commits into
mainfrom
runtime_v2

Conversation

@supernomad

Copy link
Copy Markdown
Contributor

No description provided.

This includes a decent revamp and simplification/efficiency updates for
the PMTU + NDP/ARP handling. There should be no system calls for time
going forward and they are vastly simpler.
This moves away from as much direct byte buffer interactions as possible
in favor of typed struct casting.
supernomad and others added 28 commits March 7, 2026 23:12
Plan to decompose the 11,300-line tcp/mod.rs into focused modules
(handler, listener, connection, inbound, timers, transmit) and
split 8,200 lines of tests into category-based test files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
21-task plan for decomposing tcp/mod.rs (11,300 lines) into focused
modules and categorized test files. Each task is one commit with
cargo test verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move connect(), connect_with_config(), and initiate_close() methods
into a dedicated connection.rs module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move poll_send() method into its own transmit.rs module for better
code organization, continuing the tcp handler decomposition.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move poll_timers() and evict_stale() methods into a dedicated timers
module, continuing the mechanical decomposition of the monolithic
tcp/mod.rs handler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move TcpHandler struct definition, constructor, get_connection,
get_connection_mut, remove_connection, and constants (INITIAL_RTO_MS,
SYN_R2_THRESHOLD_MS) into handler.rs. Re-export TcpHandler from mod.rs
so sibling modules and external code continue to work unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move all inbound segment processing (process_ipv4, process_ipv6,
process_segment, process_listen, process_syn_received, process_syn_sent,
process_established, process_teardown) and the is_segment_acceptable
free function into inbound.rs. mod.rs now contains only module
declarations, the TcpHandler re-export, and the test module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move ~8200 lines of inline tests from mod.rs into src/net/handler/tcp/tests/
with category-based organization:

- tests/mod.rs: shared imports, constants, and helper functions
- handshake.rs: 3-way handshake, simultaneous open, window scale
- data_transfer.rs: in-order/out-of-order data, poll_send, PSH flag
- retransmission.rs: fast retransmit, RTO, RTT estimation, limited transmit
- teardown.rs: FIN handling, close lifecycle, half-close, linger
- delayed_ack.rs: deferred ACK, flush on second segment, timer flush
- nagle.rs: Nagle algorithm, TCP_NODELAY
- keepalive.rs: keep-alive probes, linger options
- timestamps.rs: PAWS validation
- persist.rs: zero-window probing
- sack.rs: SACK blocks, scoreboard, SACK recovery
- ecn.rs: ECN negotiation, CE detection, CWR/ECE flags
- edge_cases.rs: RST handling, challenge ACKs, SWS avoidance
- congestion_tests.rs: CUBIC slow start, F-RTO

All 98 TCP tests pass unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Captures analysis of hot-path bottlenecks (per-packet Instant::now(),
redundant tsval computation, Vec allocations) and planned changes to
eliminate them. Target: millions of pkt/s for TCP echo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7-task plan covering: now threading through dispatch, tsval
pre-computation, stack array replacements, and connection
constructor cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The runtime loop caches `now = coarsetime::Instant::now()` and passes it
through the handler chain. The IPv4/IPv6 handlers were calling the no-now
TCP wrappers which called Instant::now() internally — wasting a syscall
per packet. Now both dispatch sites call the _with_now variants directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The no-`now` wrappers (process_ipv4 and process_ipv6) that internally
called Instant::now() are removed. The _with_now variants are renamed
to be the primary API (process_ipv4 and process_ipv6), keeping the
`now: Instant` parameter. All callers updated accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t::now()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Analyze 20x performance gap between TCP echo (560K pkt/s) and UDP echo
(11M pkt/s). Identify root causes: 4 data copies per echo, redundant
option parsing, software checksums on VETH, cache-unfriendly Tcb layout,
and instruction cache pressure from cold paths.

Propose 8-task plan targeting 2-5M pkt/s: consolidated option parsing,
VETH checksum bypass, fast-path for established state, RingBuffer splice,
Tcb field reordering, cached connection indices, and cold path extraction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Parse TCP timestamp and SACK block options once per segment in
process_segment, replacing 3 redundant parse_timestamp calls and
2 redundant parse_sack_blocks calls in process_established/process_teardown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a fast-path at the top of process_established that handles the
most common case (in-order data with valid new ACK, no special flags,
not in recovery, no OOO segments) in a single streamlined block with
minimal branches. On any check failure (PAWS, window space), control
falls through to the existing slow path which remains unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…o-copy echo

Add RingBuffer::transfer() to move data directly between ring buffers
without an intermediate user-space buffer, eliminating 2 memcpys.
Add TcpStream::splice() future that uses transfer() internally.
Update tcp-echo-server example to use splice() instead of read/write.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Group hot fields (rcv_nxt, snd_nxt, snd_una, snd_wnd, state, flags)
into the first 1-2 cache lines (64-128 bytes) to improve L1d hit rate
on the per-packet fast path. Fields are organized into hot/warm/ack
processing/congestion/RTT/cold tiers based on access frequency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TcpRead, TcpWrite, and TcpSplice poll methods previously called
get_connection_mut() which does an O(n) linear scan of Vec<Tcb> on
every poll. Add a Cell<usize> cached index to TcpStream that enables
O(1) lookup on the fast path, with automatic fallback to linear scan
when the index becomes stale due to connection table mutations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract three rarely-taken branches from process_established's slow path
into dedicated #[inline(never)] helper methods to reduce instruction cache
pressure on the hot path:

- handle_rst_established: RST handling with exact-match removal + challenge ACK
- handle_syn_established: challenge ACK for SYN in synchronized state
- handle_ooo_data: out-of-order data storage + SACK block generation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@supernomad supernomad closed this Mar 10, 2026
@supernomad
supernomad deleted the runtime_v2 branch March 17, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant