Mettā

decentralized internets

1 of 4

Event kernels

This post came to be as part of my LLM-assisted research, text here is wholly generated by Fable 5.1 model. All such posts are tagged with llm-gen so you can easily spot them. The summary is quite educational however, so I decided to publish it.

Distinction between process and event kernels

  • Process kernel: every user thread has its own kernel stack. When a thread traps into the kernel (syscall, page fault, interrupt), the kernel runs "on behalf of" that thread, on that thread's kernel stack. If the kernel needs to wait for something (disk I/O, a lock), it can just block mid-syscall β€” the thread's kernel state lives on its stack, and the scheduler switches to another thread's kernel stack. Linux, Windows, the BSDs, and Fuchsia all work this way.
  • Event (interrupt) kernel: there's one kernel stack per CPU, period. Every trap is treated as an event: the kernel runs a handler from start to finish, updates data structures, picks a thread to resume, and unwinds the stack back to empty. The kernel never blocks. If a thread needs to wait, the kernel marks it as waiting in a thread control block and returns β€” nothing about the operation is "kept on a stack". seL4, early L4 variants, and many RTOS kernels work this way.
Process kernelEvent (interrupt) kernel
MemoryA kernel stack per thread
(Linux: 16 KB each)
One stack per CPU β€” tiny
Kernel codeNatural, sequential; can block anywhereEvery wait must be a explicit state machine
Preemption in kernelEasy β€” just switch stacksHard; typically kernel runs to completion with interrupts off
LatencyLong syscalls can be preemptedKernel paths must be short and bounded
Verification / reasoningMany interleaved kernel stacks = hard to reason aboutKernel is atomic, run-to-completion: much easier to prove correct
(this is why seL4 chose it)
Cache/TLB behaviourStack switching pollutes cachesVery cache-friendly
  • a process kernel makes the kernel code easy to write at the cost of more memory and more complex concurrency inside the kernel;
  • an event kernel makes the kernel small, fast, and formally tractable at the cost of forcing every long operation to be written as an explicit continuation β€” which is why event kernels are almost always microkernels that push the "long" work (drivers, filesystems) out to user space.
Read more

Treacherous Metaphors

The most treacherous metaphors are the ones that seem to work for a time, because they can keep more powerful insights from bubbling up.

Alan Kay, 1984

related video

Learning JTAG

To understand how JTAG works I recommend a series of articles by Aliaksandr Kavalchuk. He describes details of the protocol and accompanies the text with amazing illustrations. Check it out:

Also, there are a few articles from other authors, describing JTAG in a more practical way:

Half-knowledge

Half-knowledge is very communicable; not so knowledge.

Mary Coleridge

OSdev tooling finished

January through May I was on and off on the project, fixing chainofcommand to work with the chain loading, in particular fighting the UNIX console and the TTY operations. Now the entire thing works, finished and merged into the main development branch. After that I started prodding the MMU setup and DTB (DeviceTree) parsing.

Read more

OSdev tooling continued

This month I spent honing the tooling story. Partially it was driven by the desire to Rewrite All the Things in Rust, and partially by my attempt to integrate all the tooling in a convenient for me way to do things.

Along the way I've done some refactoring and added support for Raspberry Pi 4-specific code.

Read more

OSdev tooling

Since my first attempt at OSdev in x86 assembly I've constantly strived to make my setup comfortable. With rust I finally achieved a nearly zero-configuration flow. There are still some tools to install but they are either a cargo install just away or entirely optional.

Developing an OS in Rust gives an opportunity to apply the benefits of the entire Rust ecosystem, so I've decided to maximally utilise what it has to offer.

Read more

Complex Systems

A simple system may or may not work. A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system.

John Gall's Systemantics

Rust on Sipeed Longan Nano board

My Longan Nano board has arrived and I tried to run Rust on it. It's a great success and here's how.

Nano is a RISC-V microcontroller (GD32VF103) with impressive GPIO capabilities and connectivity - it has a serial, JTAG and USB Type-C ports plus numerous GPIO pins on breakout connectors. It is also very well documented: there are board schematics, CPU and Peripheral datasheets, and numerous programming examples.

Read more
1 of 4