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

时间:2024-04-05 18:41:44
  • Device-Status Table设备状态表

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

    • 进行设备管理
    • 左边:一堆设备,占据一行
    • 右边:一堆设备对它的请求队列

  • DMA Direct Memory Access Structure

    _________

    |Memory|                这里发生数据拷贝过程

                    ↓              

           | Driver local buffer |

    • 原先拷贝方式
      • ↓ 拷贝的数据
      • Start end

        (Memory)

      • 通过CPU单字节拷贝,每次到driver拷贝结束产生中断通知CPU
      • Δ2 之后还有 δ3(CPUI/O结束到user process executing开始还经历了一段时间)恢复刚刚保存的数据
      • [Operating System学习笔记] Chapter 1 introduction (2)
      • 拷贝1000个字节,有1000次保存地址,1000次恢复地址,耗费了大量时间
      • 一次拷贝一块(记录需要拷贝的长度),拷贝到D的对应长度位置。最后一个拷贝完成后发送一个中断,不用CPU,用DMA控制器,告诉它从哪儿拷,拷多长,拷到哪儿去,完成后产生一个中断告诉CPU即可。
    • 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.
    • Advantages: Only one interrupt is generated per block, rather than the one interrupt per byte
    • Price: extra DMA controller, 这个过程中CPU是无法碰总线的
    • 字节为单位的中断->块为单位的中断

1.2.2 Storage Structure

  • Main memory = memory(random-access memory or RAM) - only large storage media that the CPU can access directly
    • Main memory is a volatile storage device
  • 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.
  • Storage Hierarchy
    • 3 Factors: Speed, Cost, Volatility.
    • Design of memory: It must use only as much expensive memory as necessary while

      providing as much inexpensive, nonvolatile memory as possible.(P31)

    • Buffer - 缓存 v.s. Cache - 高速缓冲 l1 cache (在CPU里面的Cache, expensive, 读取速度最快)
    • Registers 在CPU里面,Cache(in CPU),

        

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

      ssd上面都是volatile,ss(old version: electronic disk)下面都是nonvolatile.

      Electronic disk can be either.

      Caching(广义的Cache): copying information into faster storage system; main memory can be viewed as a last cache for secondary storage.

      将低级存储设备中经常被访问的数据放到高一级的存储器中提高它的效率和速度

      可以看为memory的高速缓存,如果经常读取ssd里面的数据,就放到主存,速度就提高。

  • Caching
    • Important principle, performed at many levels in a computer (in hardware, operating system, software)
    • Information in use copied from slower to faster storage temporarily
    • Faster storage (cache) checked first to determine if information is there
      • If it is(命中), information used directly from the cache (fast)
      • If not, data copied to cache and used there
    • Cache smaller than storage being cached
      • Cache management important design problem
        • cache不够谁进来
        • cache满了谁出去
      • Cache size and replacement policy
  • Performance of Various Levels of Storage
    • Hierarchy: 从上到下,越来越慢,数量级上的慢。

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

  • Migration of Integer A from Disk to Register
    • Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy
    • Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache
      • Cache coherency problem: 经常存取->升级到高速存储时,不同的cache同一个变量有不同的值

1.4 Operating - System Structure

  • Multiprogramming needed for efficiency
    • Single user cannot keep CPU and I/O devices busy at all times
    • Multiprogramming organizes jobs (code and data) so CPU always has one to execute
      • Increase CPU utilization
    • A subset of total jobs in system is kept in memory
      • since the number of jobs that can be kept simultaneously in memory is usually smaller than

        the number of jobs that can be kept in the job pool.

    • One job selected and run via job scheduling
    • When it has to wait (for I/O for example), OS switches to another job
  • 多任务:同时多个任务给到操作系统,要进行分时处理
  • 时间片(服务每个终端的极短时间)
  • A time-shared operating system allows many users to share the computer simultaneously. Since each action or command in a time-shared system tends to be short, only a little CPU time is needed for each user. As the system switches rapidly from one user to the next, each user is given the impression that the entire computer system is dedicated to his use, even though it is being shared among many users.

    多用户使用一台计算机,通过很短的时间片轮回服务每个用户,让每个用户感觉全部拥有一台计算机,实际上是很多人在共享这台计算机

  • Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing
    • Response time should be < 1 second
    • Process: Each user has at least one program executing in memory processing
    • CPU Scheduling: If several jobs ready to run at the same time
    • If processes don't fit in memory, swapping moves them in and out to run
    • Virtual memory allows execution of processes not completely in memory, use disk as an expansion of memory
  • Memory Layout for Multiprogrammed System
    • 操作系统最早载入,内存地址从0开始,图中灰色:常住内存
      • [Operating System学习笔记] Chapter 1 introduction (2)

        

1.5 Operating - System Operations

  • Interrupt driven by hardware
  • Software error or request creates exception or trap
    • Division by zero, request for operating system service
  • Other process problems include infinite loop, processes modifying each other or the operating system

  

1.5.1 Dual-Mode Operation

  • Dual-mode operation allows OS to protect itself and other system components
    • User mode and kernel mode
    • Mode bit provided by hardware to indicate the current mode: kernel (0) or user (1).
      • Provides ability to distinguish when system is running user code or kernel code
      • Privileged instructions: Some instructions designated as privileged, only executable in kernel mode
      • 书上定义:designating some of the machine instructions that may cause harm as privileged instructions.
      • System call changes mode to kernel, return from call resets it to user
    • 用户程序运行在用户模式下
    • 操作系统运行在内核模式下(至高无上的权利)

内核模式

Mode bit = 1 Ring3用户权限

用户模式

Mode bit = 0 Ring0

  • Transition from User to Kernel Mode

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

    • 系统调用流程 - 接力
      • 模式切换:不是程序切换,是程序调用了内核模式的操作系统服务,又返回用户模式继续程序的执行

1.5.2 Timer

  • Timer to prevent infinite loop / process hogging resources
    • Set interrupt after specific period
    • Operating system decrements counter
    • When counter zero generate an interrupt
    • Set up before scheduling process to regain control or terminate program that exceeds allotted time