* test: expect the JIT host's fused multiply-add, tail call and chaining caps, and export jitTail() beside jitSimd() and jitFma()
The JIT rework added caps bits 6 (fused relaxed multiply-adds), 7 (cheap
tail calls), 8 (module format v2, KW_JIT_V2=1) and 9 (chaining, unless
KW_JIT_CHAIN=0), but the JitHost test still expected bits 0-5 only, so it
failed on every run (755, not 51, on Node 24 on x86-64). The test now
derives the expected caps from the same probes and variables.
* test: expect shm views in place in worker mode with an SMP kernel
With UNKERNEL_TEST_CPUS=2 the worker shares the kernel's memory with this
thread (shm.ts, In place), so views() works there instead of failing with
EOPNOTSUPP; the shm test failed on every 2-CPU run. It now checks the
views on the shared memory there, and the EOPNOTSUPP on the UP kernel.
* test: find the forced H.264 key frame by the source's request, not by a chunk window
The camera H.264 test wanted the key frame kwcap forces after the 16th
chunk among chunks 16 to 22. The source makes it next, but the chunks it
made before reach the guest first: the host's queue and the guest's
filled buffers, as many as the guest lags behind the source's clock. With
the full suite at once the inline kernel's timer ran late, the pattern
source caught up several frames at a time, and the forced key frame came
later (or on the GOP's own key frame at 24). The test now records the
chunk the source makes after each key frame request, checks that the
guest gets that chunk as a key frame, with only the GOP's key frames
before it and the GOP counting from it, and streams 60 chunks, enough for
the queue's 32 and the guest's buffers.
* test: judge shm reads through the ring by the reads during which this thread was free
The ring's answer comes as a message to this thread, which also runs the
suite's inline kernels. The check skipped itself when this thread's timer
delay was high, but it measured that delay only after the 25 reads, so a
busy spell during the reads failed it (median 32.5 ms with a delay of
1.4 ms measured afterwards). Each read now records this thread's longest
timer delay while it runs, and the median is asserted over the reads that
saw no delay of 3 ms or more (when there are at least 3 of them).
* test: run worker-mode capture from a read() source after the concurrent suite
In worker mode the sound in and camera tests' read() sources answer on this
thread, and the worker records silence or a black frame wherever the
answer comes late. With the whole suite at once this thread runs every
inline kernel, and the source fell 200 ms or more behind at the start of a
stream: kwrec got 2357 and 2854 of its 3000 samples (worker; worker with
messages), the camera 3 of 8 pictures (worker with messages). Those four
tests now run in a suite of their own after the concurrent one, alongside
each other only, with their assertions unchanged; the inline ones and the
onRing ones (a producer on a thread of its own) stay in the concurrent
suite.
* test: read a guest's background counter again when its file is empty
The snapshot and session tests' guests count in the background with
echo $i > FILE, which truncates the file before it writes, so a cat in
between reads nothing, 0, and fails a "counts on" check (or weakens the
next one). The host now reads the counter again while its file is empty,
at most 50 times. A rename per write in the guest would also do, but at a
fork per write it loads the guest (and, inline, this thread) twice as
much.
* test: let a restored recording end before boot() returns in the snapshot capture test
A restore hides the stopped time from the guest's clock, so the restored
guest has what was left of its 3 s recording. Where the snapshot landed
late in it (a busy host), kwrec's own stop and close came before boot()
returned, and the test, which wanted nothing after the replayed open,
prepare and start, failed. It now asserts the replay first, then nothing
or the guest's stop and close, with capturing to match.
* test: derive the SMP kernel once for UNKERNEL_TEST_CPUS runs instead of at every boot
Given the bundle and more than one CPU, createKernel() derives the SMP
kernel from it on the calling thread at every boot (about 0.2 s of
patching), and in a 2-CPU run every boot() did that. The suite's boots at
once held this thread, which runs the inline kernels and the device
sources, for over 3 s: glimmer's 3 s of sound took 6.3 to 6.8 s, the PCM
ring from the worker CPU (2.97 s of that stream) overflowed and dropped
346 to 890 frames glimmer had written without an underrun, and the H.264
source made too few chunks during the guest's stall to overflow the
queue. With UNKERNEL_TEST_CPUS > 1, boot() now boots the SMP kernel that
compileTestKernel() derives once wherever it runs on more than one CPU;
sharedKernel() still boots the bundle.
---------
Co-authored-by: Pooya Parsa <pooya@pi0.io>
BPF_SYSCALL with CGROUP_BPF was 70% of what the options cost, for runc's device filter. A new generic patch, BPF_CGDEV_ONLY, loads and attaches cgroup device programs only and runs them on the interpreter, with a verifier of its own: the SMP kernel grows 128 KB gzip instead of 460 KB. Checked with a runc container on cgroup v2.
A match more than 4 KiB away from where the current one continues now has to be 32 bytes longer instead of 8. New code otherwise became tens of thousands of short copies from unrelated places, each a seek a compressor cannot predict. The SMP patch with the Kubernetes options goes from 1.51 to 1.30 MB gzip; the format, the loader and the time to make it are unchanged.
The cgroup v2 memory, CPU and cpuset controllers with CPU limits, bpf(2)
with cgroup BPF, keys, bridge netfilter, the iptables pieces kube-proxy and
flannel use, nft ct and masq, the conntrack table in procfs, and VXLAN, in
kw_smp.config only: k3s needs cpuset, which needs SMP, so the UP kernel
stays as it is.
Co-authored-by: Greg Bell <code@gregbell.ca>
* docs: document snapshots, host commands, Tailscale, VA-API, fetchRoutes, UDP, the microphone and the camera in the SDK docs and README, and list the newer devices and uses in the README's introduction
* docs: split the Display page into Display and Input, and Sound and Camera
---------
Co-authored-by: Pooya Parsa <pooya@pi0.io>
A BPF arena needs get_vm_area(), which VMALLOC_FLAT does not have; with
the patch, arena maps fail with EINVAL as on kernels without an MMU.
BPF_SYSCALL stays off in kw_defconfig, so the patch is dormant by
default; it lets a kernel turn BPF on without importing get_vm_area.
Co-authored-by: Greg Bell <code@gregbell.ca>
With net.tailscale.exitNode (--tailscale-exit-node, setExitNode() at run
time) a tailnet device that offers 0.0.0.0/0 takes all the guest's other
IPv4 traffic and its DNS in place of the backend; while it is not usable
that traffic is refused. WireGuard's source check is now the longest
prefix across peers. The page lists the tailnet's devices, picks the
exit node from a select box in Settings and the top bar panel, and shows
a set-up node's status and live controls apart from the setup form. The
README gains a section on joining a tailnet.
Microphone: kwsnd gains a capture substream fed by the host (SDK option
soundIn, the page's Microphone setting and ?mic=0, the CLI's
--sound-in-wav and --sound-in).
Camera: kwcam is a V4L2 capture device (/dev/video0) fed by the host: I420,
NV12 and YUYV at 320x240 to 1280x720, and H.264 encoded by the host's
WebCodecs encoder where it has one, with bitrate, GOP and key frame
controls (SDK option camera, the page's Camera setting and ?cam=0, the
CLI's --camera). The base's rc writes the udev database entry of
/dev/video*, so programs that list cameras through libudev find it.
kwva (protocol 5): an encode whose input surface is a camera buffer's
dma-buf names the frame to the host instead of sending its pixels, and
pixels an app writes into an exported surface reach the host (put).
The guest joins a tailnet from Node or the page: ts2021 control over
WebSocket, DERP relays, WireGuard and the packet filter in JS, loaded as
a separate chunk only when the option is used. SDK net option, CLI
--tailscale* flags and a page panel. Relay only; exit nodes, IPv6 and
real peer traffic are not covered yet.
* web: add a terminal colour theme option (Auto, Dark, Light)
* web: add an option to turn off the Terminal window's see-through glass
* web: default the terminal colours to Auto
* web: add a page colour theme option (Auto, Dark, Light)
* web: give the chrome's materials in style.css a light variant
* web: give the components' chrome classes a light variant
* web: follow the theme in the charts, the alerts' caution badge and the Docs window
* web: fix the light theme's Dock glyphs, Resume card veil and Browser toolbar hover
* web: read the shown theme from the store and type the option field names
* web: darken the light theme's faint and error colours to 4.5:1 on tints
* web: give the light terminal mid-tone colours that read under black text
* web: lighten the light terminal's green, yellow and cyan for black text on them
* web: use the dark terminal's green in the light terminal
* web: give the light terminal's green, yellow and cyan 4.5:1 on white, as its red, blue and magenta
* web: give the light theme a white status bar on iOS
* web: make the Docs window opaque
* web: post a theme change to the Docs window instead of reloading it
* docs: upgrade undocs nightly, for the Docs window's theme messages
---------
Co-authored-by: Pooya Parsa <pooya@pi0.io>
On the SMP kernel a workqueue worker in the middle of an item could wait
for kernel threads that had already parked, never reach its own park
point, and end the cycle with -EBUSY naming it. A netns teardown's
cleanup_net() does that: it waits for grace periods, the expedited
grace-period worker and other work items. A cycle started right after an
`unshare -n` exit failed 13 times in 15 on 2 CPUs and 12 in 15 on 4; beside
a loop of netns teardowns 22 of 30 and 20 of 30 failed. Docker's
containers (#59) make such teardowns routine in Debian guests.
- The TREE_RCU grace-period kthread parks only while no grace period is
in progress or requested, so that a kernel thread in synchronize_rcu()
or rcu_barrier() can reach its park point (a fixup of the park points
patch).
- Between the user and the kernel-thread phases kwparkd waits, at most
HZ/2, until every workqueue worker is idle (in TASK_IDLE), while every
kernel thread still runs (kw_park_settle_work(), a fixup of the arch
patch).
With both, every cycle of those runs passed (120 on 2 and 4 CPUs). An idle
cycle's median went from 17.9 ms to 0.3 ms on 2 CPUs; a cycle that waits
for a teardown takes 60-230 ms. kwtest's park check is unchanged (2-5 ms
mean). parking.md describes the settle step and the grace-period rule.
Based on Martin Brook's patches on the android branch of
martinbrook/unkernel (cc78ca9, 4849ed9). His settle step also ran
rcu_barrier() and waited only for workers in an uninterruptible sleep:
here the barrier cost 40-50 ms in every cycle, and a worker between two
waits (runnable) ended the wait early, so 11 of 15 cycles still failed.
Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: Martin Brook <martin.brook100@googlemail.com>
get_user() and put_user() of an aligned 1, 2, 4 or 8 bytes are now one
load or store through kw_user_addr() instead of a memcpy (memory.copy,
which the Wasm spec does not make single-copy atomic on a shared
memory), so a futex word read beside another CPU's stores cannot tear;
an unaligned access still goes through raw_copy_*_user().
kwfb's set_par checks the mappings, allocates and switches the buffer
under info->mm_lock, which fbdev's mmap holds (check_var reads the count
under it too): an mmap racing FBIOPUT_VSCREENINFO from another thread
could map the old buffer.
kwtest checks both (uaccess: FUTEX_WAIT and getcpu beside another CPU's
stores, fault-in, EFAULT and a put_user across a page; kwfb: 200 mmaps
beside a thread changing the mode), and `kwtest smp` runs the kwfb
checks. Ported from VOD-Studio/unkernel@25e90b3f.
Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: xfy <i@rua.plus>