P. 1
giao_trinh_nguyen_ly_he_dieu_hanh

giao_trinh_nguyen_ly_he_dieu_hanh

|Views: 216|Likes:
Published by chaukietlien

More info:

Published by: chaukietlien on Oct 18, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/16/2014

pdf

text

original

"') ~ ......... ....,.

,

so GLAD Due v A DAO TAO HA Nor

. . .

D~NG VU TUNG

GIAOTRiNH NGUYEN L t HE DIEU HANH

(Dung trong cae truong THeN)

NHA XUAT BAN HA N¢I - 2005

Mil. so xuat ban:

373 - 373.7 HN - 05

113/407 - 05

Lili gild thi~u

NUbc to dang buoc vao thai ky cong nghiep hoa, hien. dqi hoa nhdm duo Vi¢t Nom Ira thanh male cong nghiep van minh, hien dai.

Trong su nghiep each mang to ton do, cong tac dao 1(10 nhan luc luon gil? vai tro quan trong. Boo coo Chinh tri cua Ban Chap hanh Trung uan g Dang Cong san Vi¢t Nam tai Dai hoi Dang toan qudc ldn thu' IX dd chi ro: "Phat tricn giao due va dao tao la mot trong nlnrng dong luc quan trong thiic day str nghiep cong nghiep hoa, hien dai hoa, Ia dieu kien de: phat trien nguon file con ngiroi - yeu t6 eo ban de: phat trien X8 hoi, tang twang kinh te nhanh va ben virng".

Quan triet chit truong, Nghi quyet cua Dang va Nha nuac va nhun thuc dung dim vi?' tam quan tn;mg cua chuang trinh, gido trinh dOl vai viec nang cao chat luang dao tao, theo de' nghi clla 56 Gido due va Dao tao Ha Noi, ngay 231912003, Uy ban nhan dan thanh pho' Ha Noi dd ra Quyet dinh so' 56201QD-UB eho phep 56 Gido due va Dao tao thuc hien de' an bien soan chuang trinh, gido trinh trong cac truang Trung hoc chuyen nghiep (THCN) Ha No). Quyet dinh nay the' hien su quan tam sdu sac cua Thanh uy, VBND thanh photrong viec nang cao chat luang dao tao va pluu trien nguon nhdn life Thit do.

Tren cry s6 chuang trinh khung eua Bo Gido due va Dao tao ban hanh va nhiing kinh nghiem rut ra ttt thuc tedao tao, Sd Gido due va Esao tao dd chi' dao cdc truimg THCN td chuc bien soan chuang trinh, gido trtnh mot each khoa h9C, hf

3

tht/ng va cap nh(lt nhiing kiln thuc thuc tUn phil hap viti d6i tuang h9C sinh THCN Ha Noi.

B¢ giao trinh nay ld tai lieu gidng day wi h9C tdp trong cdc truong THCN a Ha N(Ji, dong thai fa tai lieu tham khdo him fch cho cac truang co dao tao cdc nganh ky thudt - nghiep VI;l va dong ddo ban doc quan tam den van de' huang nghiep, day nghe.

Vi¢e to' chuc bien soan bo chuang trinh, giao trinh nay La mot trong nhieu hoat dong thief thuc eua nganh giao due vii dao tao Thu do de' ky niem "50 flam gidi phong Thu do ". "50 nam thanh l(Ip nganh" va huang tai ky niem "1000 ndm Thong Long - Ha N¢i ".

Sd Giao due va Dao tao Ha Noi chan thanh cam <In Thanh uy, VBND, cae So', ban, nganh cua Thanh pha, V¥ Ciao due chuyen nghiep B¢ Guio due va Dao tao, cac nha khoa hoc, cae chuyen gia ddu nganh, cae gidng vien, cae nha qudn fy, cac nha doanh nghiep dd tao dieu kien giup diJ, dong gop y kien, tham gia H(Ji dong phdn bien, H¢i d6ng thdm dinh va H(Ji dong nghiem thu cae chuang trinh, gido trinh,

Day Iii ldn ddu tien So' Gido due va Dao tao Ha N(Ji ld chuc bien soan chuang trinh, giao trinh, Du dd het sue co' gang nhung chdc chan khong tranh khoi thieu sot, bat cap. Chung toi mong nhdn duac nhiing y kien dong gop cua ban doc de'tung buac hoan thien b(J gido trinh trong cae ldn tdi bdn sau.

GIAM DOC SO GIAo Dl)C v A DAo TAO

4

Trollg h¢ tho/Ig kiell tlu«: chuyen nganD trang hi clio hoc sinh khoa Ky thuat nuiy tinh rQ khoa Till hoc qulin IS', giao trinh Nguyen 19 h¢ dicu hanh g()[J ptuin cung cop IIlll(llg 11{'ji dung kiell thtic chung Illui't Vf! h¢ dif!u hanh nui» tinh. N 6 gi lip f1g1((fi hoc nan: bat duac IIhil'ng nguyen Iy co ban va ngllY(;'l tde lam viec Clio mot h¢ die'll lianh may tinh tting quat. TE'f {M c6 tlu!"' ap dung de' him vie: (61 \'()"i cdc h¢ dieu hanh cu tlu)' tren thuc te, hinh dung duac XLI huong p/Ulf {fI(/n Clia cae h¢ dieu hanh 111(/; trong 1l((fllg lai.

D/ phuc VI_( cong tac gidng d{ly va hoc tap, eJulng toi bien soan ClUJ}1 giao trinb Nguyen 19 he dieu hanh nluim cung ci/p tbi I1guoi lire mot .w>' kifll thuc co bdn nlui: vi" IIII/! qfc na».

Cluing Wi XiII trdn trong cam (in TS. Pill) Dlrc Toan - Hoc vien Cong Ilgh¢ BUll chinli "iffll tlu)lIg va TS. Le Ba Dang - Vi¢1I C611g IIgh¢ tlujllg till del doc VU clio nl1/(lIg 1111(111 xet l·(f n1i dUll).? gicio trinh. Cluing to! xin trdn fr{lllg aim (Ill PGS. TS. Thai Quang Vinh - \/i{'n C6ngl1g/J¢ thong till, 1'S. Luang Can D(Jng - Phd dlli nhiem klioa C6ng IIgh¢ thdl1g fill - Vlfl1 D{d hoc 1Ilr1 Hd Noi, TS. Nguy/ill ,·an Ditfp - CI1lj nhietn klioa Cong Ilgh{' th6ng till trJ((~ng Cao ddl1g Di¢11 life dti clio II/arllg y kiell dClng g6p qll~v ball de' guu: trinl: dut« hoan thifll han.

Cluing t61 xin glO" lifi ('elm.all t(ii SdGitio due vel Ddo t~1O lid N{Ji, Ball gidm hi¢1I truong Trung hoc ban ("(111,1Z ky thll{it tin hoc H« N(Ji - E5)[IH dd tao dil"11 ki41/ clio chung 1/)i hoan tluuil: cuon glao trinli lid)'.

M(Jc du dd co 1I11ie'1I ('(f Willg trong bien SO(1I1 nhung do kiln tlutc \'(7 {M!i gian ccJ IU;111 , dong thai cling lei 1c1/1 bien SO{1I1 (Tdll tien nen giao tn'1I11 kh6ng trdnh khoi nhiing thieu sot. Cllling toi mong muon nhdn duac Sl/ thong cam vci y kien dong gop n"ia die thdy co, cac ban hoc sinh, sinh vien vel ban doc de' cuon gicio trinh duoc tSt han.

TAc GIA.

5

Bai rod dau

May tinh dien tu ra dai vao nhirng narn 40 cua the ky XX. Ban dau, pharn vi su dung may tinh con rit han hep, da phan chi nham phuc VlJ. muc dfch nghien CUu khoa h9C. Han nira, de van hanh he thong can phai su dung cac cong Cl,1 phan cirng dac biet va thao tac van hanh rat phirc tap,

Cling phat trien song song voi 5V phat trien cua ky thuat dien tir, cac the he may tinh ve sau duoc cai lien ngay mot tinh vi hem, c6 toe d¢ xu 19 nhanh hem, kich thucc nho gon hem, tieu ton it nang luong han va dii lam nen mot cuoc each rnang trong linh vue xu 19, tinh toan, dieu khien tv dong ... Voi cac the he may tfnh nay doi hoi phai co su dieu khien, van hanh mot each nr dong d~ phat huy hieu qua cua n6 mot each toi uu nhat. Nhu vay, can phai co mot chuang trinh phan mem dam bolo viec giai quyet cac van de noi tren. D6 chfnh 13. cac he dieu hanh may tinh.

H¢ dieu hanh la mot t~p hop cac phan mem he thong dieu khien moi hoat dong cua may tinh va tao moi tnrong giao dien giifa nguai sir dung va may tinh. VI vay, he dieu hanh rat quen thuoc voi moi nguoi SLr dung, tit ca moi ngtroi sit dung khi lam viec vai may tinh can phai biet thao lac (du la nhirng thao lac don gian) voi mot he dieu hanh ClJ. the.

Hieu biet, narn virng nguyen ly heat dong cua he dieu hanh de tir d6 co the khai thac cac h¢ dieu hanh ClJ. the mot each co hieu qua lit mot nhu cau thirc te kh6ng thli thieu duoc doi voi cac can bo phu trach ky thuat va quan ly cac he thong may tinh.

Noi dung cuon giao trinh "Nguyen ly he dieu hanh" g6m cac kien thirc ve phan mem he thong. No cung cap cho nguoi h9C nhfrng kien thiic chung nhat ve he dieu hanh may tinh, giup nguoi hoc nam bat duqc nhfrng nguyen 19 co ban va nguyen lac lam viec cua mot h¢ dieu hanh may tinh t6ng quat, tir d6 ap dung de lam viec t6t voi cac he dieu hanh ClJ. the tren thuc te, hieu va xii 19 ducc cac van de c6 the xay ra trong h¢ thong. Dong thoi Dam bat duoc xu huang phat trien cua cac he dieu hanh moi trong tuong lai.

Cac van de cu lh~ trlnh bay trong giao trlnh nay diroc chia thanh 9 chuang:

7

ChUO'Dg 1. T6ng quan ve h~ dieu hanh: Cung cap cac kien thirc tong quat ve he dieu hanh, qua trlnh phil trien va phan loai h¢ dieu hanh; cac tinh chat eo ban ella he dieu hanh va nguyen tac thiet ke, xay dung h~ dieu hanh. Trang chirong nay cling trinh bay ve cau true, cac thanh phan co ban va cac phuc vu ella he dieu hanh.

Chuang 2. Quan Iy tien trinh: Trong h~ th6ng luon ton tai cac tien trlnh heat dong song song rna trang thai cua cluing anh huang lfin nhau va anh huang [ai hoar dong ella toan he thong. Muc tieu ella chuang nay nham gici thieu bien phap quan 19 cac tien trinh song hanh voi noi dung chinh la giili quyet bai roan tranh chap tai nguyen giira cac tien trlnh - Bai toan doan toi han.

Trong chuang nay cling de cap toi hien tuong be taco Do la tinh trang cac tien trlnh trong he thong roi vao trang thai cho doi va han dan tai lam "treo" he thong.

Chuang 3. Lap lich cho CPU: CPU 13 tai nguyen quan trong nhat cua he thong, no th~ hien sue manh xu ly cua toan bo h¢ thong. Do vay, thai gian rna CPU phuc vu cho cac tien trinh hoat dong can phai diroc khai thac mot each toi iru nhat, Chuang 3 neu fa Him quan trong cua "gio CPU" va trlnh bay cac phuong phap, cac thuat toan lap lich cho CPU cua he dieu hanh nharn dap ung yeu cau duoc phuc vu ella cac tien trlnh. Dong thai, trong chuang nay eUng gioi thieu ve ngat - mot cong cu de CPU co the dieu khien hoat dong ella cac tien trinh mot each chfnh xac.

Chuang 4. Quan Iy bQ nho trong: Nhiem VI,! cua he dieu hanh la phai cap phat khong gian nho eho cac chuang trinh hoat dong va thu hoi khi chuang trinh ket thiic. Chuang nay giai thfch qua trinh gan dia chi (cap phat khong gian nho) eho cac bien khi thuc hien mot chuang trlnh, cac cau true co ban ella chuang trlnh phan mern va cac phuong phap cap phat bo nho cua h¢ dieu hanh.

Chuang 5. Quan Iy b«) nho ngoai: BQ nho ngoai lit thiet bi dung d€ luu tfU thong tin tnroc va sau qua trlnh xu ly, tinh toano Trang chuang nay trinh bay cac bien phap quan 19 va cap phat khong gian nho nr do tren diatu, cac thuat roan lap lich cho dia tir va nguyen t~c quan ly thong tin tren bo nho phu - H¢ File.

Chuang 6. Quan 15' thiet bi: Ngoai cac thiet bi chuan mang tinh chat bat bUQC, cac h¢ th6ng may tinh do phai co kha nang ket n6i vci mot so luong tuy y cac thiet bi rna rong, Trong chuong nay trinh bay nguyen t~c t6 chuc va quan ly thiet bi ngoai vi cua h~ dieu hanh, dong thai de cap tai mot so ky thuat ap

8

dung trong quan ly thiet bi ngoai vi.

Chuang 7. Bao ve va an toan h~ thong: Bao v¢ he thong tranh khoi SI..f can thiep bat hop phap til ben ngoai cling nhtr cac nguyen nhan tiem an ben trang la mot van de eire ky phirc tap, Chuang nay neu r6 muc dieh cua viec bao v¢ he th6ng, dong thai trinh bay mot s6 bien phap bao ve va an toan h¢ thong.

Chuong 8. H¢ dleu hanh da xii IS': C6 hai phircng phap de t6 chirc cac h¢ thong da xiI ly do lit h¢ nhieu CPU (I~p hop cac CPU trong mot may tinh duy nhat) va h¢ phan tan (thuc char la cac mang may tinh). Chuang nay trlnh bay rnuc dich va cau true cua h¢ nhieu CPU va he phan tan. Dong thai neu so hroc mot s6 van de ve quan Iy rai nguyen, truyen thong tin, xir ly va truy nhap thong tin trong cac he thong nay.

Chuang 9. H¢ die" hanh DOS: Chuang nay trlnh bay mot so van de ve h¢ dieu hanh DOS - h9 dieu hanh dn. dat mot moe rat quan trong trong qua trlnh phat trien cua may tinh va cac he dieu hanh, No duoc si'r dung trong mot thai gian nrong d6i dai cho cac may tinh PC va Iii !TI¢t he dieu hanh co ban nhat. Cac van de trlnh hay mang tinh ap dung thirc te cua cac kien thirc cfa hoc trong cac chuang tnroc nhir: quan ly rien trinh, quan ly bo nho, quan ly dia tir, quan Iy thiet bi, v, v.

Cu6i cung, can xac dinh noi dung cua giao trlnh nay vc co han la dinh huang toi h¢ dieu hanh rruyen thong. Mot s6 net so bo ve cac he dieu hanh da xu Iy duoc trlnh bay chi nham rnuc dfch dinh huang eho nguoi hoc tim hieu them cac tai lieu b6 sung, nham holm thien kien thirc chung ve h~ dieu hanh.

9

Chuong 1

? ~ ~,

T6NG QUAN vs lffi DI~U HANH

M.,.c tieu

Sau chu'cmg nay, ngu'di h9C co the nam bat du'elC cac kien thirc t6ng quat ve h~ dieu hanh, qua trlnh phat trien va phan loai h(! dieu hanh: cac tfnh chat co ban cua h~ dieu himh va nguyen tac thiet ke xay dl/llg h$ dieu hanh, Hieu dtJ<;1c cau true cua cac h$ dieu hanh, cac thanh phan co ban va cac phuc vu cua he dieu hanh.

Nl}idung

Trinh bay cac khai niern co ban ve h$ dieu hanh, cac chirc nang co ban cua he dieu hanu va cac thanh phan cua he dieu hanh,

I. cxc KHAI NI(tM CO nAN 1. Tal nguyen h~ thong

MOt he thong may tinh baa gam de thiet bi phan cirng va cac chuang trlnh phan memo Trang cac tai lieu gioi thieu ve mot h¢ thong may tfnh bat ky, cac so lieu thong ke ve phan cirng lucri la nhirng yeu to diroc quan tam dau ticn va la thanh to d6 nhan bier sire manh cua he thong may tinh d6.

Tai nguyen vc phan rnern cilng duoc chii y thong qua moi quan tam ve he dieu hanh, cac chuang trlnh irng dung, cac Co' so dir lieu da cai d~t trong he thong. Trang giai doan hien nay, gia tri thuc su cua tai nguyen phan mem luon cao hon nhieu so voi gia tri cua tai nguyen phan cirng.

Dung tren phuong dicn he dieu hanh, moi cong viec cua h~ dieu hanh deu bat dau tll" mot he thong phan cirng san c6 va can phai hoat dong nhu the nao d~ phat huy diroc hieu qua cao nhat cua he thong phan cirng d6. Vi vay, trong giao trmh nay, cluing ta se t~p chung chu yeu den t~ti nguyen phan cung va dinn huang toi van de khai thac hieu qua cac tai nguyen do.

10

Dt phat huy hieu qua cua cac tai nguyen phan cung, can xem xet mot s6 dac trung co ban va danh gia gia tri cua moi thanh phan trong he thong phan ciing nham rnuc dich dua ra cac chien luoc uu tien thich dang doi voi tirng thanh phan khi X[lY dung he dicu hanh va cac chuang trinh dieu khien hoar dong he thong.

Theo each riep can cua he dieu hanh, cac ·tai nguyen phan cirng dien hinh bao gam: bo xu Iy trung tam (CPU), bo nho (trong va ngoai), he thong vao/ra (cac thiet bi vao/ra va cac chuang trinh dieu khien thiet bi) ...

Trong cac thiet bi n6i tren, CPU la tai nguyen quan trong nhat vi no lien quan true tiep den kha nang xu Jy, tinh toan cua he thong. CPU duoc dac trung b(ji hai yeu t6 la t6c d¢ xir 19 va d¢ dai tir may.

- Toe d¢ xu 19 cua CPU thuong diroc tinh thea tan s6 xung nhip dong he) hoac so luong phep tinh eo ban diroc thuc hien trong mot giUy. Dan vi do toe do duoc tinh thea MHz (tan so xung nhip ella dong h6 trang mot giay) hoac MIPS (Million Instruction Per Second • trieu phep tinh co ban trang mot giay).

- D¢ dai tir may: lu s6 hrong bit nhi phan ella toan hang trong phep tinh co ban cua CPU (tren thirc te dfi co cac loai CPU 8, 16, 32 va 64 bits, day chinh lu df) dai tir may cua cac chung loai CPU nay). D¢ dai tir may eo quan he kha mat thiet voi kha nang xu Iy thong tin cua CPU, chang han mot CPU co d¢ dai til may 4 bytes (32 bits) mac du co toe d¢ xu 19 thap han mot CPU co d¢ dai tir may 2 bytes (16 bits) nhung kha nang xu 19 thong tin cua no se cao hen nit nhieu. Nhu vay, df tang kha nang xu Iy cua CPU, cluing ta can co giai phap tang d toe dO xu Iy va d¢ dai tir may.

B9 nho cung la mot tai nguyen quan trong cua h¢ thong, cac dac trung co ban cua bo nho la thai gian truy nhap diJ lieu va dung hrcng bo nho. B¢ nho thuong duoc t6 chirc phan cap dira vao toc d¢ truy nhap. B¢ nho duoc goi ia thuc hien neu CPU c6 th~ thirc hien mot cau lenh bat ky ghi trong do. BO nho trang la mot loai bo nho thuc hien va n6 thuoc quyen quan ly cua he thong. Ngoai b¢ nho trong, cac he thong may nnh con t6n tai b¢ nho ngoai (b¢ nho phu . bo nho thir hai), thai gian truy nhap bo nho ngoai thirong lau han b¢ nho trong, Loai bo nhc ngoai duoc Slr dung pho bien hien nay la rna til, bang tir va CD - ROM. Doi voi bo nho ngoai, he dieu hanh khong quan tam toi viec n6 la loai hip co dinh

11

hay c6 thti thay d6i rna chi quan tam tai hai yeu t6: loai be nho va phuong pha]; truy nhap, loai bo nhd chi thiet bi vat 19 luu tru dfr lieu, con phirong phap truy nhap lien quan den qua trlnh tim kiern dtr lieu,

Cac thiet bi dam nhan viec chuyen giao thong tin gifta h~ thong va ngiroi su dung drroc goi la cac thiet bi ngoai vi hoac cac thiet bi vao/ra. Cac thiet bi nay duoc giin VaG may tfnh thong qua cacthiet bi dieu khien d~ tao thanh mot kenh VaO/fa. Kenh c6 chtrc nang thay CPU dieu khien su trao d6i thong tin giua bo nho trong va cac thiet bj ngoai.

TSt ca cac tai nguyen phan cung noi rren co th6 duoc khai thac thea nhieu phuong phap khac nhau nhu: khai thac dong thai (bo nho trong va ngoai), khai thac rutin t'! (may in) hoac cung cap cho ngtroi slr dung duai dang da duqe bien doi (tai nguyen ao - lai nguyen logic).

Tom lai, Ult ca. cac thiet bi va cac chuang rrinh ph.in mern deu e6 th~ coi la tai nguyen cua may tinh. Cac tai nguyen nay diroc ph an loai dua tren mtrc d<) quan trong va each thiic khai thac, v ( du: loai tai nguyen co the khai thac m¢t each dong thai, loai tai nguyen chi eo th~ khai rhac mot each tuan tu, loai tai nguyen dtroc cung cap dtt6'i dang da diroc bien d6i doi chiir so voi ban dau (goi la lai nguyen ao).

2. Khai ni~m h~ dieu himh

H~ thong may tfnh la m¢t he thong ket hop d. thiet bi phan cung va van de dieu khien, phan phoi cong viec trong toan h? thong. D~ giai quyet bai toan nay, khong th6 sir dung mot phuong phap thu cong rna can co mot co che 1\1" dong hoa, tUc la can co mot chuang trinh dieu khi~n hoat dong cua h~ thong may tfnh. Chuang trlnh d6 dtroc goi 13 he dieu hanh - M¢t thanh phan quan trong ella he thong may tinh.

De lam r6 khai niem ve h~ dieu hanh, chung ta nhan thay mot h¢ thong may

tinh co the phan chia thanh 4 lap: - Phan cirng

- H<; dieu hanh

- Cac chuong trinh irng dung

- Ngiroi sir dung (nguoi sit dung tnrc tiep, cac thiet bi chuyen dung ket n6i

voi may tfnh, cac may tfnh khac),

12

Bon lap nay eo m6i quan he mat thiet voi nhau va duge the hien qua sa do

sau:

I User 1 I T I User 3 I ~ • ~ ••••• r _ • T
,
Compiler Text Editor Program language Database
Cac chuang trlnh irng dung (Applications Programs)
_) H~ dieu hanh (Operating System) L
I J
j Phan cirng (Hardware) L
I I Hinh 1.1 - M61 quail h¢ giii'a h¢ dieu hanh va cdc lop trong 114 rh("/ng

- Xet ve phia ngtroi Slr dung thi h¢ dieu hanh can phai tao duoc rnoi twang giao dien giira nguoi sir dung va may tinh. Thong qua moi twang nay, cho phep ngiroi su dung dua ra cac Ienh, chi thi dieu khien hoat dong cua he thong.

- Xer ve phia cac chirong trinh irng dung thl he dieu hanh phai tao moi twang d6 cac chtrong trinh ling dung hoar dong; cung cap cac CO' chc cho phep kfch hoat va Ioai bo cac chirong trmh irng dung.

- Xet ve phia phan cirng thl he dieu hanh phai quan ly cac thiet bi mor each c6 hieu qua, khai thac dtroc het kha nang cua cac thiet bi, eung cap eho cac chuong trlnh va nguoi sir dung tai nguyen phan cirng khi c6 yeu cau, thu hoi khi can thiet.

Nhu vay, c6 the eoi he dieu hanh la mot tap hop cac chuang trmh he thong c6 chtrc nang tao rnoi tnrong giao dien eho ngirol sir dung, tao rnoi tnrong hoar dong cho cac chuang trlnh ling dung; quan ly va khai thac hieu qua cac thiet bi phan cirng,

3. Qua trinh phat trie;n cua h~ dieu himh

Cac he dieu hanh diroc phat trien song song voi su phat trien cua may tinh dien nr, Ban dciu, cac he dieu hanh lam viec theo phuong phap tron goi, sau d6 diroc b6 sung them cac tinh nang de c6 th~ dap ling diroc nhu cau cong viec cua

13

ngtroi su dung va su phat trien cua cac h¢ thong may tinh. Di€n hlnh HI. cac giai doan sau:

Monitor

Interrupt and trap vectors

Device drivers

Job sequencing

Control eard interpreter

User program area

Hinh 1.2 - Cdu {rile monitor elm! gidn

- Monitor dan gian: Day la he dieu hanh dau tien eo th~ nr dong hoa, sap xep cong vice eho may tfnh thi hanh. Monitor dan gian la mot chuang trmh nho tlurong tru trong bo nho. Cac chircng trinh dieu khien thiet bi (Device Drivers) biet vung dem, cac ea nho, cac thanh ghi va cac bit kiem tra ella minh.

- Thao tac Off - Line: Muc dich ella thao tac off - line la lam tang hieu qua cua cac rhiet bi phan cung. Thao tac off - line cho phep truy nhap cac thiet bi mot each logic, khong phu thuoc vao tinh chat v~t ly ella thiet bi dan den loai trir duoc hien tuong cac thiet bi vao/ra lam viec song hanh voi CPU.

- Thao tile Buffering: Buffering (thao tac tao vung dern) nham Hun tang toe cac phep trao d6i ngoai vi, dam bao toe d¢ chung cua he thong. Thao tac buffering cho phep: giam so hrong cac thao tac vao/ra vat ly, thuc hien song song cac thao tac vao/ra vci cac thao tac xU Iy thong tin khac nhau, thuc hien tnroc cac phep nhap dir lieu ...

- Thao rae SPOOL: SPOOL (Simultaneous Peripheral Operations On Line) ia che d¢ rna tilt CLl cac trao d6i vao/ra, he dieu hanh chi lam viec vai rna tu con trao d6i giita dia tir va cac thiet bi ducc thuc hien thea cac co che' rieng. Muc dich ella SPOOL Iii cho phep he dieu hanh thao tac voi cac thiet bi mot each song song, tam tang toe d¢ cua he thong mot each dang k€.

- Da chuang trlnh va chia se thai gian (Multi programing and Time sharing):

14

Trang giai doan nay, cac he dieu hanh cung cap kha nang dieu khicn hoat dong cua nhieu chuang trmh tai cimg mot thoi diem. Nhu vay, cac chuang trlnh nay deu c6 nhu cau sir dung tai nguyen trong cung mot thai diem de thuc hicn cong viec, do do tai nguyen h¢ thong bi chia se cho cac chuang trinh, Trang khi do, mot so tai nguyen cua h~ thong khong the cung cap trang che do chia se (vi du nhu CPU) dan den he dieu hanh can phai t6 chuc phan b6 tai nguyen thea co che hang doi. Khi mot chuang trlnh dU<;1c thirc hien thi cac chuang trinh con lai phai a trang thai cho dLIQ'c phan b6 tai nguyen nhung vi thai gian tai nguyen phuc vu cho hoar dong cua chuang trinh trong mot chu ky Hi rat ngan nen nguci si'r dung cam nhan nhu chuang trinh ella minh van dang thuc hien va sa hfru toan bo tai nguyen hi? thong.

- Cac che d¢ baa ve: DE dam baa eho su an toan h¢ thong va giup eho h~ thong hoat dong 6n dinh, cac he dieu hanh giai doan sau nay con b6 sung nhieu che' d¢ bao vi? nrnr: baa ve cac thiet bi I/O, bao v¢ be) nho, bao vi? CPU ... nham tranh cac hien urong tranh chap tai nguyen, str dung tai nguyen sai muc dfch va kha nang gay loi tiem <'in ella cac thanh phan he thong.

4. Phan loai ht;; dieu hanh

Dira tren phirong thirc hoat dong, dieu khien, quan ly tai nguyen ... cluing ta e6 the phan loai he dieu hanh nhu sau:

- H¢ dieu hanh dan nhiem va he dicu hanh da nhiem: he dieu hanh don nhiern HI. he dieu hanh rna tai moi thai diem chi e6 the dieu hanh hoar dong ella mot chuang trinh. Khi mot chuang trinh diroc nap vao be) nho thl no se chiern dung roan bo tai nguyen ella he thong dan den khong the thirc thi mot chuang trinh nao khac khi chuang trlnh nay chua ket thiic. H¢ dieu hanh da nhiem la he dieu hanh cho phep thuc hien nhieu chuang trlnh cung mot thai diem. Tai nguyen trong che do noat dong nay diroc chia se cho cac chuang trinh dan den cAn phai dam baa t6t tfnh binh d~ng trong van de phan phoi tai nguyen.

~ H¢ dieu hanh dan chirong va he dieu hanh da chuang: he dieu hanh dan chuang la tai moi thoi diem chi cho phep mot ngiroi str dung lam viec. H¢ dieu hanh da chuang Ia tai m6i thai diem eho phep nhieu nguoi sir dung cung lam viec.

- H¢ dieu hanh chia se thoi gian va h¢ dieu hanh thai gian thuc: Trong he dieu hanh ehia se thai gian, mot CPU luon luon phuc vu cac tien trlnh va mot tien trlnh co the roi van trang thai cho doi khi chua diroc phan b6 CPU, con trong he dieu hanh thai gian rhirc, tien trinh duqc nap vao he thong a bat ky thai

1(\) - 184

15

di8m nao deu diroc phan bD gio CPU.

- H~ dieu hanh tap trung va he dieu hanh phan tan: h~ dieu hanh tap trung duoc cai d~t tren h~ thong may chu cua mang, n6 dieu hanh moi thao tac, xu 1'.1 va tinh roan tai cac may tram. H~ dieu hanh phan tan gam hai thanh phan duoc cai dat tren may chi'! va may tram cua mang. H~ dieu hanh tai may chu chiu trach nhiem cung ling dich vu, quan 1'.1 h~ thong va thirc hien cac thao tac xU 1'; chung; he dieu hanh tai may tram c6 th8 thuc hien cac thao tac xu 1'.1 rieng.

5. Cac tinh chat co ban cua h~ dieu hanh

- Tinh tin cay: Moi hoat dong, moi thong baa cua h~ dieu hanh phai chuan xac tuyet doi. Chi khi nao chile chan dung thl h~ dieu hanh moi cung cap thong tin cho nguoi su dung. Vi du khi truy nhap rna, nell g~p Ioi truy nhap he dieu hanh co gang lap lai thao rae nhieu Ian. Neu van khong duoc, hie d6 moi dua ra cac thong bao loi.

- Tinh an toan: H~ dieu hanh can phai dam bao sao cho dir lieu va cac chuang trinh khong bi thay dDi ngoai '.I muon trong moi tnrong hop va trong moi che ~ d¢ hoat dong. De dam baa dtroc yeu to an toan, cac h¢ dieu hanh can cung cap cac co che bao v~ dir lieu va bao ve cac tai nguyen su dung chung, tranh diroc

su vi pham do vo tinh hoac co Y cua ngiroi su dung va cac chuang trinh.

- Tinh hieu qua: Cac tai nguyen ella h¢ th6ng phai duoc khai thac mot each trier d8 sao cho ngay ca. khi tai nguyen han che van co th8 giai quyet duoc nhirng yell cau phirc tap, Mot khia canh khac cua tinh hieu qua la phai duy tri h0<.11 dong dong b¢ trong toan he thong, kh6ng duoc de nhtrng thiet bi cham tri hoan heat dong cua he thong.

- Tinh ke thira: H¢ dieu hanh phai co tinh k€ thira cac iru diem, khac phuc cac nlnroc diem cua phien ban tnroc va kha nang thich nghi voi nhirng thay dDi trong nrong lai. Tfnh k€ thira la rat quan trong, ngay ca. voi cac he dieu hanh the h¢ maio Khi nang cap he dieu hanh thi tinh ke thira mang tinh chat bat buoc, Vi du nhu cac thao tac, thong bao kh6ng duoc thay d6i hose neu co thi can han che va phai diroc huang dan cu th8 khi chuyen dDi tit phien ban nay sang phien ban khac. Dam baa tinh ke thira se duy tri va phat trieo d¢i ngu ngiroi su dung, giam chi phi dao tao khi tiep can toi cac phien ban he dieu hanh moi.

- Tinh thuan lei: H~ dieu hanh ph iii sir dung de dang, co hieu qua tuy thea kien tlurc va kinh nghiern cua nguoi dung. H¢ dieu hanh phai c6 he thong tro gitip, huang dan phong phu, d:iy du giup ngiroi sir dung co th8W dao tao minh

16

1(1):- 184

ngay trong qua trinh khai thac,

Trong mot khia canh nao do, cac tinh chat tren co th~ mau thuan voi nhau nhtrng moi he dieu hanh can co ID¢t giai phap trung hoa, tru tien hop ly a tinh chat nay hoac tinh chat khac,

6. Cac nguyen t~e thiet ke va xay d,,"9 h~ dieu hanh

Khi xay dung he dieu hanh, cac modul chuang trlnh phai duoc thiet k€ dua tren mot s6 nguyen tac sau d~ dam bao cac tinh chat cua h¢ dieu hanh.

- Nguyen tac modul: H~ dieu hanh duoc xay dirng nr nhirng modul d¢c lap va gnra chung co cac quy tac lien ket thanh mot h~ thong co t6 cmrc. Nguyen tac modul th~ hien d hai dang: dang chuc nang va dang chuang trinh. Cac modul quan h~ vci nhau thong qua dtr lieu VaG va ra, quan he phan cap giua cac modul duoc thiet lap khi lien ket chung thann cac modul lon de giai quyet cac van de phirc tap, Nguyen tac Modul cho phep t6 h9'P nhirng modul da co thea nhieu each khac nhau, dam baa tinh da dang chuc nang cua h¢ dicu hann.

- Nguyen tac urong doi trong dinh vi: Cac modul chuang trinh duoc viet thea dia chi nrong doi tfnh tir dau bo nho, khi thuc hien chung moi duoc dinh vi vao mot vung nho cu the. Nguyen tac nay giup cho he thong su dung b¢ nho mot each linh hoar va h¢ dieu hanh khong bi phu thuoc vao cau hinh be) nho C1,l the.

- Nguyen tac Macro Processor: Theo nguyen tac nay, khi c6 nhiern vu C1,l the he thong se xay dung cac the yeu diu, liet kc cac cong viec phai thuc hien. Tren co sa do thirc hien cac chuang trinh wang ling voi cong viec can thuc hien. M9i he dieu hanh deu su dung nguyen tac nay trong doi thoai giita ngiroi va may tren ngon ngir van hanh. Nguyen tac nay lam cho qua trinh doi thoai linh hoat hon rna khong can toi mot chuang trlnh dich phirc tap,

- Nguyen tac l~p chuc nang: Moi cong viec phai c6 nhieu each thuc hien khac nhau voi nhfrng t6 hop modul khac nhau. Dieu nay dam bao tinh an toan cua h¢ thong (vi\n co the khai thac he thong khi thieu hoac hong mot so thanh phan nao d6) dong thai nguci si'r dung se thao tac d~ dang han doi voi h¢ thong (cung mot cong viec nhung c6 th6 thao tac thee nhieu each khac nhau). Doi khi trong he thong con t6n tai nhieu modul khac nhau cling giai quyet chung mot van de, sir da dang nay cho phep ngiroi sir dung lua chon duoc phuong phap thuc hien toi Uti cho cong viec cua mlnh,

- Nguyen tac gia tri chuan: Moi modul co the co rat nhieu tham so, viec nho het cac tham so va pham vi su dung cluing la van de rat phirc tap va modul se

2(i) - 184

17

tra nen cong kenh mot each khong can thiet. De giai quyet van de nay, trong moi modul e6 mot tap cac tham s6 ung voi nhtrng tnrong hop thuong g~p nhat, Neu trong cau lenh goi modul thieu tham s6 nao thi h~ thong se b6 sung tit t*p tham s6 nay. Nguyen tae nay the hien rat r6 trong cac he thong cai d~t.

- Nguyen tae khoi tao khi cai dat: Khi cai d~t h¢ dieu hanh, chuang trinh cai dar se tao nhirng phien ban lam viec thich hop voi nhirng tham s6 ky thuat hien eo, 10<;1i bo nhilng modul khong can thiet d~ e6 mot phien ban tci uu ca ve cau true Ian phuong thtrc hoat dong,

- Nguyen rae bao ve nhieu mire. D~ dam bao an toan he thong va dir lieu. cac chirong trinh va du lieu phai duoc baa v¢ b nhieu mire khac nhau. Ca che baa v¢ nhieu rnirc da lam giam dang ke cac 16i khong eo y cua cac tien trinh va nguoi su dung,

II. cAc CHtJC NANG CO BAN ellA H~ DI~U HANH 1. Qu~m Iy tien trinh

C6 the: eoi rien trmh HI. mot chucng trlnh dang hoat dong, khi thuc hien, tien trinh doi hoi mot s6 tai nguyen nhat dinh nhir: CPU, bo nho, cac thiet bi ... Cac tai nguyen nay se diroc cap phar eho tien trlnh vao nhirng thai diem don thiet va duoc thu hoi khi tien trlnh ket tluic. Ngoai ra, khi tien trinh hoat dong trong h¢ thong e6 the: phat sinh cac tien trlnh con. Nhu vay, nhiem vu cua he dieu hanh trong quan 19 tien trtnh la:

- Darn baa nhirng dieu kien roi thieu de: tien trlnh co the: thirc thi.

- Dam bao dieu kien cho su hoat dong song song cua nhieu tien trlnh.

- T<;lO va xoa cac lien trinh ella nguoi sir dung va he thong.

- Ngirng va bat dau lai cac tien trinh.

- Tao cac co che de dong bo hoa cac tien trinh.

- Tao cac ea che de lien lac gitta cac tien trinh.

- Tao cac co che de xu 19 be taco

2. Quan Iy bQ nho: trong

B¢ nhotrong Ia thiet bi hru tru rna CPU e6 the truy xust mot each true tiep, Khi t6 chirc mot chirong trmh, sau bien dich clurong trlnh diroc chuyen sang ngon ngG: may tinh, khi d6 n6 c6 cac dia chi nrong doi. Khi thuc hien, chuang trinh duoc nap van bo nho, cac dia chi nrong d6i se duoc chuyen d6i thanh cac

18

2(1) -184

dia chi v<)t 19 xac dinh d~ CPU c6 thtS truy xuat duoc trong qua trinh xu 19, d6 HI. qua trinh sinh dia chi. .Sau khi chuang trlnh hoat dong xong, he thong can phai giai ph6ng cac dia chi vat 19 dfi cap phat (giai ph6ng bo nho). [)6 tang hieu xuat xu 19 cua h¢ thong, tai cung mot thai diem h¢ thong co th~ cho phep nhieu chuang trinh cung t60 tai trong be) nho, Do do, he ditu hanh can thuc hien cac nhiern vu co ban trong quan 19 be) nho la:

- Cap phat va thu hoi khong gian nho cho cac lien trinh.

- Ltru trir dau vet nhirng thanh phan cua b¢ nho hien dang si'r dung va do tien

trinh nao str dung.

- Quyet dinh :rien trinh nao diroc nap vao bo nhc khi co kha nang.

- Sap xep va giai ph6ng khong gian nho khi can thiet,

3. Quan Iy be;, nhd ngoai

Khi can luu tril cac chuang trmh hoac du lieu, cac he thong may tinh bat buoc phai sir dung bo nho ngoai (rna tir, bang tit, eompaq ... ). Nhiem vu chfnh ella M dieu hanh phai dam baa duoc cac chirc nang sau:

- Quan 19 kh6ng gian nho tu do tren bo nho ngoai.

- Cap phat kh6ng gian nho ur do.

- Cung cap cac kha nang dinh vi be) nhc ngoai.

- Laplich cho bo nho ngoai.

4. Quan Iy h~ thong vao/ra

Mot trong nhirng muc tieu ella h~ dieu hanh lit ehe dau cac chi tiet phan cirng cu th€ doi voi nguoi su dung. Dieu khien hoat dong ella cac thiet bi bang each giri cac lenh dieu khitSn toi thiet bi va tiep nhan, xir 19 cac tin hieu ngat, xu 19 16i ... Han nira, he dieu hanh can cung cap mot giao dien dan gian, d<)e lap gitta cac thiet bi va h¢ th6ng. Do d6, chirc nang ella he dieu hanh trong quan 19 he thong vao/ra la:

- Che dau nhirng d~e thu cua cac thiet bi vao/ra.

- Tao lap nhirng chuang trinh d€ quan 19, dieu khi€n thiei bi chung va cac

thiet bi dac bier.

5. Quan Iy file

Khi luu tru thong tin tren bo nho ngoai, m6i thiet bi hru tru se c6 nhtrng dac tinh vat 19 khac nhau. Di! tao dieu kien thuan loi trong eOng tac hru trfr va quan 19 thong tin, h¢ dieu hanh sir dung mot dan vi luu trii' dong nhat tren tat cit cac

19

thiet bi hru trfr goi la tep tin (file). ~ co th6 de dang truy xuat, h~ dieu hanh con t6 chirc cac file thanh cac thu muc va kiem soat viec truy nhap dong thai den cung mot file. Nhu vay, trong linh vue quan 19 file, h~ dieu hanh chiu trach nhiern ve cac thao tac sau day:

- Tao va xoa file.

- Tao va xoa thu mue.

. . .

- H6 tro cac nguyen 19 thao Hie file va thu muc.

- Anh xa cac file len bo nho phu.

- Ghi du phong cac file len bo nho 6n dinh.

6. H~ thong bao v~

Khi he thong eho phep nhieu ngiroi si'r dung dong thai, cac tien trinh song hanh can phai duoc bao v¢ de tranh 51! xam pham vo tinh hoac co 9 co the gay sai lech roan he thong. H¢ dieu hanh can xay dung cac co che bao ve, cho phep dac ta str kiem scat va mot phirong tlurc de ap dung cac chien hroc baa ve thfch h<;1P. Nhir vay, muc dieh cua he thong baa v¢ la:

- Giiip eho h¢ thong hoat dong binh thirong.

- Baa ve cac tai nguyen si'r dung chung.

- Phat trien va ngan chan cac kha nang sai sot cua cac tien trlnh.

7. L~p rnanq

Mang may tfnh Hi mot tap hop cac may tinh duqe ket noi voi nhau bang moi tnrong truyen tin nharn five dieh cho phep ngiroi Slr dung dung chung iii nguyen va phuc vu cong tac truyen thong. Moi may tinh trong mang co mot bo nho doc lap va cac tien trinh co tht duoc ket noi, xu ly thong qua he thong mang, Khi do he dieu hanh pnai ho tro kha nang quan ly, ehia se tai nguyen, truyen thong tren mang thong qua cac thanh phan dieu khien giao tiep mang,

8. H~ thong giai thich I~nh (thong dich I~nh)

H¢ thong giai thich lenh la thanh phan quan trong nhat cua h¢ dieu hanh, dong vai tro tao giao dien giira may tfnh va nguoi su dung, N6 gnip may tinh hitu va xu 19 diroc cac chi thi, cac lenh cua ngiroi sir dung,

III. cAe THANH PHAN eVA Ht l>Ifu HANH

1. Cae phuc vy clla h~ dieu hanh

H¢ dieu hanh tao ra moi tnrong eho cac chuang trlnh hoat dong, do d6 h~

20

dieu hanh phai phuc vu chuang trlnh va nhirng ngiroi su dung chuang trlnh d6. Voi nhirng he dieu hanh khac nhau thl se co mot so cac phuc vu dac bier khac nhau nhirng ve nguyen tac chung, cac h¢ dieu hanh phai c6 mot s6 kieu phuc vu sau:

- Phuc vu thirc hien chuang trlnh.

- Dieu khien thao tac vao/ra,

- Cac thao tac file.

- Phat hien !oi sai sot.

- Phan phoi tai nguyen.

- Thong ke, ke' toano

- T6 chirc cac phuc vu.

2. Cae gQi h~ thong

Cac goi he thong (system call) cung cap mot giao dien giita chuang trinh dang heat dong va he dieu hanh. H~ dieu hanh cung cap hai plnrong phap dt t6 chirc thuc hien cac goi he thong:

- To chirc bang nhtrng lenh hop ngtr.

- To chirc true tiep tu chuang rrinh ng6n ngir bac cao bang each su dung

chuang trinh con.

- Cac goi he thong duoc chia thanh ba loai chinh: + Cac chuang trinh dieu khien tien trlnh thuc thi. + Cac chuang trinh thao rae voi file va thiet bi. + Cac chuang trlnh bao trl thong tin he thong.

3. Cac ehU'dng trinh h~ thong

Cac chuang trinh he thong cung cap c6ng cu eho ngiroi sir dung thirc hien

cac thao tac quan 19 va dieu khien he thong. Ditn hlnh la: - Cac chuang trinh thao tac voi file va thu rnuc.

- Cac chuang trinh th6ng tin trang thai.

- Cac chuang trlnh ho tro ngon ngu lap trtnh.

- Cac chuang trinh dieu khien nap va thirc hien chuang trinh.

- Chuang trlnh giai thich lenh (Command Interpreter).

4. Cae chuonq trinh ((ng d',mg

Cac chuang trlnh ung dung di kern h¢ dieu hanh nham muc dich ho tro eho nguoi su dung thirc hien cac thao tac irng dung co ban nhir: cac chuang trlnh soan thao van ban dan gian, cac trlnh duyet Web, cac chuang trlnh tro choi giai tri..

21

Cfiu hoi on ~p

1. Trinh bay khai ni$m ve tai nguyen h~ thong. Cho vi du minh hoa

2. Neu cac chirc nling co ban cua h~ dieu hanh, Cho vi du minh hoa

3. Trinh bay moi quan h~ giCta h$ dieu hanh va cac thanh phan trong h$ thong, tv d6 neu khai ni~m ve h~ dieu hann,

4. Phan biet h~ dieu hanh dan nhiem va da nhiern. dan sac va do hoa Cho vi du thong qua h~ dieu hanh DOS va Windows.

5. Thong qua CaG h$ dieu hann d§ hoc, cho cac vi du minh hoa de lam ro cac tinh chat co ban cua h$ dieu hanh.

6. Trinh bay cac nguyen tik thiet ke va xay dl,fng h$ dieu hanh. Cho vi du qua cac h~ dieu hanh d& hoc,

7. So sanh co che bao v¢ cua h~ dieu hanh Windows 9x va Windows 2000 hoac XP.

8. Neu cac chLfdng trlnh h$ thong, chtfcJng trinh Ung dl,lng trong'h~ dieu hanh DOS va he dieu hanh Windows.

22

Chuong 2 .

QUAN LY TIt:N TRINH

M\}c tiiu

Sau chl1dng nay, ngl1Cli h9C co the hieu du~c khai ni$m tien trinh va cac mOi quan h~ cua chUng trong h$ thong. 8iet d119C cac bien pnap quan Iy tien trlnh song hanh vol n9i dung chinh la giai quyet b8.i toan tranh chap tai nguyen giua cac tien trinh. Dong thOi, ngl1Cli hoc c6 the hinh dung dl1Q'c moi nguy hai cua be tac, biet dU9c cac muc pMng tranh be tac cua h$ elieu hanh va co the giai quyet d119C m¢t s6 tinh tranq be taco

NQidung

Trinh hay cac khai niem co ban ve tien trinh, bai toan doan toi h,;m va cac phl1dng phap gi8i quyet, Khai niern ve hi~n h1c;1ng be tac va cac bi$n phap phonq tranh be taco

1. cAe KHAI NI~M co BAN 1. Khai ni~m tien trinh

De h6 tro hoat dong da nhiem, he thong may tfnh can phai co kha nang thuc hien nhieu tac vu xu ly dong thai nhung viec dieu khien heat dong song hanh a cap d¢ phan cirng la rat kh6 khan. Vi vay, cac nha thier ke he dieu hanh de xuat mot mo hinh song hanh gia. lap bang each chuyen d6i bo xu ly qua lai giira cac chuang trinh de duy tri heat dong cua nhieu chuang trlnh tai cung mot thai diem. Trong mo hmh nay, cac chuang trinh trong h~ thong duoc 16 chirc thanh cac tien trmh (process).

Nhu vay, co the coi tien trlnh Iii mot chuang trinh dang xu ly, n6 sa htru mot con tro lenh, t~p cac thanh ghi va cac bien. De hoan thanh nhiem vu cuarntnh, cac tien trinh co the con yeu diu mot s6 tai nguyen h~ th6ng nlur: CPU, bo nho va cac thiet bi.

Chung ta can phan biet r6 hai khai niern chuang trinh va tien trlnh. Chuang trinh 1a mot thirc the thu dong chua dung cac chi thi dieu khien may tinh thi

23

hanh mot tac VI;! cu th~ nao do. Khi cho thirc hien cac chi thi nay, chuang trinh diroc chuyen thanh tien trlnh la mot thirc the hoat dong, voi con tro lenh xac dinh chi thi ke' tiep sc thi hanh kern theo cac tap Uti nguyen phuc V1,l cho hoat dong cua tien trlnh.

2. Cae tr.;mg thai ella m9t tien trinh

Trang thai cua tien trlnh t<;li moi thai diem duoc xac dinh boi heat dong hien thai cua tien trinh tai thoi di~m do. Trong suot khoang thai gian ton tai trong h~ thong, mot tien trinh co the thay ddi trang thai do rat nhieu nguyen nhan nhu: cho doi sir kien nao do xay ra, doi mot thao tac vao/ra hoan tat, het thai gian xu 19 ...

Tai moi thai diem, tien trinh co th~ nhan mot trong cac trang thai sau: - Khoi tao (new): tien trinh dang diroc tao lap.

- San sang (ready): tien trinh cho diroc cap phat CPU de xu lyr.

- Thirc nien (running): tien trinh duoc xu Jy.

- Dei (waiting): tien trlnh phai dung VI thieu Uti nguyen hoac cho mot S1,l'

kien nao del.

- Ket thuc (halt): tien trinh da hoan Hit cong viec xu IY.

Cac trang thai cua tien trinh co th6 diroc bieu dien qua so do sau:

H tnh 2 .1. Cdc trang thai ella m(Jt tien trinh

H¢ dieu hanh quan 19 hoat dong cua cac tien trinh trong he thong thong qua khoi mo ta tien trinh (Process Control Block - PCB). Kh6i rna ta tien trlnh bao gam cac thanh phan:

- S6 thu nr cua tien trinh.

- Con tro trang thai cua tien trinh (cho bier trang thai hien tai cua tien trinh).

- Vimg nno luu tru gia tri cac thanh ghi rna tien trinh dang str dung,

- Thong tin ve tai nguyen tien trinh dang su dung hoac duoc phep str dung.

24

3. Quan h~ giua cac tien trinh

Cac tien trinh hoat dong trong h¢ thong ton tai hai moi quan h~: doc lap va hop tac (song hanh).

* Quail h1 dc)c Iqp: tien trinh diroc goi iIl doc lap ncu hoat dong ella no khong gay anh huang hoac kh6ng bi anh huang bai cac tien trinh khac ciing dang hoat dong ella he thong. Tien trinh doc lap co nhirng d~e trung sau:

- Trang thai cua no khong bj chia se voi bat ky tien trinh nao khac.

- Viec thirc hicn tien trlnh la dan dinn (ket qua chi phu thuoc vao dau vao).

- Tien trinh e6 the tai hien (lap lai),

- Tien trinh co the dung hoac bat dau lai rna khong gay anh hirong toi cac

tien trlnh khac trong he thong.

* Quail h~; h(Yp Ide: tien trlnh duoc goi Ut hop tac (song hanh) nell hoat dong ella no gay anh huang hoac bi anh huang hai cac tien trlnh khac ciing dang heat dong trong h¢ thong. Tien trinh hop tac co nhfrng dac trung sau:

- Trang thai ella n6 bi chia se cho cac tien trinh khac.

- Viec tlurc hien tien trlnh khong don dinh (ket qua phu thuoc day thirc hien

tuong irng va khong dt,r baa tnroc). - Tien trinh khong th~ tai hien.

4. Vi du ve tien trinh song hanh • Bai toan nha san xuat va ngLtdi tleu dung (Producer! Consumer Problem)

* Bai todn: Gia sa e6 hai tien trlnh P V~t C song hanh. Tien trinh P cung cap thong tin cho hoat dong cua tien trinh C. Thong tin do P siln xuar duoc dat trong vung dem va C lay thong tin tir vung dem de sa dung. Trang tnrong hop vung dem co kfch thuoc han che, hay xay dung thuat toan dieu khien heat dong cua hai tien trinh tren.

* Thuat todn: Khi kfch thiroc vung dern han che se xay fa hai tnrong hop: - Vung dern day, khi d6 tien trlnh P phai b trang thai phai cho cho toi khi

co vung dern rong,

- Vung dem rong, khi do tien trinh C phai b trang thai phai cho thong tin. Giil sir:

- Vung dern chua diroc n phan nr

- Thong tin co kieu Item nao do

- Bien In chi s6 phan nr diroc san xuat

25

- Bien Out chi s6 phan tir duoc tieu thu

- Tien trlnh P san xuat thong tin chua trong bien trung gian NextP

- Tien lr'inh C tieu thu thong tin chua trong bien trung gian NextC

Khi do:

- Vimg dem rong khi III = OUI

- Vung dem day khi (Ill + I) mod 11 ::;0: Out

* Thudt toan:

Type Item = ... ;

Var Buffer: array [O .. n - 1] of Item; In, Out : O .. n - 1

Begin

(Tiell trinh P) Repeat

San xuat thong tin va chua trong NextP;

While (In + I) mod J1 = Out do Skip; Buffer/In! := NextP

In := In + 1 mod II;

Until false;

(Tili'll trinh C) Repeat

While III = Out do Skip; NexIC := Buffer/Out!; Out := Out + 1 mod II

Lay thong tin trong chua trong NextC

Until false;

End;

5. Khai ni,m ve tfli nguyen "gang" va dOiiln tbi han

Trong thuat toan tren neu ta dung met bien dem Counter (duoc khCri diu = 0) dung d~ dern s6 Iuong cac phan tir trongvung dem. Khi do gia tri ella bien Counter se tang 1 khi P san xuat them 1 tphan tiI va giam di I khi Clay di 1 phan

26

ttl. Dong thoi vung dem day khi Counter = n va vung dem rong khi Counter = O. Thuat toan co th~ viet lai nhu sau:

Type Item = ... ;

Var Buffer: array [0 .. 11- I] of Item; III, Out: 0 .. 11 - 1

Counter: O .. n

Begin

(Tiel, trinh P) Repeat

San xuat thong tin va chua trong NextP;

While C ounter =Jl do Skip; Buffer/In} := NextP;

III := III + 1 mod n;

C ounter : = C ounter + I; Until false;

[Tien.trinh C) Repeat

While Counter = 0 do Skip; NextC .= Buffer/OUlf;

OUI := Out + 1 mod II; Counter .= Counter - 1;

Lay thong tin trong chua trong NextC

Until' false;

End;

Nhan.xet, VI hai tien trlnh P va C song hanltnen co the xay ra tnrong hop trong cling mot thoi diem, tien trinh P tang bien Counter len 1 (Counter: = Counter + 1) con tien trmhC lai giam bien Counter di 1 (Counter: = Counter - 1) da.n toi ket qua sai. Nhir vay, bien Counter trong tnrong hop nay duoc goi la tai nguyen "gang". Doan trlnh sir dung bien €6unter goi la dean tm han.

27

Dfnh nghia:

Cac tai nguyen logie va vat 19 phan b6 cho cac tien trlnh song hanh ia tai nguyen "gang ':

Cac doan trinh su dung tai nguyen gang goi ia dean toi han (Critical Section).

6. Bai toan dOC1'n tCJi han

* Bai tOt/II," Gia sir co n tien trlnh Po, PI' ... , Pn.l song hanh, moi tien trinh eo mot doan toi han. Tim mot piurcng thuc sao cho cac ticn trinh vuot qua doan toi han cua minh mil khong anh hirong toi hoat dong cua he th6ng.

'i; Nluin xct : Vice giai quyet bai roan doan toi han la phai thiet ke m<)t nghi thuc sao cho cac tien trmh co th~ su dung d~ hqp tac voi nhau va thoa man ba dieu kicn:

- Dieu kien loai trir Ian nhau: l'.li moi thoi diem, chi c6 1119t tien trlnh duoc phep thirc hicn trong doan t6"i han cua minh.

- Dicu kien lien trien: khorig tien trinh nao duoc phcp (113U v6 han trong doan t6i han cua minh.

- Dieu k ien cho doi co gioi han: cac tien trinh kh6ng phai cho doi vo han truce khi di vao doan tai han cua minh.

Tren thirc te, hai xu huang rna cac he dieu hanh thuong ap dung d~ giai quyet hili toan doan toi han la:

+ Sir dung cac thuat roan cap thap: Iii cac thuat toan nam ngay trong ticn trinh.

+ Sir dung cac thuat roan cap cao: la cac thuat loan nam ngoai lien rrlnh.

II. cAe PHlJONG PHAp GIAI QUYET BAI ToAN DOA-N TOI Hf\N 1. Phltdng phap kh6a trong

1.1. Nguyen tac chung

Phuong phap nay dua tren Co' so neu hai hay nhieu tien trinh cung dinh ghi van mot dia chi nao do cua b9 nho trong, thi giai thuat chi eho phep mot tien trinh duoc thuc hien con cac tien trinh khac phii.i cho,

M6i tien trtnh sir dung mot byte trong bo nho d~ lam khoa. Khi tien trinh vao doan toi han, byte khoa cua no dUQ'C gao gia tri = 1 d~ thong bao cho cac tien trinh con lai biet Uti nguyen gang da duoc Slr dung, Khi ra khoi doan toi

28

han, byte khoa duoc gan gia tri = 0 d~ thong bao tai nguyen gang da diroc giai ph6ng.

Trude khi vao doan toi han, cac tien trinh phai kiem tra byte khoa cua cac tien trinh khac. Neu e6 byte nao d6 chua gia tri = 1 thi tien trlnh phai cho eho toi khi byte d6 nhan gia tri = O,

1.2. Thuat toan (bai toan 2 tien trlnh)

Var Kl, K2: byte;

Begin

K 1 : = 0; K2 : = 0;

(TieTl trinh J) Repeat

While K2 = 1 do Skip; KJ : = 1;

Ti61 trinh 1 vao doan 16'i han; Kl: =0;

Ph/in Call lai Clia tien trinh 1.Until false;

{Tiell trinh 2} Repeat

While K J = I do Skip; K2:= 1;

Tien trinh 2 \'ao doan toi han:

K2:= 0;

Phdn elm lai eMa riell trinh 2; Until false;

End;

Nhan xet: Nhuoc diem cua ghli thuat tren la kh6ng dam bao tinh loai trir Ian nhau. Gia si'r tien trinh 1 thuc hien nlt nhanh so voi tien trinh 2 va tien trinh 1 dang trong doan toi han con tien trinh 2 dang cho vao doan toi han, Sau khi tien trinh 1 fa khoi doan toi han --+- K 1 = 0 va tien trinh 2 thoat khoi trang thai cho nhung chua vao doan tci han --+- K2 # 1. Trong khi d6 tien trlnh 1 da tlurc hien xong phan con lai cua minh va quay tnJ lai dau tien trlnh, Vi K2 # 1 nen lien trinh 1 c6 the thuc hien phep gan Kl = 1 dan den ca hai tien trlnh cung vao doan toi han.

29

1.3. ThmI&t toan Dekker

De giai quyer nhiroc diem tren, thuat roan cua Dekker dung them mot bien khoa IT de: xac dinh d¢ Uti tien cua cac tien trinh khi ca hai tien trinh cung muon van doan toi han (IT = 1 hoac IT = 2).

Var K I. K2. IT: byte; Begin

Kl : =0; K2 : = 0; IT: = 1;

{TielJ trinh I} Repeat KI : =1;

While K2 = 1 do IfTT = 2 then

begin Kl : =0;

While IT= 2 do Skip; KJ = I;

end;

Tie'n trinh 1 \'(10 dO(1II tai han; Kl : = 0; IT : = 2;

Phdn con 19i nfa tien trinh /; Until false;

(Tie/l trinh 2) Repeat K2: =1;

While Kl = I do If IT = 1 then

begin K2: =0;

While IT = I do Skip; K2 = 1;

End;

Tien trinh 2 vilo doan toi han; K2 : = 0; IT : = 1;

30

Phan con lai cua tien trinh 1; Until false;

End;

Thuat toan Dekker giiii quyet bai toan dean tei han hop 19 trong moi tnrong hop eho du t6e d¢ thuc hien cua cac tien trlnh khac nhau.

* Vi, diem W11I/U((},C diern ctia phuong phap khoa trong

- U u diem: phuong phap khoa trong khong doi hoi cong cu dac biet, do do co th~ t6 chirc bang mot ngon ngir bat ky va thirc hien tren moi h~ thong,

- Nluroc diem: d¢ phirc tap cua thuat roan se tang khi s6 tien trinh nhieu hoac s6 hrong dean toi han trong cactien trlnh 160; cac tien trlnh phai cho doi a trang thai tich eire,

2. Phlldng phap ki.$m tra va xac I~p 2.1. Nguyen tac chung

Phuong phap nay dira vao su ho tro cua phan ctrng, co mot lenh thuc hicn hai phep xu Iy lien tuc khong bi tach rei.

Gia su ta goi lenh do la TS (Test and Set) lenh nay co 2 tham s6: bien chung G va bien rieng L (bien chung G thong thirong la mot bit trong tir trang thai hoac trong thanh ghi cal. Dang thirc thuc hien cua lenh TS (L) nhu sau:

L : = G (gall gia tri bien chung cho bien rieng) G : = 1 (gan gia tri 1 cho bien chung)

2.2. Thuat toan (bai toan 2 tien trinh)

Var LI, L2, G, IT: byte;

Begin

G : = 0; IT =1;

(Tie,l trinh 1) Repeat L1 : = 1;

While L1 = 1 do TS (L1); Tietz trinh 1 VQO doan tai han; G: = 0; IT = 2;

Phdn con lai cua tien trinh 1; Until false;

(Titll trinh 2) Repeat

31

L2 ::= 1;

While L2 = 1 do TS (L2); Tien trinh 2 vdo doan ttti han; G::= 0; TI' = 1;

P lui» con 19i Clfa til" trinh 2; Until false;

End;

*' u« diem va nhuac diem cua phuang phap kie'm tra va xae lap

- U u diem: phuong phap nay don gian, d¢ phirc tap khong tang khi s6 tien trinh va s6 doan toi han tang. Nhieu may tinh duoc trang bi toi vai lenh kieu nay dt dicu khien tien trlnh nhtr IBM PC co toi 4 lcnh.

- Nhuoc diem: tien trinh van phai cho doi rich cue; kh6 xac dinh duoc tien trlnh nao sc vao doan toi han khi co qua nhieu tien trlnh cling cho.

3. PhU'dng phap den hi~u 3.1. Nguyen tac chung

Den hieu S lit mot bien nguyen rna chi co hai phcp xu ly WAIT va SIGNAL moi thay doi diroc gia tri cua n6.

Dfnll l1;?hia phep WAIT(S):

S := S - 1

Neu S > = 0 tiep lye thuc hien tien trinh Neu S < 0 dua tien trlnh VaG hang doi

Dinh ngltia phep SIGNAL(S) S:=S+1

Neu S < = 0 dira tien trlnh trong hang doi VaG doan toi han cn« y:

- Phep WAIT va SIGNAL khong bi phan chia trong tien trinh thuc hien,

- Neu ban dau S =1 va ca hai tien trinh deu dira ra phep WAIT(S) thl chi c6

mot tien trinh diroc phep VaG doan toi han, tien trinh con lai se diroc dira vao hang doi.

3.2. Thuat toan (cho bai roan 2 tien trtnh)

Var S: byte;

Begin

S:= 1; (Tiin trtnh 1)

32

Repeat WAIT(S);

Tien trinh 1 vao doan tai han; SlGNAL(S)

Phdn COil lai cua tien trinh 1; Until false;

tne« trinh 2) Repeat WAIT(S);

Tie-II Trinh 2 vao doan t67 han; SIGNAL(S)

Phdn ron lui Clia tilil trinh 2; Until false;

End;

* Uti diem va nhuoc diem cua phuong phdp den hieu

- Uu diem: trong phuong phap nay, m6i tien trlnh chi can kiem tra quyen van doan toi han mot Ian, sau do n6 dtroc vao doan toi han hoac phai xep hang doi: trong khi doi, tien rrinh khong a trang thai tich eire vi khi mot tien trinh nao d6 ra khoi hang doi, no se bat tin hieu dira tien trmh thoat khoi trang thai cho de vao doan toi han,

- Nhuoc diem: phep WAIT va SIGNAL phai t6 chirc va xuly hang doi, do d6 phu thuoc vao tung he dieu hanh cu the va thuong diroc the hien diroi dang cac thu tuc. Khi cac tien trmh nam trong hang doi, can phai ap dung cac thuat toan xu 15' hang doi de dat dtroc ket qua loi uu.

4. PhU'cmg phap dung trinh thu ky 4.1. Nguyen tac chung

Trinh thu ky (monitor) la b¢ cac thu tuc va cau tnic thong tin dong, hoar dong trong che d¢ phan chia thoi gian, h6 tro viec thuc hien tien trlnh. M6i thai diem chi c6 mot tien trmh lam viec diroc voi monitor.

4.2. Co che hoat d(mg cua monitor

Khi tien trinh muon sir dung tai nguyen, h¢ thong g~n monitor VaG tien trinh. Neu diroc phep sir dung tai nguyen thl tien trlnh se diroc tiep tuc binh thirong neu khong thl tien trinh dtroc xep vao hang doi,

Khi tai nguyen gang diroc giai ph6ng thi monitor nhan ditu khien va bat tin

3(i) - 184

33

hieu giai ph6ng tien trinh khoi trang thai chao Cluj y;

- Monitor khong phai la mot tien trlnh rna chi la mot d6i nrong thu dong.

- Monitor nam ngoai tien trinh.

- Monitor diroc kich hoat khi tien trinh can sir dung (thong thuong monitor

duoc he thong kich hoat khi phan phoi lai tai nguyen).

* Uu diem WI nhuoc diem cua phuang phap dung trinh thu k)'

- U"U diem: monitor chua nhieu cau tnic thong tin dong nen n6 c6 the giai quyet tot van de doan loi han: monitor c6 the ghep vao lap cong CI,! he thong nen c6 tinh pho dung cao (nhieu tien trlnh co the sl'r dung diroc).

- Nhiroc diem: monitor cung co the trc thanh tai nguyen gang.

5. PhU'dng phap ta chirc liim [ac gilra cac tien trinh

H~ dicu hanh xay dung mot h¢ thong bao giita cac tien trinh dira tren 3 thao

rae co ban:

- Send message: Giri thong bao.

- Receive message: Nhan thong bao,

- Communication link: Tao m6c noi lien lac gitra cac tien trinh,

DVa vao he thong bao nay, cac tien trinh c6 the phoi hop de vao doan toi han bang each trao d6i thong bao cho nhau. H¢ thong bao su dung hai each thtrc lien lac:

- True tiep: Sang each sua hai thao tac giri va nhan.

- Gian tiep: Dung hop thu trung gian.

III. HI~N TU(jNG BE T Ac 1. Cac khai ni~m ed ban 1.1. Khai niem ve be tac

Gia sil c6 hai tien trlnh PI va P2 song hanh sil dung cac tai nguyen rl va r2 duoc dieu khien boi hai den hieu SI va ~. Tai moi thai diem, moi tai nguyen chi phuc vu cho su hoat dong cua mot tien trinh. Xet trang thai:

Thai di~m tl

t2

P2 Wait(~)

34

3(1) - 184

Wait(Sz)

Wait(S[)

Nhan xet: tai vi du tren, sau thai diem t3, tien trlnh PI roi vao trang thai cho tiii nguyen r2 dang duoc Pz su dung; sau thai diem t4, tien trlnh Pz roi vao trang thai cho tai nguyen rl dang diroc tien trlnh PI sit dung va bat dau tir day, ca. hai tien trlnh roi vao trang thai chc doi vo han va h¢ thong g~p be tac,

Nhir vay, be tac la trang thai khi hai hoac nhieu tien trlnh cling cho dqi mot sO' 51! kien nao do va neu khong c6 tac dong d~c bier ttr ben ngoai thl sl! cho dqi d6 la vo han.

1.2. I)ii~u kien xay ra be tdc trong he thong

Hien nrong be tac xay ra khi va chi khi trong he thong ton tai bon dieu kien: - Co tai nguyen gang.

- Co hien tirong gilt va doi: co mot tien trlnh dang giu mot so tai nguyen va

doi tai nguyen b6 sung dang diroc giu boi cac tien trlnh khac,

- Khong c6 he thong phan phoi lai tai nguyen: viec Slr dung tai nguyen

khong bi ngat.

- C6 hien tuong cho doi vong tron, 1.3. Cac nurc phong tranh be tac

{)~ tranh hien nrong be tac, thong thuong h~ thong ap dung ba rmrc:

- Ngan ngira: ap dung cac bien phap d~ he thong khong rei vao trang thai be tac.

- DI! bao va tranh be tac: ap dung cac bien phap d~ kiern tra cac tien trlnh

xem c6 bi rei vao trang thai be rae hay kh6ng. Neu c6 thl thong bao tnroc khi be rae xay ra.

- Nhan bier va khac phuc: tim each phat hien va giai quyet.

2. Cac bi~n phap ph6ng tranh be t~e

2.1. Ngan ngua be Mc

D~ phong ngira be tac, can phai dam bao sao cho 4 dieu kien gay be rae khong xay ra dong thoi.

2.1.1. Loai bo (iii nguyen gang

M6 phong tai nguyen gang bang cac tai nguyen co the dung chung diroc (ap dung ky thuat SPOOL).

2.1.2. LO(1,i bo ,eu t6 giii va dt;ti

Thuc hien phan bO tnroc tai nguyen; tien trlnh chi co the thirc hien khi moi tai nguyen rna n6 yeu cau da duoc pharr b6 duo Tien trlnh chi diroc phep doi tai

35

nguyen khi n6 kh6ng gitt tai nguyen nao ca. Neu tien trlnh phai doi thi moi tai nguyen n6 dang gifr phai tarn thai giiii ph6ng.

2.1.3. Xdy dung h¢ thong ngat tai nguyen

H¢ th6ng ngat tai nguyen c6 the duoc xay d1!T1g theo hai phuong phap:

- Phuong phap 1: Ncu tien trlnh dang giu mot so tai nguyen va yeu cau tai nguyen b6 sung nhung he thong kh6ng the phan b6 ngay thi moi tai nguyen rna tien trinh dang gitr se bi ngat va duoc b6 sung vao danh sach cac tai nguyen ttl do. Tien trlnh se diroc bat dau 11).i khi n6 diroc phan b6 du cac tai nguyen can thiet,

- Phuong phap 2: Neu tien trlnh dang giu mot s6 tai nguyen va yeu cau tai nguyen bo sung nhung h¢ thong khong the phan b6 ngay, khi d6 h¢ thong se kiem tra tai nguyen rna tien trlnh yeu cau c6 bi gii1 boi cac tien trinh khac cung dang doi hay kh6ng. Neu c6 thl ngilt cac tien trinh nay, thu hoi lai tai nguyen de phan b6 cho tien trlnh yeu cau: nguoc lai tien trinh yeu cau phai doi va trong khi doi, tai nguyen hien e6 cua n6 ciing c6 the bi ngar khi c6 tien trinh khac yeu diu. Tien trinh se diroc bat dau lai khi n6 duoc phan bo du tai nguyen yell cau va tai tao lai cac tai nguyen bi ngat.

2.1.4. Loai bd yen to' cha doi vong Iron

Yeu t6 cho doi vong tron e6 the diroc IO,!-i be bang each sap xep thir nr cac tai nguyen. Moi tai nguyen r duoc gan mot so thu tu [(r).

- Phuong phap 1: Tien trinh giiI tai nguyen ri, chi diroc phep doi tai nguyen rj khi [(ri) < [(rj).

- Phuong phap 2: Tien trinh dang giu tai nguyen r., muon doi tai nguyen rj thl phai giai ph6ng cac tai nguyen ri thea man dieu kien f(ri) > f'(r.)

2.2. DI! bao va tranh be tac

Nguyen rae chung cua du bao va tranh be tac la moi lan phan b6 tai nguyen cho cac tien trlnh thi he th6ng se kiem tra xem viec phan b6 d6 c6 d~y h¢ thong vao tinh trang be rae hay kh6ng. Neu c6 thi tim each giai quyet tnnrc khi be tile xay ra.

2.2.1. Khdi niem ve'diiy tien trinh an toan

Cho day tien trtnh PI' P2, ... , P, song hanh, Day tien trlnh duoc goi Hl an tcan (safe process) neu v6i moi tien trlnh Pi' tai nguyen rna Pi can c6 th~ duoc thoa man boi cac tai nguyen kha dung cua h¢ thong va tai nguyen do cac tien trinh Pi' dang giii" voi dieu kien i' < i.

36

H~ thong t1 trang thai an toan tai mot thai diem neu day tien trinh song hanh tai thai di~m do co th~ diroc sap xep thanh mot day an toano

2.2.2. Thudt toan chuyen h¢ sang trang thai an toan

Gia Slr h¢ co n tien trlnh va m kieu tai nguyen. Cac cau true dir lieu Slr dung trong thuat toan duoc xay dung nhu sau:

- Available: rnang 1 x m th~ hien s6 tai nguyen co thi sir dung cua moi kieu, Neu Availabletj) = ksuy ra e6 k tai nguyen kieu rj eo the sir dung.

- Max: mang n x m th~ hien s6 tai nguyen cue dai rna moi tien trmh yen cau.

Neu Max(i,j) = k suy fa tien trinh Pi chi co the yeu d.u eire dai k tai nguyen kieu rj. - Allocation: mang n x rn the hien s6 tai nguyen rnoi kieu hien da phan b6 cho cac lien trinh. Neu Allocation(i,j) = k suy ra tien trlnh Pi dang sir dung k tai nguyen kieu rr

- Need: mang n x rn the hienso tai nguyen con can cua moi tien trlnh. Neu Need(i,j)=k suy ra tien trlnh Pi con can k tai nguyen kieu rj.

Chii y: Need(i,j) = Max(i,j) - Alloeation(i,j)

- Request: mang n x m the hien yeu cau tai nguyen cua cac tien trinh rai moi thai diem. Nell Request(i,j) = k suy ra tien trmh Pi dang ycu diu k tai nguyen kicu rio

* T hudt toan:

If Requestti) <= Needti ) then goto Step? else error; (lien trinh yeu cau ali nguyen vuot qua guy dinh)

If Requestii) <= Available then goto Step3 else Pi wait: (khong du tai nguyen eM phan bo cho Pi)

H¢ thong du dinh phan bo tai nguyen nhir sau:

A vai lable: =Available - Requestt i)

At locationt i):=Allocation( i) + Request! i) Needti i.=Needii ) - Requestii)

Step4: Kiem tra tinh an toan cua he:

Neu he Ct trang thai an toan thi phan b6 tai nguyen thea du dinh, nguoc Iai

lien trinh Pi phai doi cung v6'i yeu cau tai nguyen Requestti), 2.2.3. Thudt toan kiem tra tinh an toan cua h¢ thong Trang thuat wan str dung them hai cau true di1li¢u sau:

Work: mang 1 x m th~ hien s6 tai nguyen kha dung cua h¢ th6ng va s6 tai nguyen do cac tien trlnh Pi' dang Slr dung voi dieu kien i' < i.

Step l :

Step2:

Step3:

37

Finish: mang 1 x n danh dau cac tien trinh da xet. * Thuat loan:

Step 1:

Khci tao:

Step 3:

Work := Available;

Finishti) :=false; (voi moi i = 1..n)

TIm i sao cho Finishii) = false va Need(i)<= Work Neu kh6ng tim thay, goto Step 4

Work := Work + Allocationti);

Step 2:

Finishti} := true; goto Step 2;

Step 4: Neu Finishti) = true voi moi i thi he thong a trang thai an toan; nguoc lai he thong gap be taco

v i du: Gia sir co 5 tien trinh va 3 kieu tai nguyen A, B, C a trang thai nhu sau:

Process Allocation Max Available
A B C A B C A B C
Po 3 0 2 7 0 3 3 3 2
Pj 2 0 9 2 2
P2 0 I 1 2 5 3
P3 0 0 2 4 3 2
Pet 2 0 0 3 2 2 a - H¢ c6 a trang thai an toan hay kh6ng?

b - Gia str tien trlnh P4 c6 yell call tai nguyen (1, 2, 2). Hoi co the phan b6 cho P4 diroc hay kh6ng?

Bili gidi

a - De xet tinh an toan cua h¢, ta din tinh rna tran Need theo c6ng thirc:

Need = Max - Allocation

Process Need
A B C
Po 4 0 1
Pj 7 1 2
P2 2 4 2
P3 4 3 0
P4 1 2 2 38

Theo thuat toan kiem tra tfnh an roan ella he ta e6:

Work := Available := (3,3,2) Finish[i] :::: false voi i = 0,1,2,3,4 xe.

Need[O] >= Work ~ Finishl O] = false Need[l] >= Work ~ Finishj l ] = false Need[2] >= Work ~ Finish[2] = false Need[3] >= Work ~ Finish[3] = false

Need[4] <= Work ~ Finish[4] = true va Work = Work + Allocation[4] = (5,3,2) Need[O] <= Work co Finish[O] = true va Work = Work + Allocation[O] = (8,3,4) Need[ I] <= Work ~ Finish] I ]=true va Work = Work + Allocation[l] = (10,4,4) Need[2] <= Work ~ Finish[2] = true va Work = Work + Allocation[2] = (10,5,5) Need[3] <= Work ~ Finish[3J= true va Work = Work + AJlocation[3] = (12,5,5)

Nhu vay, Finish[i] = true voi i = 4,0,1,2,3 dan den day tien trlnh P4, Po, PI' P2' P~~ Ia day an toan suy ra h¢ a trang thai an roan.

b - Gia sir lien trinh P4 c6 yeu call tai nguyen (l, 2, 2). Theo thuat toan chuyen he sang trang thai an toan, ta c6:

Request[4] <= Need[4] ~ thoa man Request[4] <= Available ~ thoa man

Do d6, he du dinh phan bo:

Available = Available - Request] 4] :::: (2,1,0) Allocation[ 4] :::: Allocation[4] + Request[ 4] = (3,2,2) Need[4] = Need[4] - Request[4] = (0,0,0)

va c6 trang thai nhu sau:
Process Allocation Need Available
A B C A B C A B C
Po 3 0 2 4 0 1 2 1 0
PI 2 1 0 7 1 2
P2 0 1 1 2 4 2
P3 0 0 2 4 3 0
P4 3 2 2 0 0 0 Ap dung thuat toan ki~m tra tinh an toan cua b¢ ta e6:

Work := Available r= (2,1,0)

39

Finish[i] == false voi i == 0,1,2,3,4 Xet

Need[O] >== Work c> Finish[O] = false Need[l] >= Work::::> Finish[l] = false Need[2] >= Work ee Finish[2] = false Need[3] >= Work ee Finish[3J = false

Need[4] <= Work::::> Finish[4J = true va Work = Work + Allocation[4] == (5,3,2) Need[O] <= Work ee Finish[O] = true va Work = Work + Allocationj O] = (8,3,4) Need[ I] <= Work::::> Finish[ 11 = true va Work = Work + Allocation] I] = (10,4,4) Need[2] <= Work e» Finish[2] = true va Work = Work + Allocatian[2] == (10,5,5) Need[3] <= Work::::> Finish[3] = true va Work == Work + Allocation[3] == (12,5,5)

Nhir vay, Finish[i] == true voi i == 4,0,1 ,2,3 din den day lien trinh P4, Po, PI' P2, p) a trang thai an roan, suy ra he a trang thai an toano Do do, co th€ phan b6 tai nguyen cho P-1-'

2.3. Phat hien be tac Oil lieu nhir phan 2.2.3 T huat toan:

Step 1: Tim i sao cho Finish (i) == false va Request (i) <:::::: Work Neu khong tim thay goto Step 3

Step 2: Work: == Work + Allocation (i) Finishti ): == true

Goto Step 1

Step 3: Neu ton tai i sao eho Finishti) = false thi he thong gap be tac, 2.4. Xu Iy be tac

Khi he thong gap be de, he dieu hanh co the ap dung cac phuong phap sau giai quyet:

- Thong baa cho operatorbiet de tl! xu 19

- Dinh chi hoar dong cua lien trinh: phuong phap nay dua tren viec thu hoi

lai cac tai nguyen cua nhirng lien trmh bi ket thuc, C6 the sir dung mot trong hai each dinh chi sau:

+ Dinh chi hoat dong ella moi tien trinh trong tinh trang be tac.

+ Dinh chi hoat dong IAn lirot ella tung tien trinh cho tai khi thoat khoi tinh trang he tac (khi dlnh chi tien trinh nao thi thu hoi lai tai nguyen ella tien trinh do).

40

Chit y: Khi dinh chi heat dong cua cac tien trinh cAn chu y toi cac yeu to

sau:

+ D¢ iru tien cua tien trinh

+ Tien trlnh d1i dien fa baa lau va con baa lau se hoan thanh?

+ C6 baa nhieu kieu tai nguyen va so luong tai nguyen rna rien trinh d1'l dung? + Tien trinh con can bao nhieu tai nguyen-d~ hoan thanh mot cong viec?

- Thu hOi tai nguyen: ap dung bien phap ngat tai nguyen tir mot s6 tien trinh d~ cap phat cho cac tien trinh dang co nhu cau, sau do kiern tra lai tinh trang be tac. Phuong phap nay can phai:

+ Xem xet va lira chon lien trinh nao d6 ngat tai nguyen va ngat tai nguyen nao?

+ Kha nang phuc hoi lai trang thai ban dau ella tien trinh e6 thuc hien dtroc hay khong?

+ C6 the: x ay fa kha nang mot so tien trinh khong baa gia dWJC cap du tai nguyen khong?

2.S. Ket luan chung ve phong tranh be tac

Kh6ng the dung mot plurong phap xu 19 be rae chung cho toan b() cac tinh huang. Can phai chia cac tinh huong thanh cac lop khac nhau va moi lap thl ap dung mot phuong phap xu Iy thfch hop,

Vi du:

- Tai nguyen h~ thong (Internal Resource): dung bien phap ngan ngira bang each sap thu nr tai nguyen.

- B('l nho trong (RAM): dung bien phap ngan ngira bang each ngat tai nguyen.

- Cac thiet bi co the phan bo diroc: dung cac thuat toan tranh be taco

- B9 nho dem: dung phirong phap phan b6 tnroc.

Cciu hoi va bai t{ip

1. Neu khai niern ve tien trlnh va m6i quan h~ giua cac tien trinh trong h~ thong. Trinh bay di)'ic tn.tng cua cac mai quan h~ d6.

2. Neu '1 nghTa cac tr~ng thai cua m9t tien trinh. Trinh bay n9i dung cua khai dieu khi~n tien trinh.

3. Trinh bay khai niern ve tai nguyen gang va dean tdi han (critical section), W do neu rnuc tieu cua ouan 1'1 tien trinh.

41

4. Neu khai ni~m bai toan doan toi han va trlnh bay nguyen uk chung cua cac phironq phap giai quyet bai toan dean tal han,

5. Trinh bay nguyen tac cua cac phironq phap giai quyet bei toan dean toi han.

6. Xay dljng thuat toan giai quyet bai loan doan toi han theo phuonq phap khoa trang,

kiem tra va xac lap, dung d€!n hi~u trang trLlong hop co ba hoac nhieu lien trinh.

7. Neu khai ni~m ve be tac va cac dieu kien de xay ra be tac trong he,

8. Trinh bay nguyen tac chung va cac bien phap phonq nglta be tac,

9, Neu khai niern ve day lien trinh an toan va cac thuat toan dlj bao, tranh be tac

10. Trinh bay cac bien phap giai quyet khi h~ thong g~p be taco Cho vf du doi voi mot h~ dieu hanh Cl,l the.

11. Cho mot day lien trlnh va 4 kieu tai nguyen diroc phan bo nhu sau:

Process Allocation Max Available
A B C 0 A B C 0 A B C 0
Po 0 0 1 2 0 0 1 2 1 5 2 0
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6
a - Tfnh s6 tai nguyen rna cac tien trlnh can can.
b - H~ co d tranq thai an toan hay kh6ng? c - Gia su tien trinh P1 co yeu cau tai nguyen (0,4,2,0), co the phan be; cho tien trinh P1 hay kh6ng?

12. Gia su cho day 5 tien trinh, 3 kieu tai nguyen A, B, C va yeu cau tai nguyen tLlong

U'ng cua cac tien trinh nhu sau:
Process Allocation Max Available Request
A B C A B C A B C A B C
Po 0 1 0 7 5 3 9 6 5 1 2 0
p, 2 0 0 3 2 2 1 0 2
P2 3 0 2 9 0 2 2 0 0
P3 2 1 1 2 2 2 0 0 1
P4 0 0 2 4 3 3 2 2 0 Hoi c6 the phan b6 tal nguyen cho cac tien trlnh dLlQc kh6ng?

42

Chtrong ~

LAp LICH CHO CPU

. .

Mt,lc tleu

Sau chironq nay, ngLfdi hoc e6 th~ hlnh dung diroc tam quan tronq cua "g10 CPU" va cac phuonq phap, cac thuat toan lap lich cho CPU ella h$ dleu hanh nharn dap U'ng yeu diu dLf~C phuc vu cua cac tien trlnh. Dong thoi, ngLfoi h9C cOng biet diroc m/?t cong cu d~ CPU c6 th~ dieu khi~n hoat d9ng cua cac tien trinh mot each chinh xac, d6 la ngi3t.

NQi dung

Trinh bay cac khai ni$m co ban ve glO' CPU, cac thuat toan I$p lich cho CPU, khai niern ve ngat va phLfdng phap xl! Iy ngat cua h$ dieu hanh.

I. cAe KHAI NI:¢M co BAN 1. Khai ni~m gid CPU

CPU la mot loai tai nguyen quan trong cua may tfnh. MQi tien trinh muon hoat dong duoc deu phai e6 su phuc vu cua CPU (dt xU Iy, tfnh toan ... ). Thai gian rna CPU phuc V1,l cho tien trlnh hoat dong diroc goi la gio CPU.

Tai mlli thai di6m nha:t dinh, chi e6 mot tien trlnh duoc phan ph6i gio CPU dt hoat dong (thuc hien cac lenh cua minh).

2. Cac tr~ng thai eua tien trinh lien quan den gid CPU

Trong che d¢ da chirong trinh, e6 ba trang thai cua tien trmh lien quan mat thiet den gic CPU bao gam:

-------- ~ ------; ..

~ 1------',

Hinh 3.1. Cae trang thai Clia tien trinh lien quan den gh'y CPU

~ t

43

- san sang (ready): la trang thai rna tien trtnh duoc phan ph6i dAy du moi tai nguyen can thier va dang cho gia CPU.

- Thuc hien (running): lit trang thai rna tien trlnh ducc phan ph6i day dii moi tai nguyen can thiet va gia CPU.

- Doi (waiting): la trang thai tien trinh khong thuc hien diroc VI thieu mot viti dieu kien nao d6 (doi da lieu vao/ra, doi tai nguyen bo sung ... ). Khi su kien rna 06 cho doi xuat hien, tien trinh se quay tra Iai trang thai san sang.

Nhir vay, trong suet thai gian t6n tai cua mmh, cac tien trinh se tuan thu thea sa d6 thuc hien sau:

Batddu

Sir dung CPU

1-------11 ., .

d(ti 110

sz'( dung CPU

sit dung CPU

Kef thuc

Hinh 3.2. So d() thuc hi¢1I tien trinh

M(Jt lien trinh dang trong trang thai thirc hien, no c6 th6 roi khoi trang thai boi mot trong ba ly do:

- Tien trinh da hoan thanh cong viec, khi d6 n6 tra lai gia CPU va chuyen sang cho xu ly ket thuc.

- Tien trinh nr ngat: Khi tien rrinh cho doi mot sl! kien nao do, tien trinh se diroc chuyen sang trang thai thirc hien khi xuar hien sl! kicn n6 dang chao

- Tien trlnh su dung het gia CPU danh cho n6, khi d6 n6 se duoc chuyen sang trang thai san sang.

Vice chuyen tien trinh sang trang thai sao sang ve ban chat la th1JC hien vice phan phoi lai gib CPU.

3. Khai ni~m r~p I!ch cho CPU

De dieu khien tien trlnh a nhieu trang thai khac nhau, h¢ thong thirong l6 chirc cac tir trang thai (th1JC chat la cac 'khci dieu khien tien trmh) de ghi nhan tlnh trang sir dung tai nguyen va trang thai tien trlnh. Cac tll' trang thai diroc t6 chtrc thea kieu hang doi nhu sau:

44

Ready queue ~

~
1/0 queue


~ " 1/0 queue ~ -------- L- __ I_IO_q_u_eu_e_----l

Hinh 3.3 - 56 do ttf chuc hang dai cac tien Trinh

Nhir vay, lap lich cho CPU eo nghia la t6 chirc mot hang doi cac lien trinh san sang de phan phoi gio CPU cho cluing dua tren do iru tien cua cac tien trinh; sao eho hieu suat su dung CPU la toi uu nhat,

Moi tien trinh b trang thai san sang diroc gan voi mot thir tv iru tien. Thir tu iru lien nay duoc xac dinh dua vao cac yeu to nhir: thoi diem hinh thanh tien trinh, thai gian thuc hien tien trinh, thai gian ket thiic tien trinh ...

4. Cac phU'dng phap I~p lich va yeu to danh gia

VI cac tien trtnh dien ra trong h~ thong la ngjiu nhien, do d6 khong eo thuat roan lap lich toi iru rna chi c6 nhirng thuat toan t6t doi vci nhirng dang tien trinh nao do. Cac phuong phap lap lich thuong duoc ap dung la:

- Long-term scheduler: ap dung v6i nhirng tien trinh da diroc lap danh sach va SPOOL.

- Short-term sheduler: ap dung v6i nhiing tien trinh rna rna ngu6n cua n6 da dtroc day vao bo nho trong (tien trinh da san sang nhan gio phan b6 cua CPU).

Long - term Short - term

~_t~ I Ready queue I t ~

c~ _I I/O waiting queue I]

Hinh 3.4 - Pham vi dp dung cua Long - term scheduler va Short - term scheduler

45

- Medium-term sheduler: ap dung voi nhirng tien trinh c6 thao rae swaping (nhirng tien trmh da diroc thirc hien mot phan sau d6 dua ra ngoai ... ).

Partially executed

C swapped - out processes" I

~I Ready-qu-eue------, ---___.. ~

L ~ I/O waiting queue I::...=J

Hinh 3.5 - Pham vi ap d~I11X CliQ Medium - term scheduler

Yeu t6 d6 danh gia cac phuong phap lap lich:

- SI! cong bang: moi tien trlnh dil sam hay muon cling phai diroc phan phoi gia CPU.

- Tan dung gia CPU: thai gian vo fch cua CPU cang it cang tot. Khi d6 he so throughput cua he thong cao (so hrong tien trlnh diroc phuc VI,l trong mot don vi thai gian nhieu).

- T6ng thai gian thuc hien tien trinh (Turn Around Time): duoc tinh tir khi tien trlnh bat dau cho tci khi tien trlnh ket tluic.

- Thai gian tien trinh cho diroc xu 19 trong hang doi (Wait Time).

- Thci gian dap ung (Response Time): khi tien trlnh hoat dong trong h~

thong, n6 can dung gia CPU nhieu Ian. M6i Ian can dung gia CPU tien trinh se dua ra mot yeu cau, nhu vay thai gian tinh tir khi tien trlnh c6 yeu cau gia CPU tai khi n6 diroc he thong phan b6 goi Hi thai gian dap irng.

Chit y: Viec lap Itch cho CPU lien quan den viec t6 chirc hang doi cac khoi dieu khien tien trlnh. Do d6, can t6 chirc hang doi sao eho cac yeu t6 tren la toi iru nhat.

II. cAc THUAT ToAN LAp LICH

. '.

1. First Come First Served (FCFS)

Trong thuat toan nay, d¢ iru tien phuc VI,l ticn trlnh can Cll VaG thai diem hinh thanh tien trlnh. Hang doi cac tien trlnh diroc t6 chtrc thea kieu PlPO. Moi tien trlnh deu diroc phuc vu theo trlnh nr xuat hien cho den khi ket thuc hoac bi ngat,

46

u u diem cua thuat toan nay Ia gio CPU khong bi phan phoi lai (khong bi ngat) va chi phi t6 chirc thuc hien thap nhat (vi khong phai thay d6i thir til UU tien phuc vu, thtr nr uu tien la thu tt! cua tien trinh trong hang doi),

Nhiroc diem cua rhuat toan Hl thoi gian trung blnh cho phuc vu cua cac tien trlnh la nhu nhau (kh6ng ke tien trinh ngan hay dai), do do dan toi ba nhuoc diem sau:

- Thoi gian cho doi trung blnh se tang v6 han khi he thong tiep can toi han kha nang phuc V1,l cua minh.

- Neu d¢ phat tan thoi gian thuc hien tien trlnh tang thi thoi gian cho doi trung binh cling lang theo.

- Khi co tien trinh dai, it bi ngat thl cac tien trlnh khac phai cho doi lau han. F i dZI: Cho day tien trlnh va thai gian phuc V1,l nrong irng:

T thuc hien 24

3

3

Sa do Grant bieu thi thti nr thirc hien cac tien trlnh nhir sau:

P I

o

24

27

30

Theo sa do nay, cluing ta thay thai gian cho doi ella cac tien trmh la:

Processes T thuc hien T doi

PI 24 0

P2 3 24

P3 3 27

L 30 51

dan den thoi gian cho d¢ trung binh cua cac tien trlnh III 51/3=17

2. Shortest Job First (SJF)

Thuat toan SJF xac dinh thu tu iru tien thuc hien tien trlnh dua vao tong thoi gian thirc hien tien trinh. Tien trlnh nao c6 t6ng thoi gian thirc hien ngan se diroc

47

l1U tien phuc vu tnroc.

Vi du: Cho day tien trlnh va thai gian phuc vu nrong ung:

Processes T thuc hien

PI 24

P2 3

P1 3

Sa do Grant bieu thi thii tv thuc hien cac tien trinh nhtr sau:

o

3

6

30

Theo sa do nay, cluing ta thay thai gian cho doi ella cac tien trlnh lit:

Processes T thuc hien T doi

P2 3 0

P3 3 3

PI 24 6

I ~ 9

d<1n den thai gian cho doi trung blnh ella cac tien trinh Hi 9/3=3

Uu diem ella thuar loan Ill. thai gian cho doi trung blnh ella cac tien trlnh ngan hon so voi FCFS. SJF nhanh ch6ng loai bo cac tien trinh ngan, giam s6 hrong cac tien trlnh trang hang doi.

Nhircc diem chfnh cua thuat roan la che d¢ phan phoi lai gio CPU cung diroc lip dung trang twang hop ngat cac tien trlnh dai dang thuc hien de phuc vu cac tien trmh ngan han moi xuar hien trong hang doi, Neu tien trinh moi xuat hien e6 tong thai gian thirc hien ngan nhirng vAn Ian han thoi gian can thiet d~ thuc hien n6t tien trlnhdang thuc hien thl viec ngat tien trlnh Ia kh6ng hop IY.

3. Shortest Remain Time (SRT)

Ttrcng tv nhu SJF nhung trang thuat toan nay, d¢ l1U tien thirc hien cac tien trinh dua vao thai gian can thiet de thuc hien n6t tien trinh (bang tong thai gian trtr di thai gian di'i thirc hien), Nhu vay, trong thuat toan nay can phai thuong xuyen cap nhat thong tin ve thai gian di'i thirc hien tien trlnh. Dong thai, che d¢ phan b6 lai gio CPU cung phai duoc ap dung neu khong se lam mat tinh uu viet cua thuat roan.

48

4. Round Robin (RR)

Trong rhuat toan nay, h~ thong quy dinh mot hrong tir thai gian (time quantum) khoang ttr 10 - IOO mili giay (rns),

Moi tien trlnh trong hang doi Ifin luQt diroc phan phoi mot IUQ'ng tu thai gian d€ thuc hien, Sau khoang thai gian d6, neu tien trtnh chua ket thtic hoac khong roi van trang thai doi thl no diroc chuyen ve cu6i hang doi.

Hang doi cac tien trlnh duoc t6 chirc theo kieu vong tron va cac tien trinh luon luon dam bao duoc phuc vu. Khi c6 tien trinh moi phat sinh, n6 se duoc dira vao hang doi yang tron va dUQ'C dat a vi trf phuc vu ngay. Cac tien trlnh du ngan hay dai deu c6 d¢ uu tien phuc V1,l nhu nhau.

Tren thirc te, de dam bao dQ iru tien cho cac tien trtnh dai, h¢ th6ng se phan chia cac tien trlnh thanh rn lap. SOliin diroc phuc vu va thai gian mot Hin phuc V\,I rien trinh tai moi lap khac nhau (gia sir (} lap thii i, tien trinh duoc phuc vu k, Ian va moi lan vdi thai gian q.).

Neu sau khoang thai gian da diroc phan ph6i rna lien trinh chua ket thuc hoac khong bi ngat thl n6 duoc chuyen sang lap thu i + 1 (voi k, + 1 va qj + 1 Ian hen). Luong tu thai gian se tang dAn cho den khi tien trlnh roi van lap ngcai cung (lap m). a d6 n6 se dircc phuc vu voi IUQ'ng tir qrn khong doi. Nhu vay thu tlf uu tien ella cac tien trinh se tang dan thea thoi gian xep hang doi.

Vu diem cua phuong phap phuc vu dong mire thea lap se cho phep he th6ng iru tien nhirng tien trlnh ngan (vi n6 ket tluic s6m) nmmg khong gay t6n hai Ian eho cac tien trinh dai.

Nhuoc diem Hl do phai thucng xuyen phan phoi 1~ gio CPU nen thai gian cho doi trung binh ella Round Robin c6 the Ian hen so voi FCFS.

Chu y: Trong thuat toan, can chon gia tri hrong tir thai gian (time quantum) thich hop, Neu chon gia tri time quantum Ion thi viec b6 sung tien trlnh rnoi hoac kfch hoat tien trlnh bi ngat se Hun tang thoi gian cho dci trung binh, nhung ngircc lai neu chon gia tri time quantum nho thl n6 se lam cho cac tien trlnh pnai lien tuc chuyen trang thai dan den giam h¢ 56 hfiu Ich cua CPU.

Thong tlurong gia tri time quantum duqc chon thea cong thtrc: q = t/n hoac q = t/n - s. Trong _d6: t Hi thoi gian khcng che truce; n Ia 56 tien trinh; s lit thai gian chuyen ttl tien trlnh nay sang tien trtnh khac.

Vi du: Cho day tien trinh v6i thai gian thuc hien tuong ung theo bang diroi va time quantum c6 gia tri q = 4.

4(i) -184

49

T thirc hien 24

3

3

Sa d6 Grant bieu thi tlur nr thuc hien cac tien trinh nhtr sau:

o

4

7

10

14

18

22

26

30

Theo sa dO nay, cluing ta rhay thai gian cho doi ella cac tien trlnh nhu sau:

Processes T thirc hien Tdqi
PI 24 6
P3 3 4
PI 3 7
L 30 17 dan'den thai gian cho doi trung binh cua cac tien trinh la 17/3 = 5.66. 5. Multi Level Queue (MLQ)

Thuat roan dira vao thong tin do.ngtroi sir dung eung cap va ket qua phan tich cua h¢ thong de phan chia cac tien trlnh san sang thanh cac mire hang doi e6 d¢ uu tien khac nhau.

Highes priority
I System tasks I
I Interactive I
~I Editing I
I Batch I
I Student batch I Lowest priority Hinh 3.6. T6 chuc hang d¢ cac tiln trinh trong MLQ

50

4(1) -184

Trong moi rmrc co each t6 chirc va thuc hien thieh hop, Khi co mot tien trlnh o rrurc eao ban can thuc hien thl M thong phai ngat tien trinh a cac mire thap hon d~ phuc vu tien trlnh mire cao.

e/IlIY: Tren thuc te, each to chrrc hai hang dgi dircc ap dung ph6 bien nhat,

trong db:

- Mot hang doi cho cac tien trlnh trao Mi vao/ra nhieu.

- M9t hang doi eho cac tien trlnh thuc bien tinh roan nhieu,

Cac tien trlnh b rnirc hang dgi thu nhat co d¢ uu tien cao hon nhung VI phai cho ket qua vao/ra nen khong Slr dung het hieu suat gib CPU diroc phan bo. Cac tien trlnh 6 hang doi thir hai heat dong tinh roan dira tren nen ella cac tien trlnh 6 mire thu nhat. Sau khi thuc hien, tien trlnh i:t mire nao phai quay tra ve dung mire d6 neu chua ket thuc.

6. Multi Level Feedback Queues (MLFQ)

MLFQ la thuat roan tong quit nhar d~ lap lich eho CPU. Trang thuat toan nay, he thong t6 chirc nhieu hang doi. Moi hang idqi c6 dq uu tien va each thirc t6 chirc thuc hien khac nhau. Cac tien trinh e6 the chuyin doi tir hang dci nay sang hang dci khac,

I Queue 1 I I


Queue 2 I I



1 Queue J I Hinh 3.7. T6 chile hang doi cdc tien trinh (rang MLFQ Cac yeu to can chily:

- so hrong hang doisao cho hop 19.

- Chon thuat toan thieh hop cho moi hang doi,

- Tieu chuan va each thirc ha mire mot tien trinh.

- Tieu chuan va each thirc nang mac mot tien trlnh.

- Tieu chuan va each thtrc de chi dinh mot tien trlnh moi phat sinh di vao

hang doi nao.

51

III. NGAT

1. Khai ni~m ngat (Interrupt)

De tien trlnh co the thirc hien chfnh xac, can phai co su ph6i hop nhip nhang gina hoat d¢ng cua CPU va cac thiet bi. Ngat la phuong tien de cac thier bi thong baa cho CPU biet viec thay d6i trang thai cua minh.

Tir goc d¢ CPU, ta co th~ coi ngat la viee ngirng d¢t xuat viec thirc hien mot tien trinh de chuyen sang thuc hien mot tien trinh khac khi co mot su kien nao do xay ra.

Nhu vay, ngat Hi c6ng cu de chuyen dieu khien toi mot tien trinh khac rna

tien trinh hien tai khong biet.

2. Phan loai ngat

Ngat duoc chia thanh hai loai: ngat trang va ngat ngoai.

N gat trong la ngat gay ra boi cac su kien lien q uan den hoat d eng cua CPU.

Vi du nhir cac su kien tran a nho, thuc hien phep chia cho 0, vi pham dia chi bo nhc, rna lenh sai. ..

Ngat ngoai la ngat gay fa bci cac su kien nam ngoai tien trinh dang thuc hien nlur: tin hieu dong ho, su c6 ky thuat, ngat vao/ra ...

3. Quy trinh Xlr 19 ngat

Van de quan trong trong xu ly ngat la ghi nhan thoi diem xay fa ngat. Neu xir ly ngat ngay lap tire (kh6ng cho thirc hien xong cau lenh hien thai) cho phep h¢ thong giai quyet diroc cac yeu cau cap bach nr nhien nlnrng se lam mat cau lenh hien thoi. Thuan lei hen la cho cau lenh hien thai ket thiic roi rnoi xU ly ngat, nhu vay h¢ thong can dinh ky kiem tra xem co tin hieu ngat xuat hien hay khong? Co che ghi nhan ngat nay nam ngoai cac chuong trinh xU ly ngat va phai diroc hru y khi xay dung cac chuang trlnh h¢ thong.

CO rat nhieu phuong phap lien quan den xu 19 ngat nhung quy trinh chung co the rna ta gam Dam buoc:

- Obi nhan d~c tnrng cua su kien gay ra ngat vao a nho quy dinh.

- Ghi nhan trang thai cua tien trinh bi ngat (bo dem chuang trlnh, noi dung

cac thanh ghi, che d¢ lam viec ... ).

- Chuyen dia chi chuang trinh xu 19 ng~t vao thanh ghi dia chi lenh cua CPU.

52

- Thuc hien chuang trinh xu ly st! kien.

- Khoi phuc lai tien trinh bi ngat,

Ba biroc dau cua quy trinh xu ly ngat do cac thanh phan ky thuat cua may tfnh dam nhan, hai buoc con lai do he dieu hanh dam nhan, CI,l tht nhu sau:

H¢ dieu hanh xu ly sl! kien bang cac chuang trinh xu ly ngat, moi loai su kien c6 mot chuang trinh xu Iy rieng, Viec dau tien cua chuang trlnh xu Iy ngar la hru lai cac thong tin cu the ve trang thai cua tien trinh bi ngat (cac thong tin hru lai a biroc hai do phan ciing dam nhan chi la cac thong tin chung). Phan tiep thea la doan chuang trinh xu ly 51! kien, rnoi 51! kien doi hoi mot each xu Iy khac nhau, Neu su kien khong doi hoi xu ly gAp thi he thong co tht dua tien trinh xu 1y vao hang doi.

Khi khoi phuc trang thai tien trlnh bi ngdr, neu tien trinh ngat khong tht tiep tuc thirc hien VI su kien xay ra thl sau khi th6ng bao nguyen nhan, chuang trlnh xu Iy ngat chuyen tien trmh sang bo phan xu ly ket thuc,

ChLI y: Mot so hoat dong trong xu Iy ngat phai diroc thuc hien ngay lap tire nhu nho trang thai tien trinh, xu 1y loi, ... Chuang trlnh thuc hien cac thao rae nay ph iii thuong tni trong bo nho va 13. mot thanh phan cua h¢ dieu hanh, Nhirng hoat dong xu ly it cap thiet han do cac chuang trinh khong thuong tni dam nhan, Nhir vay, ban than xu Iy ngat thuong duoc ehia thanh hai mire: mire mot va mire hai, tuy nhien khong phai 51.! kien nao cung doi hoi ca hai rmrc xu IY.

Nhirng ngat lien quan den dieu khien va hoat dong cua CPU thirong diroc chuyen toi chuang trinh ghi nhan ngat ngay lap tire dt kich hoat cac chuang trinh xu Iy ngat tuong ling. Vi vay trong hang doi luon luon c6 cac tien trlnh he thong dam bao dieu phoi, thu thap thong tin thong ke, phuc VI,l xu Iy ngat mire hai ... Khi c6 mot CPU thi ban than cac tien trlnh h~ thong nhieu khi ciing phai xep hang cho xu lY.

4. Ngtit kep

6 phan tren, chung ta moi chi xet tnrcng hop cac su kien gay ngat xay ra mot each rieng bier. Trong tnrong hop cac su kien xay ra dong thai hoac su kien gay ngar xuat hien ngay trong tien trmh xu Iy ngat, khi d6 h¢ thong se g~p mot ngat kep.

D~ xu Iy ngat kep, can gan cho m6i ngat mot thu nr I1U tien, ngat nao c6 thu nr uu tien cao se duoc xu ly tnroc.

Mot phuong phap xu 1y ngat kep khac hay duoc ap dung la phuong phap t6

53

chirc Stack. Trong tnrong hop nay, ngat c6 the diroc rna hay bi che. Khi bi che thi tin hieu ngat khong th~ Hie dong toi CPU. N giit b! che c6 th~ bi mat hoac diroc xep hang cho xu IY. Neu duoc xep hang thi sau khi co lenh rna ehe. he thong se xu Iy cac ngat xep hang.

Neu ngat moi xuar hien ngay trong hie xu Iy ngat thl n6 c6 the bi che hay duoc xu ly ngay tuy theo quan he cua hai ngat. Neu duoc xu ly ngay thi chuang trinh xu Iy ngar cfl Ir6 thanh chuang trinh bi ngat, con neu bi che (chua diroc xu 19) thi ngat moi c6 the bi mat hoac xep van hang doi. Khi chuang trinh xu Iy ngat roi vao trang thai dqi (bi ngat) thi n6 se phai a d6 cho den khi chuang trlnh dieu khien chuyen no sang rrang thai san sang (dieu nay xay ra khi CPU gap lenh rna chan).

D~ he th6ng co the hoat dong duoc binh thuong, mot 56 tin hieu ngat phai toi duoc CPU bat ky thai diem nao (vi du nhu tin hieu khi co 51! co nghiern trong hoac tin hieu nhip dong ho), Viec che ngat hoac rna che co the thuc hien bang cac cong ClJ. phan ciing hoac cac chuang trinh phan rnem do cac chuang trinh xu 19 ngat quyet dinh. Khi dang tien hanh xu 19 ngar nao d6, nell xuat hien tfn hieu ngat cling loai thi tin hieu do phai bi che de tninh ghi de thong tin vao cling mot bo nho danh cho loai ngat d6. Sau khi xu 19 xong ngat thu nhat, he thong phai rna che d~ xu 19 tiep ngar dang bi che.

Neu c6 thiet bi ky thuat ho tro phan phoi be nho khac nhau cho tung mire uu tien thl viec xir 19 ngat kep bang phuang phap gan mire uu tien se dan gian han rat nhieu.

Xu 19 ngat khong nhat thiet phai tien hanh lien tuc. Vi du xu 19 ngat vao/ra co the chia thanh hai giai doan: giai dean mot xu 19 ket qua cac phep kierntra 6 mire kenh va thiet bi; giai doan hai xu 19 ket qua cua chinh phep vao/ra. Trang khoang thai gian gifra hai giai doan, h¢ thong co th~ xu 19 cac ngat khac neu co.

Cau hoi va bai t~p

1. Cac tranq thai nao cua tien trlnh lien quan den gio CPU.

2. Khai ni~m ve l$p lich cho CPU, cac phuonq phap l$p lich va cac tieu chutln danh

gla.

3. Trinh bay cac thuat toan lap lich cho CPU.

4. Khai niern, phan loai ngat va quy trlnh xl! Iy ngat.

54

5. Cho day tien trlnh vai thai gian thirc hien tuang (fng nhu sau:

Process T thirc hien
P1 10
P2 2
P3 7
P4 1
P5 5 a - Ve sa do Grant theo cac thuat toan: FCFS, SJF, RR (q = 2)

b - Cho biet thai gian ton tai trong h~ thong ella cac tien trinh trong a m6i thu~t toano e - Tfnh thai gian cho d<;1i trung binh ella cac tien trinh trong cac thu~t toano Thuat toan

nao co thai gian cho d<;li trung binh ngan nhat.

55

Chirong 4

QUAN LV B¢ NHO TRONG

Ml:Ic ti{m

Sau chironq nay, ngVCli h9C c6 th~ hi~u duqc cac khai ni~m ve dja chi logic, dja chi vat Iy khi thirc hien chuang trinh. Nam bat duqc cac cau true co ban cua chironq trinh va cac SCI do quan Iy b¢ nho cua h~ dieu hanh, Ngoai ra, con c6 th~ biet duc;lC khai niern ve b¢ nhd ao va nguyen tac hoat d¢ng cua n6.

Nl}i dung

Trinh bay cac yeu cau cua quan 11" bo nhd, cac cau true co ban cua chuang trinh va cac sa do quan Iy b¢ nho cua h$ dieu hanh,

Khai niern b¢ nhd ao va phironq phap cai d~t b¢ nho ao,

I. cAc KHAI NItM co BAN

1. Yeu diu cua quan Iy bQ nhd trong

B¢ nho Iii thiet bi hru tru duy nhat rna thong qua do CPU eo th~ trao d6i thong lin voi moi twang ben ngoai, Do vay, nhu cau t6 chirc, quan 1y bo nho la mot trong nhlrng nhiern vI) co ban hang dau cua he dieu hanh. B¢ nho duoc t6 chtrc nhu mang mot chieu cac til nho (word), moi tu nho co mot dia chi. Vice trao doi thong tin vai rnoi tnrong ben ngoai diroc thirc hien thong qua cac thao tac doc/ghi du lieu vao mot dia chi cu the nao do trong bo nho.

H~ dieu hanh chiu tranh nhiern cap phat khong gian nho cho cac tien trinh khi co yeu duo De thuc hien t6t nhiern vu nay, he dieu hanh can phai xem xet mot so khia canh sau:

- Su nrong ung gifra dia chi logic va dia chi v~t ly: Hun the nao de chuyen d6i mot dia chi logic thanh mot dia chi vat ly?

- Quan Iy bo nho vat ly bao gorn: phan b6 kh6ng gian nho cho cac tien trlnh hoat dong; thu hoi kh6ng gian nho khi tien trlnh ket thiic: quan ly duoc khong gian nho ttr do.

- Chia se th6ng tin: cho phep cac tien trinh dang hoat dong trong bo nho co the chia se thong tin voi nhau.

56

- Baa ve bo nho: ngan chan cac tien trinh xam pham den vimg nho duoc cap phat cho cac tien trinh khac.

2. Qua trinh sinh dja chi (9an dja chi)

Thong thirong, mor chuang trinh diroc hru tni tren cac thief bi nho ngoai nhu mot tep tin nhi phan co th~ xu ly. D~ thuc hien chuong trinh, chung ta can nap n6 vao bo nho d~ tao lap cac lien trinh Wong irng va xu lY. Cac dia chi trong chuang trinh ngu6n la cac dia chi wang dci. vi the mot chuang trinh khi thuc hien se phai trai qua nhieu giai doan xu ly d~ chuyen d6i cac dia chi wong d6i thanh cac dia chi ruyet d6i trong bo nho. Lam r6 han ve van de nay, cluing ta xet quy trinh thuc hien mot chuang trlnh tren may tinh qua so do sau:

Chuongtrioh
ngon ngu bac eao
+
Chuong trinh
ngon ngu may
t
Cac modul
clurong trmh
+
Lien ket
cac modul
~
Nap
cac modul
J
Thl!c hien Hinh 4.1 - Qua trinh sinh dia chi

57

Trong qua trmh dich, cac bien ngoai diroc chuyen d6i thanh cac bien trong.

H~ thong se phan phoi khong gian nho va gan dia chi cho cac bien (dia chi xac dinh moi quan h~ giira kh6ng gian nho va cac bien) .. Cac dia chi a day diroc goi la dia chi nrong d6i - dia chi logic (vi n6 chua duoc gan vai mot b¢ nhc cu the nao),

Chuang trinh Link se m6c noi cac modul thanh mot chuang trinh hoan chinh, co the' thuc hien diroc theo mot nguyen tac chung.

Khi thuc hien, chuang trinh duoc nap vao mot bo nho cu the. Cac dja chi tuong d6i se duoc anh xa toi cacdia chi tuyet d6i - dia chi vat 1y xac dinh sao cho phi) hop voi moi truong. Thao tac nay duoc goi la dinh vi chuang trlnh.

Tir day, chting ta c6 cac khai niem:

- Dia chi logic - dia chi wang d6i: Iii dia chi do h~ thong tao ra va duoc cap phat cho cac bien khi dich chuang trinh.

- Dia chi v~t Iy' - dia chi tuyet doi: la dia chi cu the trong bo nho, dtroc cap phat cho cac bien khi thirc hien chuang trinh.

- Be) nho logic: Hl tap hop Hit ca cac dia chi logic phat sinh khi dich chuang trinh,

- B() nho vat ly: Iii tap hop tat cii cac dia chi vat ly tucng ling voi cac dia chi logic khi thuc hien chuang trinh.

- Che d¢ l~p trinh trong be) nho thirc: can xac dinh tnroc kich thuoc bo nha logic khong vuot qua k ich thuoc bo nho vat If

- Chc 0<) lap trinh trong bo nho ao: kfch thuoc bo nho logic kh6ng hi phu thuoc kich thiroc be) nho vat ly.

Cln: -):

- De thuc hien viec chuyen d6i dia chi logic thanh dia chi vat Iy vao thai diem xu ly, cac he dieu hanh su dung mot co che phan cimg MMU (Memory Management Unit).

- Chuang rrinh cua nguoi str dung chi thao tac tren cac dia chi logic clur khong thao tac voi cac dia chi vat lY. Dia chi vat ly chi duoc xac dinh khi thuc hien truy xuat dfr lieu,

II. cAc CAU TRUe co BAN CVA CHUONG TRINH

C6 nhieu phuong phap 16 clurc chuang trinh 2J bo nh6 trong d~ tlurc hien.

Cac phuong phap nay khac nhau a kieu dinh vi chuang trinh trong bo nho va

58

thai diem thuc hien phep anh xa dia chi nrong doi thanh dia chi tuyet doi. Vi du:

- Nell tai thai di~m bien dich co the biet vi tri rna chuang trinh se diroc dinh vi vao bQ nho thi trinh bien dich c6 the phat sinh ngay rna voi cac dia chi tuyet doi. Tuy nhicn, nell sau nay c6 sl! thay doi vi tri dinh vi thi se phai bien dich lai chuang trinh,

- Nell tai thai di~rn bien dich chua the biet vi trf dinh vi, trinh bien dich se phil sinh rna nrong doi. Khi nap chuang trinh, cac dia chi nrong doi moi diroc anh xa toi cac dia chi tuyet doi. Nhir vay, nell thay d6i vi tri dinh vi, hi? thong chi can nap lai chuong trinh va tinh roan lai cac dia chi tuyet doi rna kh6ng can phai bien dich lai.

- Nell co nhu cau di chuyen chuang trinh til vung nho nay sang vung nho khac trong qua trinh xir 19 thl thoi diem anh xa dia chi nrong doi thanh dia chi tuyet doi bi tri hoan den H~n thai diem xu 19 va can phai str dung co che' phan cung dac bier.

Call true mot chuang trlnh the hien each quan 19 be) nho logic va cho ta tnay hinh anh cua clnrong trlnh a bo nho vat 19 khi thuc hien. Moi chuang trinh eo the co de dang cau true sau: cau tnic tuyen tinh, cau true dong, cau true Overlay, cau true phan doan, Call true phan trang.

Chu .(': moi clurong trinh co tht diroc chia thanh nhieu modul. Cac modul co the giong hoac khac nhau ve Call true.

1. Cau true tuyen tinh

La Call true rna sau khi bien dich, cac modul duoc t~p hop thanh ITIQt chuang trinh hoan thien, chua day du moi thong tin de co the tlurc hien (trir du lieu vao); M9i bien ngoai deu diroc gan dja chi C1,l the. Khi thuc hien chi can dinh vi chuang trlnh mot tan vao bo nho.

M3

M5

Hinh 4.2 - Cdu true tuyen tinh

- Uu diem: don gian, de to chiic bien dich va dinh vi, thai gian thuc hien nhanhi VI moi cong viec chuan bi deu duoc thirc hien tnroc, he thong khong can phai bien tap them, khong mal thai gian tim kiem va nap modul chuang trinh

59

(trir dfr lieu vao), Ngiroi ta thuong lay thai gian thuc hien chuang trinh trong cau true nay lam chuan d~ danh gia, so sanh cac phircng phap to chirc khac nhau. Ngoai ra, chuong trinh cau tnic tuyen tinh c6 tinh hru dong cao, de dang sao chep chuang trinh toi cac he thong khac c6 cling t~p rna lenh rna van duy tri khi:l nang rhuc hien.

- Nhiroc diem: cau true tuyen tinh lang phi b¢ nho, rrurc lang phi ti l~ voi kfch thuoc chuang trinh, Dieu nay gay kh6 khan trong thirc te la chuang trmh cang Ian, ngiroi sir dung cang phai tiet kiern bo nho,

2. Cau true dC)ng

Trong cau true dong, cac modul chuang trinh duoc bien tap mot each rieng biet, Khi thirc hien chuang trinh, he thong ehi can dinh vi modul gee, Trong qua trinh thirc hien, can toi modul nao (da dang ky voi h¢ thong de thirc hien) thi he thong cap phat kh6ng gian nho va n~p tiep modul d6. Khi heat dong xong thi giai ph6ng modul khoi bo nho, thu hoi khong gian nho.

MO
MO MI M2
MO M3 M4
MO MS Hinh 4.3 - edlt true dong

- Uu diem: neu quan ly bo nho va to chuc tot chuang trlnh se tiel kiem b¢ nho; kfch thiroc bo nho kh6ng phu thuoc kich tluroc chuang trinh.

- Nhircc diem: trong cau true nay, trach nhiem n(;lp va xoa cac modul do ngtroi sir dung dam nhiern, do d6 cac cau lenh nap, xoa phai diroc neu ngay trong chirong trinh nguon. Dan den kfch thuoc chuang trinh nguon Ion va ngiroi sir dung can phai nam virng cau tnic chuang trinh va cac c6ng ClJ dieu khien bo nho cua h¢ dieu hanh. Ngoai ra, do phai an dinh trinh tu dinh vi modul ngay trong chuang trinh nguon nen chuang trinh c6 cau true dong se bi phu thuoc vao version cua he dieu hanh.

3. Cau true Overlay

Trong cau true Overlay, cac modul chuang trinh sau khi bien dich diroc chia

60

thanh cac mire:

Mire 0: mire chua modul g6c dung de n~p chuang trinh. Mire 1: chtra cac modul duoc goi boi rmrc o.

Mire 2: chua cac modul duoc goi boi mire 1.

Mire i: chira cac modul diroc goi boi rmrc i-L

B¢ nho danh eho chircng trtnh ding diroc ehia thanh cac rmrc wang irng voi cac mire chuong trinh. Kieh thuoc moi mire trong b¢ nho bang kich thuoc modul lcn nhat ella mire chuong trlnh wang ling.

Mue 2: 100Kb

MO
(80Kb)
MI M2
(50Kb) (90Kb)
M3 M4 M5
(50Kb) (lOOKb) (70 Kb) Mire 0: 80Kb

Mue I: 90Kb

Htnh 4.4 - ca« true Overlay

Chuang trinh ngu6n diroc viet va bien dich nhtr cac cau true khac tao thanh cac modul chirong trlnh (cac modul nay khong chua cac lenh giao tiep voi h¢ dieu hanh), De tao thanh chuang trinh cau true Overlay, ngiroi su dung can cung cap thong tin ve cac rmrc cho trlnh bien dich thong qua so d6 Overlay (trong he dieu hanh DOS, cac file nay eo phan rna rong la OVL). Modul g6e dircc hru trir trong mot file chuang trlnh rieng,

Khi thirc hien chuong trlnh, modul g6e duoc dinh vi vao be nho nhu chuang trlnh co cau true tuyen tinh. Can toi modul, nao, he thong se tlm kiem trong sa do Overlay va nap vao bo nho a mire nrong irng.

Thanh phan he th6ng duy trl hoat dong ella chuang trinh Overlay la Supervisor Overlay. Khi nap modul moi vao mot rmrc b¢ nho da diroc su dung, cac modul dang t6n tai trong do se bi xoa, De eo the su dung lai cac modul ell sau nay, he thong phai ghi tam no vao mot file tam thoi a b¢ nho ngoai, Khi can nap mot modul nao, truck het Supervisor Overlay se tim kiem trong file tam

61

thai. Viec tao file tam thai la khong can thier doi voi cac modul vao/ra nhieu Ian hoac cac modul khong thay d6i. Vi khong th~ du bao lmoc khi can thi goi modul nao nen Supervisor Overlay phai nam tlurong tni trongbo nho. Dieu nay dirong nhien se lam giam hieu qua cua cac bienphap toi iru bo nno.

Trong cau true Overlay, thong thuong nguoi ta khong xet toi cac lai goi dong rrurc (nrc la mot modul co loi goi mot modul khac cung mire). Viec goi dong mire gay kh6 khan VI modul goi co th~ bi phu truce khi modul duoc goi dinh vi xong trong bo nho, Mot sa do Overlay hop ly n6i chung khong th~ ,xuat hien .cac loi goi dong mire, de xu ly cac loi goi dong rrurc, chirong trmh .bien dich phai tao ra them mot bang thong tin dieu khien va dira vao do Supervisor Overlay moi bier diroc cac modul goi va diroc goi.

- Vu diem: cau true Overlay e6 tinhchat dinh vi dong, do do eho phep sir dung be) nho nhieu han phan bo nho rna he thong danh cho chuang trtnh, Mac du qua trinh dinh vi duoc tien hanh trong thai di€rn thirc hien chuongtrinh nhirng nhln chung cau true chuang trinh van mang tinh chat tinh, nokhong thay d6i trong tat d. cac Ian thirc hien chuang trinh.

+ So voi cau tnic dong, cau true Overlay chi doi hoi nguoi sir dung cung cap nhfrng thong tin dan gian va quan trong nhat la khong ga.n co dinh Call true vao chuang trinh ngu6n.

+ Neu nguoi su dung xay dung diroc sa do Overlay totva cac modul co d¢ dai khong qua IOn thi hieu qua cua cau true nay khongkem gi so voi cau true dong. Chinh vi vay, cac chuang trinh ung dung phan Ian dell c6 cau true Overlay (vi du nhu FOXPRO, QUATRO ... )

- Nhuoc diem: cau tnic Overlay va.n yeu cau ngtrci-sirdung eung dip thong tin phu (mac dil chi la cac thong tin dan gian), Hieu qua tiet kiem b¢ nho van phu thuoc each t6 chtrc. b6 trf cac modul cua chuong trlnh. Chi can mot vai modul c6 kfch thuoc IOn d cac rmic Overlay khac nhau thi hieu qua Slr dung bo nho se giam han.

+ Do cau true chuang trinh lit. tinh nen neu e6:b6 sung them bo nho tt! do thi hieu qua sir dung chuang trinh cua h¢ th6ng cling khong thay d6i.

4. Cau true phail dean

Chuong trlnh cua ngiroi sir dung ducc bien dich thanh tung modul d¢c lap, Thong tin ve cac modul duoc chua trong mot bang dieu khicn goi la bang quan ly dean (Segment Control Block - SCB). Trong bang quan Iy doan con chua cac

62

thong tin tro giup viec dinh vi cac modul vao bo nho.

Khi thuc hien chirong trtnh, he thong se dua vao bang quan Iy doan de nap cac modul can thiet vao trong b¢ nho cho toi khi het kha nang. Neu can nap cac modul moi nhirng thieu bo nho thl he thong se dua bot ra ngoai nhirng modul c6 khii nang khong su dung ntra.

- Uu diem: cau true nay khong yeu cau ngiroi sli dung phai khai baa them thong tin, moi c6ng viec deu do he thong dam nhan va khi dung hrong bo nho tang thi toe d¢ thuc hien chuang trmh cling tang.

- Nhiroc diem: hieu qua sli dung bo nho phu thuoc vao each phan chia chuang trinh thanh cac modul d¢c lap, Cung nhu cau tnic Overlay, cau true phan dean chi can ton rai mot vai modul co d¢ dai Ian thi hieu qua sir dung bo nho se bi giam mot each dang ke. Mat khac, chuang trinh co cau true phan dean chi ap dung duoc khi bo nho quan Iy theo kieu phan doan.

5. Cau true philn trang

Chuang trlnh duoc bien dich nhu cau tnic tuyen tinh, sau d6 duoc phan chia thanh cac phan bang nhau goi la trang. Thong tin ve cac trang duoc chua trong mot bang dieu khien goi la bang quan ly trang (Page Control Block- PCB). Moi phan til trong bang quan ly trang nrong irng voi mot trang trong chuang trinh cua nguoi Slr dung,

Khi thuc hien, he thong se dira vito bang quan Iy trang de n<;lp cac trang can thiet vao bo nho.

- U u diem: cau true phan trang phat huy duoc hieu qua Slr dung cua b¢ nho.

- Nhtroc diem: chuang trlnh chi ap dung d6i vci bo nho diroc quan ly thea

kieu phan trang.

III. cAc SO 1)6 QUAN L Y BO NH(} 1. Sd do philn heach co dinh

BQ nho duoc chia thanh n phan, kh6ng nhat thiet phai bang nhau va mOi phan duoc S11 dung nhir mot bo nho d¢c lap goi la mot phan hoach, Moi phan hoach e6 the nap duoc mot chuang trlnh va t6 chirc thirc hien mot each dong thai. Nhu vay, tren ly thuyet neu co n phan hoach thl se c6 the nap duoc n chuang trlnh va tlurc hien mot each d6ng thoi (n duoc goi la h¢ s6 song song cua he thong).

VI mOi phan hoach diroc coi nhu mot b9 nho doc lap, nen m6i chuang trtnh se co mot danh sach quan ly khong gian nhd tt! do rieng, Chuang trlnh diroc nap

63

vao phan hoach nao thi se a d6 cho den khi ket thuc,

Moi phan hoach se dtroc gan voi mot 56 lap phuc vu, chuang trlnh khi dinh vi vao b¢ nho cling diroc phan lap thea khai bao cua nguoi str dung, Moi phan hoach chi phuc VI,! cac chuang trinh thuoc lap mlnh quan 1Y. Nhir vay, cluing ta c6 the tranh diroc tnrong hop dinh vi chuang trinh nho vao vung nho Ion, tranh lang phi bo nho.

De sua d6i cau true cac phan hoach can phai nap lai h¢ dieu hanh nhung de tranh mat thong tin chung ta phai cho cho tai khi cac chuang trtnh ket thuc. Cling c6 mot s6 c6ng cl,! cho phep ket hop mot s6 phan hoach lien ke thanh mot phan hoach co cau tnic Ian han rna th6ng tin a cac phan hoach khac van duoc bao toano

H~ dieu hanh
150 Kb
Phan hoach 1 (250Kb)
Chuang trlnh I (200Kb)
___ - ~ ••••• _____ - •••• ~ _____ ~ ••••• ~ _____ w •• ••
Khong sil dung 50Kb
Phan hoach 2 (1 OOKb)
Kh6ng su dung
Phan hoach 3 (200Kb)
Chuong trlnh 2 (130Kb)
...... - - - .. - - - _. - - ~ .. - - - - - ~ - - - ~. - - - _ ... ~ - - --
Khong su dung 70Kb Hinh 4.5 - B9 nha phdn hoach etI dinh.

64

U u diem: sa do phan hoach co dinh dan gian, de t6 chirc, giam t hoi gian tim kiern, - Nhuoc diem:

+ Neu kfch thiroc chuang trinh nho han kich tluroc phan hoach chua n6 thi phan bo nho con thira se khong sir dung diroc. Hien nrong nay diroc goi lit phan doan noi vi (internal fragmentation), no dan toi tnrcng hop tong be nho tu do con Ian nhirng khong sir dung diroc, do d6 khong tan dung dtroc het kha nang bo nho, gay tang phf bo nho.

+ Chuang trlnh se khong thuc hien diroc neu kich thuoc cua n6 len han kfch thuoc cua phan hoach Jan nhat, Khi do, can phai phan hoach lai hoac ket hop cac phan hoach ke nhau thanh mot phan hoach c6 kich tlnroc Ian han.

Chu )': trong sa do phan hoach co dinh, chung ta can phai chon diroc phan hoach co kich thiroc phu hop voi kfch thuoc chuang trinh dt c6 th~ dar duoc hieu qua toi iru. Cac thuat toan thirong diroc ap dung la:

- First Fit: chon phan hoach hoach dau tien du Ian d~ cap phat.

- Best Fit: chon phan hoach c6 kich thiroc nho nhat nlurng du de cap phat.

- Worst Fit: chon phan hoach co kfch thuoc 100 nhat de cap phat.

2. Sd do phi" hoach d{mg

Trang sa do nay, bo nho c6 mot bang quan 19 khong gian nho tu do thong nhat. Khi thuc hien chuang trinh, he thong dua vao kich thircc chuang trlnh d~ phan b6 khong gian nho thfch hop. tao thanh mot vung nho doc l~p va tao bang quan 19 rieng. Khi cac chuang trinh ket thuc, bo nho danh cho n6 se bi thu hoi.

- Uu diem: tan dung duoc khong gian nho tu do (neu kich thiroc chuang trlnh nho thl he s6 song song cao, kich thuoc chuang trlnh 100, he s6 song song giam). Mat khac, cac modul dieu khien bo nho khong ph iii sao chep a nhieu noi gi6ng nhir sa do pharr hoach co dinh,

- Nhircc diem: khong gay hien nrong phan doan noi vi nhung lai xuat hien hien nrong pharr dean ngoai vi (external fragmentation) vi sau mot khoang thai gian heat dong, cac chuang trinh diroc b6 tri rai rae khap noi trong b¢ nho va be;, nho tv do c6 xu huang bi chia thanh nhieu phan, chuang trlnh co kich thircc nho lai diroc nap vao phan hoach co kich thuoc 100 han vira giai phong. Do d6, h¢ thong van quan 19 day du nlnrng khong si'r dung diroc. De khac phuc hien nrong nay can phai b6 tri lai bo nho,

+ Tim thai diem thich hop de dirng cac chuang trlnh dang heat dong,

+ Dira mot so hoac roan b¢ cac chuang trinh dang hoat dong cung trang thai ella no ra bo nho ngoai, tra lai khong gian nho cho he thong.

+ Tai dinh vi cac chuang trinh va kh6i phuc trang thai hoar dong,

5(i) - 184

65

H¢ dieu hanh
150 Kb
Chuang trinh 1
(40Kb)
Chuang trinh 2
(80Kb)
Chuang trinh 3
(70Kb)
Chuang trlnh 4
(40Kb) gdl

H~ dieu hanh 150 Kb

Chuang trlnh 3 (70Kb)

Chuang trinh 4 (40Kb)

66

H¢ dieu hanh 150 Kb

Chuang trlnh 5 (30Kb)

Chuang trinh 3 (70Kb)

B¢ nh6 tv do

gd3

Hinh 4.6 - B¢ nha phan hoach dong

5(1) - 184

H¢ dieu hanh
150 Kb
Chuang trinh 5
(30Kb)
T6 clnrc lai
(200Kb) H¢ dieu hanh

150 Kb

. Chuang trlnh 5

(30Kb)

Chuang trlnh 3

(70Kb)

Hinh 4.7 - rtf chuc lai b¢ nha

cia ;

Thai di€m thich hop d~ dung chuang trinh la thai di~m rna cac gia tri dli duoc tinh toan xong va luu vao b¢ nho hoac thanh ghi. Chi c6 thai diem nay, chung ta moi co th6 thirc hien cong viec hru va phuc hoi rrang thai chuang trlnh diroc.

Do viec dua chuang trlnh fa, dinh vi lai va phuc hOi trang thai phirc tap nen co th~ khong can dua het tat ca cac chuang trlnh ra bo nho ngoai, Khi mot chuang trlnh duoc dua ra, be nho cap phat cho n6 dtroc giai ph6ng va co kha nang rmrc dO phan doan bo nho giam. Qua trlnh nay se dung khi he so phan doan b¢ nhc dat mire an toano

Viec tai dinh vi chuang trlnh phirc tap han nhieu so voi dinh vi ban dau VI trong qua trlnh thuc hien, chuang trlnh co th~ tao ra cac cau lenh moi va dir lieu. H¢ thong can phai phan bier dau la dfr lieu tinh (khong phu thuoc V! trf bO nho),

67

dau In. dfr lieu dong (phu thuoc vi trl b¢ nhc), 3. Sd do hoan d6i (swapping)

So' do hoan d6i d ua tren nguyen tac !TI¢t chuang trlnh 6 trang thai cho doi trong !TI¢t khoang thai gian wang doi dai se diroc tarn thai chuyen fa bo nho ngoai (swap out) de giai ph6ng vung nho cap phat cho chuang trinh khac hoat dong. Khi chuang trinh ket tluic trang thai cho, n6 se diroc nap tra lai be) nho trong (swap in) d~ tiep Il.!C thirc hien.

He dieu hanh

Vung nho danh cho nguoi sir dung

B¢ nho ngoai

Chuang trlnh 1

Chuang trinh 1

Hinli 4.8 - Sa do swapping

CIUf S': khi chuang trinh diroc nap tfa lai bo nho trong c6 th~ xay fa hai twang hop: Neu qua trlnh anh xa dia chi logic thanh dia chi v~t ly duoc thirc hien vao thai dilim nap chuang trlnh thl chuang trinh can diroc cap phat lai dung vung nho !TIa n6 eta chiem giiI tnroc d6. Neu qua trlnh anh xa duoc thuc hien vao thai diem xu ly thi c6 the nap lai chuang trinh vao mot vung nho bat kyo

So' do swapping can sir dung ITI¢t b¢ nho ngoai (rhirong la rna rir), bo nho nay phai dli 1611 dli luu tru cac chuang trlnh hi hoan d6i va phai cho phep he thong truy nhap true tiep den cac chuang trinh nay.

Trang cac he swapping, can phai quan tarn roi thai gian chuyen d6i giua cac tac vu. M6i chuang trinh can diroc cap phat gia CPU du Ian d~ khong thay r6 su cham tre do cac thao tac swap gay ra. Neu khong, he thong se dung phan 160 thai gian d~ chuyen d6i cac chuang trlnh vaal ra bo nho trang, nhu vay gio CPU duoc sir dung kh6ng hieu qua.

68

Trong sa do t6 chirc nay ding gay hien nrong phan dean bO nho, do d6 phai Slr dung cac ky thuat don bo nho de loai bo hien tuong phan manh ngoai vi.

4.5(1 do phan doan

Cac sa d6 phan hoach co dinh va phan hoach dong khong ap dung diroc khi kich thtroc chuang trinh Ian han kich thuoc ~¢ nho vat IY. Ngoai fa, h¢ s6 tfch eire ella cac byte trong bo nho cilng khong diroc dong deu (cac byte diroc goi la rich cue neu noi dung ella n6 duoc sir dung de thuc hien cac cau lenh trong thai dit~m quan sat). Sa do quan Iy b¢ nho tot la sa do c6 s6 byte tich cue 16n.

Vi ngiroi sir dung kh6ng can quan tam toi chuang trlnh ella ho diroc b6 tri trong bo nho nhu the nao (lien tuc hay khong lien rue) nen trong sa do phan doan, cac modul chuang trlnh duoc bien dich mot each rieng bier. Thong tin ve cac modul chuang trlnh diroc chua lrong bang quan 1y dean - SCB (Segment Control Block), M6i phan tir trong SeB tuang irng voi mot modul cua chuang trinh va dtroc d~c tnrng boi 3 tnrong tin:

- Dau hieu 0: cho bier modul da diroc nap vao b¢ nho hay chua (D = 0 neu

modul chua diroc nap, D = I ngtroc lai).

- Dia chi A: dia chi cua vung nho se dinh vi modul.

- D¢ dai L: cho biet kich thuoc cua modul.

Ban dau, chi co truong L va D c6 gia trio SCB diroc xay dung ngay tic khi bien dich chuang trlnh.

Khi thirc hicn, SeB diroc nap VaG bo nho, dia chi dau duoc dua vao thanh ghi doan Rs.

Dia chi truy nhap dfr lieu diroc biCu dien boi cap (s,d) trong do s la so hieu modul can truy nhap, d lit dia chi wang dai tinh tir dau segment.

D~ truy nhap tai mot da lieu can phai qua hai biroc:

- Biroc I: he thong lay noi dung thanh ghi Rs cong v6i s d~ tim dtroc phan ttl thir s trong SCE. Neu tnrong dau hieu 0 = 0 (modul chua diroc nap VaG bo nhrr) thi he thong lam thu tuc nap modul V~lO bo nho, xin cap phat kh6ng gian nho theo kfeh thtroc L, tim modulo bo nho ngoai va dinh vi vao vung nho ducc cap phat, SUa lai noi dung tnrong dia chi A d6 no chi toi modul thtr s. Neu khong tim duoc modul, he thong se bao lbi va ngirng tlnrc hien, Neu tnrong dau hieu D = 1 (modul da nap vao bo nho), h¢ th6ng se tlurc hien bUC1c tiep theo.

- Biroc 2: h¢ thong Jay n¢i dung tnrong dia chi A cong voi d va truy nhap tai bo nho theo dia chi vira tinh diroc d~ doc/ ghi dfr lieu,

69

Vi du: Gia sir modul dau tien cua chuang trinh (s = 1) c6 dia chl wang doi d == 03026, do dai modul L:::: 5000, dia chi dau A = 400, modul da duoc nap VaG b¢ nho CD = 1), noi dung thanh ghi Rs Ia 3. De truy nhap tci modul, he thong cong 3 vai 1 de tim ra phan tir thtr 4 trong SCB; Lay 400 + 03026 de tim diroc dia chi 03426 truy nhap dli' lieu.

- V u diem: so' do nay khong doi hoi cong cu t6 chirc d~c biet, do d6 c6 the ap dung tren moi he thong.

- Nhucc diem: hieu qua sir dung bo nho phu thuoc VaG cau true chuang trlnh ella nguoi sir dung. Ngoai ra, sau mot thai gian hoat dong, bo nho bi phan doan, do d6 can phai t6 chirc lai bo nho bang each dira b6t mot s6 modul ra ngoai. Viec bo trf lai se dan giim han cac So' do tren vl c6 su h6 tro cua SCE. Phan ttr bi dua ra thl tnrong D se bi gan gia tri bang 0 va b¢ nho cap phat cho modul (xac dinh bang tnrong A va L) se duoc tra lai cho he thong.

Neu xuat hien nhu cau can phai t6 chirc lai b¢ nho thi van de dall tien can giai quye; la chon modul nao de dua ra ngoai. Thong thuong, 'he thong hay ap dung cac giai phap sau:

- Dua modul t6n tai lau nhat trong b¢ nho.

- Dtra modul c6 lffn Slr dung cuoi cung each thai diem hien tai lau nhat.

- Dua modul c6 tan suat sir dung thap nhat.

M6i giai phap deu c6 uu diem va nhiroc diem rieng, phu thuoc VaG tung tinh huang cu the. Vi vay, nguoi ta thucng dira ra diroi dang tuy chon.

So' d6 phan dean chi duoc ap dung dong bo voi chuang trinh c6 cau true phan dean.

M4' '1

Hinh 4.9 - Cdc modul (segment) chuang trinh

MO'.

H inh 4.10 - Anh xa chuang If/nil sang b(j nho vat 1)1

70

5. So do phan trang

Sa do phan trang HI. mot tnrong hop dac biet ella sa do phan dean. Trong sa do phan trang, bo nho chuang trinh va b¢ nho v?t ly diroc chia thanh cac phan bang nhau goi 1a trang. a bo nho vat ly, cac trang duoc danh s6 thir tJ! tir 0,1,2, ... goi la dia chi trang, nhu vay trang la dan vi dung d~ phan ph6i bo nho, S6 trang cua bo nho vat ly phu thuoc vao kfch t~u6c trang va kich thuoc bo nho (thuong HI. xac dinh) con s6 trang cua be nho chuang trinh phu thuoc vao kfch rhiroc chuang trinh (c6 the tuy y). Thong tlnrong, de tao dieu kien thuan loi trong xu 19, ngirci ta thuong dat klch thuoc trang IS. IGy thira cua 2.

Hinh 4.11 - Cdc trang chuang trinh

I Page 0 1

fpage1" !

Hinh 4.12 - B¢ nha vd; Iy va dnh xa cac trang chuang trinh

Moi trang diroc bieu dien boi mot cap (p,d) trong d6: p la s6 hieu trang va d Ia dia chi nrong doi tfnh tir dau trang.

Khi thuc hien chuang trinh, he thong xay dung mot bang quan ly trang (Page Control Block - PCB) de xac lap moi quan he giira trang vat ly va trang logic. Moi phan tir trong bang quan ly trang nrong ung vci mot trang logic va diroc dac tnrng b6'i hai twang tin:

- Dau hieu D: cho bier trang da duoc nap vao bo nho hay chua ( D = 1 dll nap; D = 0 chua nap).

- Dia chi Ap: Ia dia chi trang vat ly chua trang logic p dang xet. Neu D = ° thi Ap c6 the chua thong tin can thiet d~ tim trang 6' bo nho ngoai.

Dia chi cua bang quan Iy trang duoc chua trong thanh ghi qU~1I11y trang Rp.

De truy nhap t6i dfr lieu dn qua hai biroc:

- Buoc 1: H~ thong lay noi dung Rp cong voi p de truy nhap toi phan tu thii p trong bang quan ly trang (nrong irng voi trang p ). Neu D = ° (trang chua duoc nap vao bo nho) thl he thong se nap trang vao b¢ nho, Khi d6 D = 1 va tnrong

71

dia chi Ap se chua dia chi trang trong b¢ nho vat 1)'.

- Buoc 2: H~ thong lay dia chi trang Ap ghep voi d tao ra dia chi vat 1)' cua dfr lieu dii dua van do va truy nhap toi dia chi vira tinh diroc de dQC/ ghi dir lieu,

Uu diem: sa do phan trang lam tang toe do truy nhap btl nho (so voi sa do phan doan thi a biroc 2, phep cong diroc thay the boi phep ghep ). Mat khac, sa do khong bi hien nrong phan doan btl nho (v) kich thtroc trang logic va v~t ly bang nhau). Neu con bo nho tu do th) kfch thuoc phai chan trang, do d6 bao gia ciing du cho de dua cac trang moi vao. Tinh trang thieu b¢ nho chi rlurc su xay fa khi tat ca cac trang vat 19 da dtrcc Slr dung het.

Nhtroc diem: sa d6 phan trang can co thiet bj vat 1y h0 trrr cong viec dinh vi rrang VI rnoi trang chuang trinh khong phai 13. mot modul hoan chinh nen khong the bien d6i dia chi va nr dinh vi thea dia chi d[iu. Do do, vice dinh vi trang phai dU~1C SI! ho iro cua cac cong cu ngoai.

Cliff }':

SCi d6 phan trang dam baa he s6 song song cao cho h~ thong, kfch tluroc chuang trlnh va dfr lieu n6i chung khong han che nhtrng khi bo nho logic qua Ian thi kfch rhircc bang quan 1y trang cung tang thea va h~ th6ng sc phai t6n nhieu khong gian nho vat 19 de Iuu trii no. Tren tlnrc te, cling nhu chuang trinh, chi mot phan bang quan 19 trang lit c6 tac dung rfch C\!C trong qua trlnh thuc hien, do d6 de nang cao hieu qua cua sa do phan trang, can phai cai tien bang quan 1y trang.

Mot van de khac cling can hru y liI phai chon kfch thtroc trang sao eho phu hop VI hieu qua c!ua sa do phu thuoc nhieu van kich thiroc trang. Neu kfch thuoc trang qua nho thi kich thiroc bang quan ly trang se Ian va kha nang phai thuong xuyen nap lai trang cao. Nguoc lai, neu kich thtroc trang Ian thi s6 trang duoc nap de xu 19 se giarn, gay rae dong dang k~ den hieu qua Slr dung bo nho. Vi vay, kfch thiroc trang thirong dtroc chon giao dong tu 28 den 210. Trong cac he th6ng may tinh cua IBM, kfch thiroc cac trang thea truyen thong la 5 I 2 bytes nhtrng trong cac he thong hien nay. dung hrong b¢ nho trong tirong d6i 160 thi kich thucc trang c6 the tang nen den 4Kb.

Qua each t6 chirc va thuc hien tren, ngoai bang quan 19 trang th! h¢ thong con can b¢ nho d~ chua cac trang du lieu va chuang trlnh. S6 trang danh cho chuang trinh cang nhieu thl h¢ so song song cua he thong cang giarn, ngiroc Iai s6 trang danh cho chuang trlnh it thl he 56 song song tang nhung toe d¢ thirc

72

hien chuang trinh giam VI chuang trinh luon roi vao tlnh trang thieu trang vat ly de thuc hien. Tir do, hieu qua chung cua phirong phap nay phu thuoc vao each nap trang va thay the trang tich eire,

* Cdc giJi phdp I1C!P trang:

- Bien phap dan gian nhat la nap tat ca. cac trang cua chuang trlnh vao bo nho ngay tir dau, nhtr vay kh6ng the xay ra tinh trang thieu trang tich eve khi dang thirc hien. Trang giai phap nay, bo nho ngoai kh6ng diroc su dung de mo rong bo nho trong. Uu diem cua giai phap la dan gian nhung khong phat huy diroc hieu qua diem d~e thu cua so d6 phan trang.

- Mot giai phap khac cling eho phep giam kha nang thieu trang tfch eire rna khong can dung toi khong gian b¢ nho v~t ly qua Ian la giai phap nap tnroc (nap tnroc cac trang sap Slr dung). Giai phap eho phep ngurri Slr dung tao chuang trlnh 0 bO nho logic voi kfeh thuoc ruy y, dong thai he th6ng e6 the duy tri he s6 song song can thiet eho hoat dong co hieu qua cua roan he thong. Diem mau chot ella gi:li phap n<).p trang tnroc la phai dir bao diroc cac trang rich eire chuan bi Slr dung trong qua trinh thirc hien, Neu xac dinh ducc, ta e6 the nap tnroc cac trang nay vao bo nho nlurng viec dl! bao trang n~1O sap sir dung la eire ky kh6 khan. Do d6, chi phi nap tnroc cac trang khong dung den c6 the se IOn han rat nhieu chi phi nap cac trang thirc slf diroc sit dung,

- Thong thuong, cac he th6ng thuong ap dung giai phap nap trang theo yeu cau. Theo giili phap nay thi trang chi diroc nap khi xuat hien yeu cau truy nhap dit lieu ella trang, nhir v(IY moi lan nap trang deu thuc su la can thiet. Giai phap nay dam bao hieu qua cao khi chung ta e6 each phan b6 cac trang a bo nho ngoai hop Iy va e6 co che tim kiem t6t.

* Cdc gidi pliap tlury tlur trang:

- Neu con nhieu kh6ng gian nho nr do thi kh6ng can thiet phai thay the trang nhung khi thieu khong gian nho thl can dira mot 56 trang ra ngoai va n~p vao cac trang khac can thiet cho viec thirc hien chuang trlnh, Nguyen tac chung 1a phai thay the cac trang e6 Ian sir dung k€ tiep, each thai diem d6i trang cang xa cang t6t. Trong tnrong hop ly wang la cac trang do kh6ng con can sir dung nira nhung tren tlnrc te, kh6ng the du doan tnroc diroc cac dien bien cua chuong trtnh, Do d6, t6n tai mot s6 giai phap d6i trang cu th~ nhir sau:

- GiM phap d6i vong tron hoac d6i ngau nhien, t6 chirc dan gian nhung c6 th~ dan den kha nang d6i cac trang van con dang sit dung,

73

- Giai phap FIFO (First In First Out) - trang nao nap tnroc se bi thay the rnroc, nhu vay trang co thai gian t6n tai trong h¢ nho tau nhat se bi thay the. Neu chuang rrlnh diroc xay dung theo cau tnic tuyen tfnh thi giili phap nay rat tot con voi cac chuang trinh xay dung thea nguyen tac cau true thl co tht xay ra tnrong hop dua mot trang quan trong, dang sir dung ra ngoai, Tuy vay, giai phap nay cilng wang d6i dan gian vi chi can thea doi qua trlnh nap trang de xac dinh thtl' tv uu tien ella cac trang d.n thay the.

- Giai phap LRU (Last Recently Used) - thay the trang co Ian sir dung cu6i, each thai diem doi trang lau nhat. Giai phap nay dua tren gia thiet chuang trinh co tfnh cue be) hoa trang Slt dung, kh6ng co cac lenh chuyen dieu khien di xa cau lenh dang tlurc hien, d<1n den giai phap kh6ng dam baa toi tru trong moi tnrong hop, dong thai chi phi thuc hien cao, vi de xac dinh diroc can thay the trang nolo, he thong can phai dinh ky kiern tra, th6ng ke cac trang vao di} duoc sir dung de tim ra trang can thay the.

- Giai phap LFU (Last Frequently Used) - thay the trang co Hin sua'! Slr dung thap nhat. Doi voi giai phap nay can phai thong ke s6 Ian truy nhap trang de tinh diroc tan sua'! truy nhap.

Cac giai phap thay the rrang noi tren co the ap dung chung cho toan bo h¢ thong hoac ap dung cue h¢ cho tung chuang trinh. Trang tnrong hop ap dung cue bo cho mot chuang trinh dang thirc hien, he th6ng can phai hru trll kich thuoc bo nho da cap phat cho chuang trinh va tranh twang hop cap phat bo nho khong deu giiia cac chuang trinh.

6. Scs do ket hop phan trang va phan dean

Sa do phan trang dam bao hieu qua Slr dung h¢ nho khong phu thuoc vao cau true chuang trlnh ella ngiroi Slr dung, dieu khien trang thuan tien, dan gian. Tuy nhien, khi chuang trlnh co kieh thiroc Ian thi kfch thiroc bang quan 19 trang ciing Ian theo, dan den lang phi h¢ nho. Mat khac, neu kich thuoc trang qua nho thi kich tluroc bang quan 19 trang se 16'n va kha nang pha: tlnrong xuyen nap Iai trang eao. Nguoc lai, neu kich thuoc trang Ian thl s6 trang diroc nap de xir 19 se giam gay tac dong dang ke den hieu qua Slr dung bo nho,

So do phan doan linh hoat hon ve d(> dai cua cac dean nhirng cling chinh VI d¢ dai cua cac doan khac nhau nen phirc tap trong thirc hien va cap phar h(> nho, D~ phat huy diroc cac Uti diem va han che nhiroc .dit~m cua cac sa do tren, ngiroi ta thuong su dung so do ket hop phan trang va phan doan,

74

Trong sa do nay, chuang trlnh diroc bien dich thee so do phan doan va c6 mot bang quan ly dean chung (SCB). M6i doan trong chuang trinh lai diroc bien tap theo sa do phan trang va t<;1O ra tirng bang quan 1y trang (PCB) rieng cho rnoi doan. Khi chuang trlnh duoc n<.J.p VaG h¢ thong, he dieu hanh Sf' cap phat cho chuang rrtnh cac trang can thiet d~ chua du cac doan cua chuang trlnh.

segment I

segment 2

segment 3

Hinh 4.13 - Sa d() kef hop phon [rang - phon doan

D~ h6 tro ky thuat phan doan can c6 mot bang quan ly doan chung cho roan bo chuang trlnh nhung trong so do ket hop nay, moi doan can c6 mot bang phan trang rieng biet. Nhu vay, twang dia chi A cua phan tv thir i trong bang quan 1y doan - SCB se Iii noi chua bang quan ly trang thu i - PCBi' twang d¢ dai L chua d¢ dai cua peBi.

Khi thirc hien, bang quan ly trang sc duoc n<:tp vao bo nho va dia chi dau cua n6 diroc dua VaG thanh ghi quan 1y doan Rs. Dia chi truy nhap dfr lieu diroc bi~u dien bOi mot b¢ ba phan tv (s,p,d) trong do:

s - so hieu doan can truy nhap trong bang quan ly doan, p - so hieu trang don truy nhap trong bang quan ly trang. d - dia chi tuong doi tinh tit dau trang.

D~ truy nhap toi dfr lieu, he thong can thirc hien ba btroc:

- Biroc I: Lay noi dung thanh ghi Rs cong voi s va truy nhap tci phan tir thu strong bang quan ly doan.

- Biroc 2: Neu D = 0 thi thuc hien thu tuc n'.lp PCB nrong trng vao bo nho va cap nhat noi dung tnrong A. Khi nap xong PCB, he thong cong noi dung twang A voi p d~ truy nhap tm phan tir thu p trong PCB.

- Biroc 3: Khi tim duoc phan tir thu p trong PCB, h¢ thong se ghep noi dung cua Ap (nrong irng phan lU thu p) voi d d~ tim fa dia chi doc/ghi dfr lieu,

CI1lJ y: a so do nay, bo nho thircng diroc chia thanh ba phan chua SCB, PCB va cac trang. Ban than b¢ nho danh cho SCB va PCB cling duoc quan ly theo che d¢ phan trang.

75

IV. BO NHO An

1. Khai ni~m be;, nhd 30 (Virtual Memory)

Neu d~t toan b¢ chuang trinh vao bo nho v~lly thi kfch thuoc chuang trlnh se bi han che boi kfch thiroc bq nho vat lY.

Tren thuc te, trong nhieu tnrong hop chting ta khong can phai n~p toan b¢ chuang trinh vao bo nho vat Iy cung mot 'lUc vi tai moi thai diem, chi co mot lenh cua chuang trinh duoc thuc hien. Vi du cac chuang trinh deu co mot dean rna Xlr ly loi nhung doan rna nay rat it khi diroc SLr dung vi hiern khi loi xay ra, trong rnrcng hop nay khong can thiet phai nap doan rna xu 1y loi ngay tir dau.

Tir nhan xct tren, mot giai phap duoc de xuat Ii cho phep chuang trlnh thuc hien duoc nap tung phan vao bo nho vat IY. Nguyen l<ic cua giai phap nay la tai moi thai diem, trong bo nho vat 11' chi hru trfr cac lenh va du lieu phuc vu eho hoat dong cua chuang trinh tai thai diem do. Khi can toi cac lenh hoac dtT lieu moi, he thong sc nap chting vao bo nho tai vi tri truce do bi chiern gii1 boi cac lcnh khong con can toi nira. Voi giai phap nay, mot chuang rrrnh co the co kfch thuoc Ian han kfch thuoc vung nho cap phat eho no,

Mot each d~ thirc hien y Wong ella gi<li phap tren 13 str dung ky thuat overlay. Ky thuat overlav khong doi hoi bat ky su tro giup d~c bier nao cua he dieu hanh nhimg trai lai lap trinh vien phai biet each lap trinh theo cau true overlay va dieu nay doi hoi kha nhieu cong sire,

Dc gi<ii phong lap trlnh vien khoi cac ur duy gioi han ve bo nho, dong thai khong lam tang them mire do kho khan trong cong viec lap trinh, ngiroi ta nghi tci huang phat trien cac ky thuat nr dong, cho phep xu 11' mot chuang trinh co kich thuoc 16n trong mot vung nho nho. Mot ky thuat duoc ap dung kha phD bien do Hi ky thuat bo nho ao.

B¢ nho ao (virtual memory) la mot ky thuat cho phep xu Iy mot chuang trlnh kh6ng diroc nap toan bo vao bo nho vat 1Y. B¢ nho ao mo hlnh hoa bo nho nhu mot bang hru tru rat Ian va dong nhat, tach biet han khai niern bo nho logic va bo nho vat 1Y. Ngiroi sir dung chi nhtn thay va lam viec trong khong gian dia chi ao, viec chuyen doi sang b¢ nho vat 1y do he dicu hanh thuc hien voi su tro giiip cua cac co che phan cirng cu th~.

76

Chu }': can ket hop ky thuat swapping d~ chuyen cac phan ella chuang trinh vao/ra giira bo nho ehfnh va bo nho phu khi ctin thiet.

Nho e6 su tach bier gitra bo nho ao va bo nho vat 19 nen co th~ t6 chtrc mot bo nho ao co kich thiroc IOn han rit nhieu Ian bo nho vat 19.

B¢ nho ao cho phep giam nhe cong viec ella lap trinh vien vi ho khong can quan tam den gioi han ella h(:l nho v~t 19 cung nhu khong can t6 chirc chuang trinh thea cau true Overlay.

2. Cai d~t be? nhd ao

Bo nho ao co the duoc cai dat dua vao hai ky thuat: phan trang theo yell cau (demand paging) hoac phan dean theo yeu cau (demand segmentation). Tuy nhien, viec cap phat va thay the cac doan phirc tap hem cac trang VI cac doan co kfch thuoc khong hang nhau, do do ky thuat phan trang thea yell cau diroc ap dung phd bien han.

Mot he thong phan trang thea yeu cau Hi he thong su dung ky thuat phan trang ket hop voi ky thuat swapping. Mot chuang trlnh duoc xern nhu mot t*p hop cac trang thirong tni tren h(:l nho ngoai (thuong la rna tir). Khi din xu ly, chuang trlnh se duoc nap vao bo nho trong nhung thay VI nap toan bo chuang trinh, he thong chi nap cac trang can thiet trang thai diem hien tai, Nhu vay, mot trang chi duoc nap vao bo nho trong khi co yell cau. Voi rna hlnh nay, can phai co mot co che phan cirng phan biet cac trang dang b bo nho trang va cac trang b h(:l nho ngoai.

Co che phan cirng h6 tro ky that phan trang thea yell cau la su ket h9P gifra co che ho tro phan trang va ky thuat swapping. Co che baa gam:

- Bang trang: cau true bang trang phai phan anh diroc tlnh trang ella mot trang dans; b bo nho trang hay bo nho ngoai,

- B¢ nho ngoai: bo nho hru trii cac trang khong duqc nJ;lp vao b¢ nhc trong.

B¢ nho ngoai thirong la rna tir va phan khong gian dung dt hru tru tarn cac trang, trong ky thuat swapping diroc goi la khong gian swapping.

3. Hi~n tU'qng 16i trang

Khi he thong truy xuar tm mot trang nhung trang nay chira duoc nap vao bo

77

nho rrong se lam phat sinh mot 16i trang (page fault). H~ dieu hanh se xu Iy 16i trang theo cac biroc sau:

Step 1: Kiem tra viec truy xuat roi bo nho c6 hrrp I~ hay kh6ng.

Neu c6, goto Step 2

Nguoc lai, ket thiic chuang trinh.

Step 2: Tim vi trf chua trang can truy xuat tren dia tir

Step 3: Tim mot trang vat ly trong trong bo nho chinh Neu tun thay, goto Step 4

Neu khong, chon mot trang dang sir dung va chuyen noi dung trang nay ra bo nho ngoai (hru noi dung trang nay vao dia tu), C~P nhat bang quan Iy trang nrcng ling.

Step 4: Chuyen trang muon truy xuat tu bo nho ngoai vao bo nho trong: nap trang can truy xuat vao trang vat ly tr6ng, cap nhat noi dung bang quan ly trang.

Step 5: Tai kich heat chuang trinh.

4. Thay the trang

Khi xay fa 16i trang, he thong can phai n<;lp trang thieu vao bo nho. Neu khong con trang trong trong bo nho trong, he thong can thuc hien vice thay the lrang nrc la chon mot trang dang ton tai a bo nho trong (kh6ng duoc str dung tai thai diem hien tai) va dua no ra kh6ng gian swapping tren rna tir d~ giai phong mot trang vat Iy, danh chtl nap trang can truy xuat vao b¢ nho,

Cac thuat roan thay the trang duoc ap dung nhu trong so do quan ly bo nho theo kieu phan trang, bao gorn:

- Thay the trang co thai gian ton tai trong b¢ nho lau nhar (FIFO).

- Thay the trang co Hin Slr dung cuoi cung, each thai diem hien tai lau nhat

(LRU).

- Thay the trang c6 tan suar su dung thap nhat (LFU).

- Thay the trang c6 tan suat Slr dung nhieu nhat (MFU - Most Frequently

Used).

78

1. Giai thlch su khac biet giCi'a dla chi v~t Iy va dia chi logic.

2. Trinh bay cac diu true co ban cua chuang trinh,

3. Neu muc dlch cua quan Iy bq nhd va trinh bay nguyen t~c heat dqng cua cac so do quim Iy b9 nho.

4. Phan bi~t giCi'a phan rnanh n9i vi va phan rnanh ngo~i vi.

5. Gia sil b9 nho chinh diroc ehia thanh cac phan hoach e6 kich thiroc 600Kb, 500Kb. 200Kb, 300Kb (thea th(f tV), eho biet cac tien trinh e6 kich thuoe 212Kb. 417Kb, 112Kb va 426Kb (thea th(f tV) se du~e cap phat b¢ nho nhu the nao neu sa dunq cac thuat toan:

First - Fit, Best - Fit, Worst Fit. Thuat toan nao cho phep sa dunq b¢ nho hieu qua nhat trong trudng hop tren.

6. Trinh bay khai ni$m va muc dfch cua b¢ nho ao.

7. The nao la hi$n tu<;lng loi trang? Trinh bay phuonq phap gi8i quyet cua h$ dieu hanh khi g~p hi~n tu~ng loi trang.

79

Chtrong 5

QUAN LY BO NHeJ'NGOAI

MlJc tieu

Sau chudng nay, ngUdi hoc c6 the hieu r6 cac bien phap quan Iy va cap phat khong gian nho It! do tri!n dia nr, cac thu$t toan lap lich cho dia W va nguyen uk quan Iy thong tin tren bi? nho nqcai - He File.

NQidung

Trinh bay cac yeu cau cua quan Iy b¢l nho nqoai, cau true vat Iy cua rna W, cac phudng phap quan 11 va cap phat khong gian nho tt! do, cac thuat toan I~p lich cho rna W va mot s6 van de ve h~ file.

I. cA.e KHA.I NIEM co BAN

1. Yeu cau cua quan 19 bQ nhd nqoai

Khi can hru trir cac chuang trlnh hoac dfr lieu, cac he thong may tinh bat buoc phai sir dung bo nho ngoai (ilia tir, bang til, compaq ... ). Nhiern vu chinh cua h~ dieu hanh phai dam bao drroc cac chirc nang sau:

- Quan Iy khong gian nho nr do tren bo nho ngoai (Free Space Manage).

- Cap phat khong gian nhc tu do (Allocation Methods).

- Cung cap cac kha nang djnh vi bo nho ngoai.

- Lap lich cho bo nho ngoai (Disk Scheduling).

2. Cau true v~t 19

Xet cau true vat ly cua rna tit: rna til bao g6m mot hoac nhieu la rna d~t dong true, Moi mat ilia chia thanh cac ranh tron d6ng tam goi HI. track, moi track duoc chia thanh cac cung goi la sector, tap hop cac track cung thu tu tren cac mat ilia goi HI. cylinder (ttr tru),

Tren moi mat ilia co mot dau tir doc/ghi dfr lieu (Read/Write Heads), d~ dieu khien diiu tir doc/ghi dir lieu can co mot trinh dit~u khien dia (Disk Controler).

Thong tin tren rna duoc tham chien bOi cac thanh pharr: 6 dia, mat dia, track, sector.

80

H¢ dieu hanh xem rna nhir mang mot chien rna thanh phan la cac kh6i rna (Disk Block). M6i kh6i rna ghi cac thong tin ve mat rna, track, sector rna h¢ dieu hanh co th~ dinh V! tren do.

3. ThU' muc thiet bj

Tren moi rna thong thuong co mot thu muc thiet bi (Device Directory) cho biet rna g6m nhtrng thong tin gi, d¢ dai, kieu, nguoi so httu, thai dh~m khOi tao, vi tri, diroc phan b6 khong gian nhu the nao? .. Thir muc thiet bi dircc tao ngay a tren dia tai mot vung nho dac biet,

II. cAc PHUONG PHAp QUAN LY KHONG GIAN NHO TlJDO 1. PhU'dng phap dung bit vector (bitmap)

Khong gian rna diroc chia thanh cac kh6i (block) va diroc danh s6 tir 0 ... max. Vi du: rna mem 1.44Mb, 2 mat, 80 track/l mat, 18 sector/l track duoc danh

s6 nhu sau:

Head 0, track 0, sector 1

Block 0

Head 0, track 0, sector 18 Block 18

Head I, track 0, sector 1 Block 19

Head 1, track 0, sector 18 Block 36

Head 0, track I, sector 1

Block 37

Head 1, track 79, sector 18 Block 2879

M6i kh6i rna Slr dung mot bit d~ danh dau trang thai. Khoi rna nao d5 Slr dung thi bit trang thai co gia tri bang 1, chua Slr dung thl co gia tri bang O. Tap hop cac ky hieu 0,1 tao thanh mot bitvector (bitmap). DQc thong tin trong bitmap h¢ dieu hanh co the xac dinh diroc khong gian tu do tren rna.

Vi du: cho kh6ng gian dia til nhu hlnh 5.1, cac kh6i 2, 3,4,5, 8, 9, 10, 11,

6(j) - 184

81

12, 13, 17, 18, 25. 26. 27 la cac khoi dia tv do. Khi do bitmap quan I y khong gian nho nr do nhu sau:

11000011000000111001111110001111 ...

Phuong phap bitmap c6 uu diem la cai d~t don gian, de quan ly, de tim kiem nhfrng khoi dia nr do lien tuc rren dia nhung ton kh6ng gian hru lru danh cho bitmap (moi kh6i rna se t6n mot bit).

2. PhLtdng phap li~t ke (Free List)

Trang phirong phap nay, he th6ng S11 dung mot danh sach m6c n6i d~ liet ke cac khoi dia tu do. Can tro dau trang danh sach chi l6'i khoi rna nr do dau tien, moi kh6i c6 mot can tro d~ tro toi kh6i ke tiep (hinh 5.1). V u diem cua phirong phap la tiet kiem kh6ng gian nho nhirng lam tang thai gian truy nhap da- lieu,

3;'PhLtdng phap I~p nhem (Grouping)

Trang phuong phap nay, he thong cho phep nh6m cac khoi rna tt! do lien tiep thanh mot nh6rn. Khoi rna tv do dau nen trang nh6rn hru trir dia chi ella cac kh6i rna h! do trong nh6m. Khoi dia nr do eu6i cung trang nh6m hru tru dia chi cua kh6i dia tu do dau tien cua nhom tiep thea.

Con Ir6 (ifill daub skb

Hinh 5.1 - Mo td khong gian dia til

82

6(t) - 184

V i du: Thea hinh 5. I, ta co bang q uan 1 y khong gian nho tv do nh u sau:

Nh6m Khoi dilu Khoi cuoi
I 2 (2,3,4,5) 5 (8)
II 8 (8,9,1'0,11,12,13) 13 (17)
III 1707,18) 18 (25)
IV 25 (25,26,27) 27 ( ... ) 4. PhU'dng phap dam (Counting)

Phuong phap dem Ia su bien deli cua phircng phap lap nhom, Trang phuong phap nay, he thong lap danh sach quan ly dia chi cua cac khai dia nr do dau tien va s6 hrong cac khoi ilia tv do lien tuc ke tiep cac khoi dia do.

Vi du: Thea hlnh 5.1, ta co danh sach quan Iy khong gian nho tu do nhu sau:

Danh sach SOIUQllg
2 4
8 6
17 2
25 3 III. cAc PHUONG PHAp CAP PHAT KHONG GIAN NHO TV DO 1. Cap phat lien tue (Contiguous)

De phan bO khong gian nho cho mot file, h¢ thong chon mot doan lien tuc cac kh6i ilia tl,l do d~ cap phat cho file do. Vci phirong phap nay, d~ dinh vi file h¢ thong chi canbiet dia chi cua khoi dia tl! do dau tien va s6 hrong block da dung.

83

0.1.2030 40506•7• 80 9010 D 11 0

12 0 13 D 14 • 15 •• 16 • 17 0 18 0 19 • 20 • 21 • 22 • 23 • 24.250260270 28 • 29 • 30 • 31 •

Directory

File Start Length
fl 0 2
f2 14 3
f3 19 6
f4 28 4
f5 6 2 Hinh 5.2 - So do cap phd! lien tuc

V u diem cua cap phat lien tuc la he; tro cho phuong phap truy nhap tuan W va truy nhap tnrc tiep nhung t6n tai ba nhuoc diem chinh:

- Phai chon diroc thuat toan t6i iru de tim cac vung kh6ng gian tu do cap phat cho file (First Fit, Best Fit noac Worst Fit).

- Co the xay ra tnrong hop kh6ng du s6 khoi rna tu do lien tiep can thiet de cap phat cho file (kich thiroc file 16'0 hen vung cac khoi rna lien tuc Ian nhat). - Trong tnrong hop cac khoi rna t1! do nam tan man se kh6ng sir dung dircc, gay lang phi kh6ng gian nho,

2. Cap phat lien ket (linked)

Trong phuong phap nay, me;i file dtroc dinh vi trong thu muc thiet bi bang hai con tro, mot cai tro toi kh6i rna da:u tien, mot cai tro tm khoi rna cu6i cling da cap pnat cho file. Trong moi khoi <ITa da cap phat cling co mot con tro de tro tm kh6i rna k€ tiep,

84

Vi du: file f1 dtroc cap phat 5 khoi dia co s6 nieu 9, 16, 1, 11,25; kh6i dau lii. 9, khoi cu6i 13. 25.·

Directory

File

Start

End

24 ~ 2S l1li 26 ~ 21 ~ 28 ~ 29 ~ 30 ~ 31 ~

Hinh 5.3 . Sa d6 cap plui: lien kef

Cap phat lien ket co iru di~m Iii. sir dung diroc cac kh6i dia tu do nam tan man nhung chi hO tro truy nhap tuan tv, khong hi) tro truy nhap tnrc tiep; dq tin cay khong dam baa neu bi m1t cac can tro lien ket. M~t khac, phirong phap nay t6n kh6ng gian nho d~ hru tru cac can tro (khoang 0,38%).

3. Cap phat theo chi so (Index)

Trong phirong phap nay, d~ cf(p phat kh6ng gian nha cho mot file, he th6ng sir dung mot kh6i ilia d~c biet goi la kh6i dia chi s6 (index block) cho m6i file. Trang kh6i dia chi so chua dia chi cua cac kh6i dia da cKp phat cho file, trong thu muc thiet bi dia chi cua cac kh6i dia chi s6. Khi ffiqt kh6i dia duqc cap phat cho file thi he thong loai be dia chi cua kh6i dla nay khai danh sach cac kh6i

85

rna nr do va cap nhat vao kh6i chi s6 cua file.

Phuong phap cap phat thee chi s6 h6 tro truy nhap true tiep nhung lang phi. khong gian nho danh cho kh6i rna chi so.

Directory

n 19

Fik Index Block

16

20 D 21 D 22

28 D 29 D 30 D 31 D

24025

Hinh 5.4 - S(1 do cap phat theo chi sd

IV. L~P LlCH CHO ilIA

1. Khai ni~m vii I~p llch cho dia (Disk Scheduling)

Thci gian troy nhap dia phu thuoc ba yeu t6: thoi gian di chuyen dau tir doc/ghi den track hoac cylinder can thiet (seek-time), thoi gian dinh V! dau tir doc/ghi tai kh6i rna can truy nhap (latency-time) va thai gian truy nhap dlJli¢u (transfer-time). Thai gian dinh vi d:iu tir doc/ghi va thoi gian truy nhap dfr lieu thong thirong co dinh va phu thuoc cau tnic ky thuat cua 6 dia, Do do, dt tang t6c d¢ truy nhap rna, cac h¢ dieu hanh thirong quan tarn (ai thai gian di chuyen dau ttr doc/ghi.

86

Nhu vay, lap lich cho dia Ht xay dung cac thuat toan dich chuyen dau til doc

ghi sao cho thai gian truy nhap dia la tai lID nhat.

2. Mqt so phU'dng phap I~p lich

2.1. First Come First Served (FCFS)

De truy nhap toi mot file, h¢ thong se t6 chirc mot hang doi cac yeu cau phuc V\,I cua cac track (h.ru trfr du lieu cua file can truy nhap). Track nao co yell cau phuc vu tnroc thi dau til doc/ghi se dich chuyen toi do tnroc.

Vi du: File FI diroc phan b6 h1n hrot tai cac track co so thir W sau day: 98, 183, 37, 122, 14, 124,65,67. Dau tir doc/ghi dang dinh vi tai track co s6 thii tt.! 53 Sa do dich chuyen dau tit doc/ghi thee thuat toan FCPS diroc the hien nhu

sau:

14

37 53 6567

98

122 124

183

Hinh 5.5 • Thuat toan igp lich FCFS 2.2. Shortest Seek Time First (SSTF)

SSTF chen track nao co thai gian di chuyen dan tir doc/ghi ngan nhat thi phuc V1,l tnroc,

Theo vi du tren, sa do dich chuyen dau til doc/ghi theo thuat toan SSTP diroc the hien nhu sau:

87

14

37 53 6567

98

122 124

183

Hinh 5.6 - Thuat (aim lap lich SSTF

2.3. Scan

Trong thuat toan nay, dau ttr doc/ghi quet tir track nho nhat den track Ian nhat, sau do quet nguoc lai, track nao co nhu cau thi se phuc VI,I.

Theo VI du tren, sa do dich chuyen dAu tir doc/ghi theo thuat toan SSTF diroc the hien nhu sau:

14

37 53 6567

98

122 124

183

Hinh 5.7 - Thuat todn lijp lich Scan

2.4. C • Scan

Thuat toan nay tuong tl! nhu Scan nhirng dau tir doc/ghi kh6ng phuc vu dirong ve (khong quet ngiroc lai),

88

Thea VI du tren, sa do dich chuyen dau tir doc/ghi thea thuat toan SSTF duoc the hien nhir sau:

14

37 53 65 67

98

122 124

183

Hinh 5.8 - T hllg( todn /tJp lich C -Scan

2.5. Look

Tuang nr nhu Scan nhung trong thuat toan nay, dau tir doc/ghi chi quet trang pham vi cac track co nhu cau phuc vu, khong quet tci track dau tien hoac cu6i cung (neu cac track nay kh6ng c6 yeu Call ph1JC vu),

Thea VI du tren, sa do dich chuyen dau tir doc/ghi thea thuat toan SSfF duoc th6 hien nhir sau:

14

37 53 6567

98

122 124

183

Hinh 5.9 - Thudt loan /cJp lich Look

89

2.6. C· Look

Tucng IlJ nhu Look nhirng dau tir doc/ghi khong phuc vu duong ve. Theo vi du tren, so do dich chuyen dau tir doc/ghi theo thuat roan SSTF diroc th~ hien nhu sau:

14

37

53 6S 67

98

122 124

183

~-------

------

-----------

-------

------------

Hinh 5.10 - Thudt todn lop lich C - Look

CJUI )': Thuat toan FCFS. SSTF duoc ap dung ph6 bien, cac thuat toan kieu Scan, Look chi duoc lip dung cho nhtrng dia chiu tai Ian.

V. H~ FILE

1. Khili ni~m h~ file (File System)

Dtr lieu may tinh duoc hru tnl tren cac thiet bi nho ngoai nhir: bang ttr, dia nr, rna quang ... va dUQC tap hop mot each c6 t6 chirc theo dan vi hru trir goi la file. Nhu vay, file Iii don vi logic de h¢ dieu hanh quan 19 thong tin tren dia. File c6 th€ la mot chuang trlnh cua nguoi sir dung, mot chuang trmh cua he thong hoac mot tap hop du lieu cua ngtroi sir dung,

Tren phirong dien ngiroi Slr dung, du lieu trong file diroc t6 chirc thanh cac banghi logic rna moi ban ghi logic c6 th~ Iii mot byte hoac mot cau true du lieu nao do. San ghi logic chinh la dan vi du lieu rna cac chuang trlnh can xu 19 trong qua trinh hoat dong cua minh,

De quan 19 du lieu tren cac phuang tien hru tru ngoai mot each c6 hieu qua.

90

hedieu hanh can phai tochrrc cac file thea mot nguyen tac nhat dinh, Nhir vay, he file Ia nguyen uie rna he dieu hanh t6 chirc va quan ly cac file tren cac phuong tien hru tru.

2. Cae yeu eau ella h~ file

Mac du cac he file c6 th6 dtroc t6 chirc !heo cac nguyen. tac khac nhau nhirng can phai dam bao cac yeu call chung nhir sau:

- H¢ file phai duoc t6 chirc sao cho d~ tim kiern, de hru tru,.c~p nhat, tier kiem khong gian nho.

- Phai dim bao tfnh d¢e lap cua h¢ file voi he thong va cac thiet bi ngoai vi.

- H¢ file phai dam baa tinh an toan dir lieu khi e6 su eo chuong trmh hoac

kythu~t.

- H¢ file phai dam baa tfnh an toan trong van de truy nhap thong tin cua ngiroi sir dung.

3. Cac thao tac ella h~ file

Mot he file du phirc tap hay don gian cling dell phai cung cap cho ngiroi str dung nhirng cong cu don gian d~ e6 the thao tac voi file. Trang cac he file, tlurong c6 cac thao tac sau:

- 'F'.l0 file: cho phep ngiroi sil dung true tiep xay dung file hoac cung cap dfr lieu,

- D9C file: cho phep.ngiroi su dungdoe cac du lieu trong file, tao cac ban sao nhirng khong dircc phep sira d6i noi dung file.

- B6 sung, cap nhat da lieu vao file: cho phep nguci sil dung sua d6i noi dung file, cap nhat them da lieu vao file.

- Thay d6i thuoc tinh file: cho phep thay d6i cac thuoc tinh nhir: chi doc,

an, he thong, luu tru va gan cac quyen truy nhap file cho nguoi Slr dung khac, - Xoa file: cho.phep loai bo file khoi thief bi hru tni.

D6 truy nhap tai cac file, he file sir dung hai phuong phap:

- Truy nhap tuan nr: cac bin ghi logic trong file duoc truy nhap Ian hrot IU dau den cuoi thea dung trinh nr sap xeptrong file. V6i each thirc truy nhap nay thi hoan roan c6 the bier tnroc diroc ban ghi logic ke tiep truy nhap se la ban ghi nao, va vi vay h~ dieu hanh biet dircc vi tri tren bo nhc ngoai cua ban ghi logic

91

ke tiep can xu 19. Cach thirc truy nhap tuan tu co rmrc d¢ tt;r dong hoa cao, tuy nhien chi ap dung diroc vci cac file duoc t6 chrrc thee kieu tuan tu, M~t khac, d~ dam baa diroc mire d¢ nr dong hoa eao thl he th6ng phai dam baa thuc hien rnoi cong viec chuan bi lien quan den ban ghi cho chuang trlnh cua nguoi Slr dung.

- Truy nhap true tiep: thea each thirc truy nhap nay, he th6ng holm toan khong co tnroc thong tin ve ban ghi nao la ban ghi ke tiep can xu 19. Ngiroi lap trlnh can phai nr xac dinh ban ghi can xii ly va d~ tim duoc no, moi van de d6ng b¢ hoa phai duoc d~t ra.

Tuy mire d¢ tu dong hoa thap nhung each thirc truy nhap true tiep eho phep truy xuat cac file het sue mem deo, linh hoat, dat diroc mire d¢ chu dong eao cua chuang trinh ngiroi sii dung d6i voi cac file.

4. Quan Iy file

Thong tin (cac d~e trung) ve file diroc ghi trong thu muc thiet bi cua 6 dia nhir: ten, kieu, vi tri, kfch thiroc, thai gian cap nhat, s6lan Slr dung, thuoc tinh ... Do do, quan Iy file co nghia la t6 chirc thu muc, thiet bi sao cho viec thao tac voi cac file la t6i uu nhar.

Cac he dieu hanh tren thuc te t6n tai mot so ki~u t6 chirc:

- T6 clurc thu muc mot rrnrc (Single Level Directory): he dieu hanh chi thiet lap mot thu muc dung chung eho tat ca cac file. Kieu t6 chirc nay d~ cai d~t nhung khong thuan tien cho ngttai sir dung,

Directory

Files

Hinh 5.11 - Thu muc m(Jt cap

92

- T6 chirc thu muc hai rrnrc (Two Level Directory): he th6ng t6 chtrc hai mire thu muc, mot rmrc cho h~ thong, mot mtrc cho ngtroi si'r dung.

Master File Directory

User File Directory

Files

Hinh 5.12 - Thu muc hai muc

- T6 chirc thea cau tnic cay (Tree Directory): tren moi 6 rna co mot thu muc g6c (root directory), trong thu muc g6c c6 cac thir muc can cap mot, trong thu rnuc can cap mot ton tai cac thu muc can cap hai. .. Tap hop cac thir muc tren dia tao thanh mot cau tnic cay thir muc.

Htnh 5.13 - Cdu true ctiy

93

- T6 chirc thea do thi khong chu trlnh (Acyclic Graph Directory): kieu t6 chirc nay gall gi6ng nhu t6 chirc cay nhung mot thtr muc can .hoac file co the: thuoc hai thir muc my khac nhau.

Hinli 5.14 - Cdu true thu m~IC de) thi khong chu trinh 5. Bao v~ file va dam bao tinh toan v~n di"lli~u

Baa ve file thong qua viec gi6i han quyen truy nhap cua ngiroi su dung nhtr: doc, viet, xu ly, b6 sung, xoa. ..

Mot s6 phirong phap baa ve file dtroc ap dung Ia: dat ten, dat mat khau, liet ke quyen truy nhap, lap nhom truy nhap ...

De: dam baa tinh roan ven dii lieu, cac h¢ dieu hanh thtrong ap dung cac bien phap nhu: hru trang thai ella file qua cac qua trlnh sir dung, hru trang thai qua cac thai diem, hru tru file thea the he ...

Cau hoi va bili t~p

1. Trinh bay so hroc v~ cau true va nguyen tac hoat d¢ng cua Cia tlt. H~ dieu hanh quan Iy rna W theo don vi nao? The nao la thll rnuc thiet bj?

2. Trinh bay cac phuong phap quan Iy va cap phat kh6ng gian nhc tv do tren dia W cua h~ dieu hanh,

94

3. Trinh bay cac yeu t6 lien quan den thai gian truy nh~p dia hI, tlt d6 neu khai ni~m ve I~p ljch cho dia (disk scheduler).

4. Trinh bay khai niem ve h~ file, cac yeu cau cua h$ file va cac phuong phap t6 chtrc h$ fife.

5. Gia su vunq kh6ng gian nho cua dia tet diroc me ta qua hinh VB sau (m6i 6 la mi?t disk block).

00102030 40506070

s09DIOD[ID [2 D !3 0 [4 0 15 D

File F1 duc;lC phan be> tal cac block c6 56 hi~u: 0,2,4.5,9.13,14,15. Trinh bay phironq phap cap phat lien ket (block dau la 0, block cu6i la 2) va phuong phap cap phat theo chi so (block chi so la 15).

6. Gia su vung kheng gian nhd cua dia nr duqc me ta qua so do sau: (Cac block sam rnau la cac block da su dunq),

°Dl~2D]D4~5D6D7~8D90

LiifuJ ~ Lt::td

a • Me phong cac phLfC1ng phap quan Iy khOng gian nhb tl/ do qua so do tren,

b - File F1 co kich thUoc 3 block. M6 phong cac phudng phap cap phat kh6ng glan nhb cho F 1 qua Sd do tren.

7. Gia sa mi?t dia CU'ng co 200 track duqc ky hi~u tlt 0 den 199; cac yeu cau doc ghi dii Ii$u tal cac track theo thCttl/ sau dcly: 45, 14,9,26,87,52, 122, 183,68, 184, 185. £)au tet dQclghi dang d[nh vi ~i track 60. Ve so do dich chuyen dau tlt dQclghi theo cac thu~t toan: FCFS, SSTF, Scan, C-Scan, Look, C-Look.

95

Chuang 6 QUANLY~TB!

Ml,lc til~u

Sau chuang nay, nguai h9C co th~ phan biet dLfc;1C the nao la thiet b] chuan va thiet bj mil n?ng. Dong thai co th~ hinh dung dLfc;1c nguyen tac t6 chrrc, quan Ii thiet b] ngo~i vi cua h~ dieu hanh va mot s6 ky thuat ap dl,lng trong quan Ii thiet b] nqoai vi.

NQidung

Trinh bay cac yeu cau ve quan Iy thiet b], nguyen tac to chirc va quan Iy thiet bi cua h~ dieu hanh, cac ky thuat ap dunq trong quan Iy thiet bi.

I. NGUYEN TAc TO CHUC vA QUAN LY THIET Bl 1. Yeu C3U cua quan Iy lhiel b]

Chirc nang cua cac thiet bi ngoai vi la dam nhiern viec truyen thong tin qua lai giira cac b¢ pharr ella he thong. Do d6, yeu cau cua he dieu hanh Hi tim phuong phap to chile va truy nnap th6ng tin tren cac thiet bi.

Ngoai cac thiet bi chuan co tinh chat bat buoc (man hinh, ban phim, may in ... ) thi cac h¢ th6ng may tfnh phai eo kha nang kct noi v6i sc lircng tuy 9 cac thiet bi ngoai vi b6 sung. Cac thier bi nay eo th~ khac nhau ve ban chat va nguyen 19 hoat dong, vi vay h¢ dicu hanh can phai tim each quan ly, dieu khien va khai thac cac thiet bi mot each co hieu qua.

CPU kh6ng lam viec tnrc tiep v6i cac thier bi ngoai vi, do do can phai t6 clnrc cac thiet bi sao eho CPU kh6ng phu thuoc vao su bien dong cua cac thiet bi.

2. Nguyen lac 16 chirc va qulm Iy thiel bi

Nguyen lAc co ban d~ t6 chirc va quan 19 thiet bi dua tren eo sa: CPU chi dieu khien cac thao tac vao/ra chir kh6ng tnrc tiep thuc hien cac thao tac nay. D~ dam bao diroc nguyen tac nay, cac thiet bi khong gao tnrc tiep voi CPU rna gan voi cac thiet bi d~c biet - thiet bi quan ly (Control Device). MOt thiet bi quan 1y eo th~ ket n6i voi nhieu thiet bi vao/ra.

96

Thier bi quan Iy d6ng vai tro nhu mot may tinh chuyen dung c6 nhiern vI) dieu khien cac thiet bi ket n6i vci n6 va goi la kenh vao/ra. Moi kenh vao ra c6 ngon ngir va he Ienh rieng. Chung hoat dong doc lap v6'i nhau, doc lap voi CPU va doc lap voi cac thanh phan khac trang he thong.

Vi (11.1: d~ chuyen thong tin tir bo nho trong ra ngoai va nguoc Iai, kenh phai truy nhap tnrc tiep bo nho theo mot co che dac biet, song song va doc lap voi cpu. Co che nay duoc goi la DMA (Direct Memory Access)

Mot he th6ng may tinh co th~ e6 nhieu kenh vesslt», moi kenh vao/ra 1,,*1 c6 th~ co nhtrng kenh con cua mlnh, D~ dieu khien hoat dong cua die kenh, can c6 cac chuang trinh dieu khien rieng goi Iii chuang trinh dieu khien kenh,

D~ he thong lam viec duoc voi cac kenh thi CPU phai hieu duoc ngon ngtr kenh. Ngon ngfr kenh dtroc nap vao he thong khi n~p he dieu hanh hoac ngay ca khi he dieu hanh dang hoat dong (ngon ngif kenh thuc chat III cac trinh dieu khien kenh).

CPU dicu khien cac thao tac vao/ra thong qua cac chuang trinh dieu khien kenh wang ling voi cong vice can thirc hien (nguyen Iy macro processor). Nguyen ly dieu khien nay cho phep trong hie cac thao tac vim/ra duoc tlurc hien a thiet bi ngoai vi thl CPU vAn hoar dong song song thirc hien tinh toan va dieu khien chirng nao chua can toi ker qua vao/ra, Khi c6 ket qua vao/ra, kenh se phat tin hieu ngat baa cho CPU bier. Tuy thea hoan canh cu the, tin hieu ngat diroc xiI ly ngay hoac diroc luu tnr lai de xu ly khi c6 dieu kien hoac tham chi c6 th6 bi huy be neu he th6ng khong con quan tam den ket qua nay. Nhu vay, ngar vao/ra xuat hien sau khi phep vao/ra diroc thirc hien xong chii khong phai tnroc khi phep vao/ra diroc thirc hien, De dam bao hieu suai xu ly cao, he thong can phai biet cang sam rang tot thoi diem ket thuc cua phep vao/ra, Chinh vi vay, kenh se bao cho he thong biet ket qua vao/ra vao thoi diem sam nhat c6 the duoc va do d6 mot phep vao/ra c6 the ket thuc a nhieu rrurc, nhieu noi khac nhau nhtr: tai thiet bi dicu khien, tai thoi diem khi lenh diroc chuyen den thiet bi vao/ra, khi thiet bi vao/ra nhan ducc tin hieu dieu khien hoac sau khi phep vao ra diroc thirc hien xong tai thiet bi ngoai vi.

Phuong .phap t6 chirc nay cho phep g~n them thiet bi dong thoi dam bao cho he thong khong phu thuoc cau hlnh cua thiet bi C1,1 the, h¢ thong c6 tfnh hru dong cao (thay d6i thiet bi rna khong din thay d6i he thong, khong can sua d6i cac chuang trinh U'ng dung),

7(i) - 184

97

II. cAe KY THUJ,T Ap Dl}NG TRONG QUAN LY THIET B~ 1. Ky thu~t vung d~m

1.1. Khai niem va muc dieh ella vung d¢m

Vung dem (buffer) la mot vung nho trung gian dung lam noi hru tn1 thong

tin tam thai trong cac thao tac vim/ra.

D~ thuc hien mot thao tac vao/ra, he thong can phai thuc hien cac biroc sau: - Kfch heat thiet bi,

- Cho thiet bi dat trang thai thfch hop,

- Cho thao tac vao/ra duoc thirc hien.

Viec cho doi cac thiet bi dat trang thai thich hop chiern mot thai gian kha Ian trong t6ng thai gian thirc hien thao tic van/fa. Vi vay, d~ dam bao toe d¢ heat dong chung cua toan he thong, thao tac vao/ra can ph iii Slr dung vung dem nham muc dfch:

- Giam so hrong cac thao tac vao/ra vat IY.

- Cho phep tlurc hien song song cac thao tac vao/ra voi cac thao tac xu Iy

thong tin khac nhau.

- Cho phep thirc hien tnroc cac phep nhap dfr lieu. 1.2. Phan loai vung dem

C6 nhieu phuong phap t6 chtrc vung dern khac nhau nhirng n6i chung co th~ chia cluing thanh ba loai: vung dem trung chuyen, vung dern xu ly va vung dern vong tron.

1.2.1. Vung d¢m trung chuye"n

D6i v6i ki~u vung dern trung chuyen, he thong t6 chirc hai vung nho rieng biet: vung nho vao va vung nho ra. Vung nho vao chi dung de nhap thong tin con vung nho ra dung d~ ghi thong tin. Tuong ling trong he thong co hai lenh d~ dua thong tin vao va lay thong tin fa (read/write).

Trong chuang trinh ling dung, ngay sau khi me file, thong tin se duoc chuyen den vung nho vito. Khi g~p lenh d9C (read), thong tin se diroc chuyen tir vung nho vao tai cac dia chi nrong irng neu trong chuang trinh irng dung, nhu vay moi gia tri se duoc hru tru hai noi trong b¢ nho. Sau khi gia tri cuoi cung cua vung dern diroc lay ra xu ly, vung dem trb nen rong va he thong t6 chirc nhap thong tin moi vao thai diem sam nhat co th6 duoc. D6 giam thai gian cho doi, he thong co th€ t6 chiic nhieu vung dern vao, khi het thong tin a mot vung dern h¢ thong se chuyen sang vung dern ke tiep.

98

7{t) - 184

Doi voi vung dem ra, thong tin cung diroc xu 19 urong tu nhirng thea trlnh tl! ngiroc lai, Lenh ghi (write) kh6ng dua true tiep thong tin ra thiet bi rna dua vao vung dem ra. Khi mot vung dem ra day, he thong se chuyen sang lam viec voi vung dem ke tiep, dong thoi t6 chuc dua thong tin tir vung dem truce ra thiet bi,

Hu diem cua vung dem trung chuyen 13. c6 h¢ so song song cao, phd dung (ap dung duoc cho moi phep vao/ra), each thuc t6 chiic dan gian nhirng nhuoc diem la ton bo nho (phai t6 clurc hai vung nbo rieng), keo dai thoi gian trao d6i thong tin a b¢ nho trong,

1.2.2. Vung d~m xu If

Trong viing dem xu 19, ca thong tin vao va ra cimg duoc xu ly trong mot vung bo nho, thong tin khong can phai luu tru a nhieu vi tri khac nhau trong bo nho. Trang tnrong h<;1P nay, lenh d9C (read) xac dinh dia chi thong tin chir khong can cung cap gia tri thong tin nlur trong vung dem trung chuyen,

Loai vung dem nay c6 uu diem la tiet kiem khong gian nho, rut ngan thoi gian trao d6i thong tin 6 b¢ nho trong nhirng toe d9 giai ph6ng vung dern cham, VI vay h¢ so song song thap han so v6i vung dem trung chuyen. Mat khac, khong phai thao tac trao d6i vao/ra nao cling co th€ su dung diroc vung dern nay. Day la phuong phap t6 chirc vung dem phiic tap.

1.2.3. Vung d¢m vong tron

Trong each t6 clurc nay, he thong lam viec voi ba vung dem: mot vung dern d€ dua thong tin vao, mot vung dern de dira th6ng tin ra va mot vung dern de xu ly. Sau mot khoang thai gian nhat dinh thl chirc nang cua cac vung dem diroc trao doi eho nhau. Vong tron urc la vung dern VaG thanh vung dern xiI ly, vung dern xu ly thanh vung dem ra, vung dem ra thanh vung dern vao, Nhu vay, vung dern nay se dat hieu qua cao khi thci gian xu 19 nrong ducmg thai gian vao/ra.

Loai vung dern nay c6 th~ gan vm timg file cu the hoac g~ voi toan h¢ thong. Trang che d(> gan voi file, vung dern diroc xay dung khi rna file, xoa khi dong file va chi phuc vu rieng cho file d6. Phuong phap t6 chirc nay d~e biet thfch h<;1P khi rnoi file co mot kich thuoc ban ghi vat ly rieng, Neu tat ca. cac file deu co kfch thuoc ban ghi vat ly giong nhau thi ngiroi ta thirong dung che d¢ vung dem chung cho toan bo he thong. Vung dern diroc xay dung khi nap he thong va chua gan voi mot file cu the nao. Khi mo file, mot hoac mot so vung dem duoc gan voi file va phuc vu cho su truy nhap file d6. Khi dong file, vung dem kh6ng bi xoa rna dU<;1C tni v~ cho h¢ thong nhu ID9t tai nguyen chung.

99

Phuong phap t6 chirc nay tranh diroc viec phai thirc hien cac thu tuc tao vung dem nhieu Ian nhung n6 cung gap mot s6 han che:

C6 nhtrng thai di6m vung dern khong duoc si'r dung het, gay lang phi bo nho.

Vung dem c6 th~ tro thanh tai nguyen gang khi c6 nhieu file diroc mo dong thoi. D~ giam kha nang xay ra canh tranh vung dem, clning ta co th~ lang s6 luong vung dern ngay ttr khi nap he thong nhirng nhu vay se chiem dung nhieu bo nho va lam tang thai gian dich vu cua he th6ng, dac biet la viec dim thong tin vao cac vung dern.

2. Ky thu~t ket khoi

De giam s6 tan truy nhap vat ly, he thong con sir dung ky thuat ker khoi nrc la ghep nhieu ban ghi logic thanh mot ban ghi vat ly va viec trao d6i thong tin giua cac bo phan diroc tien hanh thea ban ghi vat lY.

Thong thuong, ton rai cac each t6 clnrc ket kh6i nhu sau:

- Moi ban ghi vat ly chua mot s6 nguyen liln cac ban ghi logic va gia tri nay la nhir nhau voi moi ban ghi v~t IY.

- Moi ban ghi vat ly chua mot s6 nguyen Ian cac ban ghi logic nhung s6 luong cac ban ghi logic khong gi6ng nhau voi nhtrng ban ghi v~t ly khac nhau. - Ban ghi vat 11' c6 d¢ dai c6 dinh, khong phu thuoc vao d9 dai cua ban ghi logic. Vi vay, ban ghi vat 11' khong nhat thiet phai chua mot s6 nguyen Ian cac ban ghi logic.

- Ban ghi vat Iy chi chua mot phan ban ghi logic va vi vay phai ket hop nhieu ban ghi vat Iy moi ducc mot ban ghi logic.

Phuong phap ket khoi duoc chon phai tuy thuoc vao van de don giai quyet va phuong thtrc hoat dong cua thiet bi, Vi du nhu thiet bi la dia til diroc quan Iy thea ki6u phan trang thl chi ap dung duoc phuong phap thir ba, voi bang tir thi co th~ ap dung plnrong phap thii hai.

Viec ket khoi con diroc sir dung nhu mot bien phap han che viec truy nhap bat hop le. Neu khong neu dung h¢ 56 ket khoi (56 ban ghi logic trong mot ban ghi v~t Iy) thi he thong se khong tiep tuc thirc hien cac phep truy nhap thong tin hoac thong tin se bi giai rna sai lenh vi h¢ 56 ket khoi da neu khong hop lY.

Phuong phap kel khoi thir tu thirong diroc ap dung khi can phai hru tril hoac sao chep cac file c6 kich thiroc Ian nhung khong mu6n Slr dung cac cong cu backup dir.lieu.

100

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->