Title: Interrupts
1Interrupts
2An Interrupt
- A signal sent to a process
- An action taken by the interrupting process
- It is an event because it occurs at a specific
instant and has no duration - An interrupt is associated with and interrupt
level
3An Interrupt (Cont.)
- A process interrupts the normal activity of
another process - The first process is called the interrupting
process, the second one is called the interrupted
process - The interrupted process will later continue its
activity from the point of interruption
4The Interrupted Process
- Decides what to do when it detects an interrupt.
- Usually releases any resources held, saves the
remaining service time, joins a queue, and
suspends itself. - Can detect one or more levels of interrupt, each
one can trigger a different response activity.
5Interrupt Handling
- When interrupted, a process executes an interrupt
routine before suspending - In the interrupt routine, the process
- Computes the remaining time
- Releases resources
- Other immediate activity
- There is usually an interrupt routine for every
interrupt level
6Flow of Activity for Interrupt Routine
7Interrupting and Interrupted Processes
8Multi-Server Multi-Queue Model with Preemption
- Every customer has a priority
- An arriving customer can interrupt the service of
another customer with a lower priority - The interrupted customer is returned to the head
of his queue, this customer is the one with the
lowest priority and that started most recently.
9The Interrupting Process
- Only sends an interrupt to a lower priority
process - Waits for the availability of a server, after the
interrupt - Waits for the availability of resources released
by the interrupted process - Can determine the remaining time of the
interrupted process.
10After the Interrupt
- The interrupting process gets access to server(s)
and resources available - Then it can reactivate the interrupted process
- Any other process can reactivate the interrupted
process - The interrupted process resumes service for its
remaining period, or can be interrupted again
11Selection of the Process to Interrupt
- The lowest priority process, lower than the
priority of the interrupting process - If there are several processes with the same
priority - the process that started most recently
- the process that has the shortest remaining time
- the process that started first
12Interrupts with PsimJ
In the interrupting process int intr_level
1 // intrrupt level pp_object.p_interrupt(
intr_level) where pp_object is a reference to
the interrupted process and intr_level is the
interrupt level
13Interrupted Process
- The interrupted process executes the following
code - if (int_level() 1) // interrupt level 1?
- // ... execute interrupt service routine
- deactivate(this) // suspend itself
-
14Parts Replacement System With Interrupts
- When a part fails, the machine object
- Removes the damaged part
- Place the damaged part in the container for
damaged parts - Interrupt the repairman object if it is carrying
out background tasks - If available, take a replacement part from the
replacement container, or wait (suspend) - Install the replacement part
15Repairman Object
- Check if there are parts in the damaged parts
container - If available, take a damaged part and repair it
- Place the repaired part in the proper container
- If there are no damaged parts available, carry
out some background task - Check for pending background job to complete
- If there is an interruption, carry out interrupt
service routine
16Java Code for Repairman Process
delay(job_per) // execute
background job pending_job false
if (int_level() REPAIR) // job
interrupted? rem_time
get_remain_t() Intrep.out.println(get_
name() " interrupted at "
get_clock()) clear_int()
// clear interrupts pending_job
true // end if
17CarWash System With Interrupts
- Multi-server system
- Priority queue for customer objects
- Simple queue for available servers
- Priority queue for bust servers
- A server can be interrupted by a customer
18Interrupts in Carwash Model
- A customer can interrupt a server that is
servicing a lower priority customer - When there are no available servers, an arriving
customer will interrupt the server with the
lowest priority customer that started most
recently - There are two queues for Server objects
available and busy_queue
19Car Process
- An arriving car joins the car priority queue
- If there are no servers available
- Examine the busy server queue, try to get the
lowest priority server that started service most
recently - If a server is found with a lower priority than
current car, interrupt the server - Suspend itself to wait for service
20Java Code in Car Process
// there are no available servers // interrupt a
busy server with lowest priority machine
(Server) Carwash.busy_queue.pllast(mtype) if
(machine ! null) Carwash.out.println(get_
name() " interrupting "
machine.get_name()) machine.p_interrupt(1)
// interrupt server else
Carwash.out.println(get_name() "
no server with lower priority available ")
21Server Process
- If car (priority) queue is empty, suspend
- If queue not empty, get the next car with the
highest priority from the priority queue - Service the car
- If interrupted
- store the remaining time of current service
- get the next car with higher priority from the
car queue
22Java Code in Server Process
// Was this service interrupted? if
(int_level() 1) // interrupt level 1
// return customer object to customer queue
Carwash.car_queue.pback (currentCustomer)
rem_time get_remain_t() // remaining
service time currentCustomer.change_servp(
rem_time) currentCustomer.set_pend()
// pending flag clear_int()
23Controller Interrupts Gate
- // interrupt gate opening and get remaining time
left - cout ltlt "Controller interrupting gate at "
- ltlt get_clock() ltlt endl
- gt_rem gate_obj-gtp_interrupt(INT_CONT) //
interrupt Gate
24Gate Checking for Interrupt
- // Check if interrupted by the controller
- // because of excessive waiting to communicate
- if (int_level() INT_CONT)
- cout ltlt "Gate interrupted, resetting
at " - ltlt get_clock() ltlt endl
- clear_int()