2013年10月11日 星期五

[IOS] Ch1 Introduction note #1


Overview

       An operating system acts as an intermediary between the user of a
computer and the computer hardware. The purpose of an operating
system is to provide an environment in which a user can execute
programs in a convenient and efficient manner.

        An operating system is software that manages the computer hard-
ware. The hardware must provide appropriate mechanisms to ensure the
correct operation of the computer system and to prevent user programs
from interfering with the proper operation of the system.


 

Introduction 

What Operating Systems Do?

  1. Intermediary between Application and Hardware.
  2. Provide user an convenient interface.
  3. Control many Application on one Hardware.
  4. Control many Users on one Hardware (multiuser environment). 
  5. Distribute computing. (linked by network)
  6. Cloud computing.

A computer system can be divided roughly into four components:



  1. Hardware -  provides basic computing resources.
    > CPU, memory, I/O devices
  2. Operating system - Controls and coordinates use of hardware among various applications and users.
  3. Application programs - define the ways in which the system resources are used to solve the computing problems of the users.
    > Word processors, compilers, web browsers, database systems, video games
  4. Users -  People, machines, other computers.


 Or view it as consisting of:
  1. Hardware
  2. Software
  3. Data

User View: the computer varies according to the interface being used.

System View: the operating system is the program most intimately involved with the hardware. In this context, we can view an operating system as a resource allocator, manages all resources and decides between conflicting requests for efficient and fair resource use. A control program, controls execution of programs to prevent errors and improper use of the computer.
 

Computer System Hardware: 

 

  1. CPU
  2. Northbridge
    •  The northbridge or host bridge was one of the two chips in the core logic chipset on a PC motherboard.
    • used to manage data communications between a CPU and a motherboard. 
    • Supposed to be paired with a second support chip known as a southbridge.
    • historically one of the two chips in the core logic chipset on a PC motherboard. (2011, all of the functions of the northbridge reside on the CPU) (Cause the improvement of the tech and the excess room in CPU)
    • reference: http://en.wikipedia.org
  3. AGP
    • Accelerated Graphics Port
    • Now replaced by PCI Express
  4. RAM 
    • Random-access memory
    • A random-access device allows stored data to be accessed directly in any random order
  5. Southbridge
    • The southbridge typically implements the slower capabilities of the motherboard in a northbridge/southbridge chipset computer architecture

  Computer-System Operation



        For a computer to start running, for instance, when it is powered up or rebooted, it needs to have an initial program to run.
        This initial program, or bootstrap program, tends to be simple.
        Typically, it is stored in read-only memory (ROM), or electrically erasable programmable read-only memory (EEPROM), known by the general term firmware,  within the computer hardware. The bootstrap program must know how to load the operating system and how to start executing that system. It initializes all aspects of the system, from CPU registers to device
controllers to memory contents.
       To accomplish this goal, the bootstrap program must locate and load into memory the operating-system kernel. The operating system then starts executing the first process, such as "init," and waits for some event to occur.


Interrupt:
  1. Occurrence of an event is signaled by an interrupt from either hardware or software.
    • Hardware: 
      • sending a signal to the CPU, usually by way of the system bus. 
      • 通常是外界的硬體裝置利用由CPU 拉出的中斷要求信號線來通知CPU 中斷的請求
    • Software
      • executing a special operation called a system call (also called a monitor call)
      •  通常是CPU 自己引發的,比如說執行了不該執行的指令、計算錯誤或者是執行某個用來產生軟體中斷的指令。
  2. When the CPU is interrupted, it stops what it is doing and immediately
    transfers execution to a fixed location.
  3. Each computer design has its own interrupt mechanism, but several functions are common.
  4. The interrupt must transfer control to the appropriate interrupt service routine.

  • One or more CPUs, device controllers connect through common bus providing access to shared memory
  • Concurrent execution of CPUs and devices competing for memory cycles
  • I/O devices and the CPU can execute concurrently
  • Each device controller is in charge of a particular device type
  • Each device controller has a local buffer
  • CPU moves data from/to main memory to/from local buffers
    • move data to main memory from local buffers: since while computing, data should be in the main memory
      • DMA controller: data exchange without CPU 
    • device controller buffer is full and need to move to main memory
      • not routine (efficiency), just interrupt while it's full
  • 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 


在一般的電腦系統裡,當裝備需要系統來服務時.有二種方法:一是 polling,由CPU一直去問裝備是否需要服務,如果需要時就去服務它,但這很浪費 CPU 的時間,另一種方法就是 IRQ 的方式,當 Device 需耍服務時就發出 IRQ,當系統收到這個 IRQ 訊號時才去服務它,這樣可大大減小系統的負擔。

IRQ: interrupt request, a hardware signal sent to the processor that temporarily stops a running program and allows a special program, an interrupt handler, to run instead.
http://en.wikipedia.org/wiki/Interrupt_request

PIC:  programmable interrupt controller, used to combine several sources of interrupt onto one or more CPU lines.
http://en.wikipedia.org/wiki/Programmable_Interrupt_Controller

IRQ是由中斷控制器所處理的,中斷控制器是用以連接 Device 和 CPU 的重要橋梁,一個Device 產生中斷後,需經過中斷控制器的轉發,訊號才能到達CPU。
中斷控制器經歷了 PIC (Programmable Interrupt Controller 可編程中斷控制器) 和APIC (Advanced Programmable Interrupt Controller 高級可編程中斷控制器) 兩個階段。
PIC 在 UP (Uni-processor 單處理器) 上使用,隨著 SMP (Symmetric Multiple Processor 對稱式多重處理器)開始使用, APIC 已漸漸取代 PIC 了。

An operating system is interrupt driven.


I/O structure

  1. [blocking I/O] 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
  2. [nonblocking I/O] [I/O multiplexing] 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 deviceindicating 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.

Blocking I/O system calls (a) do not return until the I/O is complete. Nonblocking I/O systems calls return immediately.

Example:
Blocking I/O: 
fread(fp, "buf")

直到這行執行完之前,程式會被 block 住,但是這樣比較沒有效率(若同時有 printf() 可做,他必須要等到 fread 處理完才能執行)

Nonblocking I/O:
fp1 = fread()
fp2 = printf() 
select(fp1, fp2)

可做到 I/O overlap。

        Using select(), an application can both monitor monitor several resources at the same time and can also poll for network activity without blocking.
       The select() system call identifies if data is pending or not, then read() or write() may be used knowing that they will complete immediately.

(Network programming)


Direct Memory Access Structure

  • Used for high-speed I/O devices able to transmit information at close to memory speeds
  • Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention
  • Only one interrupt is generated per block, rather than the one interrupt per byte

Storage Structure

  • Main memory – only large storage media that the CPU can access directl
  • Secondary storage – extension of main memory that provides large nonvolatile storage capacity 
  • Magnetic disks – rigid metal or glass platters covered with magnetic recording material 
    • Disk surface is logically divided into tracks, which are subdivided into sectors 
    • The disk controller determines the logical interaction between the device and the computer
  • Caching – copying information into faster storage system; main memory can be viewed as a last cache for secondary storage



Reference:  
Operating System Concepts 8th, by Silberschatz, Galvin, Gagne
Wikipedia
trap & interrupt: http://blog.yam.com/ipray/article/29032801
IRQ & PIC: http://stenlyho.blogspot.tw/2008/08/pic.html
Blocking & Nonblocking I/O: http://www.sal.ksu.edu/faculty/tim/ossg/Device/blocking.html

沒有留言:

張貼留言