Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) What is the purpose of interrupts? How does the interrupt work? Explain with

ID: 3542114 • Letter: 1

Question

1) What is the purpose of interrupts? How does the interrupt work? Explain with a diagram. What is the difference between an interrupt and trap? Explain. What are                 the different classes of interrupts. List them and explain them briefly.

2) What are the different functions of operating systems? Explain briefly.

3) What are the                 various resource allocation activities handled by the operating system? Explain.

4) What is the role of cache memory? Explain.

6) Describe virtual machine and its advantages.             

Explanation / Answer

The temporary stopping of the current program routine, in order to execute some higher priority I/O subroutine, is called an interrupt. The interrupt mechanism in the CPU forces a branch out of the current program routine to one of several subroutines, depending upon which level of interrupt occurs.



I/O operations are started as a result of the execution of a program instruction. Once started, the I/O device continues its operation at the same time that the job program is being executed. Eventually the I/O operation reaches a point at which a program routine that is related to the I/O operation must be executed. At that point an interrupt is requested by the I/O device involved. The interrupt action results in a forced branch to the required subroutine.



In addition to the routine needed to start an I/O operation, subroutines are required to:



Transfer a data word between an I/O device and main storage (for write or read operations)


Handle unusual (or check) conditions related to the I/O device


Handle the ending of the I/O device operation



Assume that the I/O device in operation is the card reader (1442). The I/O device operation that has been started, then, is the moving of a card past the read station.


Card is read while program execution continues

As soon as the card is moved far enough for one card column to be read, the card reader signals the CPU. This signal to the CPU is an interrupt request. The interrupt, however, does not occur until execution of the current instruction is completed. At that time, a forced branch occurs to an interrupt-handling subroutine.


The interrupt action can be shown pictorially in the following way:


The card continues to be read as the continuing I/O is serviced

Logical requirements of the interrupt subroutine are carried out before a return to the interrupted program.


To return to the program routine that was in progress before the interrupt occurred, another branch must be provided. This, however, is a program-controlled branch and, therefore, is not forced by the CPU.


In summary,


An interrupt request occurs at the time that an I/O operation, which otherwise proceeds in dependently of the program, requires program intervention.

The interrupt occurs after the current instruction has been completely executed.

The CPU then forces execution of a branch instruction, which causes a branch to a subroutine.

At the end of the subroutine the program branches back to the program routine that was in progress when the interrupt occurred.

An interrupt is generally initiated by an I/O device, and causes the CPU to stop what it's doing, save its context, jump to the appropriate interrupt service routine, complete it, restore the context, and continue execution. For example, a serial device may assert the interrupt line and then place an interrupt vector number on the data bus. The CPU uses this to get the serial device interrupt service routine, which it then executes as above.

A trap is usually initiated by the CPU hardware. When ever the trap condition occurs (on arithmetic overflow, for example), the CPU stops what it's doing, saves the context, jumps to the appropriate trap routine, completes it, restores the context, and continues execution. For example, if overflow traps are enabled, adding two very large integers would cause the overflow bit to be set AND the overflow trap service routine to be initiated.


Exception: These are generated internally by the CPU and used to alert the running kernel of an event or situation which requires its attention. On x86 CPUs, these include exception conditions such as Double Fault, Page Fault, General Protection Fault, etc.

Interrupt Request (IRQ) or Hardware Interrupt: This type of interrupt is generated externally by the chipset, and it is signalled by latching onto the #INTR pin or equivalent signal of the CPU in question. There are two types of IRQs in common use today.

IRQ Lines, or Pin-based IRQs: These are typically statically routed on the chipset. Wires or lines run from the devices on the chipset to an IRQ controller which serializes the interrupt requests sent by devices, sending them to the CPU one by one to prevent races. In many cases, an IRQ Controller will send multiple IRQs to the CPU at once, based on the priority of the device. An example of a very well known IRQ Controller is the Intel 8259 controller chain, which is present on all IBM-PC compatible chipsets, chaining two controllers together, each providing 8 input pins for a total of 16 usable IRQ signalling pins on the legacy IBM-PC.

Message Based Interrupts: These are signalled by writing a value to a memory location reserved for information about the interrupting device, the interrupt itself, and the vectoring information. The device is assigned a location to which it wites either by firmware or by the kernel software. Then, an IRQ is generated by the device using an arbitration protocol specific to the device's bus. An example of a bus which provides message based interrupt functionality is the PCI Bus.

Software Interrupt: This is an interrupt signalled by software running on a CPU to indicate that it needs the kernel's attention. These types of interrupts are generally used for System Calls. On x86 CPUs, the instruction which is used to initiate a software interrupt is the "INT" instruction. Since the x86 CPU can use any of the 256 available interrupt vectors for software interrupts, kernels generally choose one. For example, many contemporary unixes use vector 0x80 on the x86 based platforms.


2) Functions of an operating system



The basic functions of an operating system are:



Booting the computer


Performs basic computer tasks eg managing the various peripheral devices eg mouse, keyboard


Provides a user interface, e.g. command line, graphical user interface (GUI)


Handles system resources such as computer's memory and sharing of the central processing unit (CPU) time by various applications or peripheral devices


Provides file management which refers to the way that the operating system manipulates, stores, retrieves and saves data.


Booting the computer



The process of starting or restarting the computer is known as booting. A cold boot is when you turn on a computer that has been turned off completely. A warm boot is the process of using the operating system to restart the computer.



Performs basic computer tasks



The operating system performs basic computer tasks, such as managing the various peripheral devices such as the mouse, keyboard and printers. For example, most operating systems now are plug and play which means a device such as a printer will automatically be detected and configured without any user intervention.



Provides a user interface



A user interacts with software through the user interface. The two main types of user interfaces are: command line and a graphical user interface (GUI). With a command line interface, the user interacts with the operating system by typing commands to perform specific tasks. An example of a command line interface is DOS (disk operating system). With a graphical user interface, the user interacts with the operating system by using a mouse to access windows, icons, and menus. An example of a graphical user interface is Windows Vista or Windows 7.


The operating system is responsible for providing a consistent application program interface (API) which is important as it allows a software developer to write an application on one computer and know that it will run on another computer of the same type even if the amount of memory or amount of storage is different on the two machines.



Handles system resources



The operating system also handles system resources such as the computer's memory and sharing of the central processing unit (CPU) time by various applications or peripheral devices. Programs and input methods are constantly competing for the attention of the CPU and demand memory, storage and input/output bandwidth. The operating system ensures that each application gets the necessary resources it needs in order to maximise the functionality of the overall system.



Provides file management



The operating system also handles the organisation and tracking of files and directories (folders) saved or retrieved from a computer disk. The file management system allows the user to perform such tasks as creating files and directories, renaming files, coping and moving files, and deleting files. The operating system keeps track of where files are located on the hard drive through the type of file system. The type two main types of file system are File Allocation table (FAT) or New Technology File system (NTFS).


3)Resource allocation


In the multitasking environment, when multiple jobs are running at a time, it is the responsibility of an operating system to allocate the required resources (like as CPU, main memory, tape drive or secondary storage etc.) to each process for its better utilization. For this purpose various types of algorithms are implemented such as process scheduling, CPU scheduling, disk scheduling etc.



4)Cache memory is generally installed on a disk drive, or disk drive controller, or in a Processor.



Since memory/RAM is much faster than a disk, when you write data to the disk it goes to the cache, and the task is quickly reported as complete, thus freeing your machine for the next task. But the data is then written from the cache to the disk without using any of the machine resources.



A similar process happens when you read data from a disk. Often a disk is able to retrieve data faster then the PC can handle it. It is therefore written to the cache, where the PC can read it on demand, but the disk itself is already idle and awaiting the next instruction.



On a laptop, a large amount of cache memory saves power, as the disk can be turned off, whilst data is still in the cache. Cache memory takes a lot less power than the disk motor.



Main Processors (CPU) also have a certain amount of Cache Memory. Since the Cache is on the main chip, it can be accessed much more quickly than RAM, which is restricted by the BUS speed. So data is read from the disk, and then held in the Processor cache memory, where it is close to the processor, thus speeding up the operation of the processor.




6)virtual machine :A self-contained operating environment that behaves as if it is a separate computer. For example, Java applets run in a Java virtual machine (VM) that has no access to the host operating system. This design has two advantages:


System Independence: A Java application will run the same in any Java VM, regardless of the hardware and software underlying the system.


Security: Because the VM has no contact with the operating system, there is little possibility of a Java program damaging other files or applications.


The second advantage, however, has a downside. Because programs running in a VM are separate from the operating system, they cannot take advantage of special operating system features.