페이지

2022년 4월 15일 금요일

1.2.2 Storage Structure

 The CPU can load instructions only from memory, so any programs must first be loaded into memory to run. General-purpose computers run most of their programs from rewritable memory, called main memory (also called random-access memory, or RAM). Main memory commonly is implemented in a semiconductor technology called dynamic random-access memory(DRAM).

Computers use other forms of memory as well. For example, the first program to run on computer power-on is a bootstrap program, which then loads the operating system. Since RAM is volatile-loses its content when power is turned off or otherwise lost-we cannot trust it to hold the bootstrap program. Instead, for this and some other purposes, the computer uses electrically erasable programmable read-only memory (EEPROM) and other forms of firmwar - storage that is infrequently written to and is nonvolatile. EEPROM can be changed but cannot be changed frequently. In addition, it is low speed, and so it contains mostly static programs and data that aren't frequently used. For example, the iPhone uses EEPROM to store serial numbers and hardware information about the device.

All forms of memory provide an array of bytes. Each byte has its own address. Interaction is achieved through a sequence of load or store instructions to specific memory addresses. The load instruction moves a byte or word from main memory to an internal register within the CPU, whereas the store instruction moves the content of a register to main memory. Aside from explicit load and stores, the CPU automatically loads instructions from main memory for execution from the location stored in the program counter.

A typical instruction-execution cycle, as executed on a system with a von Neumann architecture, first fetches an instruction from memory and stores that instruction in the instruction register. The instruction is then decoded and may cause operands to be fetched from memory and stored in some internal register. After the instruction on the operands has been executed, the result may be stored back in memory. Notice that the memory unit sees only a stream of memory addresses. It does not know how they are generated (by the instruction counter, indexing, indirection, literal addresses, or some other means) or what they are for (instructions or data). Accordingly, we can ignore how a memory address is generated by a program. We are interested only in the sequence of memory addresses generated by the running program.

Ideally, we want the programs and data to reside in main memory permanently. This arrangement usually is not possible on most systems for two reasons:

1. Main memory is usually too small to store all needed programs and data permanently.

2. Main memory, as mentioned, is volatile-it loses its contents when power is turned off or otherwise lost.

Thus, most computer systems provide secondary storage as an extension of main memory. The main requirement for secondary storage is that it be able to hold large quantities of data permanently.

The most common secondary-storage device are hard-disk drivers(HDDs) and nonvolatile memory (NVM) devices, which provide storage for both programs and data. Most programs (system and application) are stored in secoundary storage untile they are loaded into memory. Many programs then use secondary storage as both the loaded into memory. Many programs then use secondary storage as both the source and the destination of their processing. Secondary storage is also much slower then main memory. Hence, the proper management of secondary storage is of central importance to a computer system, as we discuss in Chapter 11.

In a larger sence, however, the storage structure that we have described - consisting of registers, main memory, and secondary storage - is only one of many possible storage system designs. Other possible components include cach memory, CD-ROM or blu-ray, magnetic tapes, and so on. Those that are slow enough and large enough that they are used only for special purposes - to store backup copies of material stored on other devices, for example - are called tertiary storage. Each storage system provides the basic functions of storing a datum and holding that datum until it is retrieved at a later time. The main differences among the various storage system lie in speed, size, and volatility.

The wide variety of storage systems can be organized in a hierarchy(Figure 1.6) according to storage capacity and access time. As a general rule, there is a trade-off between size and speed, with smaller and faster memory closer to the CPU. As shown in the figure, in addition to differing in speed and capacity, the various storage systems are either volatile or nonvolatile. Volatile storage, as mentioned earlier, loses its contents when the power to the device is removed, so data must be written to nunvolatile storage for safekeeping.

The top four levels of memory in the figure are constructed using semiconductor memory, which consists of semiconductor-based electronic circuits. NVM devices, at the fourth level, have several variants but in general are faster than hard disks. The most common form of NVM device is flash memory, which is popular in mobile devices such as smartphones and tablets. Increasingly, flash memory is being used for long-term storage on laptops, desktops, and servers as well.

Since storage plays an important role in operating-system structure, we will refer to it frequently in the text. In general, we will use the following terminology:

- Volatile storage will be referred to simply as memory. If we need to emphasize a particular type of storage device (for example, a register), we will do so explicity.

- Nonvolatile storage retains its contents when power is lost. It will be referred to as NVS. The vast majority of the itme we spend on NVS will be on secondary storage. This type of storage can be classified into two distinct types:

1) Mechanical. A few examples of such storage systems are HDDs, optical disks, holographic storage, and magnetic tape. If we need to emphasize a particular type of mechanical storage device (for example, magnetic tape), we will do so explicitly.

2) Electrical. A few examples of such storage systems are flash memory, FRAM, NRAM, and SSD. Electrical storage will be referred to as NVM. if we need to emphasize a particular type of electrical storage device(for example, SSD), we will do so explicitly.

Mechanical storage is generally larger and less expensive per byte than selectrical storage. Conversely, electrical storage is typically costly, smaller, and faster than mechanical storage.

The design of a complete storage system must balance all the factors just discussed: it must use only as much expensive memory as necessary while providing as much inexpensive, nonvolatile storage as possible. Caches can be installed to improve performance where a large disparity in access time or transfer rate exists between two components.


Intel processor event-vector table

 vector number    :     description

0: divide error

1: debug exception

2: null interrupt

3: breakpoint

4: INTO-detected overflow

5: bound range exception

6: invalid opcode

7: device not available

8: double fault

9: coprocessor segment overrun (reserved)

10: invalid task state segment

11: segment not present

12: stack fault

13: general protection

14: page fault

15: (Intel reserved, do not use)

16: floating-point error

17: alignment check

18: machine check

19-31: (Intel reserved, do not use)

32-255: maskable interrupts

1.2.1.2 Implementation

 The basic interrupt mechanism works as follows. The CPU hardware has a wire called the interrupt-request line that the CPU sense after executing every instruction. When the CPU detects that a controller has asserted a signal on the interrupt-request line, it reads the interrupts number and jumps to the interrupt-handler routline by using that interrupt number as an index into the interrupt vector, It then starts execution at the address associated with that index. Then interrupt handler save any state it will be changing during its operating, determines the cause of the interrupts, performs the necessary processing, performs a state restore, and executes a return from interrupt instruction to return the CPU to the execution state prior to the interrupt. We say that the device controller raises an interrupt by asserting a signal on the interrupt request line, the CPU catches the interrupt and dispatches it to the interrupt, and the handler clears the interrupt by servicing the device. Figure 1.4 summarizes the interrupt-driven I/O cycle.

The basic interrupt mechanism just described enables the SPU to respond to an asynchronous event, as when a device controller becomes ready for service. In a modern operating system, however, we need more sophisticated interrupthandling features.

1. We need the ability to defer interrupt handling during critical processing.

2. We need an efficient way to dispatch to the proper interrupt handler for a device.

3. We need multilevel interrupts, so that the operating system can distinguish between high-and low-priority interrupts and can respond with the appropriate degree of urgency.

In modern computer hardware, these three features are provided by the CPU and the interrupt-controller hardware.

Most CPUs have two interrupt request lines. One is the nonmaskable interrupt, which is reserved for events such as unrecoverable memory errors. The second interrupt line is maskable: it can be turned off by the CPU before the execution of critical instruction sequences that must not be interrupted. The maskable interrupt is used by device controllers to request service.

Recall that the purpose of a vectored interrupt mechanism is to reduce the need for a single interrupt handler to search all possible sources of interrupts to determine which one needs service. In practice, however, computers have more devices (and, hence, interrupt handlers) than they have address elements in the interrupt vector. A common way to solve this problem is to use interrupt chaining, in which each element in the interrupt vector points to the head of a list of interrupt handlers. When an interrupt is raised, the handlers on the corresponding list are called one by one, until one is found that can service the request. This structure is a compromise between the overhead of a huge interrupt table and the inefficiency of dispatching to a single interrupt handler.

Figure 1.5 illustrates the design of the interrupt vector for Intel processors. The events from 0 to 31, which are nonmaskable, are used to signal various error conditions. The events from 32 to 255, which are maskable, are used for purposes such as device-generated interrupts.

The interrupt mechanism also implements a system of interrupt priority levels. These levels enable the CPU to defer the handling of low-priority interrupts without masking all interrupts and makes it possible for a high-priority interrupt to preempt the execution of a low-priority interrupt.

In summary, interrupts are used thoroughout modern operating system to handle asynchronous events(and for other purposes we will discuss throughout the text). Device controllers and hardware faults raise interrupts. To enable the most urgent work to be done first, modern computers use a system of interrupt priorities. Because interrupts are used so heavily for time-sensitive processing. efficient interrupt handling is required for good system performance.


2022년 4월 11일 월요일

1.2.1.1 Overview

 Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by way of the system bus. (There may be many buses within a computer system, but thesystem bus is the main communications path between the major components.) Interrupts are used for many other purposes as well and are key part of how operating systems and hardware interact.

When the CPU is interrupted, it stops what it is doing and immediately transfers execution to a fized location. The fized location usually contains the starting address where the service routine for the interrupts is located. 

The interrupt service routine executes; on completion, the CPU resumes the interrupted omputation. A timeline of this operation is shown in Figure 1.3.

To run the animation assicated with this figure please click here.

Inerrupts are an important part of a computer architecture. Each computer design has its own interrupt machanism, but serveral funtions are common. The interrupts must transfer control to the appropriate interrupts service routine. The straightforward method for managing this transfer would be to invoke a generic routine to examine the interrupt information. The routine, in turn, would call the interrupt0specific handler. However, interrupts must be handled quickly, as they occur very frequently: A table of pointers to interrupt routine is called indirectly through the table, with no intermediate routine needed.

Generally, the table of pointers is stored in mow memory(the first hundred or so locations). These location hold the addresses of the interrupts service routines of the various devices. This array, or interrupt vector, of addresses is then indexed by a unique number, given with the interrupt request, to provide the address of the interrupt service routine for the interrupting device. Operating system as different as Windows and UNIX dispatch interrupts in this manner.

The interrupt architecture must also svae tghe state information of whatever was  interrupted, so that it can resotre this information after servicing the instance, by modifying register values-it must explicityl save the current state and then resotre that state before retuning. After the interrupt is serviced, the saved return address is loaded into the program counter, and the interrupted computation resumes as though the interrupt had not occurred.


1.2.1 Interrupts

 Consider a typical computer operation performing I/O. To start an I/O operation, the device driver loads the appropriate registers in the device controller, in turn, examines the contents of these registers to determine what action to take (such as "read a character from the keyboard"). The controller starts the transfer of data from the device to its local buffer. Once the transfer of data is complete, the device controller informs the device driver that it has finished its operation. The device driver then gives control to other parts of the operating system, possibly returning the data or a pointer to the data if the operation was a read. For other operations, the device driver returns statrus information such as "write completed successfully" or "device busy". But how does the controller inform the device dirver that it has finished its operation? This is accomplished via an interrupt.

1.2 Computer-System Organization

 A modern general-purpose computer system consists of one or more CPUs and a number of device controllers connected through a common bus that provides access between components and shared memory(Figure 1.2). Each device controller is in charge of a specific type of device (for example, a disk drive, audio device, or graphics display). Depending on the controller, more than one device may be attached. For instance, one system USB port can connect to a USB hub, to which serveral devices can connect, A device controller maintains some local buffer storage and a set of special-purpose registers. The device controller is responsible for moving the data between the peripheral devices that it controls and its local buffer storage.

Typically, operating systems have a device driver for each device controller. This device driver understands the device controller and providers the rest of the operating system with a uniform interface to the device. The CPU and the device controllers can execute in parallel, competing for memory cycles. To ensure orderly access to the shared memory, a memory controller synchronizes access to the memory.

In the following subsections, we describe some basics of how such a system operates, focusing on three key aspects of the system. We start with interrupts, which alert the CPU to events that require attention. We then discuss storage structure and I/O structure.


2022년 4월 10일 일요일

1.1.3 Defining Operating systems

 By now, you can probably see that the term operating system vcovers many roles and functions. That is the case, at least in part, because of the myriad designs and uses of computers. Computers are present within toasters, cars, ships, spacecraft, homes, and businesses. They are the basis for game machines, cable TV tuners, and industrial control systems.

To explain this diversity, we can turn to the history of computers. Although computers have a relatively short history, they have evolved rapidly. Computing started as an experiment to determine what could be done and quickly moved to fixed-purpose systems for military uses, such as code breaking and trajectiory plotting, and governmental users, such as census calculation. Those early computers evolved into general-purpose, multifuctino mainframes, and that's when operating systems were born. In the 1960s, Moore's Law predicted that the number of transistors on an integrated circuit would double every 18 months, and that prediction has held true, Computers gained in functionality and shrank in size, leading to a vast number of users and a vast number and variety of operating systems. (See Appendix A for more details on the history of operating systems.)

How, then, can we define what an operating system is? In general, we have no completely adequate definition of an operating system. Operating systems exist becase they offer a resonable way to solve the problem of creating a usable computing system. The fundamental goal of computer systems is to execute programs and to make solving user problems easier. Computer hardware is constructed toward this goal. Since bare hardware alone is not particularly easy to use, application programs are developed. These programs require certain common operations, such as those controlling the I/O devices. The common functions of controlling and allocating resources are then brought together into one piece of software:the operating system.

In additions, we have no universally accepted definition of what is part of the operationg system. A simple viewpoint is that it includes everything a vendor ships when yuu order "the operating system. "The features included, however, vary greatly across systems. Some systems take up less than a megabyte of space and lack even a full-screen editor, whereas others require gigabytes of spce and lack even a full-screen deitor, whereas others require gigabytes of space and lack even a full-screen ditor , whereas others require gigabytes of space and are based entirely on graphical windowing systems. A more common definition, and the one that we usually follow, is that the operating system is the one program running at all times on the computer - usually called the kernel. Along with the kernel, there are two other types of programs: system programs not associated with the operating of the system.

The matter of what constitutes an operating system become increasingly important as personal computers became more widespread and operating system grew increasingly sophisticated. In 1998, the United States Department of Justice filed suit against Microsoft, in essence claiming that Microsoft included too much functionality in its operating systems and thus prevented application vendors from competing.(For example, a web browser was an integral part of Microsoft's operating systems.) As a result, Microsoft's operating systems.)As a result, Microsoft was found guilty of using its operating-system monopoly to limit competition.

Today, however, if we look at operating systems for mobile devices, we see that once again the number of features constituting the operating system in increasing. Mobile operating systems-Apple's iOS and Google's Android-Features a core kernel along with middleware that supports databases, multimedia, and graphics(to name only a few).

In summary, for our purposes, the operating system includes the always-running kernel, middleware frameworks that ease application development and provide features, and system programs that aid in managing the system while it is running. Most of this text is concerned with the kernel of general purpose operating systems, but other components are discussed as needed to fully explain operating system design and operation.