Transcript lecture01

Lecture #1
Computer System Overview
1


2
운영체제는 컴퓨터 시스템의 하드웨어를 제어하여
사용자에게 프로그램을 실행할 수 있는 환경을
제공한다
운영체제에 있어 중요한 컴퓨터 하드웨어 측면을
살펴본다
컴퓨터 시스템의 구성

컴퓨터 시스템의 계층적 구성


하드웨어(Hardware)
소프트웨어(Software)

시스템 소프트웨어(System Software)
• 운영체제(Operating System)
• 유틸리티(Utility)

응용 프로그램(Application Program)
cf) 미들웨어(Middleware)
3
End
User
Programmer
Application
Programs
Middleware
Utilities
Operating-System
Computer Hardware
컴퓨터 시스템의 계층적 구조
4
OperatingSystem
Designer
Basic Hardware Components


Processor (CPU)
Main Memory


현재 실행중인 프로그램과 데이터를 저장
I/O modules (I/O controllers, I/O processors...)

주변 장치와 CPU 사이에 데이터를 전송하는 하드웨어




5
secondary memory devices (e.g: hard disks)
keyboard, display...
communications equipment
System interconnection (e.g: Buses)
 communication among processors, memory,
and I/O modules
Printer
Hard Disk
I/O Controller
CPU
I/O Controller
System Bus
Memory
Controller
Main Memory
6
Computer Hardware Architecture
I/O Module Structure


Data to/from system bus are buffered in data register(s)
Status/Control register(s) holds




7
current status information
current control information from
I/O logic interacts with CPU via control bus
Contains logic specific to the interface of each device
CPU와 주기억장치
주기억 장치
(Main Memory)
0 00 0
중앙처 리장치
(CPU)
0 00 1
0 00 2
보조기 억장치
(Secondary
Memory)
0 00 3
·¹Áö½ºÅÍ
Á¦¾îÀåÄ¡
·¹Áö½ºÅÍ
0 00 4
0 00 5
Program
¿¬»êÀåÄ¡
·¹Áö½ºÅÍ
F FF D
F FF E
F FF F
8
Data
CPU Registers (fast memory on cpu)



9
Control & Status Registers

Generally not available to user programs

some used by CPU to control its operation

some used by OS to control program execution
User-Visible Registers

available to system (OS) and user programs

holds data, addresses, and some condition codes
현재 실행중인 프로그램의 모든 상태 정보를 저장한다
Examples of Control & Status Registers

Program Counter (PC)


Instruction Register (IR)


다음에 수행한 명령어의 주소를 저장
지금 수행중인 명령어를 저장
Program Status Word (PSW)

다음의 내용을 포함하는 레지스터 그룹:



10
condition codes and status info bits
Interrupt enable/disable bit
Supervisor(OS)/user mode bit
User-Visible Registers

Data Registers


Address Registers


11
연산하기 위한 데이터나 중간 계산 결과를 저장하는 레지스터
데이터와 명령어의 메모리 주소를 저장
인덱스 또는 오프셋 주소 등과 같이 절대 주소를 계산하기 위한
정보를 저장
The Basic Instruction Cycle




12
CPU는 다음에 수행한 명령어와 데이터를 가져온다(Fetch Cycle)
CPU는 가져온 명령어를 수행한다(Execution Cycle)
Program counter (PC) 는 다음에 수행할 명령어의 주소를
저장하고 있다
PC 레지스터 값은 fetch cycle에서 자동적으로 증가한다
Then CPU must wait for I/O to complete!





13
WRITE 명령어에 의해 제어권이
I/O 프로그램으로 넘어간다
I/O 프로그램은 입출력을 위해 I/O
Module을 준비한다(4)
CPU 는 I/O 명령이 수행 완료될
때까지 기다린다(Idle Wait)
I/O 프로그램은 I/O 명령의 수행
결과를 알려준다
CPU는 중단된 사용자 프로그램을
수행한다
Interrupts



14
I/O modules은 event(입출력 동작의 완료 여부
등)를 INTERRUPT을 통하여 CPU에 알린다
CPU은 Interrupt Handler Routine (normally part
of the OS)을 실행하여 Interrupt를 서비스한다
Interrupt Processing Routine / Interrupt Vector
Table
Instruction Cycle with Interrupts!



15
CPU 는 현재 실행중인 명령어를 완료하고 interrupt를 검사한다
만약 pending된 interrupts가 없으면, 현재 프로그램의 다음
명령어를 실행한다
Pending된 interrupt가 있으면, 현재의 프로그램 실행을 중단하고
interrupt handle를 실행한다
Interrupt Handler




16
Interrupt의 특성을 결정하고 필요한 처리 동작을
수행하는 프로그램
Interrupt가 발생하면 소프트웨어 방식 또는 하드웨어
방식으로 현재 수행중인 프로그램은 중단되고
interrupt handler가 실행된다
Interrupt handler 수행이 완료되면 중단된
프로그램을 수행한다(resume)
따라서, interrupt handler를 수행하기 전에 현재
수행중인 프로그램의 상태 정보를 저장하여야
한다(content of PC + PSW + registers + ...)
Simple Interrupt Processing
17
Interrupts improve CPU usage




18
I/O 프로그램은 I/O Module을
준비하고 I/O 명령을 전송한 후에
사용자 프로그램으로 되돌아 온다
사용자 프로그램은 I/O 동작이
일어나는 동안 실행을 계속한다(e.g:
printing)- no waiting
I/O 동작이 종료되면 사용자
프로그램은 인터럽터되며, interrupt
handler가 실행되어 interrupt를
서비스한다
사용자 프로그램 실행을 재개한다
Classes of Interrupts

I/O



Program Exception

overflows

try to execute illegal instruction

reference outside user’s memory space
Timer


19
signals normal completion of operation or error
preempts a program to perform another task
Hardware failure (e.g: memory parity error)
Multiple interrupts: sequential order



20
Disable interrupts during an interrupt
Interrupts remain pending until the processor enables
interrupts
After interrupt handler routine completes, the processor
checks for additional interrupts
Multiple Interrupts: priorities



21
Higher priority interrupts cause lower-priority interrupts to
wait
Causes a lower-priority interrupt handler to be interrupted
Example: when input arrives from communication line, it
needs to be absorbed quickly to make room for more input
Multiprogramming



22
프로그램은 I/O 장치를 통하여 입출력하는 동안 I/O
동작이 완료될 때까지 기다려야 한다
하나의 프로그램이 입출력을 기다리는 동안 CPU는
다른 프로그램을 실행할 수 있다
Interrupts are mostly effective when a single
CPU is shared among several concurrently
active processes
I/O communication techniques

3 techniques are possible for I/O operation

Programmed I/O


Interrupt-driven I/O


CPU can execute code during I/O operation: it gets
interrupted when I/O operation is done.
Direct Memory Access(DMA)

23
Does not use interrupts: CPU has to wait for completion of
each I/O operation
A block of data is transferred directly from/to memory
without going through CPU
Programmed I/O



24
I/O module performs the
action on behalf of the
processor
But the I/O module does not
interrupt the CPU when I/O is
done
Processor is kept busy
checking status of I/O
module(polling)
Interrupt-Driven I/O


Processor is free to do other work

No needless waiting

25
Processor is interrupted when I/O
module ready to exchange data
Consumes a lot of processor time
because every word read or
written passes through the
processor
Direct Memory Access(DMA)





26
CPU issues request to a DMA
module (separate module or
incorporated into I/O module)
DMA module transfers a block of
data directly to or from memory
(without going through CPU)
An interrupt is sent when the task
is complete
The CPU is only involved at the
beginning and end of the transfer
The CPU is free to perform other
tasks during data transfer
Memory Hierarchy (1)
Cost per bit,
Frequency of access
Registers
Capacity,
Access time
Main Memory
Magnetic Disk
(Secondary Memory)
Magnetic Tape
27
Optical Disk
(Tertiary Memory)
Memory Hierarchy (2)
Cost per bit,
Frequency of access
Registers
Capacity,
Access time
Cache
Main Memory
Disk Cache
Magnetic Disk
Magnetic Tape
28
Optical Disk
Cache Memory




29
Small cache of expensive but
very fast memory interacting with
slower but much larger memory
Invisible to OS and user
programs but interact with other
memory management hardware
Processor first checks if word
referenced to is in cache
If not found in cache, a block of
memory containing the word is
moved to the cache
The Hit Ratio





30
Hit ratio = fraction of
access where data is in
cache
T1 = access time for fast
memory
T2 = access time for slow
memory
T2 >> T1
When hit ratio is close to 1
the average access time is
close to T1
Locality of Reference




31
Memory reference for both instruction and data
tend to cluster over a long period of time
Example: once a loop is entered, there is frequent
access to a small set of instructions
Hence: once a word gets referenced, it is likely
that nearby words will get referenced often in the
near future
Thus, the hit ratio will be close to 1 even for a
small cache
Disk Cache




32
A portion of main memory used as a buffer to
temporarily to hold data for the disk
Locality of reference also applies here: once a
record gets referenced, it is likely that nearby
records will get referenced often in the near future
If a record referenced is not in the disk cache, the
sector containing the record is moved into the
disk cache
Read-ahead policy