操作系統(tǒng)課程設計試驗報告格式_第1頁
操作系統(tǒng)課程設計試驗報告格式_第2頁
操作系統(tǒng)課程設計試驗報告格式_第3頁
操作系統(tǒng)課程設計試驗報告格式_第4頁
操作系統(tǒng)課程設計試驗報告格式_第5頁
已閱讀5頁,還剩43頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、四 川 大 學操作系統(tǒng)課程設計報告學 院: 軟件 學 院 專 業(yè): 軟件工程 專 業(yè) 年 級: 07級 組 編 號: 第 X組 組 成 員: 喬心軻(姓名) 0743111340(學號) 何趙平(姓名) XXXXXXXX(學號) 崔蓉 (姓名) XXXXXXXX(學號) 張雯(姓名) XXXXXXXX(學號) 康小芳(姓名) XXXXXXXX(學號)提交時間: 2009年 月 日 指導教師評閱意見: . . . . .指導教師評閱成績:XXX1: XXX1: XXX1: XXX1: XXX1: 實驗項目一項目名稱:實驗目的:實驗時間:人員分工:實驗環(huán)境:實驗環(huán)境的搭建過程、選用的操作系統(tǒng)、機器

2、配置、編譯器等。實驗內(nèi)容:對實踐過程的詳細說明,針對已經(jīng)滿足的實踐要求,采用了何種算法或思想,對Nachos平臺的哪些代碼進行了什么樣的修改。實驗結(jié)果:對實踐要求的滿足程度,代碼是否編寫完成,是否調(diào)試通過,能否正常運行,本項目的要求中共滿足了哪幾項。參考文獻:實驗項目二實驗項目名稱:Nachos中的線程管理實驗項目目的:1.最多能夠同時存在128個用戶線程 2.改變?yōu)樽裱皟?yōu)先級調(diào)度”的搶占式調(diào)度 參與人員及分工:喬心軻,何趙平,康小芳完成主要代碼編寫;崔蓉,張文進行程序的測試及維護。實驗環(huán)境:n Nachos: Not Another Completely Heuristic Operati

3、ng Systemn Linuxn Gcc n Windows實驗內(nèi)容:1.對于最多能夠同時存在128個用戶線程,我們在Thread.cc中聲明了一個static變量numOfThreads;具體代碼如下:static int numOfThreads = 0;/the count of the threads在Thread的構(gòu)造函數(shù)中對其值進行加1;即每創(chuàng)建一個線程時,都會把numOfThreads加1;+numOfThreads; 并在SimpleThread()中進行了如下修改,完成了最多能夠同時存在128個用戶線程。static voidSimpleThread(int which)

4、if(numOfThreads<128) for(inti=0;i<(kernel->currentThread->Time()-(kernel->currentThread->executeTime)+2;i+) cout << "* thread " <<which<<" looped "<<kernel->currentThread->executeTime<<" times.n"cout<<"pri

5、ority "<<kernel->currentThread->Priority()<<"n"kernel->currentThread->Yield(); elseif(count = 0) printf("The number of the threads can not be larger than 128!n");kernel->currentThread->Yield(); count+; 為了實現(xiàn)遵循“優(yōu)先級調(diào)度”的搶占式調(diào)度策略,首先為Thread增加了三個變量:exec

6、uteTime;time;priority在Thread.h中對它們的聲明:public: Thread(char* debugName);/ initialize a Thread Thread(); / deallocate a Thread/ NOTE - thread being deleted/ must not be running when delete / is called int executeTime;/The time that this thread has executed / basic thread operation void setExTime(int ex

7、T);/set the executeTime of the thread to exT int Time();/return the time that the thread should be served void setTime(int t);/set the time that the thread should be served to t void setPriority(int pri); /set the priority of the thread to priint Priority(); /return the priority of the thread privat

8、e: / some of the private data for this class is listed above int time; / the time that the thread should be served int priority; /the priority of each thread在Thread.cc中的實現(xiàn):Thread:Thread(char* threadName) name = threadName; stackTop = NULL; stack = NULL; status = JUST_CREATED; for (int i = 0; i <

9、MachineStateSize; i+) machineStatei = NULL;/ not strictly necessary, since / new thread ignores contents / of machine registers space = NULL; executeTime=1; setPriority(0); setTime(2);在Fork()中對numOfThreads進行了+1操作:void Thread:Fork(VoidFunctionPtr func, void *arg) Interrupt *interrupt = kernel->int

10、errupt;Scheduler *scheduler = kernel->scheduler;IntStatus oldLevel;DEBUG(dbgThread, "Forking thread: " << name << " f(a): " << (int) func << " " << arg); StackAllocate(func, arg); oldLevel = interrupt->SetLevel(IntOff); scheduler->

11、ReadyToRun(this);/ ReadyToRun assumes that interrupts / are disabled! (void) interrupt->SetLevel(oldLevel); +numOfThreads; /-/Thread:setExTime/ set the executeTime of the thread to exT/-voidThread:setExTime(int exT) executeTime = exT;/-/Thread:setPriority/ set the priority of the thread to pri/-v

12、oidThread:setPriority(int pri) priority=pri;/-/Thread:Priority/ return the priority of the thread/-intThread:Priority() return priority;/-/Thread:setPriority/ set the time of the thread to t/-void Thread:setTime(int t) time=t;/-/Thread:Time/ return the time of the thread need to run/-intThread:Time(

13、) return time;并在SimpleThread()中進行了如下修改:static voidSimpleThread(int which) if(numOfThreads<128) for(int i=0;i<(kernel->currentThread->Time()-(kernel->currentThread->executeTime)+2;i+) cout << "* thread " <<which<<" looped "<<kernel->cur

14、rentThread->executeTime<<" times.n"cout<<"priority "<<kernel->currentThread->Priority()<<"n"kernel->currentThread->Yield(); elseif(count = 0) printf("The number of the threads can not be larger than 128!n");kernel->cur

15、rentThread->Yield(); count+; 對Scheduler.cc中進行了以下修改,實現(xiàn)了按照優(yōu)先級進行線程的調(diào)度,返回最高優(yōu)先級的線程,讓其運行。Thread *Scheduler:FindNextToRun () ASSERT(kernel->interrupt->getLevel() = IntOff); if (readyList->IsEmpty() return NULL; else Thread *highestPri = readyList->RemoveFront(); for (int i =1;i<readyList-

16、>NumInList();i+) if(readyList->IsEmpty() return highestPri; if(readyList->Front()->Priority()<=highestPri->Priority() readyList->Append(highestPri);highestPri = readyList->RemoveFront(); return highestPri; 并在Run()中進行了以下修改:在Run()代碼的最后加了以下語句:kernel->currentThread->setPrio

17、rity(kernel->currentThread->Priority()+1);kernel->currentThread->setExTime(kernel->currentThread->executeTime+1);實驗結(jié)果和結(jié)論:對實驗進行的測試,首先編譯通過測試:經(jīng)過編譯測試,程序已完成了以上要求,具體測試如下:對遵循“優(yōu)先級調(diào)度”搶占式調(diào)度的實現(xiàn):voidThread:SelfTest() DEBUG(dbgThread, "Entering Thread:SelfTest"); for(int i=0;i<=3;i

18、+)Thread *t = new Thread("forked thread");t->setPriority(3-i);t->Fork(VoidFunctionPtr) SimpleThread, (void *) numOfThreads); 對最多只有128個用戶線程存在的實現(xiàn):參考文獻:實驗項目三實驗項目名稱:Nachos中的文件管理系統(tǒng)實驗項目目的: 實現(xiàn)多個線程同時存在內(nèi)存,虛擬地址到物理地址的轉(zhuǎn)換,限制程序大小,不實現(xiàn)缺頁中斷處理 不實用虛擬內(nèi)存 維護二類頁表 實頁頁表(空閑頁表):操作系統(tǒng)維護(Machine中創(chuàng)建)nachos現(xiàn)在有多少頁表是

19、可以供用戶使用 線程頁表:各線程維護自己的頁表參與人員及分工:喬心軻,何趙平,康小芳完成主要代碼編寫;崔蓉,張文進行程序的測試及維護。實驗環(huán)境:n Nachos: Not Another Completely Heuristic Operating Systemn Linuxn Gcc n Windows實驗內(nèi)容:首先是在Machine.h中對空閑頁表及其相關(guān)函數(shù)進行了聲明: TranslationEntry *freePageTable; /空閑頁表 TranslationEntry NextFreePage();/下一個空閑的頁 int NumOfFreePage();/剩余空閑頁的數(shù)目其

20、次在Machine.cc中空閑頁表進行初始化以及函數(shù)的實現(xiàn):Machine:Machine(bool debug) int i; for (i = 0; i < NumTotalRegs; i+) registersi = 0; mainMemory = new charMemorySize; for (i = 0; i < MemorySize; i+) mainMemoryi = 0; freePageTable = new TranslationEntryNumPhysPages; for (i = 0; i < NumPhysPages; i+) freePageTa

21、blei.virtualPage=i;freePageTablei.physicalPage = i;freePageTablei.valid = TRUE;freePageTablei.use = FALSE;freePageTablei.dirty = FALSE;freePageTablei.readOnly = FALSE; #ifdef USE_TLB tlb = new TranslationEntryTLBSize; for (i = 0; i < TLBSize; i+)tlbi.valid = FALSE; pageTable = NULL;#else/ use lin

22、ear page table tlb = NULL; pageTable = NULL;#endif singleStep = debug; CheckEndian(); /-/Machine:NextFreePage()/-TranslationEntry Machine:NextFreePage() for(int i = 0;i<NumPhysPages;i+) if(freePageTablei.valid=TRUE)return freePageTablei; /-/Machine:numOfFreePage()/-intMachine:NumOfFreePage() int

23、num = 0; for(int i = 0;i<NumPhysPages;i+) if(freePageTablei.valid=TRUE)num+; return num;對AddrSpace.cc的修改如下:AddrSpace:AddrSpace() AddrSpace:AddrSpace() if(pageTable!=NULL) for(int i=0;i<numPages;i+)pageTablei.valid = TRUE;pageTablei.use = FALSE;pageTablei.dirty = FALSE;pageTablei.readOnly = FAL

24、SE; delete pageTable; 為了實現(xiàn)限制程序大小以及實現(xiàn)線程頁表和空閑頁表的轉(zhuǎn)換,對代碼進行了如下修改:bool AddrSpace:Load(char *fileName) OpenFile *executable = kernel->fileSystem->Open(fileName); NoffHeader noffH; unsigned int size; if (executable = NULL) cerr << "Unable to open file " << fileName << "

25、;n"return FALSE; executable->ReadAt(char *)&noffH, sizeof(noffH), 0); if (noffH.noffMagic != NOFFMAGIC) && (WordToHost(noffH.noffMagic) = NOFFMAGIC) SwapHeader(&noffH); ASSERT(noffH.noffMagic = NOFFMAGIC);#ifdef RDATA/ how big is address space? size = noffH.code.size + noffH.

26、readonlyData.size + noffH.initData.size + noffH.uninitData.size + UserStackSize; / we need to increase the size/ to leave room for the stack#else/ how big is address space? size = noffH.code.size + noffH.initData.size + noffH.uninitData.size + UserStackSize;/ we need to increase the size/ to leave r

27、oom for the stack#endif numPages = divRoundUp(size, PageSize); size = numPages * PageSize; ASSERT(numPages <= NumPhysPages);/ check we're not trying/ to run anything too big -/ at least until we have/ virtual memory DEBUG(dbgAddr, "Initializing address space: " << numPages <

28、;< ", " << size); pageTable = new TranslationEntrynumPages;if(kernel->machine->NumOfFreePage()>=numPages)for(int i=0;i<numPages;i+)TranslationEntry temp = kernel->machine->NextFreePage();pageTablei.virtualPage=temp.virtualPage;pageTablei.physicalPage=temp.physica

29、lPage;pageTablei.valid=FALSE;pageTablei.use=FALSE;kernel->machine->freePageTabletemp.physicalPage.valid = FALSE;kernel->machine->freePageTabletemp.physicalPage.use = TRUE; /sgeTablei.virtualPage=0;/ then, copy in the code and data segments into memory/ Note: this code assumes that virtua

30、l address = physical address int i=0;if (noffH.code.size > 0) DEBUG(dbgAddr, "Initializing code segment."); DEBUG(dbgAddr, noffH.code.virtualAddr << ", " << noffH.code.size); for(;i<(noffH.code.size/PageSize);i+) executable->ReadAt(&(kernel->machine-&g

31、t;mainMemorypageTablei.physicalPage), PageSize, noffH.code.inFileAddr+i*PageSize);cout<<"Page "<<pageTablei.virtualPage<<" for code segment is used!n" cout<<"Page for code is allocatedn" if (noffH.initData.size > 0) DEBUG(dbgAddr, "Initia

32、lizing data segment.");DEBUG(dbgAddr, noffH.initData.virtualAddr << ", " << noffH.initData.size);for(;i<(noffH.code.size/PageSize)+(noffH.initData.size/PageSize);i+)executable->ReadAt(&(kernel->machine->mainMemorypageTablei.physicalPage), PageSize, noffH.in

33、itData.inFileAddr+i*PageSize);cout<<"Page "<<pageTablei.virtualPage<<" for data segment is used!n" #ifdef RDATA if (noffH.readonlyData.size > 0) DEBUG(dbgAddr, "Initializing read only data segment.");DEBUG(dbgAddr, noffH.readonlyData.virtualAddr <

34、;< ", " << noffH.readonlyData.size);for(;i<(noffH.code.size/PageSize)+(noffH.initData.size/PageSize)+(noffH.readonlyData.size/PageSize);i+) executable->ReadAt( &(kernel->machine->mainMemorypageTablei.physicalPage), PageSize, noffH.readonlyData.inFileAddr+i*PageSize

35、);cout<<"Page "<<pageTablei.virtualPage<<" for readOnlydata segment is used!n" #endif elsecout<<"Not enough space for the program!n"delete pageTable; delete executable;/ close file return TRUE;/ success實驗結(jié)果和結(jié)論:程序已編譯通過,實現(xiàn)了1.多個線程同時存在內(nèi)存,虛擬地址到物理地址的轉(zhuǎn)換

36、,限制程序大小,不實現(xiàn)缺頁中斷處理2.維護二類頁表(1)實頁頁表(空閑頁表):操作系統(tǒng)維護(Machine中創(chuàng)建)nachos現(xiàn)在有多少頁表是可以供用戶使用(2)線程頁表:各線程維護自己的頁表具體如下:編譯通過:測試:參考文獻:實驗項目四實驗項目名稱:Nachos中的文件管理模塊升級實驗項目目的:l 多個線程不能同時對一個文件進行寫操作,因為會發(fā)生沖突,但是可以同時進行讀操作.l 將簡單的通過信號量進行控制的同步機制修改為讀者/寫者問題的機制. l 實現(xiàn)目錄結(jié)構(gòu)的多級機制參與人員及分工:實驗環(huán)境:n Nachos: Not Another Completely Heuristic Operat

37、ing Systemn Linuxn Gcc n Windows實驗內(nèi)容:實現(xiàn)多個線程不能同時對一個文件進行寫操作,因為會發(fā)生沖突,但是可以同時進行讀操作. 將簡單的通過信號量進行控制的同步機制修改為讀者/寫者問題的機制:在SynchDisk.h中的修改如下: private: int readcount; /count the number of the readers int writecount; /count the number of the writers Disk *disk; / Raw disk device Semaphore *x; Semaphore *y; Semap

38、hore *z; Semaphore *wsem; Semaphore *rsem; 在SynchDisk.cc中的構(gòu)造函數(shù)中對信號量進行初始化。SynchDisk:SynchDisk() x = new Semaphore("synch disk", 1); y= new Semaphore("synch disk", 1); z = new Semaphore("synch disk", 1); wsem= new Semaphore("synch disk", 1); rsem= new Semaphore(

39、"synch disk", 1); lock = new Lock("synch disk lock"); disk = new Disk(this); readcount=0; writecount=0;在SynchDisk.cc中的析構(gòu)函數(shù)中把信號量的指針刪除。SynchDisk:SynchDisk() delete disk; delete lock; delete x; delete y; delete z; delete wsem; delete rsem;在ReadSector函數(shù)中進行的修改如下:voidSynchDisk:ReadSect

40、or(int sectorNumber, char* data)while(TRUE) z->P();/只有一個讀進程可以進入 rsem->P(); x->P(); readcount+; if(readcount=1) wsem->P(); x->V(); rsem->V(); z->V(); x->P(); lock->Acquire(); disk->ReadRequest(sectorNumber, data); lock->Release(); x->V(); readcount-; if(readcount=0

41、) wsem->V(); x->V();voidSynchDisk:WriteSector(int sectorNumber, char* data)while(TRUE)y->P();/多個寫進程可以進行排隊writecount+;if(writecount=1)rsem->P();y->V();wsem->P();lock->Acquire();disk->WriteRequest(sectorNumber, data);lock->Release();wsem->V();y->P();writecount-;if(writ

42、ecount=0)rsem->V();y->V();實現(xiàn)目錄結(jié)構(gòu)的多級機制:創(chuàng)建了一個SubFileHeader類:主要就是把FileHeader的內(nèi)容拷貝過去了;然后在FileHeader中進行了如下修改:boolFileHeader:Allocate(PersistentBitmap *freeMap, int fileSize) int hdr_size;SubFileHeader *subHdr30;numBytes = fileSize;if(fileSize<NumDirect*SectorSize) printf("filehdr.cc 50 ->n"); numHdrSectors = divRoundUp(fileSize, SectorSize); if (freeMap->NumClear() <

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論