mikro - Introducing a C ++ Mikro Kernel mikro Low level C ++ Design - - PowerPoint PPT Presentation

mikro introducing a c mikro kernel
SMART_READER_LITE
LIVE PREVIEW

mikro - Introducing a C ++ Mikro Kernel mikro Low level C ++ Design - - PowerPoint PPT Presentation

mikro - Introducing a C ++ Mikro Kernel Victor Aperc & Julien Freche Introduction Kernel types mikro - Introducing a C ++ Mikro Kernel mikro Low level C ++ Design Victor Aperc & Julien Freche considerations Features and


slide-1
SLIDE 1

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

mikro - Introducing a C++ Mikro Kernel

Victor Apercé & Julien Freche

viaxxx@lse.epita.fr julien.freche@lse.epita.fr http://lse.epita.fr/

slide-2
SLIDE 2

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Outline I

1

Introduction

2

Kernel types Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

3

mikro

4

Low level C++

5

Design considerations

6

Features and progress Implemented features Missing features

7

Conclusion

slide-3
SLIDE 3

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Introduction

Introduction

slide-4
SLIDE 4

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

mikro id

Kernel type: micro kernel Status: experimental now but intended to be in production (if we can :D) Language: C++ Fathers: Victor Apercé, Julien Freche Birth: in early September 2013 Place of birth: LSE, near Paris, France

slide-5
SLIDE 5

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Some figures about mikro

The most active project of the LSE this year 2 repositories: kernel and User land 2 main authors and 2 contributors ~900 commits representing 5.2 commits per day ~27,000 lines

slide-6
SLIDE 6

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Kernel types

Kernel types

slide-7
SLIDE 7

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Introduction to kernel

Introduction to kernel

slide-8
SLIDE 8

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Kernel land/User land

Kernel land

Code running at a privileged level of the CPU Bugs are most of the time fatal

User land

Tasks running at a low privileged level Bugs can be recovered by Kernel land

slide-9
SLIDE 9

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Kernel

Kernel

Interface between software and hardware A part is running in Kernel land but not necessary all Core of the operating system 2 main types: monolithic and micro kernel

slide-10
SLIDE 10

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Main component of Kernel

Main components of kernel are: Paging (will be discussed in an other talk) VFS: Virtual File System Binary loader Scheduler Processor init (will be discussed in an other talk) Drivers

slide-11
SLIDE 11

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Monolithic/Micro kernel explained

Monolithic/Micro kernel explained

slide-12
SLIDE 12

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Monolithic kernel

Monolithic kernel

Almost everything privileged is in Kernel land Availability of dynamic module loading - most of the time Very big System functionality access: through system calls

slide-13
SLIDE 13

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Micro kernel

Micro kernel

The less as possible resides in Kernel land No dynamic module loading Very light Kernel components are User land processes: services System functionality access: through IPC

slide-14
SLIDE 14

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

IPC

Inter Process Communication

Communication between 2 User land processes Message passing in micro kernels Will be discussed in an other talk

slide-15
SLIDE 15

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Component location

Components Micro kernel Monolithic kernel Paging Kernel & User Kernel land VFS User Binary Loader User Scheduler Kernel or User Processor Init Kernel Drivers User

slide-16
SLIDE 16

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Examples

Monolithic kernels

Windows (hybrid :D) Darwin, MacOS X kernel (hybrid :D) Linux *BSD STOS

Micro kernels

QNX Mach L4 family, the reference

slide-17
SLIDE 17

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Monolithic/Micro kernel comparison

Monolithic/Micro kernel comparison

slide-18
SLIDE 18

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Complexity

Monolithic kernel

Very complex Hard to maintain Kernel must be reentrant

Micro kernel

Kernel land is simple User land is hard to design and complex Supposed to be easier to maintain Kernel don’t need to be reentrant

slide-19
SLIDE 19

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Security

Monolithic kernel

Kernel land is big so many possible bugs Possibility to exploit dynamic code loading in Kernel land Bugs are most of the time fatal

Micro kernel

Kernel land is simple so less possible bugs Bugs in User land are not fatal Still possible exploits in User land services Security can be mathematically proved like seL4

slide-20
SLIDE 20

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Performance

Monolithic kernel

Very fast due to system calls

Micro kernel

Slower because of IPC context switches IPC must be as fast as possible to improve performance This problem hasn’t been really solved yet

slide-21
SLIDE 21

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types

Introduction to kernel Monolithic/Micro kernel explained Monolithic/Micro kernel comparison

mikro Low level C++ Design considerations Features and progress Conclusion

Knowledge background

Monolithic kernel

First kernels Design used a lot Less fun, recipe already exists

Micro kernel

Rare design Still researches on the topic But let room to innovations!

slide-22
SLIDE 22

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

mikro

mikro

slide-23
SLIDE 23

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Why’s mikro a micro kernel?

More challenging Pretty fan of the micro kernel idea More fun because there’s no recipe

slide-24
SLIDE 24

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

What makes mikro different?

Not a L4 clone but inspired from L4 We want it to be as fast as we can IPC will be different from other micro kernel (see other talk) mikro code has been designed to be "one day" in production Developed with newer technologies:

clang is the default compiler C++ is the official language of mikro

slide-25
SLIDE 25

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Low level C++

Low level C++

slide-26
SLIDE 26

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

C- - ?

Common question:

Is it possible to code a kernel in C++ ?

Answer:

Yes, it is, but you will have to drop some features: RTTI: Run-Time Type Information STL: Standard Template Library Local static variables Global objects New and delete operators ...

slide-27
SLIDE 27

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Who am I anyway ?

RTTI

C++ mechanism that gives informations about an object’s data type at runtime. This is useful for dynamic_cast<> and typeid operators. Used when handling exceptions. Virtual functions work without RTTI (using vtables). You can port a C++ RunTime lib and an Unwind lib to restore these features.

slide-28
SLIDE 28

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Template Paradise

STL

Library that provides generic templated classes and associated algorithms. Depends on the libc No stream operators Some of the containers may be usable if extracted from the lib. You can port libstdc++, STLPort or uSTL for example to restore these features.

slide-29
SLIDE 29

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Guards, protect me !

Local static variables

These variables are declared as static inside a function and are preserved across different calls. The compiler will generate a code that will looks like:

__guard guard ; i f ( ! ( ( char∗)& guard ) [ 0 ] ) i f ( __cxa_guard_acquire (&guard ) ) { / / E f f e c t i v e v a r i a b l e i n i t __cxa_guard_release (&guard ) ; }

This code is, of course, simpler that the real generated code. You can code __cxa_guard_* to support this feature.

slide-30
SLIDE 30

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Init me

Constructor of global objects have to be called before entering the C++ entry point. You can do it with the following:

mov $ s t a r t _ c t o r s , %ebx jmp 2 f 1: c a l l ∗(%ebx ) add $4 , %ebx 2: cmp $end_ctors , %ebx jb 1b c a l l k_main

The symbols start_ctors and end_ctors are generated by the

  • compiler. You can call destructors with a similar code.
slide-31
SLIDE 31

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

No throw, please !

You will have to code new and delete operators by yourself. The usual new operator will throw an exception on error but you probably don’t want that.

void ∗ operator new ( s i z e _ t s i z e ) noexcept ; void

  • perator

d e l e t e ( void ∗p ) ;

The new operator will have to call your kernel internal allocator. Do not forget to check the return value. Do not use new in a constructor, you cannot check the return value.

slide-32
SLIDE 32

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Design considerations

Design considerations

slide-33
SLIDE 33

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Pick one

How to separate generic code from arch-specific code ? Using inheritance ? Using templates ? Using macro ?

slide-34
SLIDE 34

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Not so good..

Inheritance Parent Class: arch generic Inherited Class: arch specific Considerations: First naive idea You can change program behavior at run-time. Useless here. Overhead due to vtables and pointer manipulation. Pay attention to not compile useless code.

slide-35
SLIDE 35

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Not so bad..

Macro Macro name: arch generic Expanded name: arch specific Considerations: Less readable. You have to find the macro definition to understand. C style. Pretty powerful.

slide-36
SLIDE 36

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

First try

Templates Base template: arch generic Specialized template: arch specific Considerations: Some code has to be in the header file. Specialized templates do not receive methods from the base template. You cannot easily write an arch generic interface...

slide-37
SLIDE 37

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Hybrid

The solution implemented in mikro is hybrid and inspired by the PIMPL design pattern.

c l a s s MemoryManager { public : i n l i n e void i n i t ( ) { arch . i n i t ( ) ; } MemoryManagerImpl<ARCH_GENERIC> arch ; };

This solution is not perfect but it works and can also be used for

  • ther things like changing scheduler at compile time.
slide-38
SLIDE 38

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Features and progress

Features and progress

slide-39
SLIDE 39

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Implemented features

Implemented features

slide-40
SLIDE 40

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Awesome

Kernel: Paging SMP IPC vm86 Userland: minimal libc mikro lib vesa Bootloader: module loading ext2 support configuration file

slide-41
SLIDE 41

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Of course it works !

Tested on: qemu bochs VirtualBox Real hardware You can easily create a USB stick with mikro and test it on your hardware.

slide-42
SLIDE 42

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Missing features

Missing features

slide-43
SLIDE 43

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Not my fault

Kernel: Support x86_64 and armv7 Better scheduler Time management Improve IPC Probably a lot of bugs to fix Userland: VFS Paging daemon Process creation in userland Drivers

slide-44
SLIDE 44

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress

Implemented features Missing features

Conclusion

Let’s dream

Other features we want to add if we can: Linux compatible driver API Metadata oriented file system "datameat" port on mikro Unix program ports And much more...

slide-45
SLIDE 45

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Conclusion

Conclusion

slide-46
SLIDE 46

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Almost done

mikro highly active project very fun to code ! a good way to learn new stuff not usable yet but mainly because of the userland

slide-47
SLIDE 47

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

I want YOU!

You can contribute to the project. Main page: http://www.lse.epita.fr/projects/mikro.html Kernel repo (lse): http://git.lse.epita.fr/?p=mikro.git Kernel repo (bb): http://bitbucket.org/mikroteam/mikro Userland repo (lse): http: //git.lse.epita.fr/?p=mikro-userland.git Userland repo (bb): http: //bitbucket.org/mikroteam/mikro-userland

slide-48
SLIDE 48

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

Contacts

Julien Freche julien.freche@lse.epita.fr @JulienFreche Victor Apercé viaxxx@lse.epita.fr Mailing List: mikro@lse.epita.fr Feel free to contact us if you have any questions about the

  • project. We will be happy to answer.
slide-49
SLIDE 49

mikro - Introducing a C++ Mikro Kernel Victor Apercé & Julien Freche Introduction Kernel types mikro Low level C++ Design considerations Features and progress Conclusion

The end

Thank you for your attention