View
2
Download
0
Category
Preview:
Citation preview
Operating Systems and Computer Networks
Process Scheduling Part 2
Prof. Dr.-Ing. Axel HungerAlexander Maxeiner, M.Sc.
Institute of Computer EngineeringFaculty of Engineering
University Duisburg-Essen
Dr.-Ing. Pascal A. Klein & Alexander Maxeiner M.Sc.
Alexander.maxeiner@uni-due.de
Alexander Maxeiner, M.Sc.University Duisburg-Essen
2Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Process Management|
Time Sharing|
Synchronization of Processes
|
Scheduling Classification
|
Scheduling Algorithms
Agenda
Alexander Maxeiner, M.Sc.University Duisburg-Essen
3Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
A program
• resides in local memory
• partially or entirely transferred to main memory upon execution
The program can be comprised of:
• Programs, sub-routines
• Data
• Instruction pointers
• Stack pointers
• CPU states
• Register contents
Program Execution
Alexander Maxeiner, M.Sc.University Duisburg-Essen
4Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Modern software consists of more than one process.
If a program is executed, all processes necessary for a certain task are loaded into main memory.
One processor core can only execute one task at a time.
OS needs
• to monitor free resources (cores, cache, etc)
• to open tasks
• to allocate CPU time
• change between tasks
• To keep track of current active tasks
Process Management
Alexander Maxeiner, M.Sc.University Duisburg-Essen
5Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Process Management
Alexander Maxeiner, M.Sc.University Duisburg-Essen
6Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Problematic are idle times within the CPU. When an operation waits for I/O Data the CPU does nothing.
Longer idle times decrease throughput of the System leading to performance drop.
In case of idle times the OS needs to switch processes in order to keep the CPU busy.
The perfect Computer system has 0% idle time. In reality this is almost impossible, since context changes between processes are also lost time for computing.
Increased throughput can be achieved by planning ahead and optimal use of scheduling algorithms.
Idle times
Alexander Maxeiner, M.Sc.University Duisburg-Essen
7Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Processes are split up into segments.
Each segment is part of the entire process and consists of at least one complete operation within the CPU.
Each segment is given a specific amount of time at the CPU.
How much (amount of time) and when (it is given the time) depends on the implemented algorithm.
Multitasking: time-multiplexing, only one CPU (or Core) is occupied with several tasks. Processor power is shared between tasks to execute all tasks semi-parallel.
Segmenting tasks
Alexander Maxeiner, M.Sc.University Duisburg-Essen
8Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Problem 1: How to optimize efficiency in the use of CPU?
Problem 2: How to change between processes?
Time Sharing
Alexander Maxeiner, M.Sc.University Duisburg-Essen
9Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Difficult to calculate depends on the situation
• E.g.: 5 processes need 20% of the total CPU power within a certain timeframe. Perfect scenario?
• Which process is first, which one is last?
In reality: Difficult for users to estimate CPU demands of processes, therefore difficult to implement time demands.
Number of segments indicator of actual processing expenditure, but only as an approximation.
OS equipped with algorithms to estimate CPU times of processes. Actual processesing time may vary.
CPU Utilization
Alexander Maxeiner, M.Sc.University Duisburg-Essen
10Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Actual predetermination not possible, but approximation
Probabilistic view of CPU Utilization:
CPU utilization = 1 – pn
n – number of processes
pn – probability that all processes wait for I/O (CPU idle time)
Works only on independent processes. Dependent processes are merged into one independent.
All processes share I/O probability. Can be derived from cache-/ register hit rates.
CPU Utilization
Alexander Maxeiner, M.Sc.University Duisburg-Essen
11Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
CPU utilization = 1 – pn
Theoretically: Infinite amount of processes simultaneously at the CPU -> CPU utilization = 1
Formula ignores time for context changes. Switch between one process and another not instantaneously.
The more processes are lined up the more time for context changes is wasted.
Cap the amount of tasks processed by the CPU & plan ahead.
CPU Utilization
Alexander Maxeiner, M.Sc.University Duisburg-Essen
12Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Time Wheel Model
P8 P1
P2
P3
P4
P5P6
P7
Context change T
t
P1: Terminal IO (Keyboard or mouse)P2: Account P3: PrintP4..P7
User 1, 2, 3, 4
Alexander Maxeiner, M.Sc.University Duisburg-Essen
13Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Time needed to switch can be between μs and ns
Address range of an old process has to be saved and updatedby complex memory management
OS has to step in between different processes. Time efficient procedures needed.
Process change
tProcess1 OS Process2 OS Process1 OS etc.
Alexander Maxeiner, M.Sc.University Duisburg-Essen
14Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
When a process/task changes: stack pointer, registers, etc. must be changed
Two methods:
1. Complete set of user data / process data is stored in a private memory space
2. Context change by pointers only
• Pointer targets the actual program state within memory.
• Pointers point to start of memory slot with data.
Memory mustn’t change or task will be corrupted upon resuming
Process change
Alexander Maxeiner, M.Sc.University Duisburg-Essen
15Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
A PCB is an entry in the process table
Process table contains all information on currently running tasks.
Data structure with information to manage scheduling
Needed for correct and efficient process management
Contains:
• Process identification data (unique identifier)
o e.g.: process id, parent process, user identifier, etc.
• Process state data (status of a process)
o e.g.: content of CPU general-purpose registers, CPU process status, stack and frame pointers, etc.
• Process control data (to manage process itself)
o e.g.: process scheduling state, Process structuring information, Process Privileges, Process Number (PID), Program Counter (PC), CPU Registers, Memory Management Information, etc.
Process Control Block
Alexander Maxeiner, M.Sc.University Duisburg-Essen
16Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Time Sharing
Scheduler
I/O-readlines
CPU
Reentrant
Code
Computer / OS
PC2
PC1
M2
M1
Peripheral memory Virtual Machine
(virtual parallel)
Task 1
Task 2
Alexander Maxeiner, M.Sc.University Duisburg-Essen
17Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Interrupt - Time Sharing
Save PCBof process 1
Load PCBof process 2
Save PCBof process 2
Load PCBof process 1 RUNNING
RUNNING Scheduler or Interrupt
Process 1
READY
Process 2
RUNNING
READY
SCHEDULER OR INTERRUPT
Alexander Maxeiner, M.Sc.University Duisburg-Essen
18Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
A process queue
Start
end
PCBi
Register,
etc.
PCBk
Register,
etc.
PCBa
Register,
etc.
CPU-Queue
NIL
Pointer in the Queue
Start
end
Disk QueuePCBb
Register,
etc.
PCBx
Register,
etc.
NIL
Alexander Maxeiner, M.Sc.University Duisburg-Essen
19Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Problems with context changes:
Processes are not finished if interrupted by other processes. May lead to huge delays in relevant, but time consuming processes.
The more processes are on hold, the more context changes will occur leading to huge overly-times, decreasing the system efficiency.
Pointer-based context changes block memory. Memory depletion.
Memory stored context changes lead to increased loading times, decreasing overall efficiency.
Context changes
Alexander Maxeiner, M.Sc.University Duisburg-Essen
20Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
When to change between processes?
a) by cyclic flow control (polling), i.e. processes call for data, program-controlled
b) time-controlled in certain given intervals with a real-time clock
c) by request (interrupt) via the technical process event-controlled.
Synchronization
Alexander Maxeiner, M.Sc.University Duisburg-Essen
21Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Drawback: CPU is always busy with polling, though it is often idle due to I/O operations.
Cyclic Flow Control
e.g.:
5 processes:
4 idle, 1 busy.
PA
PB
C/D2
C
D
Px : Process looking forData polling
Cyclic Flow Control (Polling)
Alexander Maxeiner, M.Sc.University Duisburg-Essen
22Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
If time intervals too short number of data swapping increases until a process is finished decrease of overall efficiency
If time intervals too long finished process will leave the CPU with idle time
Time-controlled
idle time?Time A
PA
Px : Process execution
Time A
PB
Alexander Maxeiner, M.Sc.University Duisburg-Essen
23Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Process requests (triggered by the technical process):
• can be announced at any time
• have high priority (importance) by
opriority in execution and/or
oblocking other requests
also leads to context change
High priority tasks can be executed fast.
Interrupts can be activated if higher priority
task finished loading data.
Request (Interrupt)
Interrupt?
Process Scheduling
PA
ExecuteInterrupt
Px : Process execution
Alexander Maxeiner, M.Sc.University Duisburg-Essen
24Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
A background process is interrupted by two interrupts
Interrupt - Example
BGP
IRS1
IRS2
IRS1
BGP
Interrupt
BGP: Backgroundprocess
IRSi: Interrupt Subroutine i
Ii: Interrupt i
Priority
Time
I1 I2
Alexander Maxeiner, M.Sc.University Duisburg-Essen
25Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Problem: Multiple processes or threads need CPU resources at the same time
OS chooses the next steps for the upcoming queued processes (to be processed)
Three different types of environments
• Batch
• Interactive
• Real time
Why Scheduling?
Alexander Maxeiner, M.Sc.University Duisburg-Essen
26Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
The scheduler needs to be planned with respect to the following criteria:
• Use/efficiency of CPU-Utilization (40 % - 90 %)
• Throughput (completed processes / time unit)
• Cycle time (time from input to output of the results)
• Waiting time (Waiting in the CPU Waiting Queue)
• Response time (In interactive systems: Time to reaction)
• Turnaround time (The time until a job is finished)
Planning Criteria
Alexander Maxeiner, M.Sc.University Duisburg-Essen
27Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Non-Preemptive scheduling:
• process is picked and started until it blocks (either on I/O or waiting state) or voluntarily releases the CPU
• process will not be forcibly suspended until a higher priority interrupt occurs
Preemptive scheduling:
• process starts and runs for a fixed amount of time
• If process still runs at end of time cycle, it is suspended
• requires a clock interrupt occurring at the end of every time interval to give control of CPU back to scheduler
Scheduling Methods
Alexander Maxeiner, M.Sc.University Duisburg-Essen
28Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Big systems working on steady bulky jobs
Non-preemptive is fine
no users waiting for quick results
Long processing acceptable
Reducing of process switches
Planning - batch systems
Main Memory
CPU
Disk
• Throughput• Turnaround Time• CPU Utilization
Alexander Maxeiner, M.Sc.University Duisburg-Essen
29Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
OS in a PC bundles Jobs in Batches
Usually only done in multi-core systems
Batches send to cores for processing
Batch in PC
Main Memory
Core 1
• Throughput• Turnaround Time• CPU Utilization
Core 2
Job Batch
Alexander Maxeiner, M.Sc.University Duisburg-Essen
30Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
PC, Webserver, ATM ...
Preemptive is needed
More than one process running all the time
All users are in big hurry...
Planning in Interactive Systems
• Response Time• Proportionality – meets
users‘ expectations
Alexander Maxeiner, M.Sc.University Duisburg-Essen
31Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Systems which keep in real time constraints
immediate action needed
Preemptive handling not needed
• processes need to be securely finished
• processes will not block for long
Only specialized software used
Application runs well-known and specialized programmesstrongly compatible with the application
Real Time Systems
• Meeting Deadlines• Predictability
Alexander Maxeiner, M.Sc.University Duisburg-Essen
32Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Scheduling Goals
• Meeting Deadlines• Predictability
• Response Time• Proportionality – meets
users‘ expectations
• Throughput• Turnaround Time• CPU Utilization
• Fairness(fair amount of share
• Policy enforcement(strategy enforcement)
• Balance(all parts of system shouldbe busy)
Alexander Maxeiner, M.Sc.University Duisburg-Essen
33Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Depend on certain events:
• scheduler selects next process queue of ready processes from the OS
Scheduling decisions can be made:
• in transition from running to blocked state (waiting for I/O – 4)
• in transition from running to ready state (Interrupt – 2)
• in transition from blocked to ready state (I/O end – 5)
• Upon termination of a process
Scheduler
BlockedRunning
Ready
4
23
5
Existent
1
6When?
Alexander Maxeiner, M.Sc.University Duisburg-Essen
34Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Fairness
• Each process needs fair share of CPU time
• comparable processes should get comparable service
Utilization of resources
• keep all parts of the system busy
Algorithm must be executed efficiently
• No wasting of resources
• Minimized overhead
Requirements of Scheduling Algorithms
Alexander Maxeiner, M.Sc.University Duisburg-Essen
35Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Static (a priori) Scheduling Algorithms Scheduling decisions take place at a fixed time interval
Process coordination:
• Scheduling is planned before the programs run
• Input of a scheduling algorithm is a set of processes which will be considered for scheduling
• Processes arriving the scheduler during the runtime of a process, stored for next cycle
• Scheduled processes run until all of them are done and/or until the given time is over.
Conditions for static algorithms:
• No dynamic process creation during the program
• Event-driven processes can be incorporated only if the time conditions are schedulable
Classsifications of Scheduling Algorithms
Alexander Maxeiner, M.Sc.University Duisburg-Essen
36Prof. Dr.-Ing. Axel HungerInstitute of Computer Engineering OSCN – Process Scheduling
Dynamic Scheduling Algorithms
Coordination of processes takes place while the processes are running
Times of updates:
• at fixed time intervals
• as soon as a new process is created
• as soon as a process ends
Advantages and disadvantages
• event-driven processes must be coordinated
• decision making during scheduler operation costs time
• Lack of efficiency: heuristics are required!
Classsifications of Scheduling Algorithms
Recommended