Introduction to OS: Embedded System 연구실
Introduction to OS: Embedded System 연구실
Introduction to OS
Embedded System
-1-
Outline
Overview Process and Threads Scheduling
1 Introduction
-2-
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-
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-
1 Introduction
-5-
Computer system
Hardware
Physical devices Microprogram Machine Language
1 Introduction
System Programs
Operating system Compilers, editors, command interpreter
Application Programs
-6-
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
In RISC machine?
-7-
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-
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
-9-
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 -
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 -
Outline
Overview Process and Threads Scheduling
1 Introduction
- 12 -
Introduction to processes
Process
An abstraction of a running program
1 Introduction
Pseudo parallelism
Rapid switching back and forth of the CPU btw programs
- 13 -
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 -
Process model
1 Introduction
- 15 -
1 Introduction
Process
An activity of some kind Has a program, input, output, and a state
- 16 -
Process Hierarchies
1 Introduction
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 -
Process States
cat chpater1 chapter2 chapter3 | grep tree
The first process
Running cat
1 Introduction
- 18 -
1 Introduction
- 19 -
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 -
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 -
1 Introduction
- 22 -
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 -
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 -
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 -
1 Introduction
- 26 -
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
- 27 -
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 -
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
- 29 -
Threads
The system redesign is needed
1 Introduction
- 30 -
Outline
Overview Process and Threads Scheduling
1 Introduction
- 31 -
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
- 32 -
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
- 33 -
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 -
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 -
1 Introduction
Hard RT Scheduling
Dynamic
Preemptive Non-preemptive
Static
Preemptive Non-preemptive
Soft RT Scheduling
- 36 -
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 -
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 -
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
- 39 -
1 Introduction
the point in time when a request for a task execution is made the time when a task becomes ready for execution
- 40 -
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
Schedule period
The least common multiples of the periods of periodic tasks
- 41 -
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 -
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 -
Dynamic Scheduling
Scheduling Independent Tasks
Rate Monotonic Algorithm Earliest Deadline First (EDF) Algorithm Least Laxity (LL) Algorithm
1 Introduction
- 44 -
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
1 Introduction
- 46 -
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 -
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
- 48 -
Multiprocessor systems
Neither EDF nor LL algorithm is optimal.
1 Introduction
LL algorithm can handle task scenarios that EDF algorithm cannot handle.
- 49 -
RM vs EDF
Deadlines
1 Introduction
dA d1 d2 d3 d4
dB d5 d6 d7
dC
High Rate
Low Rate
- 50 -
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 -
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 -
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 -