WINGERT A Thread Migrating OS for Real-Time Applications Alexander - - PowerPoint PPT Presentation

wingert a thread migrating os for real time applications
SMART_READER_LITE
LIVE PREVIEW

WINGERT A Thread Migrating OS for Real-Time Applications Alexander - - PowerPoint PPT Presentation

WAMOS @ HSRM Wiesbaden 2014-02-13 A. Zuepke WINGERT A Thread Migrating OS for Real-Time Applications Alexander Zpke alexander.zuepke@hs-rm.de About Me WAMOS @ HSRM Wiesbaden 2014-02-13 A. Zuepke Alexander Zpke 1999 2003:


slide-1
SLIDE 1

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

WINGERT A Thread Migrating OS for Real-Time Applications

Alexander Züpke

alexander.zuepke@hs-rm.de

slide-2
SLIDE 2

2

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

About Me

Alexander Züpke 1999 – 2003: Diploma in Computer Engineering

University of Applied Sciences Gelsenkirchen

2003 – now: Kernel Hacker on PikeOS

SYSGO AG, Klein-Winternheim

2012 – now: PhD Student

RheinMain University of Applied Sciences Wiesbaden

slide-3
SLIDE 3

3

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Wingert

Win·gert m., Pl: Win·ger·te

German word in Rhine-Hessian dialect for a vineyard

derived from the Middle High German word wîngarte (wine garden)

slide-4
SLIDE 4

4

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Wingert OS

WIesbaden Next Generation Experimental Real-Time Operating System

… or: WINGERT Is a New Great Experimental Real-Time Operating System

slide-5
SLIDE 5

5

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Outline

  • Motivation
  • System Architecture
  • Various Use Cases of Thread Migration
  • Resource Management
  • Futexes and Locking
  • Current Status of the Implementation
  • Conclusion
  • Outlook
slide-6
SLIDE 6

6

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Motivation

Safety Critical Systems …

slide-7
SLIDE 7

7

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke
slide-8
SLIDE 8

8

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke
slide-9
SLIDE 9

9

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Motivation

Safety requirements for shared resources

  • IEC 61508

“An E/E/PE* safety-related system will usually implement more than one safety function. If the safety integrity requirements for these safety functions differ, unless there is sufficient independence of implementation between them, the requirements applicable to the highest relevant safety integrity level shall apply to the entire E/E/PE safety-related system.”

  • ISO 26262

“Freedom of interference”

* E/E/PE: electrical / electronic / programmable electronic

slide-10
SLIDE 10

10

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Motivation

Mixed-criticality system Separation by Partitioning ARINC 653:

– Spatial Partitioning – Time Partitioning

OS Kernel P3 less critical

user mode supervisor mode

P1 most critical P2 critical P4 least critical

slide-11
SLIDE 11

11

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Own Experience: Micro kernels are nice, but building reliable systems with them is still too painful! Lots of engineering challenges:

– bounded WCET when Linux runs on top? – independent analyses of partitions? – more threads + more synchronization = more safety?

Motivation

slide-12
SLIDE 12

12

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

System Architecture

  • Design Choices

– Hierarchical system design – Small TCB – Minimalistic kernel

  • Address spaces
  • Threads
  • Capabilities
  • Resource partitioning
  • Preemptive kernel
  • State of the art scheduling

– Thread migration

shared driver 1 P3 less critical P1 most critical P2 critical P4 least critical OS Kernel shared driver 2

slide-13
SLIDE 13

13

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

slide-14
SLIDE 14

14

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

  • Definition of “thread migration” in literature

– a client lends its thread to the server – the server is a passive entity

  • Examples

– Mach (Ford) – Sun's Spring – Pebble – Composite – …

P3 P1 P2 P4 OS Kernel

slide-15
SLIDE 15

15

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Decompose a thread into Body and Soul:

  • Body: user part of a thread

– register context – user stack

  • Soul: kernel part of a thread

– scheduling attributes – kernel stack

Ghost: soul without a body

initial state idle threads

Body

  • Entry point
  • User Stack
  • TLS

Soul

  • Priority
  • Deadline
  • Kernel Stack
slide-16
SLIDE 16

16

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Decompose a thread into Body and Soul:

  • Body: user part of a thread

– register context – user stack

  • Soul: kernel part of a thread

– scheduling attributes – kernel stack

  • Ghost: soul without a body

– initial state – idle threads Body

  • Entry point
  • User Stack
  • TLS

Soul

  • Priority
  • Deadline
  • Kernel Stack
slide-17
SLIDE 17

17

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Synchronous call and return operations:

– a soul migrates back and forth between bodies – forms a call chain

active body free body soul

slide-18
SLIDE 18

18

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Synchronous call and return operations:

– a soul migrates back and forth between bodies – forms a call chain

active body free body

  • ccupied body

soul call

slide-19
SLIDE 19

19

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Synchronous call and return operations:

– a soul migrates back and forth between bodies – forms a call chain

active body

  • ccupied body

call

slide-20
SLIDE 20

20

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Synchronous call and return operations:

– a soul migrates back and forth between bodies – forms a call chain

  • ccupied body

return free body active body

slide-21
SLIDE 21

21

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Synchronous call and return operations:

– a soul migrates back and forth between bodies – forms a call chain

return free body active body

slide-22
SLIDE 22

22

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

The forward operation:

– to call another body – without keeping the caller occupied

slide-23
SLIDE 23

23

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

The forward operation:

– to call another body – without keeping the caller occupied

c a l l

slide-24
SLIDE 24

24

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

The forward operation:

– to call another body – without keeping the caller occupied

forward

slide-25
SLIDE 25

25

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

The forward operation:

– to call another body – without keeping the caller occupied

slide-26
SLIDE 26

26

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

The forward operation:

– to call another body – without keeping the caller occupied

return

slide-27
SLIDE 27

27

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Asynchronous fork / join operations:

– fork: tell an idle soul to call a body – join: asynchronous call returns

fork go for It!

slide-28
SLIDE 28

28

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Asynchronous fork / join operations:

– fork: tell an idle soul to call a body – join: asynchronous call returns

call

slide-29
SLIDE 29

29

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Asynchronous fork / join operations:

– fork: tell an idle soul to call a body – join: asynchronous call returns

slide-30
SLIDE 30

30

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Asynchronous fork / join operations:

– fork: tell an idle soul to call a body – join: asynchronous call returns

return

slide-31
SLIDE 31

31

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Asynchronous fork / join operations:

– fork: tell an idle soul to call a body – join: asynchronous call returns

join I'm done!

slide-32
SLIDE 32

32

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Signals and Exception Handling:

  • Exceptions

– implicitly turn exceptions into calls to exception-handlers – pass faulting register context to called body

Signals

signal delivery: force a soul into a (non-voluntary) call software raised exception

call Exception Handler Faulter

slide-33
SLIDE 33

33

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thread Migration

Signals and Exception Handling:

  • Exceptions

– implicitly turn exceptions into calls to exception-handlers – pass faulting register context to called body

  • Signals

– signal delivery: force a soul

into a (non-voluntary) call

– software raised exception

call Exception Handler Faulter Other force exc.

slide-34
SLIDE 34

34

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

call Q

slide-35
SLIDE 35

35

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

Q

slide-36
SLIDE 36

36

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

call Q

slide-37
SLIDE 37

37

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

Q waiting

slide-38
SLIDE 38

38

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

Q r e t u r n waiting

slide-39
SLIDE 39

39

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Concurrent Access

  • Two souls want to enter the same body …

– First come, first serve! The other soul has to wait. – Entry wait queue Q – FIFO or priority ordering – Priority inheritance

Q

slide-40
SLIDE 40

40

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q

slide-41
SLIDE 41

41

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q park

slide-42
SLIDE 42

42

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q call

slide-43
SLIDE 43

43

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q unpark

slide-44
SLIDE 44

44

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q unpark

slide-45
SLIDE 45

45

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q r e t u r n

slide-46
SLIDE 46

46

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q

slide-47
SLIDE 47

47

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Parking Souls

  • The Parking Lot:

– a place where souls can rest outside the body – parking: put the currently active soul in P – unparking: move a parked soul from P to Q – the parking queue P is an unsorted queue

P Q r e t u r n

slide-48
SLIDE 48

48

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Interrupt Handling

  • Threaded interrupt handlers

– A dedicated soul is waiting on an interrupt

  • interrupt happens, interrupt source is masked
  • The waiting soul calls the associated body

– Upon return

  • the interrupt is handled
  • unmask the interrupt source again
slide-49
SLIDE 49

49

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

slide-50
SLIDE 50

50

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Strict Task Hierarchy

– Strict parent ↔ child relation – Initial task started by the kernel – Tasks can only grant their own

resources to their children

– Deleting a task deletes all children

and grand children

Root Task 1 Task 7 Task 6 Task 2 T 3 T 5 T 4

slide-51
SLIDE 51

51

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Resources managed by the kernel

– Kernel and User Threads – Address Spaces – Communication Channels – Interrupts – Kernel memory – Free system memory

  • Allocators

– Coarse granular (4K pages) – Fine granular (Object Space → capabilities)

slide-52
SLIDE 52

52

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Kernel memory

– Accounted per task – FIFO list with free 4K pages

  • Coarse memory allocations

– 4K sized pages (MMU granularity) – Task descriptors – Thread Control Blocks + kernel stack (souls) – Page tables – Object Space pages

slide-53
SLIDE 53

53

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Object Space

– One OS per task – Object = single capability – Fine granular memory allocator

  • 2-level lookup-table
  • using 4K pages

– 16K+ entries of 64 byte – OS can grow, but not shrink

→ lock free access!

  • Tasks can only access their own Object Space

– Safety: no partition interference through locking – Security: no covert channels

slide-54
SLIDE 54

54

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Capabilities in Object Space

– Reference to own task (entry #0) – Child Tasks – Child Address Spaces – Souls – Bodies – Ports (communication endpoints) – Interrupts

  • Other Capabilities

– Memory → implicit by virtual address

slide-55
SLIDE 55

55

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Resource Management

  • Communication Channels

– Handle cross task communication – Port: channel endpoint – Channel: two endpoints

  • client and server side objects
  • granted to child tasks
  • Operations

– Server binds body to port – Client calls port – Channel remains open until closed

client port server port grant g r a n t child task child task call

slide-56
SLIDE 56

56

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Locking

slide-57
SLIDE 57

57

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Futexes

  • Derived from Linux
  • 32-bit Integers in user space
  • Fast path: use atomic ops
  • Use syscalls only on contention
  • The kernel maintains a wait queue
  • Tricky with resource partitioning!

unlocked locked locked w/ contention 1 waiter locked w/ contention 2+ waiters

slide-58
SLIDE 58

58

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Futexes

Partition B Partition A SHM Futex lock lock

Partitioned Environment Problem

Q: Wait queue belongs to Partition A or Partition B? Pre-allocate wait queues?

Place head of wait queue into user space, next to the futex

a thread

slide-59
SLIDE 59

59

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Futexes

Partitioned Environment Problem

– Q: Wait queue belongs to

Partition A or Partition B?

– Pre-allocate wait queues?

Place head of wait queue into user space, next to the futex

Partition B Partition A SHM Futex lock lock Wait Queue ? ?

slide-60
SLIDE 60

60

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Futexes

Partitioned Environment Problem

– Q: Wait queue belongs to

Partition A or Partition B?

– Pre-allocate wait queues?

Place head of wait queue into user space, next to the futex

Partition B Partition A SHM Futex lock lock Wait Queue ? ?

slide-61
SLIDE 61

61

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Futexes

  • Futex wait queue

– FIFO sorted

O(1) time

– Priority sorted

O(log n) time

– Implementation in linear space

  • Primitives

– Mutexes – Condition variables – Barriers – Counting semaphores – Reader-writer locks

slide-62
SLIDE 62

62

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Locking Architecture

Futexes

– use between threads in the same partition – shareable between multiple address space

  • but only if all parties trust each other
  • must have the same level of criticality

Body & Soul RPC

– Parking concept → monitor – use between threads in different partitions

  • encapsulate critical operations in a dedicated body
  • caller must trust callee, but not vice versa
slide-63
SLIDE 63

63

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Locking Architecture

Locking Improvements:

– Apply to both Futexes and RPC – Priority Ceiling Protocol

  • Combine futexes with “lazy user space prio switching”
  • Raise and lower thread priority in user space
  • Kernel synchronizes scheduling priority on IRQ / syscall

– (Migratory) Priority Inheritance Protocol

  • Blocked threads boost the priority of lock holders
  • May inherit CPUs as well
  • Problem: robust implementation …

… what if the lock holder blocks? … limit recursions?

slide-64
SLIDE 64

64

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Finally ...

slide-65
SLIDE 65

65

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Implementation

  • Implementation in C99 with GNU extensions
  • GCC 4.3 to 4.8
  • LLVM/Clang 3.3 to 3.4
  • Supported Architectures:

– X86 32 bit and 64 bit – ARM v6 and v7 – PowerPC e500+ cores or newer

  • Open Source License
slide-66
SLIDE 66

66

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Implementation

  • Work in progress (January 2014):

– Shown features are 70% implemented – 20,000 lines of C code (including tools + test code) – 2,000 lines of assembler code

  • TODO:

– Priority sorting in RPC calls and Futexes – Cross-address space calls – Soul parking and Interrupt Handling – Internal SMP locking in the kernel – Priority Inheritance!

slide-67
SLIDE 67

67

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Conclusion

  • Body & Soul: building-block for multi-threaded

execution environments like POSIX Pthreads

– Pthread_create/join → fork / join – Signals → “forced call” + Exception Handling – Synchronization → Futexes

  • Overall concept should fit the requirements
  • f mixed criticality systems
slide-68
SLIDE 68

68

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Outlook

  • Focus on extending Futexes first

– Papers for my PhD!!!

  • Userspace?

– Bionic Libc (Android) + OpenMP – PikeOS paravirtualized Linux – Benchmark-Suite

  • Drivers?

– Rump kernel (NetBSD drivers and stacks) – Genode OS Framework

slide-69
SLIDE 69

69

WAMOS @ HSRM Wiesbaden 2014-02-13

  • A. Zuepke

Thank you for your attention! Questions?