Download presentation
Presentation is loading. Please wait.
Published byAmelia Elliott Modified over 6 years ago
1
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Be able to define the term Interrupts, To be able to describe the role of interrupts and Interrupt Service Routines (ISR) Key Words Interrupt, Buffer, Priority, Stack
2
An analogy… You arrive at work, your task for the day is to write a report, it’s due in tomorrow. The phone rings – what do you do? You receive an about an event next week A colleague asks you to help with an error message that appeared on their screen. You’re hungry – the report is not going well… You receive an from your manager – she needs last months sales figures, the deadline was last Thursday!
3
In our analogy you did a lot of things intuitively, without thinking
But the system you used is almost identical to that of interrupts What do you think an interrupt is? Can you think of a situation where one might occur? Could you summarise how they are handled?!
4
Interrupts - Definition
The operating system needs to respond to input devices and other system-wide events, for example when the hard drive is ready to serve another request or the user has pressed a key on the keyboard. The OS needs to be made aware of these events in order to decide which course of action to take. These signals, sent from hardware to the CPU, are known as interrupts. Software can also generate interrupts during normal execution. An interrupt is, therefore, a request for attention, for CPU time.
5
Interrupt Examples Hardware commands Program / Software Timer
Reset Button pressed Power Supply failure Power-down command (screen off, hibernate etc) These send a physical signal to the CPU via the interrupt chip. Program / Software Software is also allowed to issue interrupts to the CPU. For example software has detected that an error has occurred and will issue a software interrupt for the CPU to run some instructions to try to clear the error. Timer Some programs trigger a 'timer interrupt' for example a data-logging application that *has* to read an input sensor every 1 second. Or perhaps a screen recording application that has to read the next screen update. Input / Output devices Devices such as the keyboard and mouse – key presses, movements, clicks etc. Other Input - Output devices include Hard Disk – Request to read or write data Optical Disk Printer Graphics tablet
6
How does it work? When an interrupt occurs, a signal is sent to the CPU via a control bus or, in the case of a software interrupt, a flag is set. A special register, known as the interrupt register, is then updated by flipping a bit to 1.
7
IRQ flag Device Flag Timer 1 Keyboard 2 Programmable 3 COM 1 4 COM 2 5 Term 2 6 Floppy 7 8 RTC timer 9 10 11 12 Mouse 13 Co-processor 14 ATA/IDE 1 15 ATA/IDE 2
8
Important things to note…
More than 1 interrupt can be registered at once It is NOT the job of the CPU to decide WHICH interrupt will be handled If more than one of the same interrupt is generated before the CPU has had a chance to deal with it, the second and subsequent interrupts are ignored. This is a fairly common occurrence for low-priority interrupts such as I/O) tasks or timers. The OS will decide which interrupt to handle based on priority
9
When an interrupt occurs, the CPU will, on the next instruction cycle, run some special OS code to inform it of the interrupt. The currently running process will be interrupted so that this event can be handled. It is important for the OS to make this decision as it will know more about the context of what the user is doing. The OS, if it chooses, can ignore interrupts. This is called “Masking” For example, keyboard interrupts can be safely postponed while interrupts such as hardware switches must be dealt with immediately. When an interrupt occurs, the CPU has the role of informing the OS rather than dealing with the interrupt itself.
10
A Modified Fetch – Execute Cycle
11
Interrupt service routines
Hardware and software can trigger interrupts and these are then dealt with by calling an interrupt service routine (ISR). When a device driver loads, it will register interest in a specific interrupt so that when the interrupt occurs the code within the device driver will be executed. The ISR does not continuously check the status of the device. As ISRs are part of the device driver, the OS is effectively using the driver to process the interrupt.
12
Interrupt Service Vectors
13
Saving the state When an interrupt is processed the following things need to happen: Save the processor state Execute the ISR Restore the processor state To further complicate things, interrupts can be interrupted by… interrupts… So we need a data structure to handle this
14
These are copied to something called the “stack”
Stacks To preserve the CPU state so it can be later resumed, the following need to be saved: PC ACC General Purpose Registers These are copied to something called the “stack”
15
Imagine the processor state is one object.
Each time we need to save the state, it is “pushed” on to the stack – a special area of RAM When we want to retrieve, we “pop” the state off the stack This is a FILO system This data structure allows multiple levels of interrupt handling to occur.
17
Buffers A buffer is a small block of memory inside hardware devices such as printers, keyboards and hard drives where work currently being handled by that device is stored. When a keyboard key is pressed, for example, an interrupt is sent to the CPU and the key stroke stored in the keyboard’s buffer. However, sometimes the OS may not be ready to deal with the keyboard stroke and so masks the interrupt. Meanwhile, more keys may have been pressed. Instead of losing the key strokes, the buffer stores the values until the OS is ready. If interrupts are not serviced in time, it is possible to overflow a buffer, which is bad news
18
There is a very specific algorithm used to deal with buffers and interrupts when saving data to a slower device: A chunk of data is sent by the CPU to the device and stored in a buffer. The device will slowly save the data while the CPU is free to do other tasks. When the buffer is empty, an interrupt is sent to the CPU. At the start of the next FDE cycle the interrupt is processed by informing the OS. More data is sent to the device and the cycle repeats. This will continue until all data has been saved.
19
Buffers and interrupts – an example
A user wishes to save a 30 MB file onto the hard drive. In order to do this, the file will need to be stored in small chunks of 1 MB. Using the buffer and interrupt system, the first chunk is sent to the hard drive, which, in turn, writes it to the disk. While this is occurring, the CPU will continue doing other tasks, such as dealing with keyboard interrupts or playing music. Once the hard drive has finished saving the file, it sends an interrupt to the CPU requesting more data, which is duly sent by the CPU
20
Advantage The CPU is much faster than any other part of the computer. If the CPU waited for the hard drive to finish saving before it did anything else (i.e. was synchronous), a lot of CPU cycles would be wasted. Interrupts allow the CPU to make much better use of time.
21
Summary – you should know…
A multitasking operating system can run more than one process. Interrupts are used to halt the current process. These are signals to the CPU to request processor time. Interrupts can be generated by hardware, software or the processor. When an interrupt is received, a program called an Interrupt Service Routine (ISR) will run. The ISR is held in stack memory that uses a pointer to indicate the item in the stack to be executed next. Some processes involve a delay, for example printing a document: the computer can send the data faster than the printer can process it. A small area of memory called a buffer allows printing to appear continuous. As the buffer empties, an interrupt is sent for more data to be sent. Flags are used to indicate when an interrupt has occurred. Interrupts use priorities to indicate that a process is more critical so should be handled first.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.