[Operating System学习笔记] Chapter 1 introduction (1)

What is an Operating System:

  • manages the computer hardware
  • (Definition 0) provides a basis for application programs and acts as an intermediary between the computer user and the computer hardware
  • Goals:
    • Execute user programs and make solving user problems easier.
    • Make the computer system convenient to use.
  • Use the computer hardware in an efficient manner

      

1.1 What Operating Systems Do

Computer System Structure

Four Components of Computer System (not operating system):

  • Hardware
    • Contents: the central processing unit (CPU), the memory, and the input/output (I/O) devices
    • Function: provides the basic computing resources
  • Operating system
    • Function: controls and coordinates the use of the hardware among the various application programs for the various users.
  • Application programs
    • Contents: word processors, spreadsheets, compilers, and web browsers
    • Function: define the ways in which these resources are

      used to solve users' computing problems

  • Users
    • People, machines, other computers

[Operating System学习笔记] Chapter 1 introduction (1)

Other statements of OS:

  • performs no useful function by itself
  • provides an environment within which other programs can do useful work.

  

1.1.1 User View

Interfaces

Goal of OS

(1)PC

maximize the work (or play) that the user is performing

(2)Terminal

maximize resource utilization— to assure that all available CPU time, memory, and I/O are used efficiently and that no individual user takes more than her fair share.

(3)Workstations (1)+(2)

compromise between individual usability and resource utilization.

  

1.1.2 System View

Definition 1: the program most intimately involved with the hardware.

Function (Definition 2 - Resource Allocator):

  1. manages resources in a computer system

    Resources in a computer system: CPU time, memory space, file-storage space, I/O devices, and so on.

  2. decides between conflicting requests for efficient and fair resource use (P26)

Definition 3 - Control Program: A control program manages the execution of user programs

to prevent errors and improper use of the computer

  

1.1.3 Defining Operating Systems

The common functions of controlling and allocating resources are then brought together into one piece of software: the operating system.

Common Definition (Definition 4 - kernel): the operating system is the one program running at all times on the computer

  

  

1.2 Computer-System Organization

1.2.1 Computer-System Operation

  • Computer Startup
    • Bootstrap program
      • Essence: Initial program - loaded at power-up or reboot
      • Location: stored in ROM or EPROM, known as firmware
        • Firmware: In electronic systems and computing, firmware[a] is a computer program that provides the low-level control for the device's specific hardware. Firmware can either provide a standardized operating environment for the device's more complex software (allowing more hardware-independence), or, for less complex devices, act as the device's complete operating system, performing all control, monitoring and data manipulation functions. <wiki>
      • Function: initialize all aspects of system
      • Mission: Load OS, start executing OS
  • Computer System Organization

     [Operating System学习笔记] Chapter 1 introduction (1)

  • One or more CPUs and a number of device controllers connected through a common bus that provides access to shared memory (Figure 1.2).
  • The CPU and the device controllers can execute concurrently, competing for memory cycles.
  • Each device controller is in charge of a specific type of device (for example, disk drives, audio devices, and video displays).
  • To ensure orderly access to the shared memory, a memory controller is provided whose function is to synchronize access to the memory.
  • Computer-System Operation
    • I/O devices and the CPU can execute concurrently.
    • Each device controller is in charge of a particular device type.(1.2.3)
    • Each device controller has a local buffer.
    • CPU moves data from/to main memory to/from local buffers
    • I/O is from the device to local buffer of controller.
    • Device controller informs CPU that it has finished its operation by causing an interrupt.

    DEVICES <--------I/O-------> local buffers (device controller) <------CPU-------> main memory

    |                                                                                                         

                                          Interrupts

  • Interrupt
    • Definition: A Signal from either the hardware or the software to signal the occurrence of an event.

Hardware

Sending signals to CPU usually by system bus

Software

Triggering system call(namely, monitor call, a special operation)

  • Interrupt Timeline

    [Operating System学习笔记] Chapter 1 introduction (1)

    • I/O发出请求-空闲到发送-告知CPU数据满-CPU开始处理数据-数据处理完毕-CPU回去处理原来的
    • I/O request和数据开始传输的时间间隔
      • I/O设备初始化的过程-从idle转移到transferring初始化的一段时间
    • CPU接收到done之后转到I/O interrupt processing状态的时间间隔
      • 为刚才执行的程序保存地址(PC-位置, 各个寄存器的值)
    • The interrupt must transfer control to the appropriate interrupt service routine. (应该是I/O-transfer done那里吧)
      • to invoke a generic routine to examine the interrupt information;
      • the routine, in turn, would call the interrupt-specific handler.
    • Interrupt vector
      • Essence: a table of pointers of interrupt routines, and is indexed by a unique device number, given with the interrupt request, to provide the address of the interrupt service routine for the interrupting device.
      • Goal: provide the necessary speed to handle interrupts quickly
      • Reason of speeding up: no intermediate routine needed
      • Generally, the table of pointers is stored in low memory (the first 100 or so locations).
      • 可以理解为一个从发出中断的设备指向对应中断服务程序的向量,通过这个向量,中断可以直接将控制传输给中断服务程序
  • Common Functions of Interrupts
    • Media: Interrupt transfers control to the interrupt service routine generally, through the interrupt vector, which contains the addresses of all the service routines.
    • Protection: Interrupt architecture must save the address of the interrupted instruction.
    • Non-Synchronous: Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.
    • Trap: A trap is a software-generated interrupt caused either by an error or a user request.
    • Driving: An operating system is interrupt driven.
  • Interrupt Handling
    • The operating system preserves the state of the CPU by storing registers and the program counter.
    • Determines which type of interrupt has occurred:

Polling

通过客户程序选取外设,小程序费时费力才能找到中断源设备

Actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output (I/O), and is also referred to as polled I/O or software-driven I/O.<wiki>

Vectored interrupt system

设备直接将处理器指派给合适的服务程序

In computer science, a vectored interrupt is a processing technique in which the interrupting device directs the processor to the appropriate interrupt service routine. This is in contrast to a polled interrupt system, in which a single interrupt service routine must determine the source of the interrupt by checking all potential interrupt sources, a slow and relatively laborious process.<wiki>

  • Separate segments of code determine what action should be taken for each type of interrupt

1.2.2 Storage Structure

1.2.3 I/O Structure

  • I/O structure

    [Operating System学习笔记] Chapter 1 introduction (1)

    • After I/O starts, control returns to user program only upon I/O completion.
      • Wait instruction idles the CPU until the next interrupt
      • Wait loop (contention for memory access).
      • At most one I/O request is outstanding at a time, no simultaneous I/O processing.
    • After I/O starts, control returns to user program without waiting for I/O completion.
      • System call – request to the operating system to allow user to wait for I/O completion.
      • Device-status table contains entry for each I/O device indicating its type, address, and state.
      • Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt.
    • Two I/O Methods
      • Synchronous
        • 用户发送请求,等待硬件数据传输之后再去做其他事
        • 同步:数据传输不完,程序不返回

          [Operating System学习笔记] Chapter 1 introduction (1)

      • Asynchronous
        • 用户发送请求,硬件开始数据传输,用户转而做其他事,数据传输完成后再通知用户
        • 异步:一启动传输马上回来,继续接受用户请求、响应用户

          [Operating System学习笔记] Chapter 1 introduction (1)