Process Management and FreeBSD Process Structure - Prof. Stephen Chapin, Study notes of Operating Systems

An overview of process management concepts, including definitions of key terms like process, user mode, kernel mode, user state, and kernel state. It also discusses scheduling and the historical development of multiprogramming in unix. The second part of the document delves into the specifics of the freebsd process structure, including its main entries, substructures, and states. It covers process id, signal state, tracing information, real-time timer and cpu utilization, process group id, credentials, memory management, file descriptors, system call vector, resource accounting, statistics, and signal actions.

Typology: Study notes

Pre 2010

Uploaded on 08/09/2009

koofers-user-c56
koofers-user-c56 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Process Management
Process Management
CIS 657
CIS 657
Definitions
Definitions
Process: program under exe cution
Process: program under exe cution
User mode:
User mode:
normal
normal
execution mode
execution mode
Kernel mode: privileged exe cution mode; required for,
Kernel mode: privileged exe cution mode; required for,
e.g., I/O operations
e.g., I/O operations
User state: registers, PC, PS W, stack pointers, plus
User state: registers, PC, PS W, stack pointers, plus
memory contents
memory contents
Kernel state:
Kernel state:
Process st ructure (always resident)
Process structure (alw ays resident)
User struc ture (only resident when process i s; very little left in
User structure (only re sident when process is; very little left in
FreeBSD 5.2.1)
FreeBSD 5.2.1)
Multiprogramming and
Multiprogramming and
Multitasking Support
Multitasking Support
Context switching: changing the currently
Context switching: changing the currently
running process (changing execution cont ext)
running process (changing execution cont ext)
Hardware dependent; some I SA define instructions
Hardware dependent; some ISA define instructions
to save processor context; ot hers must explicitly
to save processor context; ot hers must explicitly
save
save
Kernel software state saved/l oaded explicitly
Kernel software state saved/ loaded explicitly
Optimization is a very good id ea
Optimization is a very good i dea
Scheduling: deciding which process to run next
Scheduling: deciding which process to run next
Related to CS, in that the CS just picks the process
Related to CS, in that the CS just picks the process
at the head of the ready que ue; scheduler maintains
at the head of the ready que ue; scheduler maintains
ready queue
ready queue
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Process Management and FreeBSD Process Structure - Prof. Stephen Chapin and more Study notes Operating Systems in PDF only on Docsity!

Process Management Process Management

CIS 657CIS 657

Definitions

Definitions

 Process: program under executionProcess: program under execution

 User mode:User mode: ““normalnormal”” execution modeexecution mode

 Kernel mode: privileged execution mode; required for,Kernel mode: privileged execution mode; required for,

e.g., I/O operationse.g., I/O operations

 User state: registers, PC, PSW, stack pointers, plusUser state: registers, PC, PSW, stack pointers, plus

memory contentsmemory contents

 Kernel state:Kernel state:

 Process structure (always resident)Process structure (always resident)

 User structure (only resident when process is; very little left inUser structure (only resident when process is; very little left in

FreeBSD 5.2.1) FreeBSD 5.2.1)

Multiprogramming and Multiprogramming and

Multitasking Support

Multitasking Support

 Context switching: changing the currentlyContext switching: changing the currently

running process (changing execution context)running process (changing execution context)

 Hardware dependent; some ISA define instructions

Hardware dependent; some ISA define instructions

to save processor context; others must explicitly to save processor context; others must explicitly

save save

 Kernel software state saved/loaded explicitlyKernel software state saved/loaded explicitly

 Optimization is a very good idea

Optimization is a very good idea …

 Scheduling: deciding which process to run nextScheduling: deciding which process to run next

 Related to CS, in that the CS just picks the process

Related to CS, in that the CS just picks the process

at the head of the ready queue; scheduler maintains at the head of the ready queue; scheduler maintains

ready queue ready queue

Historical Comment Historical Comment

 Early UEarly UNIXNIX didndidn’’t have multiprogrammingt have multiprogramming

support: only one process in memory at a timesupport: only one process in memory at a time

 MMU support allowed multiple processes, butMMU support allowed multiple processes, but

synchronous disk I/O meant no multitasking

synchronous disk I/O meant no multitasking

(no automatically switching between(no automatically switching between

processes)processes)

 In 1972 asynchronous disk I/O made itIn 1972 asynchronous disk I/O made it

possible to switch between processes, sopossible to switch between processes, so

UUNIXNIX got real multitasking.got real multitasking.

Scheduling

Scheduling

 Processes haveProcesses have ““burstsbursts”” of activity (both CPUof activity (both CPU

bursts and I/O bursts)bursts and I/O bursts)

 We characterize processes by the ratio of

We characterize processes by the ratio of

these bursts:

these bursts:

 Lots of I/O, little CPU: I/O bound (interactive)Lots of I/O, little CPU: I/O bound (interactive)

 Lots of CPU, little I/O: CPU bound (

Lots of CPU, little I/O: CPU bound ( noninteractive

noninteractive )

)

 Real-time processes must haveReal-time processes must have subportionssubportions

completed by particular deadlines; think ofcompleted by particular deadlines; think of

factory-floor automation.factory-floor automation.

BSD Scheduling

BSD Scheduling

 BSD uses a priority-based round robinBSD uses a priority-based round robin

scheme favoring interactive processesscheme favoring interactive processes

 Processes have dynamic prioritiesProcesses have dynamic priorities

Jobs get a time slice

Jobs get a time slice

 Complete your time slice: priority dropsComplete your time slice: priority drops

 Give up the CPU before the end: priority

Give up the CPU before the end: priority

stays the same

stays the same

 Inactive processes have priority increasedInactive processes have priority increased

5.2.1 FreeBSD Process Structure 5.2.1 FreeBSD Process Structure

Process

Structure

Thread list

process group

credential

VM space

file descriptors

resource limits

statistics

signal actions

process control block

process kernel stack

session

region list

file entries

syscall vector user structure

Thread List Entries

Thread List Entries

Pointer from

Process Struct

Scheduling info

Thread control block

Thread kernel stack

Machine-dependent

Thread information

Scheduling info

Thread control block

Thread kernel stack

Machine-dependent

Thread information

Process Structure Main Entries

Process Structure Main Entries

 Process ID: process id and parentProcess ID: process id and parent

PIDPID

 Signal state: signals pendingSignal state: signals pending

delivery, current mask, and actions

delivery, current mask, and actions

Tracing information

Tracing information

Real-time timer and CPU utilization

Real-time timer and CPU utilization

counterscounters

Process Structure SubstructuresProcess Structure Substructures

 Process group ID: process group andProcess group ID: process group and

session for this processsession for this process

 Credentials: real, effective, and savedCredentials: real, effective, and saved

UID and GIDUID and GID

 Memory Management: virtual addressMemory Management: virtual address

space management (page tables)space management (page tables)

File descriptors: pointers to open file

File descriptors: pointers to open file

entries and

entries and

cwd

cwd

Process Structure Substructures II

Process Structure Substructures II

 System call vector: FreeBSD supports systemSystem call vector: FreeBSD supports system

call numbering for Linux, OSF/1, SVR4.call numbering for Linux, OSF/1, SVR4.

 Resource Accounting: system/user time used,

Resource Accounting: system/user time used,

memory allocation, paging and disk I/O, etc.memory allocation, paging and disk I/O, etc.

 Statistics (kept in user structure): accountingStatistics (kept in user structure): accounting

informationinformation

 Signal actions (kept in user structure): pointersSignal actions (kept in user structure): pointers

to signal handlers, list of blocked signals, etc.to signal handlers, list of blocked signals, etc.

Process States

Process States

 NEW: process is partially createdNEW: process is partially created

 NORMAL: process has resourcesNORMAL: process has resources

allocated for executionallocated for execution

 RUNNABLE: threads ready to runRUNNABLE: threads ready to run

 SLEEPING: threads awaiting eventSLEEPING: threads awaiting event

 STOPPED: threads stopped by signal orSTOPPED: threads stopped by signal or

parent process parent process

 ZOMBIE: process is partially terminatedZOMBIE: process is partially terminated

256 Priorities and 5 Classes256 Priorities and 5 Classes

224-255224-255IDLEIDLE Idle userIdle user

160-223160-223TIMESHARETIMESHARE Time-sharing userTime-sharing user

128-159128-159REALTIMEREALTIME Real-time userReal-time user

64-12764-127 KERNKERN Top half of kernelTop half of kernel

Bottom half of kernel

Bottom half of kernel

(interrupt)(interrupt)

ITHD

ITHD

RangeRange ClassClass TypeType

Meaning of

Meaning of

Priorities

Priorities

 First, classes arenFirst, classes aren’’t really meaningfult really meaningful

 Highest priority (lowest number) threadHighest priority (lowest number) thread

always* runs

always* runs

 Bottom half > Top half >Bottom half > Top half > RealtimeRealtime >>

Timeshare > IdleTimeshare > Idle

 rtpriortprio() system call sets priority for() system call sets priority for

RealtimeRealtime and Idle threads--not adjustedand Idle threads--not adjusted

by kernel

by kernel

  • Not really.

User

User

vs

vs

. Kernel priority

. Kernel priority

 kg_user_prikg_user_pri field holds current userfield holds current user

priority (that in the TIMESHARE class)priority (that in the TIMESHARE class)

 td_prioritytd_priority may be differentmay be different

 AA thread running in the kernel (e.g., afterthread running in the kernel (e.g., after

system call) has its priority temporarily system call) has its priority temporarily

changed to be in KERN class changed to be in KERN class

 When asleep, and immediately afterWhen asleep, and immediately after

awakened awakened

 Priority for service over user-priority threadsPriority for service over user-priority threads

Queues Queues

 Run queues: hold threads ready to executeRun queues: hold threads ready to execute

 Not a single ready queue;

Not a single ready queue; 64 queues

64 queues

 All

All threads in same queue

threads in same queue are treated as same

are treated as same

priority priority

 Sleep queues: hold threads waiting on events

Sleep queues: hold threads waiting on events

 Hashed data structure, optimized for searching onHashed data structure, optimized for searching on

wait channel wait channel

 In older versions of the OS, these heldIn older versions of the OS, these held

processes, notprocesses, not threadsthreads

Sleep() and Sleep Queues

Sleep() and Sleep Queues

 LOOKUP(x) hashes an identifier to a sleep

LOOKUP(x) hashes an identifier to a sleep

queue (

queue ( kern_synch

kern_synch .c)

.c)

 IdentIdent can be a void *,can be a void *, intint, or other (generally a, or other (generally a

pointer).pointer).

 The sleep routines do not determine howThe sleep routines do not determine how

many identifiers there are in the systemmany identifiers there are in the system

 Threads can give up the CPU by

Threads can give up the CPU by making a

making a

sleep() call (passing wait channel ID and

sleep() call (passing wait channel ID and

priority at which to be awakened)priority at which to be awakened)

Algorithm for Sleep

Algorithm for Sleep

1.1. AcquireAcquire sched_mutexsched_mutex locklock

Record the wait channel in the thread

Record the wait channel in the thread

structure, and hash the channel to find a

structure, and hash the channel to find a

sleep queuesleep queue

3.3. Set the threadSet the thread’’s prioritys priority for when it isfor when it is

awakened, set SLEEPING flagawakened, set SLEEPING flag

4.4. Place thread at end of sleep queuePlace thread at end of sleep queue

5.5. CallCall mi_switchmi_switch() to context switch() to context switch

((sched_locksched_lock automatically released)automatically released)

Process Priority Calculation Process Priority Calculation

 From proc.h:From proc.h:

 kg_estcpukg_estcpu provides estimate of recent CPU utilizationprovides estimate of recent CPU utilization

 kg_nicekg_nice user-settable weighting factor betweenuser-settable weighting factor between – – 2020

and 20 (default 0)

and 20 (default 0)

 Recalculate every 4 ticks:Recalculate every 4 ticks:

kg_user_prikg_user_pri = PRI_MIN_TIMESHARE += PRI_MIN_TIMESHARE +

((kg_estcpukg_estcpu / 4) + 2 x/ 4) + 2 x kg_nicekg_nice;;

 kg_user_pri

kg_user_pri = max(

= max( kg_user_pri

kg_user_pri , PRI_MIN_TIMESHARE)

, PRI_MIN_TIMESHARE)

 kg_user_prikg_user_pri = min(= min(kg_user_prikg_user_pri, PRI_MAX_TIMESHARE), PRI_MAX_TIMESHARE)

 PRI_MIN_TIMESHAREPRI_MIN_TIMESHARE = 160,= 160, PRI_MAX_TIMESHAREPRI_MAX_TIMESHARE = 223= 223

Scheduling Calculations II

Scheduling Calculations II

 kg_estcpukg_estcpu incremented every clock tick forincremented every clock tick for

the current processthe current process

kg_estcpu

kg_estcpu

aged (decayed) every second;

aged (decayed) every second;

forgets about 90% of the history in aforgets about 90% of the history in a

variable time periodvariable time period

Load_weight = (2 * load) / (2 * load + 1);Load_weight = (2 * load) / (2 * load + 1);

kg_estcpukg_estcpu = Load_weight *= Load_weight * kg_estcpukg_estcpu ++ kg_nicekg_nice;;