Top Banner
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro
25

ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Dec 14, 2015

Download

Documents

Cuthbert Boyd
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: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

ITFN 3601Introduction to Operating

Systems

Lecture 3

Processes, Threads

& Scheduling Intro

Page 2: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Agenda

ProcessesCreationTerminationStates

ThreadsDefinitionUser vs. Kernel ThreadsHybrid Threads

Intro to Scheduling

Page 3: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Processes

A process is an executing ProgramConsist of Program, input, output and a

stateMultiprogrammingPseudo-Parallel Execution

Page 4: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Process Creation

System Initialization

System call by running process

User request to create new process

Initiation of a batch job

Page 5: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Process Termination

Normal exit

Error Exit

Fatal Error

Killed by another process

Page 6: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Process Internals

StatesRunningReadyBlocking

Process Control BlockStateRegisters & MemoryPC, SP, Files

Running

ReadyBlocked

Page 7: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 8: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Thread Usage

Programming model becomes simplerEasy to create and destroySpeeds up applicationsUseful on systems with multiple CPUs

Page 9: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 10: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 11: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 12: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 13: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Advantages and Disadvantages of Kernel-Level Threads

Kernel threads are expensive!Kernel does not understand application

behavior

Page 14: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 15: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Hybrid Implementation

Scheduler ActivationThread-aware Kernel for User-threadsViolates Fundamental ‘Flow-of-Control’Upcalls

Pop-Up ThreadingImplicit Thread CreationReceives Message and processes them

Page 16: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 17: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 18: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 19: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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)

Page 20: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Process Control

Each Process must maintain it’s own PCB

Information that Multiple Processes may use is duplicated

Page 21: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Thread Control

Each Process has a PCB

Each Thread has a TCB

Shared information is Shared, not Duplicated

Page 22: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Scheduling

Process ConditionsProcessor BoundI/O Bound

Scheduling how?PreemptiveNon-preemptive

Page 23: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

Scheduler Goals

Generic goalsFairness of processor allocationEnforcement of scheduling policiesBalance of utilization

Batch-based goalsThroughput of jobsTurnaround on jobs

Page 24: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

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

Page 25: ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.

The End