+ All Categories
Home > Documents > sh (parent)

sh (parent)

Date post: 04-Jan-2016
Category:
Upload: tobias-hatfield
View: 41 times
Download: 0 times
Share this document with a friend
Description:
제 27 강 : estabur(). struct user k-stack. PAR PDR. Kernel a.out. sh (parent). < KERNEL>. ls (child). struct user k-stack. sh a.out. u--stack. At this point, context switch: kernel points to new image. PAR PDR. struct user k-stack. ls a.out. - PowerPoint PPT Presentation
17
1 sh (parent) ls (child) At this point, context switch: kernel points to new image PAR PDR < USER > PAR PDR ls a.ou t u-- stack u-- stack Kerne l a.ou t struct user k- stack struct user k- stack struct user k- stack < KERNEL> sh a.ou t 제 27 제 : estabur()
Transcript

1

sh(parent)

ls(child)

At this point, context switch: kernel points to new image

PAR PDR

< USER >

PAR PDR

lsa.out

u--stack

u--stack

Kernel

a.out

struct user k-stack

struct user k-stack

struct user k-stack

< KERNEL>

sha.out

제 27 강 : estabur()

2

sh(parent)

ls(child)

At this point, context switch: kernel points to new image

PAR PDR

< USER >

PAR PDR

lsa.out

u--stack

u--stack

Kernel

a.out

struct user k-stack

struct user k-stack

struct user k-stack

< KERNEL>

sha.out

retu()

3

Chapter Seven• After copying parent’s image, … • expand() 2250

– change the size of allocated space for user program– expand or shrink memory space– internally, calls malloc() & mfree()

• estabur 1650 (7-4)– now user space addresses are determined– keep note in struct user

• text, data, stack addresses

– invoked whenever expand/shrink/relocated

• sureg (1739) (7-4)– loads these mapping addresses from struct user– into CPU (user) mapping registers

stack

data

text

4

Chapter Seven• After copying parent’s image, … • expand() 2250

– change the size of allocated space for user program– expand or shrink memory space– internally, calls malloc() & mfree()

• estabur 1650 (7-4)– now user space addresses are determined– keep note in struct user

• text, data, stack addresses

– invoked whenever expand/shrink/relocated

• sureg (1739) (7-4)– loads these mapping addresses from struct user– into CPU (user) mapping registers

stack

data

text

PAR PDR

< USER >

5

Chapter Seven• After copying parent’s image, … • expand() 2250

– change the size of allocated space for user program– expand or shrink memory space– internally, calls malloc() & mfree()

• estabur 1650 (7-4)– now user space addresses are determined– keep note in struct user

• text, data, stack addresses

– invoked whenever expand/shrink/relocated

• sureg (1739) (7-4)– loads these mapping addresses from struct user– into CPU (user) mapping registers

stack

data

text

PAR PDR

< USER >

user k-stack

PAR PDR

< KERNEL >

retu()

sureg()

6

PAR PDR

< USER >

PAR PDR

sha.out

u--stack

Kernel

a.out

struct user k-stack

struct user k-stack

lsa.out

u--stack

struct user k-stack

1. Parent is creating child2. fork() allocate memory space for child expand()malloc() 1628

Address for child is determined text, data, stack addresses

CPU needs this addr. whenever ls runs

Save addresses in struct user u estabur()

1629

3. To run Pchild

CPU’s kernel -PAR must point to Pchild

retu() 2228

now, u belongs to arising Pchild

CPU’s user - PAR must point to Pchild

load addresses from (new) u sureg() 2229

retu()

sureg()

< KERNEL>

7

8

1. Creating a new process2. Allocate memory space for new

process expand()malloc()

1628

Address for new process is determined

CPU need this addr. whenever this proc runs

So save this address in struct user estabur()

1629

9

swtch(1) wakeup setrun

Current process retires

Process #0 runs

10

swtch(2)3. Time to run Pchild CPU’s kernel level PAR must point to Pchild retu() 2228

Now, u belongs to arising Pchild CPU’s user level PAR must point to Pchild load addresses from (new) struct user u sureg() 2229

11

CPU & Context Switch

CPUGeneral Register Address Mapping Registers

PAR PDR

User

PAR PDR

KERNEL

R0 R1 R2 R3 R4

EP EP(K)SP SP(K)

sureg() retu()InterruptHandler

retu()

12

Ch 8 When does process switching occur? [Case 1]

– When active process voluntarily gives up CPU• eg tape read cannot be completed immediately • sleep() swtch() savu() retu() …

[Case 2] – CPU is interrupted by urgent job during user mode

[Case 3] – CPU was interrupted by urgent job during kernel

mode• CPU not preempted. Before kernel returns to user mode

…• Kernel tests runrun to check if urgent process is waiting• If yes, call swtch()

– remember critical section problem,…– kernel mode CPU is not preempted immediately– interrupt handler just sets the runrun variable instead

13

1550

main()

1826

newproc()

1940

sched()

2066

sleep()

2178

swtch()

1627

2084

1968

1637

14

schedSwapping Manager

calls sleep()

15

PS (line # 0164) --- CPU PSW (see 2095)rp is proc[] of current process

waiting eventupdate proc[] state

priority

no interrupt here please (mutual exclusion) interrupt handler also changes process state

swtch()

Will not return for a very long time

process running in kernel mode

calls sleep() to give up CPU

Waiting event -- eg &buffer: use address as a bit pattern

Has been saved before swtch( ) at 2065

16

swtch(1) wakeup setrun

wakeup( ) (2113) (8-3)Wakes up ALL processes waiting for chan:

i.e. (i from 0 to NPROC)Why?

Some events are exclusive eg buffer for DMA Other events are shared eg “Printer Power ON” So, the caller of sleep() must determine …

calls setrun()

setrun ( ) (2134)just change process state in proc[] – SRUN = readyIs waking process higher priority than current process?this process will be dispatched later at that point (on return from sleep()), waking process checks whether the reason for sleeping has gone away in other words – it could be a premature return …. (eg -- other process took away the only buffer …)

17

swtch(2)


Recommended