CS3101 Lecture 1

Basic Elements

1. Processor - Central Processing Unit (CPU)

Two components: Control Unit Arithmetic (CU) & Logic Unit (ALU)

Works repeatedly and continuously in cycles to execute instructions

 

2. Main Memory - Random-Access Memory (RAM)

随机存取, 指的是当存储器中的数据被读取或写入时,所需要的时间与这段信息所在的位置或所写入的位置无关

Consists of a set of locations defined by sequentially numbered addresses

Stores data and programs

Volatile (Data lost when power off)

 

3. I/O Modules

Moves data between the computer and the external environment like storage (hard drive)

 

4. System Bus

 Provides for communication among processors, main memory, and I/O modules

Instruction Execution

 


Instruction Execution

 A program consists of a set of instructions stored in memory

 

 Machine cycle:

  1. Processor reads (fetches) an instruction from memory*
  2. Processor interprets (decodes) the current instruction
  3. Processor executes the instruction*
  4. Processor stores the result back to memory

Processor Registers - special memory locations inside the processor that can be accessed very fast:

  1. Program Counter (PC) holds next address of the instruction to be fetched
  2. Fetched instruction loaded into Instruction Register (IR) (For decoding)
  3. Execution result stored in Accumulator (AC) temporarily
  4. Program Status Word (PSW) contains execution status information

Example of program execution

 

The first 4 bits from opcode like 0001(1 hex): Load AC from memory, 0010(2hex): Store AC to memory, 0101(5 hex): Add to AC from memory. 

The remain 12 bits refer to a memory address

 


Interrupts*

Interrupt the normal sequencing of the processor by other modules.

Provided to improve processor utilization

中断模式就是说CPU不主动访问这些设备, 只管处理自己的任务. 如果有外部设备要与CPU联系,或要CPU处理一些事情,它会给CPU发一个中断请求信号. 这时CPU就会放下正在进行的工作, 将其暂时保存在Program Counter (PC), 转而寻找中断请求源, 并处理这个外设的请求. 处理完中断后,CPU返回去继续执行中断以前的工作。 

看书(cpu处理一个进程) -> 电话响(外设发起中断请求) -> 放下书并插书签(中断并保存) -> 接电话(cpu处理另一个进程) -> 继续看书(cpu回到原先进程) 

 

Uniprogramming vs Multiprogramming:

Uniprogramming: only one program is running at a given time. 

Multiprogramming: processor has more than one program to execute. 

Example:

With multiprogramming, the improvement of average resource utilization, throughput and response times is evident.


The Memory Hierarchy

 Major constraints in memory: amount, speed, expense

 

Cache memory:

Reminder: Processor must access memory at least once per instruction cycle -> processor execution is limited by memory cycle time, but processor speed is much faster than memory access speed!

Solution: Copy the information in use from slower to faster (but smaller) storage (cache memory) temporarily.

Cache is checked first to determine if the information is there.

  • If it is, information used directly from the cache
  • If not, data copied to cache and used there

CPU缓存(Cache Memory)是位于CPU与内存之间的临时存储器,它的容量比内存小的多但是交换速度却比内存要快得多. 高速缓存的出现主要是为了解决CPU运算速度与内存读写速度不匹配的矛盾,因为CPU运算速度要比内存读写速度快很多,这样会使CPU花费很长时间等待数据到来或把数据写入内存. 在缓存中的数据是内存中的一小部分,但这一小部分是短时间内CPU即将访问的,当CPU调用大量数据时,就可先缓存中调用,从而加快读取速度. 

The principle of locality:  Data which is required soon is often close to the current data. If data is accessed, then it’s neighbors might also be accessed in the near future

  

 

Secondary memory(storage devices):

-Provide large nonvolatile storage capacity

-Use to store program and data files

-Common used: magnetic disks

  • 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.

 


I/O Communication Techniques

 When the processor encounters an instruction relating to I/O, it executes that instruction by issuing a command to the appropriate I/O module. Three techniques are possible for I/O operations:

-Programmed I/O    (Performance is poor)

  • CPU issues a command to I/O module -> I/O module performs the requested action and set the I/O status register-> CPU periodically checks the status of I/O module until it determines the instruction is completed.   

 

-Interrupt-driven I/O    (More efficient)

  • CPU issues a command to I/O module and then goes on to do some other useful work -> I/O module will then interrupt CPU to request service when it is ready to exchange data with CPU -> CPU executes the data transfer and then resumes its former processing

 

-Direct memory access (DMA)   (Most efficient)

Perform by a separate module

  • When CPU wishes to read/write, it issues a command to DMA module containing much information -> DMA module transfers the entire block of data directly to and from memory without going through CPU

 


Operating System Objectives & Functions

 A program that controls the execution of application programs.

An interface between applications and hardware.

Main objectives of an OS:

  • Convenience - Making a computer more convenient to use
  • Efficiency - Allowing computer resources to be used efficiently
  • Ability to evolve - Permitting effective development, testing and introduction of new system functions

 OS as a User/Computer Interface:

  • Programmer makes use of a set of system programs (utilities) in developing an application for end user
  • The most important collection of system programs comprises the OS

OS services:

  • Program development - provides facilities and services, such as editors and debuggers, to assist the programmer in creating programs.
  • Program execution - handles steps need to be performed to execute a program. 
  • Access I/O devices - provides a uniform interface so that programmers can access I/O devices using simple reads and writes.
  • Controlled access to files - provides protection mechanisms to control access to the files for the system with multiple users
  •  System access - for shared or public systems, OS controls access to the system as a whole and to specific system resources in order to provide protection of resources and data from unauthorized users and resolve conflicts for resource contention. 
  • Error detection and response - provide a response that clears the error condition with the least impact on running applications. 
  • Accounting - collect usage statistics for various resources and monitor performance parameters such as response time.

OS as Resource Manager:

A computer is a set of resources for the movement, storage, and processing of data. 

The OS is responsible for managing these resources

  • determines how much processor time is to be devoted to the execution of a particular user program
  • controls the allocation of main memory
  • decides when an I/O device can be used by a program in execution
  • controls access to and use of files. 

Major topics of an OS:

  • Operating Systems are among the most complex pieces of software ever developed.

 

posted @ 2018-01-17 09:06  Charonnnnn  阅读(392)  评论(0编辑  收藏  举报