Architecture

How Syx is put together today. This page summarises the architecture documents and decision records of the source tree; where they give a number, it is the number used here. Syx changes quickly, and the documents in the tree are authoritative.

Execution model

Syx targets IA-32 and runs on one CPU. The kernel runs with interrupts disabled: every IDT entry is an interrupt gate and the only sti are the return to user mode and the idle loop. The kernel is therefore never preempted, and that is the only mutual exclusion most kernel data needs. There are no locks in the kcall paths.

The cost is explicit: the length of a kernel path is time during which IRQs wait, and timer ticks beyond one pending period are lost. So kernel paths must be short and bounded; scans of all pages or all page-table entries are not allowed on frequent paths. User code is preempted at the end of its time slice; the scheduler picks the ready thread with the highest weight, with ageing.

User code enters the kernel through a trampoline page mapped in every process at 0xB0000000 (int $0x91). All arguments and results are 32-bit registers; larger data travels through validated user pointers. Errors are negative values that encode whether they come from the kernel or from a server, a category and a code.

Objects and handles

A handle is a per-process capability: an index, a 15-bit generation and a set of rights. The object it names is shared by every handle to it. Rights live in the handle, capabilities in the object; an operation needs both. A stale handle is rejected by its generation. Handles move between processes during an invoke in three modes: borrowed for the duration of the call, transferred, or cloned.

ObjectRole
VMOMemory object; mapped, read, written, resized; may have a pager.
RESResource hosted by a server process; the target of an invoke.
PAGERHandler in a server that supplies the missing pages of a VMO.
WATCHERWaits on many objects: bindings with a filter mask and a tag, level-triggered.
OPERATIONOne-slot completion object: status, result and optionally a handle.
TIMERSignaled at a deadline, optionally periodic.
CELLUp to 32 bytes with a lock owned by a process; a held lock is a request queued on an OPERATION, never a wait.
PROCESSAddress space, threads and handle table.
IRQA hardware interrupt line delivered to a user-space driver.
INTERRUPTPer-thread object used to deliver POSIX-style signals to user code.

Each object has a 32-bit signal mask, which is state rather than events. A watcher reports a binding when its pending bits become non-zero and keeps reporting it until they are cleared; pending bindings take turns, so one object that stays signaled does not hide the others.

The invoke

The invoke (kcall 68) is a synchronous, migrating-thread call. The calling thread checks the handle, copies the request, switches to the server's address space and returns to user mode in the server's handler, on one of the server's invoke stacks. When the handler ends (kcall 69, or a plain return) the response and its handles are copied back and the thread returns to its client. No server thread is involved and nothing is queued in the kernel.

LimitValue
Request or response dataup to 1024 bytes, a multiple of 4
Handles per request or responseup to 4; created in two phases, all or nothing
Invoke stacks per server process16, of 64 KiB, with guard pages
Kernel stack per thread8 KiB, shared by all its nested invokes
Nesting today3 levels, enforced by free kernel stack
One thread crosses three processes: an application invokes fatfs, whose handler invokes the ide driver; each kcall 69 returns one level. applicationipc_level 0 fatfsipc_level 1 ideipc_level 2 kcall 68 kcall 68 kcall 69 kcall 69 handler on a fatfs invoke stack ide handler caller's thread back in the caller The kernel stack of the thread holds one frame per level; each level costs about 1.6 KiB of it.
Figure 2. The deepest real chain today: a file read that reaches the disk driver. One thread, three address spaces. The thread's kernel stack is shared by all levels, which is what bounds the nesting.

Bounded nesting

A handler may invoke another server. The depth is bounded twice: by a maximum IPC level, and, before that, by the space left on the thread's 8 KiB kernel stack. Each level costs about 1.6 KiB; the deepest path a handler can start without invoking again was measured at about 2.1 KiB. The kernel refuses a new level with KERR_INVOKE_TOO_MANY_NESTS when less than 3712 bytes remain, which allows three nested levels today. A canary at the bottom of every kernel stack is checked on each schedule and invoke, and the kernel builds with a per-function stack usage limit, so a new large frame breaks the build instead of the stack.

Handlers never sleep

A handler runs on its client's thread and holds one of the server's sixteen invoke stacks. A handler that sleeps keeps both, so it makes other clients wait or fail; its client cannot be interrupted while it is inside the server; and a wait that depends on another request to the same server is a deadlock.

Syx therefore moves every wait out of the server. A handler either answers, or starts the work and answers at once; the client waits outside, at IPC level 0, on an OPERATION it passed with the request. The server completes it later from its own threads (a watcher loop and a few workers). This was introduced service by service (pipes, wait4, the terminal, then the filesystem), measured with a kernel inventory of every wait made inside a handler, and then enforced:

Kernel rule (ADR 0027)

A thread running a handler on behalf of another process gets KERR_INVOKE_WAIT_IN_HANDLER at once, without sleeping, from a sleep, a wait on an object, or a wait with a deadline. A poll still works. Futex waits on leaf locks, held for a few instructions, are allowed and reported. A server's own threads may wait: they hold no client.

A file read in two steps: a synchronous attempt that answers would-block after starting the fill, then an asynchronous request with an OPERATION that the server completes from its watcher when the device read ends. client (posixrt) fatfs handler fatfs watcher ide invoke: readat (synchronous form) start fill: async device read UERR_IO_WOULD_BLOCK invoke: readat_vmo_async(vmo, op) accepted, joins the fill waits on op at ipc_level 0 (kcall 110) device read done supply pages to the file's VMO; copy data into the client's VMO complete op (kcall 92) client reads the result (kcall 93)
Figure 3. A read that misses the cache (ADR 0025). The handler never waits: it starts the fill and answers. The client waits at IPC level 0, holding no invoke stack. Requests that do not need the device are served in the first step.

Invoke stacks

Even with no handler sleeping, a server can run out of invoke stacks: a client preempted at the end of its time slice inside a handler keeps its stack until it runs again. With many ready clients in a tight loop, more than sixteen can be inside one server at once.

Since ADR 0028 a pure client (a thread at IPC level 0 whose process hosts no resource and no pager) waits for a stack instead of failing, and freed stacks are handed to waiters in FIFO order, so a new request never overtakes them. The argument that this cannot deadlock is the previous rule: such a client holds nothing the holders need, and the holders are handlers that need only the CPU. Pager requests wait in the same queue. Any other invoke with no free stack still fails at once with KERR_INVOKE_NO_STACK.

VMOs and pagers

A missing page of a VMO with a pager is requested by a kernel-initiated invoke into the pager's process, on the faulting thread: a page fault in one process runs pager code in another. The pager supplies the page with a kcall, either from a buffer or, for a filesystem, directly from the VMO the device read into.

A pager that has started a device read may answer PAGER_PENDING. Its invoke stack is released at once, and the faulting thread sleeps in the kernel until the request is closed: by a supply, by an explicit failure, by a resize, a pager change, or the death of the pager's process. The request is recorded before the pager is called, so a second fault on the same page joins it instead of invoking the pager again.

Two threads fault on the same file page. The kernel records one page-in request, invokes the pager once, the pager answers pending, and both threads are woken when the page is supplied. thread A thread B kernel fatfs (pager, watcher) fault on page p record request for p pager invoke {offset, size} PAGER_PENDING, stack freed sleeps fault on p joins: no second invoke supply p (kcall 114) wake all waiters Both threads find p present and resume.
Figure 4. Pages in flight (ADR 0025, section 5). Concurrent faults on one page make one request, whatever the pager answers.

Asynchronous filesystem

The filesystem servers (fatfs, ramfs, bifs) share a library, fscore, that keeps one resizable VMO per file node as its cache, kept coherent by the write path, and a per-mount buffer cache for metadata. Device reads go through fscore; the backend maps a file block to a device block.

  • Two-step requests. Every request keeps a synchronous form that never waits in the server. Only the three requests that may need the device — read, lookup, and directory read — have an asynchronous form completed on an OPERATION.
  • Server threads. Each server has a watcher loop that completes device reads, and four workers with a bounded queue of 64 jobs for the requests that must wait for a lock or for the device. Past the bound a request is answered busy and the client retries.
  • No open-file state in the server. Requests carry their offset (readat/writeat on the node). The file position is POSIX state, kept by the POSIX layer; a description shared after fork keeps its position in a CELL.
  • Writable storage. ramfs has no fixed limits on files or sizes and may use half of RAM; FAT is read-only.

The POSIX layer

Syx is not Linux; it emulates Linux for programs linked with musl. Whatever exists only because Linux programs expect it lives in the emulation layer, never in the kernel or the native services.

  • posixrt runs inside every POSIX process. musl calls it instead of trapping, through a table of Linux i386 syscall numbers. It holds file descriptors, positions and signal state, and implements fork and execve itself; it stays in the process across both.
  • svc/posix is the POSIX server: pids, process groups and sessions, zombies and reparenting, pipes, wait4, alarm and interval timers.
  • Blocking calls such as a pipe read or wait4 return IO_PENDING from the server and complete on an OPERATION; posixrt waits with a deadline and is interruptible by a signal. select and poll use one readiness wait across pipes and terminals, with the signal mask applied atomically for pselect.
  • Faults reach posixrt and become SIGSEGV, SIGBUS or SIGFPE; a bad pointer passed to a syscall becomes EFAULT.

Time

The kernel knows only a monotonic clock with microsecond resolution (the PIT at 1000 Hz, with the current period read from the counter) and a timer queue with no fixed limit. Date and time of day belong to a user-space time service, which reads and sets the CMOS clock through a separate RTC driver and publishes the offset in a page shared with every POSIX process.

Measurement

Performance work starts from measurement. The profiler records tick samples, kernel time per entry reason (using the TSC, since the kernel runs with interrupts off), invoke time per server, and per-syscall counts and times in posixrt. A session is controlled from inside Syx and reported on the host. Run-time log levels can be set per module without rebuilding.