net: a frame wakes the stack, instead of waiting for the clock
The network thread waited on the timer and nothing else, so a frame that landed just after a poll sat in the ring for up to 10 ms -- the largest fixed latency in the system. That was deliberate when the stack was new (a receive path woken by an interrupt is much harder to debug than one that is asked) and there is now a working stack to compare against, which is exactly when it becomes safe to do. The frame is still *pulled* by the thread through .receive. It has to be: a call into lwIP can reach the driver, the driver can sleep on the buffer cache, and an interrupt handler may do neither. netdev_rx_signal() delivers nothing and reads no ring -- it only ends the wait early. The wait stays on the timer tick rather than moving to a channel of its own, and that is the design. lwIP's timers must still run when the link is silent, so the clock has to remain a floor under the wait, and sleep() cannot wait on two things at once. Joining the tick's existing wakeup costs nothing and leaves one wait with one predicate. rx_signal lives under tickslock for the same reason it gets no lock of its own: sleep() releases tickslock atomically, so a driver setting the flag and waking under that lock cannot lose the wakeup by arriving between the predicate test and the sleep. A private lock would not be held across the sleep, and that window would be back. Calling it from interrupt context is safe on the same terms the timer handler already relies on -- acquire() disables interrupts, so a CPU holding tickslock cannot be interrupted into it. The e1000 signals on RXT0 (a frame or burst has landed) and RXDMT0 (the ring has fallen below its threshold, which is when waiting for the clock hurts most). Measured rather than asserted: /proc/netif reports wake_rx and wake_tick, and across three pings rx_frames and wake_rx both went 2 -> 6 -- every received frame woke the thread through the interrupt. wake_tick keeps advancing as the idle floor, which is what lwIP's timers need. socktest still passes and ping is still 0% loss. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
e80f7b287b
commit
3034efd300
7 changed files with 138 additions and 17 deletions
|
|
@ -108,8 +108,30 @@ received frames and runs its timers.
|
|||
|
||||
**A thread rather than the interrupt handler, and the reason is the lock:** a
|
||||
call into lwIP can reach the driver, the driver can sleep, and an interrupt
|
||||
handler cannot. So the interrupt keeps doing what it always did — clear the
|
||||
cause register — and this thread polls.
|
||||
handler cannot. So the frame is always *pulled*, by this thread, through
|
||||
`.receive`.
|
||||
|
||||
The interrupt's only job is to end the thread's wait early. `netdev_rx_signal()`
|
||||
is what a driver calls from its handler; it delivers no frame and reads no ring.
|
||||
Without it a frame that arrived just after a poll sat there until the next clock
|
||||
tick — up to 10 ms, and the largest fixed latency in the system.
|
||||
|
||||
**The wait stays on the timer tick rather than moving to a channel of its own**,
|
||||
and that is the design rather than an accident. lwIP's timers must still run when
|
||||
the link is silent, so the clock has to remain a floor under the wait, and
|
||||
`sleep()` cannot wait on two things at once. Joining the tick's existing wakeup
|
||||
costs nothing and leaves one wait with one predicate.
|
||||
|
||||
The flag lives under `tickslock` for the same reason it does not get a lock of
|
||||
its own: `sleep()` releases `tickslock` atomically, so a driver setting the flag
|
||||
and waking under that lock cannot lose the wakeup by arriving between the
|
||||
predicate test and the sleep. A private lock would not be held across the sleep,
|
||||
and that window would be back.
|
||||
|
||||
`/proc/netif` reports `wake_rx` and `wake_tick` so this is observable rather
|
||||
than assumed — if `wake_rx` stays at zero while frames arrive, the interrupt is
|
||||
not reaching the stack and the thread is running on the clock exactly as it used
|
||||
to. Measured across three pings: `rx_frames` and `wake_rx` both went 2 → 6.
|
||||
|
||||
`netinit()` runs after `sinit()` because `kthread_create` needs a usable process
|
||||
table, and it returns immediately: everything happens in that thread, which
|
||||
|
|
@ -237,11 +259,6 @@ be fixed before `recvfrom` could report a source address at all.
|
|||
- **No resolver reachable from userland.** lwIP's DNS client is compiled but
|
||||
nothing exposes it, so `ping` takes a dotted quad. `localhost` is special-cased
|
||||
in the program rather than resolved.
|
||||
- **Receive is polled.** The network thread looks at the NIC every timer tick
|
||||
when the link is idle, so an arriving frame waits up to 10 ms. Waking the
|
||||
thread from the e1000 interrupt is the real fix, and was deliberately not the
|
||||
first version: a receive path woken by an interrupt is much harder to debug
|
||||
than one that is asked.
|
||||
- **No routing table.** With two interfaces up, the first is the default route
|
||||
and the second is reachable only by an address on its own subnet. That is a
|
||||
rule rather than an accident, and it is not routing.
|
||||
|
|
|
|||
|
|
@ -101,9 +101,13 @@ These are the galling ones — the replacement exists, is tested, and is unused.
|
|||
`text.c` and `ttf.c` both exist and work. The console still indexes
|
||||
`font_data[256][16]`.
|
||||
- [ ] **Load a font from disk** and point the console at it.
|
||||
- [ ] **Interrupt-driven receive.** The network thread polls the NIC every timer
|
||||
tick, so a frame waits up to 10 ms. Waking it from the e1000 interrupt was
|
||||
deliberately not the first version; it is time.
|
||||
- [x] ~~**Interrupt-driven receive.**~~ The e1000's handler calls
|
||||
`netdev_rx_signal()`, which ends the network thread's wait early; the frame
|
||||
is still *pulled* by the thread, because an interrupt handler can neither
|
||||
sleep on the buffer cache nor take the lwIP lock. The wait stays on the
|
||||
tick so lwIP's timers keep their floor. Proven rather than assumed:
|
||||
`/proc/netif` gained `wake_rx`/`wake_tick`, and across three pings
|
||||
`rx_frames` and `wake_rx` both went 2 -> 6.
|
||||
|
||||
**Structural, because everything after this compounds on it:**
|
||||
|
||||
|
|
|
|||
|
|
@ -51,11 +51,6 @@ Three things the stack owed on the day it landed, all still owed:
|
|||
- **No routing table.** With two interfaces up, the first is the default route
|
||||
and the second is reachable only by an address on its own subnet. That is a
|
||||
rule rather than an accident, and it is not routing.
|
||||
- **Receive is polled.** The network thread looks at the NIC every timer tick
|
||||
when the link is idle, so an arriving frame waits up to 10 ms. Waking that
|
||||
thread from the e1000 interrupt is the real fix, and was deliberately not the
|
||||
first version: a receive path woken by an interrupt is much harder to debug
|
||||
than one that is asked.
|
||||
|
||||
`setsockopt` returning 0 for everything is in
|
||||
[foundations.md](foundations.md) instead, because the Wayland work needs it.
|
||||
|
|
|
|||
Loading…
Reference in a new issue