Computer Systems Fundamentals Lecture 10 PDF
Document Details
Uploaded by MagicalNarcissus5616
Tags
Summary
This document is a lecture on computer systems fundamentals, covering software layers. The lecture introduces concepts like Input-Output, interrupts, and device drivers. It focuses on how these components interact and function. This lecture is suited for computer science or IT students at the undergraduate level.
Full Transcript
Computer Systems Fundamentals H175 34 Lecture 10 Software Layers continued The Input-Output Layer The Input/Output Layer manages communications between the CPU and peripherals (disk drives, keyboard, mouse etc) If another layer requires access to...
Computer Systems Fundamentals H175 34 Lecture 10 Software Layers continued The Input-Output Layer The Input/Output Layer manages communications between the CPU and peripherals (disk drives, keyboard, mouse etc) If another layer requires access to a device, e.g. sending data to the printer, a request is sent to the I/O layer Interrupting Each device will have an interrupt priority, and it interrupts the CPU when it is ready to send or receive data This interrupt signal is sent to the Kernel, which then directs the correct I-O process to handle the request Interrupt Service Routine When an interrupt request reaches the CPU, it causes the CPU to interrupt the task that it was doing and change to another routine -an interrupt service routine (ISR) Once an IRQ is accepted by the CPU, it must identify the source of the request and locate the appropriate ISR in memory. The PIC identifies the IRQ responsible for the interrupt When the ISR is completed, the CPU returns to the program it was executing and resumes its previous task Character I-O This is where data is transferred one character at a time Usually this is an eight- bit transfer on each interrupt Even large quantities of data are transferred one byte at a time This is used for the keyboard, mouse, joystick, com ports and printer Block I-O Block I-O is used when larger amounts of data (normally 2 kb) are read into or written back out from memory The data is transferred in blocks into memory, then transferred out to the device using Direct Memory Access (DMA) Another interrupt is sent when the device has finished transferring the data Device Drivers A device driver is software that controls a particular device attached to a computer Device drivers are often specific to a particular release of an operating system, e.g. Windows 98 device drivers may not work with Vista Many device drivers are nowadays built into the operating system – for example, USB flashdrives http://www.funpecrp.com.br Device Drivers Device Drivers More complex devices often require their own, dedicated device drivers which must be installed by the user Device Drivers Device driver files have the extension DLL or EXE. VXD is a virtual device driver A virtual device driver handles software interrupts from the system, and are used to monitor the status of a hardware device that has variable settings Device drivers are stored on the Hard Disk and are loaded into RAM along with the OS on bootup Device Management The Input - Output system controls and shares access to devices; where several processes require it, the IO system will place the jobs in a queue Jobs are then released to the peripheral when it becomes available. The queued jobs are held in a spool file (the most common example of this is a print spooler) We can control the operation of the print From www.maran.com spooler from the user interface – e.g. to change the order, or cancel a job The Memory Management Layer The Memory Management layer shares the physical memory of the computer between processes and programs Usually there is not enough physical memory available, so Virtual Memory is used Memory already allocated out is protected against access by other programs Physical and Virtual Memory In modern systems, many programs can be running simultaneously, all of which require memory Each memory segment is tagged with information about which process owns it, so it cannot be used by anything else Any attempt to use a tagged segment will be prevented As there is no effective limit on the number of programs that can run simultaneously, there will never be enough From www.howstuffworks.com physical memory – so Virtual Memory is also used Paging Physical memory is split into a number of logical pages; when a program requires memory, it is allocated a number of pages If all the available pages are already in use the memory management system looks for a page that it can reclaim This is normally done by choosing the “oldest” page (least recently loaded) or the one which has been idle the longest (least recently used) The page is then swapped out to a file on the Hard Disk (the Swap File) Pages are then swapped in and out between RAM and the HDD as required Swap File The Memory Management Unit (MMU) automatically translates the logical addresses used by programs into the physical addresses where the information is actually stored The set of physical memory locations is known as the memory space The set of virtual memory locations is known as the address space Memory Mapping Mapping between the address space and the memory space is carried out by means of a page table Memory addresses come in two parts - the page number, and an offset within that page The MMU uses the page number to look up the page table, which holds information about that page number, including whether it is currently present in memory Segmentation The biggest disadvantage of paging is that all the pages are the same size; this is wasteful if the page sizes are large, but they will need swapped a lot if they are small Segmentation divides up memory into blocks of variable sizes. Details of the segments allocated to various processes are stored in a segment table Combinations Most systems use a combination of segmentation and paging - each variable-length segment is made up of several fixed-length pages with its own page table Each entry in the segment table contains protection bits, indicating whether that segment can be read or written to by other processes From www.onlineappsbda.com Allocation Algorithms First Fit algorithm - the allocator keeps a list of free blocks and scans along the list for the first block that is large enough to satisfy the request Buddy system - the allocator will only allocate blocks of certain sizes, and has many free lists, one for each permitted size. When the allocator receives a request for memory, it rounds the requested size up to a permitted size, and returns the first block from that size's free list Suballocators A suballocator (a form of memory management program) obtains large blocks of memory from the memory manager and allocates the memory to the application in smaller pieces From www.memorymanagement.org Thrashing Thrashing is used to describe where the workload cannot be effectively held within physical memory, and constant data swapping, to the detriment of system performance, occurs The term was first used © 40 Years of Computing at for tape operating Newcastle - IBM System 360 systems to describe the Model 67 c.1969 sound the tapes made IBM 360/67 Time sharing system when data was being rapidly written to and This model was particularly prone read from them to thrashing! The Kernel The kernel is the most central, and most protected, layer of the Operating System The kernel is responsible for multi-tasking process control error handling interrupt management Two Types of Multi-tasking All modern operating systems support multi-tasking - the computer can handle several processes simultaneously There are two distinct types of process management – Co-operative and Pre-emptive Co-Operative Multitasking Each process controls the processor for as long as it needs it It can permit other programs to use it temporarily Older versions of both Microsoft Windows and Mac OS implemented cooperative multi-tasking Cooperative multi-tasking depended on the co- operation of the process in question, to hand back resources to other From processes http://developer.apple.com/documentation/mac/Pr Badly designed software ocesses/Processes-13.html often led to system freezes with notes on co-operative multitasking or hang-ups Pre-emptive Multitasking Preemptive multi- tasking uses a scheduler to allocate out processor time Each process is allocated a regular time slice As different processes have different needs, This is the first true pre-emptive OS from Microsoft – Windows 95. See the system will assign http://www.kernelthread.com/mac/vpc/win.html for more interesting stuff on multitasking systems and a priority to each older operating systems. process Process States Running processes can be either – waiting for input or output (I/O bound) fully utilising the processor (CPU bound) I/O bound processes can be blocked until a response arrives - other processes can have access to the processor in the meantime. When the data arrives, it triggers an interrupt, allowing the blocked process to resume The 4 Process States Running: a currently executing process Ready (Waiting): the process is ready to be run Blocked: waiting for a specific event to occur, for example waiting for input from the user Terminated: the process has finished its From wikimedia commons run Process Sub-states Ready Suspend: the process has been swapped out into Virtual Memory, to free up main memory for another process Blocked Suspend: the process is swapped out of main memory because it is in a wait state Process Monitoring Software 1. Running process 2. Ready process 3. Process blocked waiting for some event 4. Blocked suspended process 5. Ready suspended process From 6. In the picture, http://visualos.sourceforge.net/docs/html/Manu process 1 is blocked al-en/x223.html Inter-Process Communication This is a set of techniques for the exchange of data between processes This can be on a single, standalone PC or over a network IPCs require a client (the process that requests the data) and a server (the process that supplies it) There are a number of mechanisms within Windows that provide IPC IPC Mechanisms Clipboard shares data between applications Dynamic Data Exchange (DDE) is a protocol that allows applications to can exchange data between applications in different formats Object Linking and Embedding (OLE) is used for compound documents, e.g. embedding an Excel http://www.vista-files.org/programs/salaat chart in a Word document -time/salaat-time.html IPC Mechanisms File mapping uses a pointer to attach another file, e.g. sending an e-mail attachment in Outlook Express Anonymous pipes are used to transfer data from one process into another Named pipes are similar, but used to transfer data between unrelated processes or processes on different computers Remote Procedure Call (RPC) allows applications to call functions from a central code repository, for example using dll library files Winsock communicates with other socket implementations on other types of systems, in particular for internet connections Interrupts In the I/O layer we saw how hardware could trigger a processor interrupt; there are also software interrupts which do the same thing There are typically 256 types of interrupt in a modern system; 16 of these are hardware- generated, 240 are software-generated In addition, there are 16 From more software interrupts http://users.ece.utexas.edu/~valvano/assmbly/st which can simulate the ack.htm - what happens after an interrupt is triggered hardware ones Interrupt Handling The kernel handles all of the interrupts, exceptions, system service calls and virtual memory management Like the hardware interrupts, some of the software interrupts have higher priority than others When an interrupt occurs, it is handled by an interrupt service routine (ISR) Other ISRs are The kernel includes ISRs for provided by many system interrupts such the system clock and DRAM device drivers refresh Masked Interrupts In modern operating systems, low-priority interrupts are masked (blocked) while a higher-priority interrupt is being processed Thread A is running. Interrupt IRQx causes A high priority interrupt handler Intx to run, which is preempted by IRQy and its handler Inty. Inty returns an interrupt will, however, event causing Thread B to run; Intx returns an event causing Thread C to run. From take precedence over http://www.bitctrl.de/qnx/qnx6_sysarch/qnx6_sys arch_2b.shtml a lower priority interrupt