0% found this document useful (0 votes)
51 views21 pages

Chöông 1 (Boå Sung) : A. Heä Thoáng Maùy Tính

The document discusses the basic architecture of computer systems including CPU architecture, operation, I/O structure and storage hierarchy. It covers the fetch-execute cycle of the CPU, interrupt handling, I/O techniques like polling, interrupt-driven I/O, DMA and caching. It also discusses hardware protection mechanisms like dual mode, privileged instructions, memory protection using base and limit registers, and timer interrupts.

Uploaded by

Minh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views21 pages

Chöông 1 (Boå Sung) : A. Heä Thoáng Maùy Tính

The document discusses the basic architecture of computer systems including CPU architecture, operation, I/O structure and storage hierarchy. It covers the fetch-execute cycle of the CPU, interrupt handling, I/O techniques like polling, interrupt-driven I/O, DMA and caching. It also discusses hardware protection mechanisms like dual mode, privileged instructions, memory protection using base and limit registers, and timer interrupts.

Uploaded by

Minh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Chöông 1 (boå sung)

A. Heä thoáng maùy tính


 Kieán truùc cô baûn cuûa heä thoáng maùy tính
 Cô cheá vaän haønh cuûa heä thoáng
 Caáu truùc heä thoáng xuaát nhaäp (I/O)
 Caáu truùc vaø phaân caáp heä thoáng löu tröõ

1.A.1
Kieán truùc cô baûn cuûa heä thoáng
maùy tính

Keyboard
Disks Monitor
Mouse Printer

Disk controller USB controller Graphics adapter


CPU

MEMORY

Ñeäm döõ lieäu (local buffer)

1.A.2
Chu trình hoaït ñoäng cuûa CPU

Fetch Next Execute


Start HALT
Instruction Instruction

1. Chu trình ñôn giaûn (khoâng coù ngaét quaõng)

Interrupts
disabled

Fetch Next Execute Check for interrupt;


Start
Instruction Instruction Interrupts Process interrupt
enabled

HALT

2. Chu trình coù ñieàu khieån ngaét quaõng

1.A.3
Ngaét quaõng
 Phaân loaïi: ngaét quaõng do
– Program: traøn soá hoïc, chia cho 0, truy caäp boä nhôù baát hôïp phaùp
– Timer: cho pheùp CPU thöïc thi moät taùc vuï naøo ñoù theo ñònh kyø
– I/O: keát thuùc taùc vuï I/O, xaûy ra loãi trong I/O
– Hardware failure: Hö hoûng nguoàn, loãi memory parity,…
– Trap (software interrupt): yeâu caàu dòch vuï heä thoáng (goïi system
call),…

Löôïc ñoàà thôøi gian khi process coù yeâu caàu caùc taùc vuï I/O
1.A.4
Quaù trình xöû lyù ngaét quaõng
User Interrupt vector
Program table
0
0 0

2
 00ffe23f interrupt
0x21 routine


1 21 00ffe23f ret

i int. 0x21
i+1
N
ffffffff

Interrupt
handler

1.A.5
Quaù trình xöû lyù ngaét quaõng (tt)

I/O interrupts

Khoâng coù ngaét quaõng Coù ngaét quaõng

1.A.6
Caáu truùc heä thoáng
I/O
Caùc kyõ thuaät thöïc hieän I/O

 Polling
– Ñeå göûi döõ lieäu ra moät thieát bò I/O
(thoâng qua I/O port), CPU ghi byte döõ
lieäu vaøo thanh ghi döõ lieäu (data
PIO register), sau ñoù thieát laäp moät bit (bit
 1) cuûa thanh ghi ñieàu khieån (control
register) ñeå baùo hieäu cho I/O controller.
(PIO: programmed I/O)

– I/O controller ñoïc byte döõ lieäu töø


thieát bò I/O, xoùa bit ñieàu khieån (bit 
0). CPU tieáp tuïc göûi byte keá.

– I/O controller khoâng gaây ra ngaét moãi


khi xong vieäc. CPU phaûi duøng cô cheá
polling ñeå kieåm tra traïng thaùi thieát bò
I/O

– Truyeàn döõ lieäu töøng byte moät


1.A.8
Caùc kyõ thuaät thöïc hieän I/O (tt)
 Interrupt-driven I/O
– CPU khoâng poll maø I/O controller seõ
gaây ra ngaét quaõng moãi khi saün X
saøng cho taùc vuï I/O.
X
– Trong luùc thieát bò I/O thöïc thi leänh,
CPU coù theå thöïc thi coâng vieäc khaùc.

– Polling vaø interrupt-driven I/O ñeàu tieâu


toán thôøi gian xöû lyù cuûa CPU bôûi vì
CPU phaûi copy byte döõ lieäu ñöôïc
ñoïc/ghi  memory.

– Thích hôïp cho caùc thieát bò I/O coù toác


ñoä khoâng cao (keyboard, mouse)

1.A.9
Caùc kyõ thuaät thöïc hieän I/O (tt)

 Phöông phaùp thöïc hieän I/O

kernel kernel

Synchronous Asynchronous

- - - : “bypassing”

1.A.10
Caùc kyõ thuaät thöïc hieän I/O (tt)

 Asynchronous I/O

Caùc haøng ñôïi (wait queue) I/O

1.A.11
Caùc kyõ thuaät thöïc hieän I/O (tt)
 Direct Memory Access (DMA)
– CPU göûi yeâu caàu ñeán module DMA (=
DMA controller)

– Module DMA chuyeån moät khoái döõ lieäu


giöõa boä nhôù vaø thieát bò I/O maø khoâng
caàn CPU can thieäp.

– Khi xong moät taùc vuï göûi nhaän thì phaùt


khôûi moät ngaét quaõng.

– CPU chæ tham gia vaøo giai ñoaïn khôûi ñaàu


vaø keát thuùc cuûa vieäc truyeàn nhaän döõ
lieäu

– Trong khi ñang truyeàn nhaän döõ lieäu, CPU


coù theå thöïc thi coâng vieäc khaùc

– Thích hôïp cho caùc thieát bò coù toác ñoä cao


(ñóa) 1.A.12
Caáu truùc & phaân caáp
heä thoáng löu tröõ
Heä thoáng löu tröõ

 Löu tröõ laø moät trong nhöõng daïng thöùc I/O quan troïng
– Boä nhôù chính (main memory, primary memory)
 CPU chæ coù theå truy caäp tröïc tieáp thanh ghi (registers) vaø boä
nhôù ROM, RAM

– Boä nhôù phuï (secondary storage)


 Heä thoáng löu tröõ thoâng tin beàn vöõng (nonvolatile storage)

 Ñóa töø (magnetic disks): ñóa meàm, ñóa cöùng, baêng töø

 Ñóa quang (optical disk): CD-ROM, DVD-ROM

 Flash ROM: USB disk

1.A.14
Phaân caáp heä thoáng löu tröõ

Toác ñoä cao

vd: file-system data

Giaù thaønh thaáp


Dung löôïng lôùn

1.A.15
Cô cheá caching

 Caching
– naïp tröôùc döõ lieäu vaøo thieát bò löu tröõ toác ñoä cao hôn
 Taïi sao phaûi duøng cache?
– Cheânh leäch lôùn giöõa toác ñoä CPU vaø toác ñoä boä nhôù RAM, ñóa,…
– Khai thaùc nguyeân lyù cuïc boä (locality)
 Kích thöôùc cache nhoû  phaûi quaûn lyù cache: thay noäi dung
cache
 Trong cô cheá caching, moät döõ lieäu coù theå ñöôïc löu tröõ nhieàu
nôi  phaûi baûo ñaûm tính nhaát quaùn döõ lieäu: cache coherency
problem

A: döõ lieäu

1.A.16
Baûo veä phaàn cöùng – dual mode
 Cô cheá dual-mode: caàn coù phaàn cöùng hoã trôï
– User mode – thöïc thi vôùi quyeàn haïn cuûa user bình thöôøng
– Kernel mode (coøn goïi laø supervisor mode, system mode, monitor
mode) – coù toaøn quyeàn truy xuaát taøi nguyeân heä thoáng
Phaàn cöùng coù theâm mode bit ñeå kieåm soaùt mode hieän haønh:
– mode bit = 0: kernel mode
– mode bit = 1: user mode
– Khi coù ngaét hoaëc coù loãi xaûy ra, heä thoáng seõ chuyeån sang kernel
mode.

1.A.17
Baûo veä phaàn cöùng – I/O

 Leänh I/O ñeàu laø privileged instruction


– Users khoâng ñöôïc pheùp töông taùc tröïc
tieáp vôùi caùc thieát bò I/O maø phaûi
thoâng qua lôøi goïi system call

System call
– Laø phöông thöùc duy nhaát ñeå process
yeâu caàu caùc dòch vuï cuûa heä ñieàu
haønh

– System call seõ gaây ra ngaét meàm (trap),


quyeàn ñieàu khieån ñöôïc chuyeån ñeán
trình phuïc vuï ngaét töông öùng, ñoàng
thôøi thieát laäp mode = 0 (kernel mode).

– Heä ñieàu haønh kieåm tra tính hôïp leä,


ñuùng ñaén cuûa caùc ñoái soá, thöïc hieän
yeâu caàu roài traû quyeàn ñieàu khieån
veà leänh keá tieáp ngay sau lôøi goïi
system call, mode = 1.
1.A.18
Baûo veä phaàn cöùng – Boä nhôù
Vd: baûo veä boä nhôù duøng 2 thanh ghi

- Truy caäp boä nhôù ngoaøi vuøng xaùc ñònh


bôûi thanh ghi base vaø thanh ghi limit seõ sinh
ra trap

- Leänh naïp giaù trò cho caùc thanh ghi base vaø
thanh ghi limit ñeàu laø privileged instruction
(b)

(a)

1.A.19
Baûo veä phaàn cöùng – CPU

 Baûo veä CPU


– Baûo ñaûm OS duy trì ñöôïc quyeàn ñieàu khieån
– Traùnh tröôøng hôïp CPU bò keït trong caùc voøng laëp voâ haïn
Cô cheá thöïc hieän laø duøng timer ñeå kích khôûi caùc
ngaét quaõng ñònh kyø
– Boä ñeám timer seõ giaûm daàn sau moãi xung clock.
– Khi boä ñeám timer baèng 0 thì ngaét timer ñöôïc kích hoaït  heä
ñieàu haønh seõ naém quyeàn ñieàu khieån.

 Leänh naïp giaù trò boä ñeám timer laø moät privileged
instruction.

1.A.20
Timer

 Coù theå söû duïng timer ñeå thöïc hieän cô cheá time-
sharing.
– Thieát laäp timer gaây ngaét ñònh kyø N ms (N: time slice, quantum
time) vaø ñònh thôøi CPU sau moãi laàn ngaét.

 Coù theå duøng timer ñeå tính thôøi gian troâi qua (elapse
time)

1.A.21

You might also like