Top Banner
Real-Time Kernels and Operating Systems
32

Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Real-Time Kernels and Operating Systems

Page 2: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Operating System:

Software that coordinates multiple tasks in processor, including peripheral interfacing

Types of task activities:data exchange / sharingsynchronizationschedulingresource sharing

Real-time OS (RTOS): one or more tasks must execute within specified time constraints

Page 3: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_00

Example: tasks in meal preparation cannot all be completed in a strict sequence

Page 4: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Single process/task: required resources:

Process stackMemory address spaceRegisters (in CPU)PC I/O ports and network connectionsFile descriptors…

Process state: PC value, register contents, etc. at a given time

Which must be shared with other processes?How can this sharing be managed efficiently?

Page 5: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_01

In embedded systems we can think of the CPU as a resource for the current task: CPU is a shared resource

Multitasking: more than one task needs to execute, in a seamless manner

CPU, other resources must be shared

Page 6: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_02

Multiple processes, typically running concurrentlyQ: what are some typical processes?

Page 7: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_03

Tasks switch from “running” to “ready/waiting” and back according to a scheduleQ: what should be length of turn? Who gets priority?

Page 8: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Common sharing strategies:

Multiprogramming: task runs until it needs to wait on an external event (e.g., I/O)

Real-time: certain tasks have deadlines that must be met

Time-sharing: each process gets a time slice; processes are preempted when time slice is up, must wait for next turn

Page 9: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_04

Task context: what is the state of task—e.g., register contents; when tasks are swapped, contexts must also be swapped and task that is not running must have its information saved

Task statesIn simple system

Page 10: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

Thread: smallest set of resources a task needs (PC and stack, e.g.—if not running, must have copy of register contents)

Terminology:

Process= “heavyweight thread”

Smallest set of resources = “lightweight thread”

Page 11: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_05

Single-thread design: one process

Page 12: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_05

Multiple threads

Page 13: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_07

Process privilege levels affect operations it can carry out without assistance from other processes:

Child process: shares codespace, has own data space, data,status, stack

Multiple threads: each has itsown stack, status information

Process: separate addressspace

Reentrant code: child process can use same code, needs different local variables

Page 14: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_07

Foreground tasks: initiated by interrupt or real-time constraint—higher priority levels

Background tasks—not interrupt-driven—lower priority levels—e.g. monitoring tasks, intensive processing tasks

Page 15: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_07

Operating system:

Kernel—portion of OS providing basic functions:

Scheduler: Schedule tasks for execution

Dispatcher: Choose (“dispatch”) task to run

Intertask and interprocess communication: Ensure tasks can communicate as needed and are synchronized as needed

Page 16: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_07

Necessary services to carry out these jobs:

Manage processes and tasks, deal with “deadlocks”

Manage memory, I/O system, file system

RTOS: make sure deadlines are met; make sure behavior is DETERMINISTIC (not necessarily “fast”)

Hard real-time; system delays are known or at least bounded

Soft real-time: critical tasks have priority and are allowed to run to completion

Page 17: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_08

OS architecture:Virtual machine model:Very modular but may not match real machine

Page 18: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_09

OS architecture:Typical architecture

Page 19: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_10

TCB: task control block—required for each task or process to be executed

Task states:ReadyExecutedormant

Page 20: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_11

Code for a task control block:

Page 21: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_12

Example: simple system, 3 asynchronous tasks sharing a common data buffer--get data--perform computation--display dataTask queue implemented as arrayWill run “forever”No preemption (each task runs to completion)

Page 22: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_13b

Kernel example

Page 23: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_14a

Same tasks—using task control blocks

Page 24: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_12

Some problems with this system;

Can get stuck in one taskEx: user does not input data so we are stuck in the “get” taskSolution: use interrupts, break task into prompt and task to get data when it is available

Shared data bufferIn this example, only 1 task is active at a time so there is no conflict

Page 25: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_15

Typical function to set address to correct interrupt:

Page 26: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_17a

Modification to allow interruptsPart 1 of 3):

Page 27: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_17b

Modification to allow interruptsPart 2 of 3):

Page 28: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_17c

Modification to allow interruptsPart 3 of 3):

Page 29: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_18

Registers:Can organize as multiple contexts

Page 30: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_19

Registers:Can organize as overlapping contexts—saves overhead on variable passing

Page 31: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_20

Stack: typical stack frame organization

Page 32: Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.

fig_11_21

Runtime stack: multiple task information must be stored