The microkernel OS Escape Nils Asmussen FOSDEM14 1 / 25 - - PowerPoint PPT Presentation

the microkernel os escape
SMART_READER_LITE
LIVE PREVIEW

The microkernel OS Escape Nils Asmussen FOSDEM14 1 / 25 - - PowerPoint PPT Presentation

Introduction Tasks Memory VFS Demo The microkernel OS Escape Nils Asmussen FOSDEM14 1 / 25 Introduction Tasks Memory VFS Demo Outline Introduction 1 Tasks 2 Memory 3 VFS 4 Demo 5 2 / 25 Introduction Tasks Memory VFS


slide-1
SLIDE 1

Introduction Tasks Memory VFS Demo

The microkernel OS Escape

Nils Asmussen FOSDEM’14

1 / 25

slide-2
SLIDE 2

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

2 / 25

slide-3
SLIDE 3

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

3 / 25

slide-4
SLIDE 4

Introduction Tasks Memory VFS Demo

Motivation

Beginning Writing an OS alone? That’s way too much work! Port of UNIX32V to ECO32 during my studies Started with Escape in October 2008 Goals Learn about operating systems and related topics Experiment: What works well and what doesn’t? What problems occur and how can they be solved?

4 / 25

slide-5
SLIDE 5

Introduction Tasks Memory VFS Demo

Overview

Basic Properties UNIX-like microkernel OS Open source, available on github.com/Nils-TUD/Escape The kernel and the GUI are written in C++, the rest in C Runs on x86, ECO32 and MMIX Besides libgcc and libsupc++, no third party components ECO32 MIPS-like, 32-bit big-endian RISC architecture, developed by Prof. Geisse for lectures and research MMIX 64-bit big-endian RISC architecture of Donald Knuth as a successor for MIX (the abstract machine from TAOCP)

5 / 25

slide-6
SLIDE 6

Introduction Tasks Memory VFS Demo

Overview

Hardware µ-kernel

Tasks Memory VFS libc libcpp libfs libgui

privileged mode user mode

vesa iso9660 ata ext2

Drivers

vterm fileman top cat ls ps

Applications

winmng uimng keyb guishell head less ... libinfo ... ...

6 / 25

slide-7
SLIDE 7

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

7 / 25

slide-8
SLIDE 8

Introduction Tasks Memory VFS Demo

Processes and Threads

Process Virtual address space File-descriptors Mountspace Threads (at least one) . . . Thread User- and kernelstack State (running, ready, blocked, . . . ) Scheduled by a round-robin scheduler with priorities Signals . . .

8 / 25

slide-9
SLIDE 9

Introduction Tasks Memory VFS Demo

Processes and Threads

Synchronization Process-local semaphores Global semaphores, named by a path to a file Userspace builds other synchronization primitives on top

“User-semaphores” as a combination of atomic operations and process-local semaphores Readers-writer-lock . . .

Priority Management Kernel adjusts thread priorites dynamically based on compute-intensity High CPU usage → downgrade, low CPU usage → upgrade

9 / 25

slide-10
SLIDE 10

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

10 / 25

slide-11
SLIDE 11

Introduction Tasks Memory VFS Demo

Memory Management

Physical Memory Most of the memory is managed by a stack for fast alloc/free

  • f single frames

A small part handled by a bitmap for contiguous phys. memory Virtual Memory Upper part is for the kernel and shared among all processes Lower part is managed by a region-based concept mmap-like interface for the userspace

11 / 25

slide-12
SLIDE 12

Introduction Tasks Memory VFS Demo

Virtual Memory Management

dynlink (text) VM (proc 1) VM (proc 2) flags=shared,exec size=16K, procs=1,2 flags=write,grow,stack size=12K, procs=2 flags=write,grow size=16K, procs=1 flags=shared,exec size=20K, procs=1,2 0x00000000 text 0xBFFFFFFF 0xA0000000 data stack1 stack2 libc.so (text) text data stack1 libc.so (text) MMIO free area layouted area free area layouted area /bin/hello /lib/libc.so dynlink (text)

12 / 25

slide-13
SLIDE 13

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

13 / 25

slide-14
SLIDE 14

Introduction Tasks Memory VFS Demo

Basics

The kernel provides the virtual file system System-calls: open, read, mkdir, mount, . . . It’s used for:

1

Provide information about the state of the system

2

Unique names for synchronization and shared memory

3

Access userspace filesystems

4

Access devices 14 / 25

slide-15
SLIDE 15

Introduction Tasks Memory VFS Demo

Drivers and Devices

Drivers are ordinary user-programs They create devices via the system-call createdev These are usually put into /dev Devices can also be used to implement on-demand-generated files (such as /system/fs/$fs) The communication with devices works via asynchronous message passing

15 / 25

slide-16
SLIDE 16

Introduction Tasks Memory VFS Demo

IPC between Client and Driver

dev foo int id = createdev("/dev/foo",...); driver

creates

16 / 25

slide-17
SLIDE 17

Introduction Tasks Memory VFS Demo

IPC between Client and Driver

dev foo int id = createdev("/dev/foo",...); driver

creates

int fd = open("/dev/foo",IO_MSGS);

points to creates inbox

client channel

  • utbox

17 / 25

slide-18
SLIDE 18

Introduction Tasks Memory VFS Demo

IPC between Client and Driver

dev foo int id = createdev("/dev/foo",...); driver

creates

int fd = open("/dev/foo",IO_MSGS);

points to creates inbox

client channel

  • utbox

msg.arg1 = 10; send(fd,MSG_BAR,&msg,sizeof(msg)); receive(fd,&mid,&msg,sizeof(msg));

18 / 25

slide-19
SLIDE 19

Introduction Tasks Memory VFS Demo

IPC between Client and Driver

dev foo int id = createdev("/dev/foo",...); driver

creates

int fd = open("/dev/foo",IO_MSGS);

points to creates inbox

client channel

  • utbox

msg.arg1 = 10; send(fd,MSG_BAR,&msg,sizeof(msg)); receive(fd,&mid,&msg,sizeof(msg));

points to

driver int fd = getwork(id,&mid,&msg,sizeof(msg),0);

19 / 25

slide-20
SLIDE 20

Introduction Tasks Memory VFS Demo

IPC between Client and Driver

dev foo int id = createdev("/dev/foo",...); driver

creates

int fd = open("/dev/foo",IO_MSGS);

points to creates inbox

client channel

  • utbox

msg.arg1 = 10; send(fd,MSG_BAR,&msg,sizeof(msg)); receive(fd,&mid,&msg,sizeof(msg));

points to

driver int fd = getwork(id,&mid,&msg,sizeof(msg),0); msg.arg1 = 1; send(fd,MSG_RESP,&msg,sizeof(msg));

20 / 25

slide-21
SLIDE 21

Introduction Tasks Memory VFS Demo

Integrating devices into the read-write-pattern

As in UNIX: Devices should be accessable like files Messages: DEV OPEN, DEV READ, DEV WRITE, DEV CLOSE Devices may support a subset of these message If using open/read/write/close, the kernel handles the communication Transparent for apps whether it is a virtual file, file in userspace fs or device

21 / 25

slide-22
SLIDE 22

Introduction Tasks Memory VFS Demo

Achieving higher throughput

Copying everything twice hurts for large amounts of data sharebuf establishes shmem between client and driver Easy to use: just call sharebuf once and use this as the buffer Clients don’t need to care whether a driver supports it or not Drivers need just react on a specific message, do an mmap and check in read/write whether the shared memory should be used

22 / 25

slide-23
SLIDE 23

Introduction Tasks Memory VFS Demo

Mounting

Concept Every process has a mountspace, that is inherited to childs clonems gives your process its own copy Mountspace is a list of (path,fs-con) pairs Kernel translates fs-system-calls into messages to fs-con

23 / 25

slide-24
SLIDE 24

Introduction Tasks Memory VFS Demo

Mounting

Concept Every process has a mountspace, that is inherited to childs clonems gives your process its own copy Mountspace is a list of (path,fs-con) pairs Kernel translates fs-system-calls into messages to fs-con Example

// assuming that an ext2 -instance has been started // to create /dev/ext2 -hda1 int fd = open("/dev/ext2 -hda1", ...); mount(fd , "/mnt/hda1");

23 / 25

slide-25
SLIDE 25

Introduction Tasks Memory VFS Demo

Outline

1

Introduction

2

Tasks

3

Memory

4

VFS

5

Demo

24 / 25

slide-26
SLIDE 26

Introduction Tasks Memory VFS Demo

The End Get the code, ISO images, etc. on: https://github.com/Nils-TUD/Escape Thanks for your attention!

25 / 25