Docstoc

Implementing Unix Processes

Document Sample
Implementing Unix Processes Powered By Docstoc
					Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Processes: Unix way of Implemntation
Arvind W. Kiwelekar akiwelekar@gmail.com 02140262041

January 27, 2009

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Uninx Memory Model

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Why we need Virtual Memory management scheme?
1 High-level Language Program 2 3 4 5

Compiler

Machine-level Language Program

1024

Logical Address and Physical Memory Address
Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Separting reference of program element from it’s actual location in memory
◮

Context (i) More than one program resides in memory. (ii) Exact size of physical memory is not in advance. Problems (i) Overlapping of physical memory locations (ii)Address generated by a compiler may exceed boundry of .physical memory. (iii) Programms need to be loaded in contiguous memory locations. Solution Separates address reference of an intstruction or data from it’s actual location. Techniques Used Virtual Memory. Consequences More time required to refer a memory element.

◮

◮

◮ ◮

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Use of Indirection
Process Physical Memory Page 1 Text Region Table Page 2

Data

Page 3

Page n-1 Stack

Page n

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Unix Memory Model
Physical Memory Process Table Per Process Region Table Region Table Page 1

Page 2

Page 3

Page n-1

Page n

Why this extra level of indirection?
Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

An Actual Example
empty 137k 852k 764k 433k Per Process Region Table 8k 333k Region Table 87k 252k 727k 941k 1096k

Page Size 1 KB Virtual Address 68432 68432-65536 =2896-2048 =848 =986K+848 =1010512

32k 64k

541k 783k 986k 896k

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Features of Unix Memory Model
◮

Address space of a process is divided in three logical regions called text, data, and stack. Logical region are contiguous memory locations. Physical memory area is divided into equal sized memory pages. Per process region table, region table are main data structure used to manage memory. Stack is a dynamic memory area used to store PCB when process performs a function call.

◮ ◮

◮

◮

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Role of Stack Region (Scenario 1 Only User Defined Functions)
main ( ) { int i ; userFun1 ( i ) ;
addr of Frame 1

}
Frame 2

local var c = parameters for userFun1() Address of the instruction to be executed after userFun1() addr of Frame 0 local var i = Frame 1 parameters for main() Address of the instruction to be executed after main()

userFun1 (){ int c userFun2 ( c ) } userFun2 (){ int a; }
Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Role of Stack Region (Scenario 2 User Defined and system Functions)
main ( ) { int i ; userFun1 ( i ) ; } userFun1 (){ int c fork (); } userFun2 (){ int a; }
Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation
Frame 2

User Stack

Kernel Stack

addr of Frame 1 local var c = parameters for userFun1() Address of the instruction to be executed after userFun1() addr of Frame 0 local var i = Frame 1 parameters for main() Address of the instruction to be executed after main() Frame 1 addr of Frame 0 local var in fork parameters for fork() Address of the instruction to be executed after fork()

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Separting Syscall processing from User defined functions

◮

Unix processes access kernel functionality by calling a system call (eg. fork, creat, write) When a syscall is called it executes a hardware inteerupt call trap that swiches process to kernel model. For each process two different stacks are used one to process user function and other to process syscall.

◮

◮

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Kernel Memory Map
Addr of Page Table Kernel Register Triple 1 Kernel Register Triple 2 Kernel Register Triple 3 VA 0 1M 2M 4M User Register Triple 1 User Register Triple 2 User Register Triple 3 Number of Pages

User Process Region Table

Kernel Page Table

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Unix Process Model

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Process State Diagram
intReturn, interrupt() syscall, interrupt() 1 user Running returnTo User() 7 preempt()

return() 9 zombie 2 kernel Running sleep()

exit()

preempted

asleepIn Memory

4

wakeUp()

3

ready2Run, inMemory enough Memory()

swap out()

swap out()

swapIn()

8

fork() created

notEnough Memory() 6 sleep, swapped wakeUp() 5 ready2Run, swapped

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Public Data Fields of the Process Table

ProcessTable
+state +uArea +userID +PID(Parent) +eventDescriptor +schedulingParameter +signalToBeHandled +timers

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Private Data Fields of Process Table
uArea
+processTable +userID +timers(user,kernel) +signalHandling +loginTerminal +sysCallErrors +syscallReturn +I/oPArameters +pwd +userFileDescriptor +limitFields +permissionModes
Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Process Context
◮

User-Level Context ◮ Program Text ◮ Data Region ◮ Stack Region ◮ Shared Memory Register-Level Context ◮ Program Counter ◮ Stack Pointer ◮ Program Status Register ◮ Gneral Purpose Register System-Level Context ◮ Process table entry ◮ u-area ◮ Pregion entry, region tables, page table ◮ The kernel stack

◮

◮

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Main Events that cause Context Saving

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Algorithms for Handling Interrupt

algroithm inthand i n p u t : none o u t n o n e : none { save c u rre n t context l a y e r ; determine i n t e r r u p t source ; fi n d i n t e r r u p t vecto ; c a l l interrupt handler ; restore previous context layer ; }

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Algorithms for invoking system call
algroithm s y sc a l l i n p u t : Syste m C a l l number o u t n o n e : R e s u l t o f Syste m C a l l { f i n d e n t r y i n system c a l l t a b l e c o r r e s p o n d i n g t o s y s t e m c a l l number d e t e r m i n e number o f p a r a m e t e r s t o s y s t e m c a l l c opy p a r a m e t e r s from u s e r a d d r e s s s p a c e t o u−a r e a save current context fo r a b o r t iv e return i n v o k e s y s t e m c a l l c ode i n k e r n e l i f ( e r r o r duri ng e x e c u t i o n of system c a l l ) { s e t r e g i s t e r 0 i n u s e r saved r e g i s t e r c onte xt to errNo t u r n on c a r r y b i t i n PS r e g i s t e r i n u s e r s a v e d r e g i s t e r c o n t e x t } else s e t r e g i s t e r s 0 , 1 i n u s e r saved r e g i s t e r c onte xt to r e t u r n v a l u e s }

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation

Unix Memory Model

Unix Process Model

Main Events that cause Context Saving

Context Switch

algroithm switchContext i n p u t : none o u t n o n e : none { D e c i d e w h e t h e r t o do a c o n t e x t s w i t c h and w h e t h e r a c o n t e x t s w i t c h i s p e r m i s s b l e now ; Save t h e c o n t e x t o f t h e o l d p r o c e s s ; f i n d the b e s t p ro c e s s to s c h e d u l e f o r e xe c u t i o n ; restore it ’ s context layer ; }

Arvind W. Kiwelekar akiwelekar@gmail.com02140262041 Processes: Unix way of Implemntation


				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:198
posted:1/28/2009
language:English
pages:22