Anda di halaman 1dari 54

1 Introduction

Introduction to OS

Embedded System

-1-

Embedded System Lab

Outline
Overview Process and Threads Scheduling

1 Introduction

-2-

Embedded System Lab

Introduction
Computer software
System programs
Manage the operation of the computer itself

1 Introduction

Application programs
Perform the actual work the user wants

Operating system
The most fundamental system program Controls all the computer's resources Provides the base upon which the application programs can be written

-3-

Embedded System Lab

Introduction
Operating system
A layer of software on top of the base hardware

1 Introduction

To manage all parts of the system To present the user with an interface or virtual machine Easier to understand and program

Think about some assembly (or C) programs that you wrote in a small microcomputer!

-4-

Embedded System Lab

1 Introduction

-5-

<Tanenbaum & Woodhull>

Embedded System Lab

Computer system
Hardware
Physical devices Microprogram Machine Language

1 Introduction

System Programs
Operating system Compilers, editors, command interpreter

Application Programs

-6-

Embedded System Lab

Hardware
Physical devices

1 Introduction

CPU, IC, capacitors, resistors, wires, power supplies, CRT Electrical engineer

Microprogram
A layer of primitive software controlling physical devices To provide a cleaner interface to the next layer In ROM An interpreter
Fetching the machine language
macro language Assembly language

Carrying out as a series of more little steps(microlanguage)

In RISC machine?

-7-

Embedded System Lab

Hardware
Machine Language
The number of machine language
From RISC to CISC

1 Introduction

I/O devices
controlled by loading values into special device registers Many parameters timing

-8-

Embedded System Lab

System Programs
Operating system

1 Introduction

To all hardware-related-complexity To give the programmer a more convenient set of instructions to work with Runs in kernel mode or supervisor mode Protected from user tampering by the hardware

Other system software


Command interpreter (shell) Window systems Compilers, Editors Similar application-independent programs NOT part of the operating system

-9-

Embedded System Lab

Application Program
Purchased or written by the users to solve their particular problem examples

1 Introduction

Word processing, Spreadsheets, Engineering calculations Game program, Banking system, Airline reservation Web browser IGRIP, ROBCAD, QUEST, VirtualNC Vision (Image processing) libraries Motion libraries

- 10 -

Embedded System Lab

Operating System
A extended (virtual) machine

1 Introduction

To provide users with a convenient interface (Top-down view) A simple and high-level abstraction to deal with computers To hide a lot of very complex hardware-details
disks, interrupts, timers, memory management, and other low-level features

A resource manger
To mange all the pieces of a complex system (Bottom-up view) To provide for an orderly and controlled allocation of the processors, memories, and I/O devices among the various programs competing for them To manage and to protect information as well as hardware

- 11 -

Embedded System Lab

Outline
Overview Process and Threads Scheduling

1 Introduction

- 12 -

Embedded System Lab

Introduction to processes
Process
An abstraction of a running program

1 Introduction

Pseudo parallelism
Rapid switching back and forth of the CPU btw programs

True hardware parallelism of multiprocessor

- 13 -

Embedded System Lab

Process
An executing program

1 Introduction

Including the current values of the program counter, registers, and variables

Conceptually
Each process has its own virtual CPU

In reality
The real CPU switches back and forth from process to process Switching back and forth: multiprogramming

- 14 -

Embedded System Lab

Process model

1 Introduction

- 15 -

<Tanenbaum & Woodhull>

Embedded System Lab

Process and program


Analogy

1 Introduction

A computer scientist who is baking a birthday cake for his daughter


A birthday cake recipe program Cake ingredients input data Computer scientist CPU Activity process

What will happen if his son comes running in crying?


Switch from processes

Process
An activity of some kind Has a program, input, output, and a state

- 16 -

Embedded System Lab

Process Hierarchies

1 Introduction

In very simple systems (or for a single application)


Possible to have all the processes when the system comes up

In most systems
Creation and destroy of processes during operations Processes need a way to create other processes
Only one parent for each process One or more children for each process

- 17 -

Embedded System Lab

Process States
cat chpater1 chapter2 chapter3 | grep tree
The first process
Running cat

1 Introduction

The second process


Running grep

Grep may block if no input is available

Two cases of process stop


Block
Logically, typically no input

OS allocates the CPU to another process for a while


Ready and able to run

- 18 -

Embedded System Lab

1 Introduction

- 19 -

<Tanenbaum & Woodhull>

Embedded System Lab

Three States of A Process


Running
Actually using the CPU at that instant

1 Introduction

Ready
Runnable temporarily stopped to let another process run Temporarily no CPU available

Blocked
Unable to run until some external event happens Blocked process cannot run even if the CPU is available

- 20 -

Embedded System Lab

Four Transitions
Transition 1
When a process discovers that it cannot continue

1 Introduction

Transitions 2 and 3
Caused by the process scheduler (a part of OS) Transition 2
the scheduler decides that the running process has run long enough It is time to let another process have some CPU time

Transition 3
When all the other processes have had their fair share and it is time for the first process to get the CPU to run again

Transition 4
When the external event for which a process was waiting happens (e.g. the arrival of some input)
- 21 -

Embedded System Lab

1 Introduction

- 22 -

<Tanenbaum & Woodhull>

Embedded System Lab

Process Modell
The lowest level of the OS
Scheduler

1 Introduction

The rest of OS
Nicely structured in process form

Scheduler
All the interrupt handling and details of actually starting and stopping processes are hidden away in the scheduler Quite small

- 23 -

Embedded System Lab

Implementation of Processes
Process table

1 Introduction

One entry per process Each entry contains all information about the process
Process state, program counter, stack pointer, memory allocation, the status of its open files, its accounting and scheduling information, and everything else about the process All that must be saved when the process is switched form running to ready state the process can be restarted later as if it had never been stopped

- 24 -

Embedded System Lab

Threads
Scheduled flows of control in a process Lightweight (or light) processes Share
A single address space A set of global variables

1 Introduction

Are distinguished by
Program counters Stack pointers

- 25 -

Embedded System Lab

1 Introduction

- 26 -

<Tanenbaum & Woodhull>

Embedded System Lab

Threads
A file server
Maintaining a cache of recently used files in memory to improve performance Fig. 2-6(b)

1 Introduction

Multithreads share the same address space and thus can share the same memory cache

Fig. 2-6(a)
The three threads in three processes do not share and cannot

In browsers for World Wide Web


Many images can be requested at the same time by having multiple threads speeding up performance in most cases
Since with small images, the set-up time is the limiting factor, not the speed of the transmission line

- 27 -

Embedded System Lab

Threads
A thread table is needed in the case of

1 Introduction

Multiple threads are present in the same address space One entry per thread Some items in each entry
Program counter, registers, states

Like processes
Threads can be in running, ready, or blocked state

- 28 -

Embedded System Lab

Threads
OS is not aware of the threads
Threads are managed entirely in user space
User-level threads

1 Introduction

Advantage
Switching threads is much faster than that of a kernel call

Disadvantage
When one thread blocks, the kernel blocks the entire process

OS is aware of the threads


OS handles threads Kernel must have a thread table
Listing all the threads in the system

- 29 -

Embedded System Lab

Threads
The system redesign is needed

1 Introduction

In order to introduce threads into an existing system,

- 30 -

Embedded System Lab

Outline
Overview Process and Threads Scheduling

1 Introduction

- 31 -

Embedded System Lab

Process Scheduling
Scheduler

1 Introduction

The part of the OS to decide which process to run first in more than one runnable processes scheduling algorithm Is concerned with deciding on policy, not providing a mechanism

Criteria about a scheduling algorithm


Fairness a fair share of the CPU in each process Efficiency keep the CPU busy 100% of the time Response time min response time for interactive users Turnaround min the time batch users must wait for output Throughput max the number of jobs processed per hour

- 32 -

Embedded System Lab

Process scheduling
Criteria about a scheduling

1 Introduction

Contradictory goals Criteria 3 (response time) and 4 (turnaround) Any scheduling algorithm favoring some class of jobs hurts another class of jobs

Complication in schedulers
Every process is unique and unpredictable
I/O concentrated process, calculation concentrated process Cannot predict the life of process

Nearly all computers


Timer or clock, sure that no process runs too long Interrupt periodically

- 33 -

Embedded System Lab

Process scheduling
Preemptive scheduling
Allowing processes that are logically runnable to be temporarily suspended

1 Introduction

Nonpreemptive scheduling
Run to completion Simple and easy to implement Not suitable for general-purpose systems with multiple users Suitable for some dedicated system
Data base server All processes in DB are under the control of a single master, which knows that each child is going to do and about how long it will take.

- 34 -

Embedded System Lab

Process scheduling
Round robin scheduling: Equal (fair) scheduling Priority scheduling: Max quantum Shortest job first

1 Introduction

Appropriate for batch jobs for which the run times are known in advance

Guaranteed scheduling
Compare (actual CPU had)/(CPU time entitled)

Lottery scheduling
Difficult to implement the guaranteed scheduling

Real-time scheduling
- 35 -

Embedded System Lab

Classification of Scheduling Algorithms


Real-Time Scheduling
Soft Hard

1 Introduction

Hard RT Scheduling
Dynamic
Preemptive Non-preemptive

Static
Preemptive Non-preemptive

Soft RT Scheduling

- 36 -

Embedded System Lab

Classification of Scheduling Algorithms


Dynamic
on-line scheduling decision at run-time

1 Introduction

Static
pre-run-time (or off-line) scheduling decision at compile time Scheduler needs complete prior knowledge about task-set characteristics
Maximum execution times Precedence constraints Mutual exclusion constraints deadlines

- 37 -

Embedded System Lab

Classification of Scheduling Algorithms


Preemptive Non-preemptive
Appropriate for many short tasks
compared to the time it takes for a context switch

1 Introduction

Centralized vs Distributed
In a dynamic distributed RT system
Centralized or distributed scheduling are possible

Centralized
Critical point of failure Communication bottleneck
Because of up-to-date information on the load situations in all nodes

- 38 -

Embedded System Lab

Schedulability Test

1 Introduction

A test to determine whether a set of ready tasks can be scheduled s.t. each task meets its deadline Sufficient, exact, and necessary schedulability tests
If (s.s.) test is positive, schedulable If (n.s.) test is negative, not schedulable

Optimal scheduler
It will find a schedule if an exact schedulability test indicates the existence of such a schedule

The complexity of an exact schedulability test algorithm


NP(non deterministic polynomial) -complete problems intractable

- 39 -

Embedded System Lab

Periodic and sporadic tasks


Task request time

1 Introduction

the point in time when a request for a task execution is made the time when a task becomes ready for execution

Periodic and sporadic tasks


Based on the task request time

All future request times of a periodic task


Known a priori

- 40 -

Embedded System Lab

Periodic tasks
A task set {Ti}
Period pi Deadline interval di

1 Introduction

The diff btw the deadline of a task and the task request time

Execution time ci Laxity li


di ci

Schedule period
The least common multiples of the periods of periodic tasks

- 41 -

Embedded System Lab

Periodic tasks
Necessary schedulability test

1 Introduction

The sum of utilization factors must be less or equal to the number of processors.

Utilization factor of Ti , mi
The percentage of time the task Ti requires service from a processor

- 42 -

Embedded System Lab

Sporadic tasks
The request times of sporadic tasks

1 Introduction

Are not known a priori A minimum interval btw two any two request times of sporadic tasks is needed in order to be schedulable.

Aperiodic task
No constraint on the request times of task activations

- 43 -

Embedded System Lab

Dynamic Scheduling
Scheduling Independent Tasks
Rate Monotonic Algorithm Earliest Deadline First (EDF) Algorithm Least Laxity (LL) Algorithm

1 Introduction

Scheduling Dependent Tasks


The Kernelized Monitor

- 44 -

Embedded System Lab

Rate monotonic algorithm

1 Introduction

A dynamic preemptive algorithm based on static task priorities Assumptions about the task set
A set of periodic independent hard real-time tasks (The deadline interval of every task Ti) = (its period pi). The required max computation time of each task ci is known a priori and is constant. Negligible context switching time Sum of utilization factors for n tasks

The highest static priority on the shortest periodic task


- 45 -

Embedded System Lab

Rate monotonic algorithm


This algorithm guarantees that all tasks will meet their deadline if all assumptions are satisfied. Optimal for single processor systems If task periods are multiple of the period of the highest priority task, the utilization factor can approach the max theoretical limit.

1 Introduction

- 46 -

Embedded System Lab

Earliest deadline first (EDF) algorithm

1 Introduction

An optimal dynamic preemptive algorithm in single processor systems based on dynamic priorities Assumptions
A set of periodic independent hard real-time tasks (The deadline interval of every task Ti) = (its period pi). The required max computation time of each task ci is known a priori and is constant. Negligible context switching time

The processor utilization m can go up to 1, even when the tasks periods are not multiples of the smallest period. The highest priority on the earliest deadline

- 47 -

Embedded System Lab

Least laxity algorithm


Optimal for single processor systems Same assumptions as EDF

1 Introduction

A set of periodic independent hard real-time tasks (The deadline interval of every task Ti) = (its period pi). The required max computation time of each task ci is known a priori and is constant. Negligible context switching time

The highest priority on the shortest laxity


(laxity) = (deadline interval) (computation time)

- 48 -

Embedded System Lab

Multiprocessor systems
Neither EDF nor LL algorithm is optimal.

1 Introduction

LL algorithm can handle task scenarios that EDF algorithm cannot handle.

- 49 -

Embedded System Lab

RM vs EDF
Deadlines

1 Introduction

dA d1 d2 d3 d4

dB d5 d6 d7

dC

High Rate

Low Rate

- 50 -

Embedded System Lab

RM vs EDF
Deadlines

1 Introduction

dA d1 d2 d3 d4

dB d5 d6 d7

dC

High Rate

Low Rate

Rate Monotonic

Deadline Violations

A B

- 51 -

Embedded System Lab

RM vs EDF
Deadlines

1 Introduction

dA d1 d2 d3 d4

dB d5 d6 d7

dC

High Rate

Low Rate

EDF

Rate Monotonic

Deadline Violations

A B

- 52 -

Embedded System Lab

EDF vs LLF in Two Processors


A B C

1 Introduction

EDF

P1 P2
LLF

B C

P1 P2
- 53 -

A B C
Embedded System Lab

References

1 Introduction

A. S. Tanenbaum and A. S. Woodhull, Operating System, Prentice Hall, 1997. M. M. Mano, Computer System Architecture, Prentice Hall, 1993. R. E. Bryant and D. R. OHallaron, Computer Systems: A Programmers Perspective, Prentice Hall, 2003. ETAS, www.etas.com H. Kellermann, et. al. Electrical and Electronic System Architecture: Communication Network, Power Distribution System, Central Services and Wiring Harness, ATZextra 2008. T. Thomsen and G. Drenkhahn, Ethernet for AUTOSAR, 2008. iSYSTEM Users Manual, EVB-5567 Evaluation & Development Kit for Freescale PowerPC MPC5567 Microcontroller, 2009. W. J. Greig, Integrated Circuit Packaging, Assembly and Interconnections, Springer, 2007. J. Fjelstad and C. Mitchell, The Past, Present and Future of IC Packaging, 2004 Topline , Surface Mount Nomenclature and Packaging. E. Visser, Model-driven software development, 2010

- 54 -

Embedded System Lab

Anda mungkin juga menyukai