Modern Operating Systems 笔记 - Input/Output

操作系统 DMA 内存映射 中断 Unix

Principles of I/O Hardware

Devices & Controllers

  • block devices stores information in fixed-size blocks, each one with its own address.
  • character devices delivers or accepts a stream of characters, without regard to any block structure.
  • device controller/adapter takes the form of a chip on the parentboard or a printed circuit card that can be inserted into a (PCI) expansion slot.

Memory-Mapped I/O

Each control register is assigned a unique memory address to which no memory is assigned.

Pros:

  • if special I/O instructions are needed to read/write the device control registers, access to them requires nothing more than standard C code, otherwise needs the use of addembly code.
  • with memory-mapped I/O, no special protection mechanism is needed to keep user processes from performing I/O.
  • With memory-mapped I/O, every instruction that can reference memory can also reference control registers.

Cons:

  • most computers nowadays have some form of caching of memory words. Caching a device control register would be disastrous.
  • If there is only one address space, then all memory modules and all I/O devices must examine all memory references to see which ones to respond to.

Modern Operating Systems 笔记 - Memory Management

操作系统 虚拟内存 页表 LTB

No Memory Abstraction

Running multiple programs by static relocation: Modify the second program on the fly as it loaded it into memory.

The lack of memory abstraction is still common in embedded and smart card systems.

A Memory Abstraction: Address Spaces

Address space is the set of addresses that a process can use to address memory.

Dynamic relocation uses base and limit registers to map each process’ address space onto a different part of physical memory in a simple way.

The disadvantage of relocation using base and limit registers is the need to perform an addition and comparison on every memory reference.

Swapping is used to deal with memory overload, bringing in each process in its entirety, running for a while, then putting it back on the disk.

When swapping creates multiple holes in memory, it’s possible to combine them all into one big one, which is called memory compaction. Free memory can be recorded as bitmaps or linked lists.

Modern Operating Systems 笔记 - Deadlocks

操作系统 算法 死锁

Resources

A preemptable resource is one that can be taken away from the process owning it with no ill effects.

A nonpreemptable resource is one that cannot be taken away from its current owner without causing the computation to fail.

Resource Acquisition

  1. Request the resource.
  2. Use the resource.
  3. Release the resource.

A possible implementation:

  1. down on the semaphore to aquire the resource.
  2. using the resource.
  3. up on the semaphore to release the resource.

Modern Operating Systems 笔记 - Interprocess Communication

操作系统 IPC 中断 互斥量 信号量

race conditions

Two or more processes are reading or writing some shared data and the final result depends on who runs precisely when.

Critical Regions

mutual exclusion

Prohibit more than one process from reading and writing the shared data at the same time.

critical region

Also called critical section , the part of the program where the shared memory is accessed.

Conditions to a good solution

  1. No two processes may be simultaneously inside their critical regions
  2. No assumptions may be made about speeds or the number of CPUs
  3. No process running outside its critical region may block other processes
  4. No process should have to wait forever to enter its critical region

Modern Operating Systems 笔记 - Threads

fork pthread sed 线程 内核空间 操作系统 用户空间 进程

Thread Usage

  1. Multiple activities going on at once with the ability to share an address space
  2. Lighter weight than processes, easy to create and destroy.
  3. Overlap activities with substantial I/O to speeding up the application.
  4. Useful on systems with multiple CPUs.

Three ways to construct a server

  1. Thread. Parallelism, blocking system calls.
  2. Single-threaded process. No parallelism, blocking system calls.
  3. Finite-state machine. Parallelism, nonblocking system calles, use interrupts to simulate thread.

Classical Thread Model

Processes are used to group resources together; threads are the entities scheduled for execution on the CPU. There are no protection betwwen threads because (1) it’s impossible, and (2) it should not be nessessary.

While threads share one memory space, it takes fewer space to maintain a thread, including Program Counter, Registers, Stack and State.

Modern Operating Systems 笔记 - Processes

操作系统 进程 Unix Windows fork kill sed

pseudoparallelism

The illusion of parallelism while CPU is switching from process to process quickly.

The Process Model

process is an instance of an executing program, is the activity of a program.

If a program is running twice, it counts as two processes.

Process Creation

Processes are created when

  1. System init
  2. Process creation system call by a running process
  3. A user request to create a new process.
  4. Init of a batch job.

导航: 上一页 下一页

🔝