itfn 3601 introduction to operating systems lecture 3 processes, threads & scheduling intro
TRANSCRIPT
Agenda
ProcessesCreationTerminationStates
ThreadsDefinitionUser vs. Kernel ThreadsHybrid Threads
Intro to Scheduling
Processes
A process is an executing ProgramConsist of Program, input, output and a
stateMultiprogrammingPseudo-Parallel Execution
Process Creation
System Initialization
System call by running process
User request to create new process
Initiation of a batch job
Process Internals
StatesRunningReadyBlocking
Process Control BlockStateRegisters & MemoryPC, SP, Files
Running
ReadyBlocked
Threads
Lightweight ProcessesThreads handle all execution activitiesA thread is a program counter, a stack,
and a set of registersThread creation is relatively cheap in
terms of CPU costs
Thread Usage
Programming model becomes simplerEasy to create and destroySpeeds up applicationsUseful on systems with multiple CPUs
User-level threads
User-level threads are managed by runtime library routines linked into each application so that thread management operations require no thread intervention
User-level threads are also flexible; they can be customized to the needs of the language or user without kernel modification
User-level threads execute within the context of traditional processes
Advantages and Disadvantages of User-Level Threads
Thread operations do not have to cross protection boundary
Parameters do not need to be copiedApplications can link in the correct
thread management policy for their needs
Advantages and Disadvantages of User-Level Threads
Performance is inherently better in user-level threads
User-level threads that issue blocking calls to the kernel will block an entire process
Threads in the Kernel
Avoids the system integrations problems exhibited by user-level threads because the kernel directly schedules each applications threads onto physical processors
Performance has been typical of an order magnitude worse than the best-case performance of user-level threads.
Employ user-level threads, which have good performance and correct behavior provided the application is uniprogrammed and does no I/O, or employ kernel threads, which have worse performance but are not as restricted
Advantages and Disadvantages of Kernel-Level Threads
Kernel threads are expensive!Kernel does not understand application
behavior
User vs. Kernel Threads
Software Threads No System Calls for
SwappingProcess-Blocking
System CallsDual-Conflicting
SwapsProcess Level ThreadKernel Level Process
OS ThreadsKernel Calls to Swap
ThreadsThread-Blocking
System CallsDual-Coordinated
SwapsKernel Level ThreadKernel Level Process
Hybrid Implementation
Scheduler ActivationThread-aware Kernel for User-threadsViolates Fundamental ‘Flow-of-Control’Upcalls
Pop-Up ThreadingImplicit Thread CreationReceives Message and processes them
Scheduler Activations
Threads are needed for parallel applicationsUser-level and kernel-level threads both have
problemsUser-level threads offer good performance, but
do not handle I/O wellKernel-level threads are expensive, but correct
Scheduler Activations
SAs notify user-level schedulers of changes in kernel scheduling decisions
SAs provide kernel space for threads that block in the kernel
Create one activation for each virtual processor
Kernel creates SAs to upcall into applications, notifying them of scheduling events
Scheduler Activations
Key difference between SAs and kernel threadsWhen an SA blocks, the application is notified by a
different SAThe blocking SA’s thread is marked blocked and the old SA
is freedThe new SA can now be scheduledThe number of SAs under control of the application never
changes (unless requested/told explicitly)
Kernel level state is passed to thread system on upcall, so that registers of the blocking thread are accessible to the user-level scheduler
Popup Threads
Thread is created spontaneously to handle an incoming request
Incoming message mapped into thread’s address space
Advantages over traditional request:No waiting on work (no context needs to be saved)Creating new thread is cheaper than restoring old
thread (no context is saved)
Process Control
Each Process must maintain it’s own PCB
Information that Multiple Processes may use is duplicated
Thread Control
Each Process has a PCB
Each Thread has a TCB
Shared information is Shared, not Duplicated
Scheduler Goals
Generic goalsFairness of processor allocationEnforcement of scheduling policiesBalance of utilization
Batch-based goalsThroughput of jobsTurnaround on jobs
Scheduler Goals II
Interactive System GoalsResponse time for user I/OProportions should be maintained
Real-time System GoalsDeadlines must be met for process
completionSystem performance must be predictable