SlideShare a Scribd company logo
Ruslan Bukin: FreeBSD/RISC-Vand Device Drivers
Personal Background
● FreeBSD arch ports (ARM, MIPS, RISC-V, x86)
● Drivers (Sound, DMA, Ethernet, MMC, …)
● DTrace support (ARMv8, RISC-V)
● HWPMC
Overview
● History
● porting process
● challenges
● status updates
● drivers support
Timeline
● start: jun 15
● printf: aug 15
● kernel works: oct 15
● userland works: dec 15
● Commit to FreeBSD svn: jan 16
● SMP: feb 16
● KDB: mar 16
● :Dtrace: apr 16
● Modules: may 16
● ISA v1.9: Jun 16
● FPU: nov 16
● ISA v1.10:
RISC-V privilege levels
● M-mode : bootloader (BBL)
● S-mode: FreeBSD kernel
● U-mode: /bin/init
● supported combination of modes
○ M
○ M, U embedded with protection
○ M, U, S
BBL
● firmware/bootloader
● M-mode
● console, timers, IPI
● All traps switch mode to M
○ can delegate traps to S-mode using mtdeleg instruction
Start of Work
● toolchain
○ GCC
○ LLVM (no support at the time)
Template
● cp -R sys/arm64 sys/riscv
● do {
● vi sys/riscv/…
● make TARGET_ARCH=riscv64
● } while ($?)
Prepare Hardware
● Emulators
○ spike
○ QEMU
● FPGA
● root disk
● emulators speed up booting and can inspect regs, single step etc
Porting: early asm code
● _start in locore.S
● put machine in known state
● initial page tables
● enable MMU and branch to virtual addressing
● setup stack pointer
● jump to c-code
Porting: kernel (1)
● console
● atomics: atomic_add(), atomic_readandclear(), …
○ need to test them well, debugging later will be painful
● Initialize physmap table
○ can hard code at first
● PMAP implementation
PMAP
● 40 functions to implement
○ pmap_enter()
○ extract
○ remove
○ invalidate
○ protect
○ activate
○ unwire
○ …
● most difficult part in the kernel
Porting kernel (2)
● Exceptions
● cpu_switch(): only changing kernel context
● fork_trampoline(): newly created user thread, kernel -> user mode change
● Kernel VA <-> user VA copy functions
○ copyin
○ copyout
○ ...
Porting kernel (3)
● Timer driver
● Interrupt controller driver
● Disk driver
● Done
Challenges #1: page table base
RISC-V only has 1 page table base register, AArch64 has 2
kernel and user space can’t each have its down
● kernel page directory
● user page directory
● Solution: merge kernel user into one user page table directory
○ takes CPU time
○ RISC-V community rejected 2 base reg proposal
Challenge #2: single Thread Pointer register
● PCPU pointer
● solution: store GP (global pointer) to supervisor stack
● Reload GP on return from user thread
Porting: userspace (1)
● jemalloc
● csu: crt1.S, crtN.S, crti.S
● libc
○ syscalls
○ setjmp, longjmp, _set_tp
● msun (libm)
Porting: userspace(2)
● Compile world
● statically linked /bin/sh
● rtld
● signals (required by e.g. csh job control)
Porting: finale
● challenging parts
● pmap in kernel
● rtld in userspace
● 6 months from scratch
● 25k line diff (200 new files)
● (thanks lots of people)
Status Update
● v1.10 of Privileged spec
● HiFive1 board release
● FreeBSD board is planned on Q1 2018
● GCC 7 target upstream
● NVIDIA wants to ship RISC-V uC
● Next workshop in San Jose
SiFive HiFive1
● TSMC 180nm
● 320+ MHZ
● 16k SRAM
VC707
● SiFive Xilinx prototype board
Privileged Arch: v1.10 changes
● Not compatible on S-mode with v1.9
○ next version “should” be compatible with v1.10 on S-mode
● Changes
○ built-in macros and compiler arguments changed
○ SBI interface, VM changes, BBL changes
○ Physical Memory Protection (PMP) Unit introduced
○ Support for FDT
Compiler Arg changes
● -mno-float, -msoft-float removed
● -march=rvimafdc -mabi=lp64
● a:; atomic
● …
Compiler Built-in defines
● __riscv ...
SBI interface changed
● old way: pre-defined function address in physical memory
● new way: ecall to upper (machine) privilege level
● required for
○ timer
○ console
○ ipi
○ shutdown
○ Hart ID
PMP unit
● R/W/Xon 4-byte granularity, 16 regions
● composable with MMU
● can be locked in M-mode
● when enabled, modes below M hae no memory permissions
Virtual Memory changes
● VM turn on/off using satp register
● supervisor can’t access user pages by default
○ syscalls: set SUM bit in sstatus reg
● R, W, X controlled separately
○ X-only pages
○ W-only pages
“C” - Compressed Extension
● saves space
● compresses some instructions to 2 bytes (like Thumb)
● comparable to microMIPS
○ space savings: 16%(RISC-V 64-bit kernel) vs 20% (MIPS 32-bit kernel)
FDT Support
● GENERIC kernel
● timer/console moved from OFW bus to nexus bus
● #./spike -dump-dts
● #./spike -m2048 -p8 /path/to/bbl
Hardware support for v1.10 privilege spec
impl status
Spike full support
RocketChip unknown
lowRISC un
QEMU un
GEM5 un
real hw N/A
Future plans
● ASIC chips and boards
● LLVM
● ports and pkgs
○ QEMU user (syscall emulation) mode
● bhyve support?
Device driver
● How to attach
● Resources
○ how to access
○ where to request
Driver Frameworks
● kld
● newbus(9)
● rman(9)
● cdevsw
● ofw and FDT
● bus_space
● bus_dma
● sysctl
● SYSINIT
SYSINIT
test_handler(mod, what, arg) {
switch (what) {
case MOD_UNLOAD:
case MOD_UNLOAD:
}
}
DECLARE_MODULE(test, SI_SUB_VM,...)
newbus(9)
● rooted tree
● device is a bus if it has children
● (root -> nexus bus -> ofwbus -> simplebus -> spi, uart0
● -> RISC-V console)
newbus methods
● methods: probe, attach
● DRIVER_MODULE(test, simplebus, methods)
Resources
● Device tree sources (DTS)
● bus_alloc_resources
● bus_setup_intr(dev, intr_func, …)
cdevsw
● char device
● open, read, ioctl, mmap, poll
● fd = open(“/dev/test”, …)
Frameworks / subsystems
● SPI, I2C, xdma, ifnet, callout, pci, sound(9), wifi, vt(4), taskqueue(9)
Self Made FreeBSD/MIPS board
● (custom designed board)
● 27 capacitors
● 1 resistor
● 1 pin header
● 1 xtal
● 1 MIPS CPU (from PIC)
● 2 layer PCB
● 2MB flash (1.7 MB used for FreeBSD)
Q&A
● How do you test your atomics implementations? A: didn’t test. lost time
● Schematics for MIPS board? A: designed using Windows tools. Only took two hours
● Any driver challenges? A: lots, spent 6 months, worked hard.
● Did single page table cause rework of core kernel code? A: only machine dependent parts
○ PTE has bits for supervisor and userspace access
● Challenge of rtld? A: I don’t remember. I remember it was difficult.

More Related Content

What's hot

BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2 BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2
Linaro
 
Unix Ramblings
Unix RamblingsUnix Ramblings
Unix Ramblings
Bill Miller
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
Lightweight Virtualization: LXC Best Practices
Lightweight Virtualization: LXC Best PracticesLightweight Virtualization: LXC Best Practices
Lightweight Virtualization: LXC Best PracticesWerner Fischer
 
BUD17-310: Introducing LLDB for linux on Arm and AArch64
BUD17-310: Introducing LLDB for linux on Arm and AArch64 BUD17-310: Introducing LLDB for linux on Arm and AArch64
BUD17-310: Introducing LLDB for linux on Arm and AArch64
Linaro
 
BKK16-304 The State of GDB on AArch64
BKK16-304 The State of GDB on AArch64BKK16-304 The State of GDB on AArch64
BKK16-304 The State of GDB on AArch64
Linaro
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!
Linaro
 
Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USB
Samsung Open Source Group
 
LAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVALAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVA
Linaro
 
BUD17-300: Journey of a packet
BUD17-300: Journey of a packetBUD17-300: Journey of a packet
BUD17-300: Journey of a packet
Linaro
 
BKK16-402 Cross distro BoF
BKK16-402 Cross distro BoFBKK16-402 Cross distro BoF
BKK16-402 Cross distro BoF
Linaro
 
BUD17-214: Bus scaling QoS update
BUD17-214: Bus scaling QoS update BUD17-214: Bus scaling QoS update
BUD17-214: Bus scaling QoS update
Linaro
 
BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101 BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101
Linaro
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrency
Viller Hsiao
 
Terminals and Shells
Terminals and ShellsTerminals and Shells
Terminals and Shells
Hoffman Lab
 
LAS16-405:OpenDataPlane: Software Defined Dataplane leader
LAS16-405:OpenDataPlane: Software Defined Dataplane leaderLAS16-405:OpenDataPlane: Software Defined Dataplane leader
LAS16-405:OpenDataPlane: Software Defined Dataplane leader
Linaro
 
OVN DBs HA with scale test
OVN DBs HA with scale testOVN DBs HA with scale test
OVN DBs HA with scale test
Aliasgar Ginwala
 
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
PROIDEA
 
BKK16-403 Android HAL Consolidation Status
BKK16-403 Android HAL Consolidation StatusBKK16-403 Android HAL Consolidation Status
BKK16-403 Android HAL Consolidation Status
Linaro
 
Emx Dev Boards - EmxARM9A03 - Overview
Emx Dev Boards - EmxARM9A03 - OverviewEmx Dev Boards - EmxARM9A03 - Overview
Emx Dev Boards - EmxARM9A03 - Overview
Emertxe Information Technologies Pvt Ltd
 

What's hot (20)

BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2 BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2
 
Unix Ramblings
Unix RamblingsUnix Ramblings
Unix Ramblings
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
 
Lightweight Virtualization: LXC Best Practices
Lightweight Virtualization: LXC Best PracticesLightweight Virtualization: LXC Best Practices
Lightweight Virtualization: LXC Best Practices
 
BUD17-310: Introducing LLDB for linux on Arm and AArch64
BUD17-310: Introducing LLDB for linux on Arm and AArch64 BUD17-310: Introducing LLDB for linux on Arm and AArch64
BUD17-310: Introducing LLDB for linux on Arm and AArch64
 
BKK16-304 The State of GDB on AArch64
BKK16-304 The State of GDB on AArch64BKK16-304 The State of GDB on AArch64
BKK16-304 The State of GDB on AArch64
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!
 
Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USB
 
LAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVALAS16-507: LXC support in LAVA
LAS16-507: LXC support in LAVA
 
BUD17-300: Journey of a packet
BUD17-300: Journey of a packetBUD17-300: Journey of a packet
BUD17-300: Journey of a packet
 
BKK16-402 Cross distro BoF
BKK16-402 Cross distro BoFBKK16-402 Cross distro BoF
BKK16-402 Cross distro BoF
 
BUD17-214: Bus scaling QoS update
BUD17-214: Bus scaling QoS update BUD17-214: Bus scaling QoS update
BUD17-214: Bus scaling QoS update
 
BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101 BUD17-TR02: Upstreaming 101
BUD17-TR02: Upstreaming 101
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrency
 
Terminals and Shells
Terminals and ShellsTerminals and Shells
Terminals and Shells
 
LAS16-405:OpenDataPlane: Software Defined Dataplane leader
LAS16-405:OpenDataPlane: Software Defined Dataplane leaderLAS16-405:OpenDataPlane: Software Defined Dataplane leader
LAS16-405:OpenDataPlane: Software Defined Dataplane leader
 
OVN DBs HA with scale test
OVN DBs HA with scale testOVN DBs HA with scale test
OVN DBs HA with scale test
 
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
CONFidence 2017: Escaping the (sand)box: The promises and pitfalls of modern ...
 
BKK16-403 Android HAL Consolidation Status
BKK16-403 Android HAL Consolidation StatusBKK16-403 Android HAL Consolidation Status
BKK16-403 Android HAL Consolidation Status
 
Emx Dev Boards - EmxARM9A03 - Overview
Emx Dev Boards - EmxARM9A03 - OverviewEmx Dev Boards - EmxARM9A03 - Overview
Emx Dev Boards - EmxARM9A03 - Overview
 

Similar to Bsdtw17: ruslan bukin: free bsd/risc-v and device drivers

SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016
Koan-Sin Tan
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
GlobalLogic Ukraine
 
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
eurobsdcon
 
HKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case studyHKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case study
Linaro
 
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
Scott Tsai
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
Emertxe Information Technologies Pvt Ltd
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation GuideBKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
Linaro
 
µCLinux on Pluto 6 Project presentation
µCLinux on Pluto 6 Project presentationµCLinux on Pluto 6 Project presentation
µCLinux on Pluto 6 Project presentation
edlangley
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
Linaro
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Yandex
 
MOVED: The challenge of SVE in QEMU - SFO17-103
MOVED: The challenge of SVE in QEMU - SFO17-103MOVED: The challenge of SVE in QEMU - SFO17-103
MOVED: The challenge of SVE in QEMU - SFO17-103
Linaro
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
FromDual GmbH
 
Time to rethink /proc
Time to rethink /procTime to rethink /proc
Time to rethink /proc
Kir Kolyshkin
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
AnastasiaStulova
 
LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205
Linaro
 
UKUUG presentation about µCLinux on Pluto 6
UKUUG presentation about µCLinux on Pluto 6UKUUG presentation about µCLinux on Pluto 6
UKUUG presentation about µCLinux on Pluto 6
edlangley
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
dotCloud
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Docker, Inc.
 
Speeding up ps and top
Speeding up ps and topSpeeding up ps and top
Speeding up ps and top
OpenVZ
 
Speeding up ps and top
Speeding up ps and topSpeeding up ps and top
Speeding up ps and top
Kirill Kolyshkin
 

Similar to Bsdtw17: ruslan bukin: free bsd/risc-v and device drivers (20)

SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
 
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...Smartcom's control plane software, a customized version of FreeBSD by Boris A...
Smartcom's control plane software, a customized version of FreeBSD by Boris A...
 
HKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case studyHKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case study
 
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
Bsdtw17: johannes m dieterich: high performance computing and gpu acceleratio...
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation GuideBKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
 
µCLinux on Pluto 6 Project presentation
µCLinux on Pluto 6 Project presentationµCLinux on Pluto 6 Project presentation
µCLinux on Pluto 6 Project presentation
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
 
MOVED: The challenge of SVE in QEMU - SFO17-103
MOVED: The challenge of SVE in QEMU - SFO17-103MOVED: The challenge of SVE in QEMU - SFO17-103
MOVED: The challenge of SVE in QEMU - SFO17-103
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Time to rethink /proc
Time to rethink /procTime to rethink /proc
Time to rethink /proc
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
 
LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205
 
UKUUG presentation about µCLinux on Pluto 6
UKUUG presentation about µCLinux on Pluto 6UKUUG presentation about µCLinux on Pluto 6
UKUUG presentation about µCLinux on Pluto 6
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
 
Speeding up ps and top
Speeding up ps and topSpeeding up ps and top
Speeding up ps and top
 
Speeding up ps and top
Speeding up ps and topSpeeding up ps and top
Speeding up ps and top
 

More from Scott Tsai

Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?
Scott Tsai
 
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
Scott Tsai
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Scott Tsai
 
Bsdtw17: allan jude: zfs: advanced integration
Bsdtw17: allan jude: zfs: advanced integrationBsdtw17: allan jude: zfs: advanced integration
Bsdtw17: allan jude: zfs: advanced integration
Scott Tsai
 
Bsdtw17: theo de raadt: mitigations and other real security features
Bsdtw17: theo de raadt: mitigations and other real security featuresBsdtw17: theo de raadt: mitigations and other real security features
Bsdtw17: theo de raadt: mitigations and other real security features
Scott Tsai
 
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicumBsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Scott Tsai
 
Bsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessionsBsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessions
Scott Tsai
 

More from Scott Tsai (7)

Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?Bsdtw17: brooks davis: is it time to replace mmap?
Bsdtw17: brooks davis: is it time to replace mmap?
 
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
Bsdtw17: arun thomas: risc v berkeley hardware for your berkeley software dis...
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
 
Bsdtw17: allan jude: zfs: advanced integration
Bsdtw17: allan jude: zfs: advanced integrationBsdtw17: allan jude: zfs: advanced integration
Bsdtw17: allan jude: zfs: advanced integration
 
Bsdtw17: theo de raadt: mitigations and other real security features
Bsdtw17: theo de raadt: mitigations and other real security featuresBsdtw17: theo de raadt: mitigations and other real security features
Bsdtw17: theo de raadt: mitigations and other real security features
 
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicumBsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
Bsdtw17: mariusz zaborski: case studies of sandboxing base system with capsicum
 
Bsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessionsBsdtw17: lightning talks/wip sessions
Bsdtw17: lightning talks/wip sessions
 

Recently uploaded

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 

Bsdtw17: ruslan bukin: free bsd/risc-v and device drivers

  • 1. Ruslan Bukin: FreeBSD/RISC-Vand Device Drivers Personal Background ● FreeBSD arch ports (ARM, MIPS, RISC-V, x86) ● Drivers (Sound, DMA, Ethernet, MMC, …) ● DTrace support (ARMv8, RISC-V) ● HWPMC Overview ● History ● porting process ● challenges ● status updates ● drivers support Timeline ● start: jun 15 ● printf: aug 15 ● kernel works: oct 15 ● userland works: dec 15 ● Commit to FreeBSD svn: jan 16 ● SMP: feb 16 ● KDB: mar 16 ● :Dtrace: apr 16 ● Modules: may 16 ● ISA v1.9: Jun 16 ● FPU: nov 16 ● ISA v1.10: RISC-V privilege levels ● M-mode : bootloader (BBL) ● S-mode: FreeBSD kernel ● U-mode: /bin/init ● supported combination of modes ○ M ○ M, U embedded with protection ○ M, U, S BBL ● firmware/bootloader ● M-mode ● console, timers, IPI ● All traps switch mode to M ○ can delegate traps to S-mode using mtdeleg instruction Start of Work ● toolchain ○ GCC ○ LLVM (no support at the time) Template ● cp -R sys/arm64 sys/riscv ● do { ● vi sys/riscv/… ● make TARGET_ARCH=riscv64 ● } while ($?) Prepare Hardware ● Emulators
  • 2. ○ spike ○ QEMU ● FPGA ● root disk ● emulators speed up booting and can inspect regs, single step etc Porting: early asm code ● _start in locore.S ● put machine in known state ● initial page tables ● enable MMU and branch to virtual addressing ● setup stack pointer ● jump to c-code Porting: kernel (1) ● console ● atomics: atomic_add(), atomic_readandclear(), … ○ need to test them well, debugging later will be painful ● Initialize physmap table ○ can hard code at first ● PMAP implementation PMAP ● 40 functions to implement ○ pmap_enter() ○ extract ○ remove ○ invalidate ○ protect ○ activate ○ unwire ○ … ● most difficult part in the kernel Porting kernel (2) ● Exceptions ● cpu_switch(): only changing kernel context ● fork_trampoline(): newly created user thread, kernel -> user mode change ● Kernel VA <-> user VA copy functions ○ copyin ○ copyout ○ ... Porting kernel (3) ● Timer driver ● Interrupt controller driver ● Disk driver ● Done Challenges #1: page table base RISC-V only has 1 page table base register, AArch64 has 2 kernel and user space can’t each have its down ● kernel page directory ● user page directory ● Solution: merge kernel user into one user page table directory ○ takes CPU time ○ RISC-V community rejected 2 base reg proposal Challenge #2: single Thread Pointer register ● PCPU pointer ● solution: store GP (global pointer) to supervisor stack
  • 3. ● Reload GP on return from user thread Porting: userspace (1) ● jemalloc ● csu: crt1.S, crtN.S, crti.S ● libc ○ syscalls ○ setjmp, longjmp, _set_tp ● msun (libm) Porting: userspace(2) ● Compile world ● statically linked /bin/sh ● rtld ● signals (required by e.g. csh job control) Porting: finale ● challenging parts ● pmap in kernel ● rtld in userspace ● 6 months from scratch ● 25k line diff (200 new files) ● (thanks lots of people) Status Update ● v1.10 of Privileged spec ● HiFive1 board release ● FreeBSD board is planned on Q1 2018 ● GCC 7 target upstream ● NVIDIA wants to ship RISC-V uC ● Next workshop in San Jose SiFive HiFive1 ● TSMC 180nm ● 320+ MHZ ● 16k SRAM VC707 ● SiFive Xilinx prototype board Privileged Arch: v1.10 changes ● Not compatible on S-mode with v1.9 ○ next version “should” be compatible with v1.10 on S-mode ● Changes ○ built-in macros and compiler arguments changed ○ SBI interface, VM changes, BBL changes ○ Physical Memory Protection (PMP) Unit introduced ○ Support for FDT Compiler Arg changes ● -mno-float, -msoft-float removed ● -march=rvimafdc -mabi=lp64 ● a:; atomic ● … Compiler Built-in defines ● __riscv ... SBI interface changed ● old way: pre-defined function address in physical memory ● new way: ecall to upper (machine) privilege level ● required for ○ timer ○ console
  • 4. ○ ipi ○ shutdown ○ Hart ID PMP unit ● R/W/Xon 4-byte granularity, 16 regions ● composable with MMU ● can be locked in M-mode ● when enabled, modes below M hae no memory permissions Virtual Memory changes ● VM turn on/off using satp register ● supervisor can’t access user pages by default ○ syscalls: set SUM bit in sstatus reg ● R, W, X controlled separately ○ X-only pages ○ W-only pages “C” - Compressed Extension ● saves space ● compresses some instructions to 2 bytes (like Thumb) ● comparable to microMIPS ○ space savings: 16%(RISC-V 64-bit kernel) vs 20% (MIPS 32-bit kernel) FDT Support ● GENERIC kernel ● timer/console moved from OFW bus to nexus bus ● #./spike -dump-dts ● #./spike -m2048 -p8 /path/to/bbl Hardware support for v1.10 privilege spec impl status Spike full support RocketChip unknown lowRISC un QEMU un GEM5 un real hw N/A Future plans ● ASIC chips and boards ● LLVM ● ports and pkgs ○ QEMU user (syscall emulation) mode ● bhyve support? Device driver ● How to attach ● Resources ○ how to access ○ where to request Driver Frameworks ● kld ● newbus(9) ● rman(9) ● cdevsw ● ofw and FDT ● bus_space ● bus_dma ● sysctl ● SYSINIT
  • 5. SYSINIT test_handler(mod, what, arg) { switch (what) { case MOD_UNLOAD: case MOD_UNLOAD: } } DECLARE_MODULE(test, SI_SUB_VM,...) newbus(9) ● rooted tree ● device is a bus if it has children ● (root -> nexus bus -> ofwbus -> simplebus -> spi, uart0 ● -> RISC-V console) newbus methods ● methods: probe, attach ● DRIVER_MODULE(test, simplebus, methods) Resources ● Device tree sources (DTS) ● bus_alloc_resources ● bus_setup_intr(dev, intr_func, …) cdevsw ● char device ● open, read, ioctl, mmap, poll ● fd = open(“/dev/test”, …) Frameworks / subsystems ● SPI, I2C, xdma, ifnet, callout, pci, sound(9), wifi, vt(4), taskqueue(9) Self Made FreeBSD/MIPS board ● (custom designed board) ● 27 capacitors ● 1 resistor ● 1 pin header ● 1 xtal ● 1 MIPS CPU (from PIC) ● 2 layer PCB ● 2MB flash (1.7 MB used for FreeBSD) Q&A ● How do you test your atomics implementations? A: didn’t test. lost time ● Schematics for MIPS board? A: designed using Windows tools. Only took two hours ● Any driver challenges? A: lots, spent 6 months, worked hard. ● Did single page table cause rework of core kernel code? A: only machine dependent parts ○ PTE has bits for supervisor and userspace access ● Challenge of rtld? A: I don’t remember. I remember it was difficult.