24
The Functions of The Functions of Operating Systems Operating Systems Interrupts Interrupts

The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Embed Size (px)

Citation preview

Page 1: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

The Functions of The Functions of Operating Systems Operating Systems

InterruptsInterrupts

Page 2: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Learning ObjectivesLearning Objectives

Explain how interrupts are used to obtain processor time.

Explain how processing of interrupted jobs may later be resumed.

Identify typical sources of interrupts

Describe algorithms and data structures associated with interrupts.

Page 3: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

The simplest way of obeying instructionsThe simplest way of obeying instructions

Sometimes the Sometimes the normal order of normal order of operation is changed operation is changed by an interrupt.by an interrupt. See next slide.See next slide.

Page 4: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

InterruptsInterrupts

Signals sent to the processor by devices / Signals sent to the processor by devices / programs indicating that they require the programs indicating that they require the attention of the processor.attention of the processor. Due to errors or because of speed mismatch Due to errors or because of speed mismatch

implications.implications.i.e. In order to save time, perform other tasks and i.e. In order to save time, perform other tasks and wait to be interrupted by the I/O device when it is wait to be interrupted by the I/O device when it is ready to continue.ready to continue.

Page 5: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Types Of InterruptsTypes Of Interrupts

Page 6: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

I/OI/O oror HardwareHardware interrupt interrupt

Generated by hardware (I/O devices) to signal a Generated by hardware (I/O devices) to signal a service request service request (allows resolution of speed mismatch (allows resolution of speed mismatch

implications)implications) or an error has occurred. or an error has occurred. E.g. E.g.

Printer has emptied the buffer and wants it refilled.Printer has emptied the buffer and wants it refilled.

Printer is out of paper or is not connected.Printer is out of paper or is not connected.

Close down safely in the event of a power failure from:Close down safely in the event of a power failure from: A A UUninterruptible ninterruptible PPower ower SSupply (upply (UPSUPS) which took over when ) which took over when

the main electricity was lost but now its rechargeable power the main electricity was lost but now its rechargeable power supply is running low.supply is running low.

The device which measures how much power is still left in a The device which measures how much power is still left in a laptop battery informs the processor it is running low.laptop battery informs the processor it is running low.

Page 7: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Timer Timer // Clock Clock Interrupt Interrupt

Generated at fixed intervals.Generated at fixed intervals.

Allows for display refresh and to control access Allows for display refresh and to control access to processor in multi-access or multi-to processor in multi-access or multi-programming system.programming system.

Page 8: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

ProgramProgram interrupt interrupt

Generated due to an error in a program:Generated due to an error in a program: Violation of memory use Violation of memory use (trying to use part of the (trying to use part of the

memory reserved by the OS for another use).memory reserved by the OS for another use). An attempt to execute an invalid instruction An attempt to execute an invalid instruction

(e.g. division by zero)(e.g. division by zero)..

Page 9: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Terms

Job / Process / Task / Program are all equivalent terms.

Cycle is an instruction in a job / process / task / program .

Page 10: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Managing interruptsManaging interrupts

After the execution of After the execution of an instruction (an instruction (current current cyclecycle), the processor ), the processor must see if an must see if an interrupt has occurred interrupt has occurred and service it. and service it. i.e. Obey a new set of i.e. Obey a new set of

instructions.instructions.

Page 11: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Type/Source of interrupt is checked and priority (different types have

different priorities) of interrupt compared with current job.

How this priority is decided is called How this priority is decided is called scheduling and is dealt with in the and is dealt with in the next presentation..

Page 12: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

If higher:If higher:

Page 13: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Masking / Disable Masking / Disable equal or lower priority interruptsequal or lower priority interrupts

Mask out, refuse or disable all interrupts of an Mask out, refuse or disable all interrupts of an equal or lower priority than the current interrupt equal or lower priority than the current interrupt being serviced. being serviced. Effectively meaning that any further interrupts will Effectively meaning that any further interrupts will (in the (in the

execution of the current one)execution of the current one) have to be of a higher priority have to be of a higher priority if it is to interrupt the current interrupt.if it is to interrupt the current interrupt.

This is done by using a Programmable Interrupt Controller This is done by using a Programmable Interrupt Controller (PIC) which is separate from the processor(PIC) which is separate from the processor. A. All interrupts have ll interrupts have to state their Interrupt Priority Level (IPL)to state their Interrupt Priority Level (IPL) and t and the PIC does not he PIC does not pass on any new interrupts to the processor unless they have pass on any new interrupts to the processor unless they have a higher IPL a higher IPL (lower priority(lower priority interrupts interrupts are therefore simply ignored) are therefore simply ignored)..This allows the current interrupt to be executed without having This allows the current interrupt to be executed without having to waste time considering equal or lower priority interrupts.to waste time considering equal or lower priority interrupts.http://en.wikipedia.org/wiki/Interrupt_handler

How this priority is decided is called How this priority is decided is called scheduling and is dealt with in the and is dealt with in the next presentation..

Page 14: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

How can the interrupted program be How can the interrupted program be resumed from where it left off when the resumed from where it left off when the

interrupt has been serviced?interrupt has been serviced?The state of the current job is saved by saving the contents of all the The state of the current job is saved by saving the contents of all the registers registers (s(small, permanent storage locations within the CPU used for a mall, permanent storage locations within the CPU used for a particular purpose)particular purpose) in the processor so that the processor can use in the processor so that the processor can use them to service the interrupt but can load their contents back in to them to service the interrupt but can load their contents back in to resume the job being interrupted once the interrupt has been resume the job being interrupted once the interrupt has been serviced. serviced. The first register to be saved is one called the The first register to be saved is one called the Program CounterProgram Counter which holds which holds

the address of the next instructionthe address of the next instruction.. Then the other registers are saved.Then the other registers are saved.

For more information see the For more information see the Von Neumann Architecture Von Neumann Architecture PresentationPresentation, later in this course..

Page 15: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Scheduling processes and the Process Control Block (PCB).

Each job is allocated a block of memory called a process control block. This will hold the following information:

Process Identity Number. Current state of the job when the job was last left. The contents of each register when the job was last left on a stack. What priority the process has. Estimated time for the job to be finished. It's current status, whether it is waiting for I/O, whether it's waiting to use the

CPU. Pointers pointing to areas in memory reserved for this process and resources

that could be used.

When a process is stopped, the above details are loaded into the Process Control Block, ready for next time the process uses CPU time. When that time comes, the contents of the PCB are moved into the CPU and the process repeats itself!

Page 16: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Interrupt Service Routine (ISR)Interrupt Service Routine (ISR)Place the current job in a “queue of interrupts” Place the current job in a “queue of interrupts” (position depends on its type/source and priority)(position depends on its type/source and priority)..An appropriate interrupt service routine (ISR), An appropriate interrupt service routine (ISR), depending on the type and actual taskdepending on the type and actual task of the of the interrupt, is loaded and run.interrupt, is loaded and run. Device driver in case ofDevice driver in case of devicesdevices.. Exception Exception / signal/ signal / trap handler in case of software/ trap handler in case of software

interrupts.interrupts.OK, I have been interrupted. Now the CPU asks the hardware: OK, I have been interrupted. Now the CPU asks the hardware: 'What do you want me to do'? In other words: 'Which interrupt 'What do you want me to do'? In other words: 'Which interrupt service routine should I run?'service routine should I run?'

Interrupt is serviced by the processor.Interrupt is serviced by the processor.

How this priority is decided is called How this priority is decided is called scheduling and is dealt with in the and is dealt with in the next presentation..

Page 17: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Enable ALL interruptsEnable ALL interruptsWhen the interrupt is complete the processor will When the interrupt is complete the processor will start considering all interrupts of a lowerstart considering all interrupts of a lower priority. priority. i.e. enablei.e. enable or or restorerestore or unmask or unmask all equal and lower all equal and lower

priority interrupts.priority interrupts.

Restore the contents of the registers for the next Restore the contents of the registers for the next process in the queue of interrupts.process in the queue of interrupts.Resume this process.Resume this process.

Page 18: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

If an ISR is being run If an ISR is being run (lower priority interrupts (lower priority interrupts

are being masked) are being masked) then it is ignored until the then it is ignored until the current interrupt is finished then its priority is current interrupt is finished then its priority is compared to jobs in the queue, if lower than compared to jobs in the queue, if lower than the next waiting job then or otherwise:the next waiting job then or otherwise:

Allocate the job a position in a job queue according Allocate the job a position in a job queue according to its priorities.to its priorities.

If equal or lower:If equal or lower:

How this priority is decided is called scheduling and is dealt with in the next presentation.How this priority is decided is called scheduling and is dealt with in the next presentation.

Page 19: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

SummarySummary::1.1. Disable interrupts of a lower priority.Disable interrupts of a lower priority.

2.2. Save the contents of the program counter on a stack in the Process Save the contents of the program counter on a stack in the Process Control Block.Control Block.

3.3. Save Save all other registersall other registers and and any other information needed to resume any other information needed to resume the current process.the current process.

4.4. Load and run the appropriate Interrupt Service routine (ISR).Load and run the appropriate Interrupt Service routine (ISR).

5.5. If a higher priority interrupt is received then go to step 1.If a higher priority interrupt is received then go to step 1.

6.6. When ISR is complete enable all interrupts of a lower priority and When ISR is complete enable all interrupts of a lower priority and

complete the task next in the queue of interruptscomplete the task next in the queue of interrupts..When the next task has been chosen:When the next task has been chosen:

7.7. Restore all other registers.Restore all other registers.

8.8. Restore the Program Counter.Restore the Program Counter.

9.9. Continue execution of the interrupted original process.Continue execution of the interrupted original process.

Page 20: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

http://www.scriptoriumdesigns.com/embedded/interrupts.php• Also note:

• Some websites like the one above state that only the PC is saved before running the ISR and that it is part of the ISR’s job to save any of the other registers it will use; so that the previous job can resume from where it left off. This is so other registers are not saved unnecessarily as only the PC will definitely be changed (the address of the next instruction).

• If this is so, steps 3 & 4 and 6 & 7 (as the ISR would have to restore the registers it saved) on the previous slide, should be swapped round. This appears to be why mark schemes differ slightly from other sources in regards to the exact sequence, and therefore I predict some flexibility here.

www.le.ac.uk/eg/fss1/lect_int_transparencies.doc

For more research:For more research:

Page 21: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

PlenaryPlenary

State and explain allState and explain all the different types of the different types of interrupt that may occur.interrupt that may occur.

Page 22: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

Types of Interrupt Types of Interrupt

I/O interruptI/O interrupt Generated by an I/O device to signal that a Generated by an I/O device to signal that a

job is complete or an error has occurred. job is complete or an error has occurred. E.g. E.g.

Printer is out of paper or is not connected.Printer is out of paper or is not connected.

Timer interruptTimer interrupt Generated at fixed intervals.Generated at fixed intervals. Allows for display refresh and to control access to Allows for display refresh and to control access to

processor in multi-access or multi-programming processor in multi-access or multi-programming system.system.

Page 23: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

PlenaryPlenary

How is an interrupt handled by a How is an interrupt handled by a processor which is working on another processor which is working on another task?task?

Page 24: The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of

SummarySummary::1.1. Disable interrupts of a lower priority.Disable interrupts of a lower priority.

2.2. Save the contents of the program counter and all other registers on Save the contents of the program counter and all other registers on a stack in the Process Control Block.a stack in the Process Control Block.

3.3. Save any other information needed to resume the current process.Save any other information needed to resume the current process.

4.4. Load and run the appropriate Interrupt Service routine (ISR).Load and run the appropriate Interrupt Service routine (ISR).

5.5. If a higher priority interrupt is received then go to step 1.If a higher priority interrupt is received then go to step 1.

6.6. When ISR is complete enable all interrupts of a lower priority and When ISR is complete enable all interrupts of a lower priority and

complete the task next in the queue of interruptscomplete the task next in the queue of interrupts ..If continuing a previous task:If continuing a previous task:

7.7. Restore all other registers.Restore all other registers.

8.8. Restore the Program Counter.Restore the Program Counter.

9.9. Continue execution of the interrupted original process.Continue execution of the interrupted original process.