5–7 Oct 2026
Europe/Prague timezone

Coroutines for Linux kernel

Not scheduled
30m
Networking Track Networking Track

Speaker

Marek Behún

Description

There are multiple kernel drivers which could benefit were it possible to somehow do coroutines in C. Coroutines would make these drivers easier to comprehend, extend with new code paths, and debug.

The most common use case lies in simplifying complex state machines. For example consider the main state machine sfp_sm_main() in drivers/net/phy/sfp.c. Each invocation executes code for a specific state, updates the state, and returns. The current implementation even relies on goto statements to jump between cases. As a result, understanding the control flow requires tracking disjointed code paths or drawing manual state diagrams.

Using coroutines, this logic can be transformed into a straightforward, linear sequence using standard loop and conditional structures (if, for, while). By leveraging GNU C computed gotos, we can implement mechanics similar to C++20's co_await and co_return. With some trickery, it is even possible to preserve variable values across suspension points.

Let's explore hiding this underlying complexity behind clean, maintainable macros and discuss whether this approach can be safely implemented for production code.

Author

Presentation materials

There are no materials yet.