Operating Systems Principles Process Management and Coordination Lecture 4: The Operating System Ker - PowerPoint PPT Presentation

1 / 143
About This Presentation
Title:

Operating Systems Principles Process Management and Coordination Lecture 4: The Operating System Ker

Description:

Main Topics in the Lecture. Process and thread management. Interrupt and trap handling ... Point to the PCB of the parent process. A link list of PCBs of the ... – PowerPoint PPT presentation

Number of Views:910
Avg rating:3.0/5.0
Slides: 144
Provided by: taiwe
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems Principles Process Management and Coordination Lecture 4: The Operating System Ker


1
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • ??????

2
Content
  • Kernel Definitions and Objects
  • Queue Structures
  • Threads
  • Implementing Processes and Threads
  • Process and Thread Descriptors
  • Implementing the Operations
  • Implementing Sync/Comm Mechanisms
  • Semaphores and Locks
  • Building Monitor Primitives
  • Clock and Time Management
  • Communications Kernel
  • Interrupt Handling

3
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Kernel Definitions and Objects

4
Windows Kernel
5
Windows Kernel
Hardware dependent functions are placed in the
kernel.
6
OS Kernel
  • A basic set of objects, primitives, data
    structures, processes from which the remainder of
    the system may be built on its top.
  • In other words, the kernel transforms the
    hardware into an OSs machine.

7
OSs Machine
I am staying on the top of an OS machine.
8
Kernel Objects
  • Kernel defines/provides mechanisms to implement
    various policies.
  • Four classes of possible functions and objects in
    a kernel
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output

9
Kernel Objects
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output
  • Process and thread management
  • Process Creation
  • Process Destruction
  • Process Communication/Synchronization

10
Kernel Objects
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output
  • Interrupt and trap handling
  • Responding to signals triggered by various system
    events.
  • Some system events
  • Process termination
  • I/O completion
  • Time-out of clock
  • Error
  • Hardware malfunction

11
Kernel Objects
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output
  • Interrupt and trap handling
  • Responding to signals triggered by various system
    events.

...... ...... ......
...... Do_I/O ......
Start I/O
Interrupt Service Routine
12
Kernel Objects
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output
  • Resource management
  • Primitives for maintaining, allocating, and
    releasing system resources.
  • Some system resources
  • CPUs
  • Timers
  • Main memory
  • Secondary storage
  • I/O devices
  • Files

13
Kernel Objects
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output
  • Input/output
  • Read, write, and control operations for
    initiating and supervising the transfer of data
    between I/O devices and main memory or registers.

14
Main Topics in the Lecture
  • Process and thread management
  • Interrupt and trap handling
  • Resource management
  • Input/output

Main topics
15
Process Creation Hierarchy
Kernel
ps
OS process
user 1 login
user j login
user n login
user processes
. . .
. . .
application processes.
. . .
Interaction with kernel objects
16
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Queue Structures

17
Queues
  • OS needs many different queues
  • e.g., ready queues, wait queues.
  • Single-level queues
  • Implemented as array
  • Fixed size
  • Efficient for simple FIFO operations
  • Implemented as linked list
  • Unbounded size
  • More overhead, but more flexible operations

18
Single-Level Queues
Circular Array Implementation
Link List Implementation
19
Priority Queues
Array indexed by priority
20
Priority Queues
Binary heap of priority
21
Priority Queues
Binary heap of priority
Array implementation of binary heap
22
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Threads

23
Address Spaces
Virtual Memory
Memory
24
Address Spaces
Virtual Memory
Memory
OS
User Programs
25
Processes
Only one process can be activated at a time.
Each process thinks that it owns all memory.
Their address spaces are different.
26
Context Switching
Only one process can be activated at a time.
Each process thinks that it owns all memory.
Context Switching
Context Switching
27
Context Switching
Only one process can be activated at a time.
Each process thinks that it owns all memory.
The context switching among processes, i.e., to
change address space, is very time consuming.
28
Threads
  • Each process can have multiple threads.
  • They share the same address space.
  • The context switching among threads in the
    process is efficient.
  • Lightweight process ? Mesa

29
Processes and Threads
30
Processes and Threads
  • Process has one or more threads
  • All threads in a process share
  • Memory space
  • Other resources
  • Each thread has its own
  • CPU state(registers, program counter)
  • Stack
  • Threads are efficient, but lack protection from
    each other

31
OS Support for Processes/Threads
Microsoft Windows
Process Thread Functions
  • Create a new Process/thread
  • Initiate or make a thread ready
  • Destroy or terminate a thread
  • Delay or put a thread to sleep for a given amount
    of time
  • Synchronize threads through semaphore, events, or
    condition variables
  • Perform lower-level operations, such as blocking,
    suspending, or scheduling a thread.

32
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Implementing
  • Processes and Threads

33
Process and Thread Descriptors
  • System needs some data structures to keep track
    the state and miscellaneous information, e.g.,
    identification, resources used, accounting
    information, of processes and treads.
  • In the following, we are dealing with a system
    composed solely of processes, much of concept
    will also apply to threads.

34
Process Control Block (PCB)
35
Process Identification
A system-wide unique identifier.
36
State Vector
37
CPUs State
Contain necessary data, e.g., program counter,
data register, and flag register, to restart
the process at the point of last interruption.
38
Processor ID
To identify the processor that is executing the
process. Make sense only for multiprocessor
system.
39
Memory
Memory map information. Physical Memory ? Virtual
Memory
40
Status
41
Status
Point to the list, e.g., ready list or wait list,
on which the process may reside.
42
More on Status
  • Basic process status
  • running, ready, and blocked
  • State transition diagram

43
Process Activation and Suspension
Suspend Thread
Resume Thread
  • Some applications require a process (or thread)
    can be suspended by programs.
  • For examples
  • Suspension of a debugging program
  • Needed by the internal, e.g., to detect or
    prevent a deadlock.

44
The Finer State Transition Diagram
45
The Finer State Transition Diagram
Active Processes
Suspended Processes
46
Creation Tree
47
Creation Tree
A link list of PCBs of the child processes
Point to the PCB of the parent process.
48
Priority
  • Two methods
  • Single-integer value
  • Two-leveled valued
  • Base priority Changeable part

Used by scheduler to decide which process should
be running next.
49
Priority
  • Two methods
  • Single-integer value
  • Two-leveled valued
  • Base priority Changeable part

Windows NT priority classes
50
Others
  • CPU time used
  • Time remaining
  • Resource used
  • Resource claimed
  • Resource quotas
  • Number of I/O requests since creation
  • . . .

51
Processes and Threads (Windows 2000)
52
Windows 2000 (EPROCESS)
Executive Process
53
Kernel Process Block
54
Processes and Threads (Windows 2000)
EPROCESS
ETHREAD
55
Windows 2000 (ETHREAD)
56
Kernel Thread Block
57
Windows 2000 Thread States
58
Implement Operations on Processes
  • Create
  • Establish a new process
  • Destroy
  • Remove one or more process
  • Suspend
  • Change process status to suspended
  • Activate
  • Change process status to active

cobegin/coend forall fork/join/quit
. . . . . .
59
Implement Operations on Processes
  • Create
  • Establish a new process
  • Destroy
  • Remove one or more process
  • Suspend
  • Change process status to suspended
  • Activate
  • Change process status to active

Operating on PCBs CSs must be cared
60
Create
61
Create
Create(s0, m0, pi, pid) p Get_New_PCB()
pid Get_New_PID() p-gtID pid
p-gtCPU_State s0 p-gtMemory m0
p-gtPriority pi p-gtStatus.Type
ready_s p-gtStatus.List RL
p-gtCreation_Tree.Parent self
p-gtCreation_Tree.Child NULL insert(self-gt
Creation_Tree.Child, p) insert(RL, p)
Activate() Scheduler()
pid Get_New_PID()
Get_New_PCB()
s0
m0
ready_s
RL
self
NULL
pi
62
Create
Create(s0, m0, pi, pid) p Get_New_PCB()
pid Get_New_PID() p-gtID pid
p-gtCPU_State s0 p-gtMemory m0
p-gtPriority pi p-gtStatus.Type
ready_s p-gtStatus.List RL
p-gtCreation_Tree.Parent self
p-gtCreation_Tree.Child NULL insert(self-gt
Creation_Tree.Child, p) insert(RL, p)
Activate() Scheduler()
The calling process
63
Create
Create(s0, m0, pi, pid) p Get_New_PCB()
pid Get_New_PID() p-gtID pid
p-gtCPU_State s0 p-gtMemory m0
p-gtPriority pi p-gtStatus.Type
ready_s p-gtStatus.List RL
p-gtCreation_Tree.Parent self
p-gtCreation_Tree.Child NULL insert(self-gt
Creation_Tree.Child, p) insert(RL, p)
Activate() Scheduler()
64
Suspend
65
Suspend
Suspend ( )
Suspend?
We choose not.
66
Suspend
Suspend(pid) p Get_PCB(pid) s
p-gtStatus.Type if ((sblocked_a)(sblo
cked_s)) p-gtStatus.Type blocked_s
else p-gtStatus.Type ready_s if
(srunning) cpu p-gtProcessor_ID
p-gtCPU_State Interrupt(cpu) Scheduler()

returns all registers values of the cpu and
frees the cpu.
67
Activate
68
Activate
Activate ( )
Activate?
We choose not.
69
Activate
Activate(pid) p Get_PCB(pid) if
(p-gtStatus.Type ready_s)
p-gtStatus.Type ready_a Scheduler()
else p-gtStatus.Type blocked_a
70
Destroy
We need to release all resources associated with
the process.
What special action needs to be taken if the
process is running?
71
Destroy
Destroy ( )
Killed?
We choose to kill child processes.
72
Destroy
subroutine Kill_Tree ( )
killed
Kill_Tree(p) for (each q in
p-gtCreation_Tree.Child) Kill_Tree(q) if
(p-gtStatus.Type running) cpu
p-gtProcessor_ID Interrupt(cpu)
Remove(p-gtStatus.List, p) Release_all(p-gtMemo
ry) Release_all(p-gtOther_Resources)
Close_all(p-gtOpen_Files) Delete_PCB(p)
Marked the corresponding cpu free.
73
Destroy
subroutine Kill_Tree ( )
killed
Kill_Tree(p) for (each q in
p-gtCreation_Tree.Child) Kill_Tree(q) if
(p-gtStatus.Type running) cpu
p-gtProcessor_ID Interrupt(cpu)
Remove(p-gtStatus.List, p) Release_all(p-gtMemo
ry) Release_all(p-gtOther_Resources)
Close_all(p-gtOpen_Files) Delete_PCB(p)
74
Destroy
Destroy ( )
Destroy(pid) p Get_PCB(pid)
Kill_Tree(p) Scheduler()
75
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Implementing
  • Sync/Comm Mechanisms

76
General Resource Access Scheme
Semaphores, locks, monitors, messages, time, and
other hardware and software objects are
considered resources.
Request(res) if (Free(res)) Allocate(res,
self) else Block(self, res)
Scheduler()
Release(res) Deallocate(res, self) if
(Process_Blocked_in(res,pr)) Allocate(res,
pr) Unblock(pr, res) Scheduler()
77
Implementing Semaphores/Locks
  • CPU usually doesnt support P and V operations
    directly.
  • Test-and-Set instruction ? supported mostly
  • It atomically tests and modifies the contents of
    a memory location.
  • It can be used to implement general semaphores in
    multiprocessor systems.
  • In uniprocessor systems, it is sufficient to
    disable interrupts before accessing a semaphore.

78
The Story (80x86)
79
The Story (80x86)
Access resource
80
The Story (80x86)
Access resource
Lock XCHG
81
The Story (80x86)
Access resource
82
The Story (80x86)
The spin locks
Access resource
Lock XCHG
83
The Story (80x86)
The spin locks
Job Done
Access resource
Lock XCHG
84
The Story (80x86)
The spin locks
Job Done
Access resource
85
The Story (80x86)
The spin locks
Job Done
Access resource
Lock XCHG
86
Test-and-Set CPU Instruction
TS(R, X)
R X
Indivisible Atomic
0 locked is locked
1 locked is unlocked
X 0
87
Spin Locks on Binary Semaphore
sb ? 0, 1
Request( res ) if (Free(res))
Allocate(res, self) else Block(self,
res) Scheduler()
Release( res ) Deallocate(res, self) if
(Process_Blocked_in(res,pr)) Allocate(res,
pr) Unblock(pr, res) Scheduler()
88
Spin Locks on Binary Semaphore
sb ? 0, 1
Request( res ) if (Free(res))
Allocate(res, self) else Block(self,
res) Scheduler()
Release( res ) Deallocate(res, self) if
(Process_Blocked_in(res,pr)) Allocate(res,
pr) Unblock(pr, res) Scheduler()
Pb
Sb
Sb
Vb
Sb1
Sb1
Sb0
wait until Sb1
89
Spin Locks on Binary Semaphore
sb ? 0, 1
Pb(Sb) do TS(R, Sb) while(!R)/ wait
loop /
Vb(Sb) Sb1
90
Spin Locks on Binary Semaphore
sb ? 0, 1
Pb(Sb) do TS(R, Sb) while(!R)/ wait
loop /
Vb(Sb) Sb1
91
General Semaphores w/ Busy Wait
P(s) Inhibit_Interrupts Pb(mutex_s) s
s-1 if (s lt 0) Vb(mutex_s)
Enable_Interrupts Pb(delay_s)
Vb(mutex_s) Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s) s
s1 if (s lt 0) Vb(delay_s) else
Vb(mutex_s) Enable_Interrupts
92
Disallowing Preemption
P(s) Inhibit_Interrupts Pb(mutex_s) s
s-1 if (s lt 0) Vb(mutex_s)
Enable_Interrupts Pb(delay_s)
Vb(mutex_s) Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s) s
s1 if (s lt 0) Vb(delay_s) else
Vb(mutex_s) Enable_Interrupts
Disallowed to be preempted by a higher-priority
process.
Disallowed to be preempted by a higher-priority
process.
93
Interrupt Inhibition
P(s) Inhibit_Interrupts Pb(mutex_s)
s s-1 if (s lt 0) Vb(mutex_s)
Enable_Interrupts Pb(delay_s)
Vb(mutex_s) Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s)
s s1 if (s lt 0) Vb(delay_s) else
Vb(mutex_s) Enable_Interrupts
94
Uniprocessor
P(s) Inhibit_Interrupts Pb(mutex_s)
s s-1 if (s lt 0) Vb(mutex_s)
Enable_Interrupts Pb(delay_s)
Vb(mutex_s) Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s)
s s1 if (s lt 0) Vb(delay_s) else
Vb(mutex_s) Enable_Interrupts
95
Busy Wait
P(s) Inhibit_Interrupts Pb(mutex_s)
s s-1 if (s lt 0) Vb(mutex_s)
Enable_Interrupts Pb(delay_s)
Vb(mutex_s) Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s)
s s1 if (s lt 0) Vb(delay_s) else
Vb(mutex_s) Enable_Interrupts
96
Avoiding Busy Wait
P(s) Inhibit_Interrupts Pb(mutex_s)
s s-1 if (s lt 0) Block(self, Ls)
Vb(mutex_s) Enable_Interrupts
Scheduler() else Vb(mutex_s)
Enable_Interrupts
V(s) Inhibit_Interrupts Pb(mutex_s)
s s1 if (s lt 0) Unblock(q, Ls)
Vb(mutex_s) Enable_Interrupts
Scheduler() else Vb(mutex_s)
Enable_Interrupts
97
Implementing Monitors (Hoare)
Initial values
mutex 1 condsem_c 0 urgent 0
condcnt_c 0 urgentcnt 0
condcnt_c processes wait on c
Need a semaphore for processes blocked on c, say
condsem_c.
c.wait c.signal
Need a semaphore for signaling processes, say
urgent.
mutually exclusive access for processes
urgentcnt signalers
Need a mutex, say mutex.
98
Mutual Access of Processes
Initial values
mutex 1 condsem_c 0 urgent 0
condcnt_c 0 urgentcnt 0
monitor QueueHandler struct Queue
queue condition itemAvail, freenodeAvail void
AddToQueue( int val ) if ( queue is full )
freenodeAvail.wait . . . add val to the end
of the queue . . . itemAvail.signal /
AddToQueue / int RemoveFromQueue() if ( queue
is empty ) itemAvail.wait . . . remove
value from queue . . . freenodeAvail.signal ret
urn value / RemoveFromQueue /
99
Mutual Access of Processes
Initial values
mutex 1 condsem_c 0 urgent 0
condcnt_c 0 urgentcnt 0
monitor QueueHandler struct Queue
queue condition itemAvail, freenodeAvail void
AddToQueue( int val ) if ( queue is full )
freenodeAvail.wait . . . add val to the end
of the queue . . . itemAvail.signal /
AddToQueue / int RemoveFromQueue() if ( queue
is empty ) itemAvail.wait . . . remove
value from queue . . . freenodeAvail.signal ret
urn value / RemoveFromQueue /
100
Mutual Access of Processes
Initial values
mutex 1 condsem_c 0 urgent 0
condcnt_c 0 urgentcnt 0
P(mutex)
Procedure_body
if(urgentcnt) V(urgent) else V(mutex)
101
wait/signal
Initial values
mutex 1 condsem_c 0 urgent 0
condcnt_c 0 urgentcnt 0
c.wait
c.signal
condcnt_c condcnt_c 1 if (urgentcnt)
V(urgent) else V(mutex) P(condsem_c) / wait
/ condcnt_c condcnt_c - 1
if (condcnt_c) urgentcnt urgentcnt 1
V(condsem_c) P(urgent) / wait /
urgentcnt urgentcnt - 1
102
Clock and Time Management
  • Why OS needs time?
  • Performance measurement
  • Processor Scheduling
  • Time-Stamping Events
  • e.g., I/O and file system call
  • Deadlock and other fault detection
  • . . . . . . . .

103
Clock and Time Management
  • Most systems provide hardware
  • ticker issues periodic interrupt
  • countdown timer issues interrupt after a set
    number of ticks
  • Build higher-level services with this h/w
  • Wall clock timers
  • Typical functions
  • Update_Clock increment tnow (invoked each time
    tick)
  • Get_Time return current time
  • Set_Time(tnew) set time to tnew
  • Must maintain monotonicity

104
Countdown Timer (Alarm Clocks)
  • Processes or threads may need timeout signal at
    some specified time in the future.
  • Examples
  • Delay an amount of time to wait I/O completion
  • Sleep to hand over CPU time
  • Block until awakened by timer signal events
  • Typical Function
  • Delay(tdel)? block process for tdel time units

105
Implementation of Delay(tdel)
To block process for tdel time units.
  • Implementation using hardware countdown

semaphore delsem Delay(tdel)
Set_Timer(tdel) /set hardware timer/
P(delsem) /wait for interrupt/ Timeou
t() /called at interrupt/ V(delsem)
106
Logical Countdown Timers
How to implement multiple logical timers?
  • Implement multiple logical countdown timers using
    a single hardware timer
  • Functions
  • tn Create_LTimer() ? create new timer
  • Destroy_LTimer(tn)
  • Set_LTimer(tn, tdel) ? logically equivalent to
    Set_Timer(tdel)

107
Priority Queue withAbsolute Wakeup Times
Set_LTimer(tn, tdel)
Hardware Timers
108
Priority Queue withAbsolute Wakeup Times
Set_LTimer(??, 35)
Wall-clock
Hardware Timers
103
109
Priority Queue withAbsolute Wakeup Times
Wall-clock
Countdown
Hardware Timers
104
105
106
107
108
109
110
111
112
113
114
115
103
12
11
10
9
8
7
6
5
4
3
2
1
0
TQ
p5
138
p4
150
110
Priority Queue withAbsolute Wakeup Times
Wall-clock
Countdown
Hardware Timers
115
115
0
20
TQ
p5
138
p4
150
111
Priority Queue with Time Differences
Set_LTimer(tn, tdel)
Hardware Timer
112
Priority Queue with Time Differences
Set_LTimer(??, 35)
Countdown
Hardware Timer
12
12
32
37
32
37
47
35
113
Priority Queue with Time Differences
Countdown
Hardware Timers
12
11
10
9
8
7
6
5
4
3
2
1
0
TQ
p5
3
p4
10
114
Priority Queue with Time Differences
Countdown
Hardware Timers
0
20
TQ
p5
3
p4
10
115
Communication Primitives
Assume that the communication processes are in
the same machine.
Memory
Memory
OS
OS
The same physical memory used.
Process q
Process p
Different physical memory used.
Address space for process q
Address space for process p
116
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
Communication send/receive
Process q
Process p
Address space for process q
Address space for process p
117
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
Process q
Process p
send(p,m)
receive(q,m)
sbuf
rbuf
Address space for process q
Address space for process p
118
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
Different address mappings for p and q.
Process q
Process p
send(p,m)
receive(q,m)
How?
Address space for process q
Address space for process p
119
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
sbuf
sbuf
send(p,m)
Process q
Process p
send(p,m)
Address space for process q
Address space for process p
120
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
rbuf
rbuf
sbuf
sbuf
send(p,m)
Process q
Process p
receive(q,m)
rbuf
Address space for process q
Address space for process p
121
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
rbuf
rbuf
sbuf
sbuf
send(p,m)
Process q
Process p
receive(q,m)
rbuf
Address space for process q
Address space for process p
122
Communication Primitives
send/receive can be blocked or nonblocked.
OS
OS
rbuf
rbuf
sbuf
sbuf
send(p,m)
Process q
Process p
receive(q,m)
rbuf
Address space for process q
Address space for process p
123
Communication Primitives
Use pool of system buffers
Copying through system buffers (Processes in the
same machine)
124
Communication Primitives
Use pool of system buffers
Copying accross network (Processes in the
different machines)
125
Operating Systems PrinciplesProcess Management
and CoordinationLecture 4The Operating System
KernelImplementing Processes and Threads
  • Interrupt Handling

126
Why Interrupt Handling?
The program to serve interrupt is called
interrupt handler (IH) or interrupt service
routine (ISR).
  • Many events occur at an unpredictable time, i.e.,
    asynchronously
  • Polling is impractical
  • Transfer of control out of normal process
    temporarily upon coming of an event and, then,
    back.
  • To remove the notion of asynchronous events from
    higher levels of kernel, the OS, and applications
  • Process abstraction processes are almost to have
    independent activities and operating in parallel.
  • For example, OS and applications dont deal with
    I/O completion event directly.

127
Types of Interrupt
We deal with hardware interrupt in the following.
  • External Interrupts
  • Generated by hardware
  • Asynchronous
  • E.g., I/O completion, time-out, the arrival of
    message (network card),
  • Internal Interrupts
  • Generated by software
  • Synchronous
  • E.g., Exceptions (instruction errors), SVC

128
Interrupt Controller (82C59A)
129
Interrupt Controller (82C59A)
80x86 uses STI and CLI to temporarily enable and
disable all interrupts, respectively.
Interrupt requests are priority-leveled. IHs of
high-priority events can preempt those of lower
priority.
to CPU
Signaled By I/O Devices
Interrupt requests are maskable.
130
Interrupt Handling
Each interrupt has an interrupt service routine
(ISR).
ISR7 . . . . . . . . . . IRET
ISR6 . . . . . . . . . . IRET
ISR5 . . . . . . . . . . IRET
Normal Job
ISR4 . . . . . . . . . . IRET
ISR3 . . . . . . . . . . IRET
ISR2 . . . . . . . . . . IRET
CPU
ISR1 . . . . . . . . . . IRET
ISR0 . . . . . . . . . . IRET
IRQ0
Interrupt Controller (e.g., 8259)
INT
IRQ1
IRQ2
IRQ3
IRQ4
IRQ5
IRQ6
IRQ7
stack
131
Interrupt Handling
Each interrupt has an interrupt service routine
(ISR).
ISR7 . . . . . . . . . . IRET
ISR6 . . . . . . . . . . IRET
ISR5 . . . . . . . . . . IRET
Normal Job
ISR4 . . . . . . . . . . IRET
ISR3 . . . . . . . . . . IRET
ISR2 . . . . . . . . . . IRET
CPU
ISR1 . . . . . . . . . . IRET
ISR0 . . . . . . . . . . IRET
Put the value of flag register, and program
counter (PC) into the stack.
IRQ0
Interrupt Controller (e.g., 8259)
INT
IRQ1
IRQ2
IRQ3
IRQ4
IRQ5
IRQ6

IRQ7
flag
stack
132
Interrupt Handling
Each interrupt has an interrupt service routine
(ISR).
ISR3 Push used registers (PUSHA) . .
. . . . . . . . . . . . . . . . . . . . .
Pop used registers (POPA) Return from
interrupt (IRET)
ISR7 . . . . . . . . . . IRET
ISR6 . . . . . . . . . . IRET
ISR5 . . . . . . . . . . IRET
Normal Job
ISR4 . . . . . . . . . . IRET
ISR3 . . . . . . . . . . IRET
ISR2 . . . . . . . . . . IRET
CPU
ISR1 . . . . . . . . . . IRET
ISR0 . . . . . . . . . . IRET
IRQ0
Interrupt Controller (e.g., 8259)
INT
IRQ1
IRQ2
Read Interrupt Vector
IRQ3
IRQ4
IRQ5
IRQ6

IRQ7
flag
stack
133
Interrupt Handling
Each interrupt has an interrupt service routine
(ISR).
ISR3 Push used registers (PUSHA) . .
. . . . . . . . . . . . . . . . . . . . .
Pop used registers (POPA) Return from
interrupt (IRET)
ISR7 . . . . . . . . . . IRET
ISR6 . . . . . . . . . . IRET
ISR5 . . . . . . . . . . IRET
Normal Job
ISR4 . . . . . . . . . . IRET
ISR3 . . . . . . . . . . IRET
ISR2 . . . . . . . . . . IRET
CPU
ISR1 . . . . . . . . . . IRET
ISR0 . . . . . . . . . . IRET
IRQ0
Interrupt Controller (e.g., 8259)
INT
IRQ1
IRQ2
IRQ3
IRQ4
IRQ5
IRQ6

IRQ7
flag
stack
134
Interrupt Handling
Each interrupt has an interrupt service routine
(ISR).
ISR7 . . . . . . . . . . IRET
ISR6 . . . . . . . . . . IRET
ISR5 . . . . . . . . . . IRET
Normal Job
ISR4 . . . . . . . . . . IRET
ISR3 . . . . . . . . . . IRET
ISR2 . . . . . . . . . . IRET
CPU
ISR1 . . . . . . . . . . IRET
ISR0 . . . . . . . . . . IRET
IRQ0
Interrupt Controller (e.g., 8259)
INT
IRQ1
IRQ2
IRQ3
IRQ4
IRQ5
IRQ6
IRQ7
stack
135
Standard Interrupt Handing Sequence
  • Save state of interrupted process/thread
  • Identify interrupt type and invoke IH
  • IH services interrupt
  • Restore state of interrupted process (or of
    another one if the interrupt for awakening a
    waiting process)

136
The Typical Sequence for Using a Hardware Device
...... ...... ......
...... Do_I/O ......
Start I/O
Interrupt Service Routine
137
The Typical Sequence for Using a Hardware Device
138
The Typical Sequence for Using a Hardware Device
?
start I/O
?
?
?
?
?
?
?
?
139
Synchronization Primitives Needed
P/V wait/signal
140
Monitor Object-Oriented Approach
Device Driver Implemented Using monitor
Called while I/O completion.
Called by the processes need to do I/O.
141
Implementing Using Monitor
142
Example Monitor Clock Server
143
Example Monitor Clock Server
monitor Clock_Server int tnow
Update_Clock() . . . tnow tnow 1
/ Perhapes update time structure also /
int Get_Time() . . . return(tnow)
/ Perhaps return some more complex structure
instead / Set_Clock(int tnew) . .
. tnow tnew
Write a Comment
User Comments (0)
About PowerShow.com