L e s s
- n
s L e a r n e d f r
- m
P
- r
t i n g H e l e n O S t
- R
I S C
- V
Martjn Děcký martjn@decky.cz
February 2019
L e s s o n s L e a r n e d f r o m P o r t i - - PowerPoint PPT Presentation
L e s s o n s L e a r n e d f r o m P o r t i n g H e l e n O S t o R I S C - V Martjn Dck martjn@decky.cz February 2019 Who Am I Passionate programmer and operatjng systems enthusiast With a specifjc
February 2019
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 2
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 4
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 5
Custom microkernel Custom user space htup://www.helenos.org
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 6
3-clause BSD permissive license htups://github.com/HelenOS
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 7
Breath-fjrst rather than depth-fjrst Potentjally targetjng server, desktop and embedded
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 8
IA-32 (x86), AMD64 (x86-64), IA-64 (Itaninum), ARM, MIPS, PowerPC, SPARCv9 (UltraSPARC)
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 9
Fine-grained modular component architecture No monolithic components even in user space
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 10
Architecture based on a set of guiding design principles Asynchronous bi-directjonal IPC with rich semantjcs
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 12
“Extremely well-commented source code” (Open Hub)
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 13
High-quality architecture High-quality implementatjon Verifjcatjon
Development process
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 15
architecture independent shared architecture dependent architecture dependent
bootstrap routines CPU mgmt atomics & barriers I/O mgmt platform memory mgmt platform drivers debugging support context switching interrupt handling platform library routines shared platform drivers shared debugging support hierarchical page table support global page hash table support
hardware abstraction layer
kernel unit tests memory backends memory zones mgmt frame allocator slab allocator address space mgmt memory reservation spinlocks wait queues work queues interrupt & syscall dispatch thread scheduler thread & task mgmt kernel lifecycle mgmt lists, trees, bitmaps concurrent hash table generic resource allocator ELF loader string routines misc routines kernel debug console IPC kernel log hardware resource mgmt system information cycle & time mgmt tracing support read- copy- update capabilities cache coherency synchro- nization interface
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 16
device manager device drivers client session vterm bdsh vfs fjle system drivers FAT exFAT ext4 ISO 9660 UDF MINIX FS TMPFS Location FS kernel naming service loader task monitor klog location service logger init transport layer protocols tcp udp link layer protocols loopip ethip slip inetsrv networking management dnsrsrv dhcp nconfsrv human interface clipboard audio
input console compositor remote console remote framebufger
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 17
Privileged ISA Specifjcatjon version 1.7, toolchain support not upstreamed yet Targetjng Spike 18 hours net development tjme
Many things besides the ISA itself were not nicely documented (e.g. ABI, HTIF) and had to be reverse-engineered from Spike Even some ISA details were sketchy (memory consistency model) Generally speaking, the ISA itself looked nice (except the compressed page protectjon fjeld)
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 18
Some minor improvements (e.g. more standard page protectjon bits)
Observatjon: The HTIF input device has a horrible design
– No interrupts – Polling requests are bufgered
Stjll no decent “reference platgorm”
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 20
Looks more reasonable than Spike CLINT, PLIC, NS16550 UART, VirtIO
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 21
A Raspberry Pi (USB, ethernet, HDMI, sound), but with a RISC-V CPU supportjng the Supervisor mode
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 22
Isolatjon of unprivileged processes, inter-process communicatjon, hierarchical control
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 23
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 24
client VFS tmpfs
naming service
naming service
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 25
26 Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 27
Passing arguments in registers and on the stack Passing direct pointers to memory structures
Passing arguments in a subset of registers Privilege level switch, address space switch Scheduling (in case of asynchronous IPC) Data copying or memory sharing with page granularity
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 28
Communicatjng partjes identjfjed by a “call gate” (capability) containing the target address space and the PC of the IPC handler (implicit for return)
Call gates stored in a TLB-like hardware cache (CLB) CLB populated by the microkernel similarly to TLB-only memory management architecture
Async Jump/Call, Async Return and Async Receive instructjons Using the CPU cache like an extended register stack engine
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 29
Much fjner granularity than pages (typically 64 to 128 bytes) A separate virtual-to-cache mapping mechanism before the standard virtual-to-physical mapping
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 30
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 31
Again, similar mechanism to TLB-only memory management Dedicated instructjons for context store, context restore, context switch, context save, context load
Context data could be potentjally ABI-optjmized
Autonomous mechanism for event-triggered context switch (e.g. external interrupt) Effjcient hardware mechanism for latency hiding
The equivalent of fjne/coarse-grained simultaneous multjthreading
The sofuware scheduler is in charge of settjng the scheduler policy The CPU is in charge of scheduling the contexts based on ALU, cache and other resource availability
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 32
Effjcient delivery of interrupt events to user space device drivers
Without the routjne microkernel interventjon
An interrupt could be directly handled by a preconfjgured hardware context in user space
A clear path towards moving even the tjmer interrupt handler and the scheduler from kernel space to user space Going back to interrupt-driven handling of peripherals with extreme low latency requirements (instead of polling)
The usual pain point: Level-triggered interrupts
Some coordinatjon with the platgorm interrupt controller is probably needed to automatjcally mask the interrupt source
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 33
RV128 could provide 64 bits for the capability reference and 64 bits for object
128-bit fmat pointers are probably useless anyway
Simplifying the implementatjon of managed languages’ VMs Working with multjple virtual address spaces at once
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 34
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 35
Useful for data-centric applicatjons for sharing large amounts of memory between processes
The primary reason for removal was not performance, but portability
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 36
Switching the EPT and passing register arguments Current implementatjon limited to 512 entry points Practjcally usable even for very fjne-grained virtualizatjon with the granularity of individual functjons
Liu Y., Zhou T., Chen K., Chen H., Xia Y.: Thwartjng Memory Disclosure with Effjcient Hypervisor-enforced Intra-domain Isolatjon, 22nd ACM SIGSAC Conference on Computer and Communicatjons Security, 2015
– “The cost of a VMFUNC is similar with a syscall” – “… hypervisor-level protectjon at the cost of system calls”
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 37
Hardware-based capability model for byte-granularity memory protectjon Extension of the 64-bit MIPS ISA
Evaluated on an extended MIPS R4000 FPGA sofu-core 32 capability registers (256 bits)
Limitatjon: Infmexible design mostly due to the tjght backward compatjbility with a 64-bit ISA
Several design and implementatjon issues, deemed not productjon-ready
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 38
This prevented them from replacing monolithic operatjng systems and closed the vicious cycle
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 39
Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V 40
Basic research Applied research Prototype development Collaboratjon with academia and other technology companies
Previous microkernel experience is a big plus “A startup within a large company” Shaping the future product portgolio of Huawei
Including hardware/sofuware co-design via HiSilicon
41 Martjn Děcký, FOSDEM, February 2nd 2019 Lessons Learned from Portjng HelenOS to RISC-V