操作系统课程设计试验报告格式.doc_第1页
操作系统课程设计试验报告格式.doc_第2页
操作系统课程设计试验报告格式.doc_第3页
操作系统课程设计试验报告格式.doc_第4页
操作系统课程设计试验报告格式.doc_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

四 川 大 学操作系统课程设计报告学 院: 软件 学 院 专 业: 软件工程 专 业 年 级: 07级 组 编 号: 第 X组 组 成 员: 乔心轲(姓名) 0743111340(学号) 何赵平(姓名) XXXXXXXX(学号) 崔蓉 (姓名) XXXXXXXX(学号) 张雯(姓名) XXXXXXXX(学号) 康小芳(姓名) XXXXXXXX(学号)提交时间: 2009年 月 日 指导教师评阅意见: . . . . .指导教师评阅成绩:XXX1: XXX1: XXX1: XXX1: XXX1: 实验项目一项目名称:实验目的:实验时间:人员分工:实验环境:实验环境的搭建过程、选用的操作系统、机器配置、编译器等。实验内容:对实践过程的详细说明,针对已经满足的实践要求,采用了何种算法或思想,对Nachos平台的哪些代码进行了什么样的修改。实验结果:对实践要求的满足程度,代码是否编写完成,是否调试通过,能否正常运行,本项目的要求中共满足了哪几项。参考文献:实验项目二实验项目名称:Nachos中的线程管理实验项目目的:1.最多能够同时存在128个用户线程 2.改变为遵循“优先级调度”的抢占式调度 参与人员及分工:乔心轲,何赵平,康小芳完成主要代码编写;崔蓉,张文进行程序的测试及维护。实验环境:n Nachos: Not Another Completely Heuristic Operating Systemn Linuxn Gcc n Windows实验内容:1.对于最多能够同时存在128个用户线程,我们在Thread.cc中声明了一个static变量numOfThreads;具体代码如下:static int numOfThreads = 0;/the count of the threads在Thread的构造函数中对其值进行加1;即每创建一个线程时,都会把numOfThreads加1;+numOfThreads; 并在SimpleThread()中进行了如下修改,完成了最多能够同时存在128个用户线程。static voidSimpleThread(int which) if(numOfThreads128) for(inti=0;icurrentThread-Time()-(kernel-currentThread-executeTime)+2;i+) cout * thread which looped currentThread-executeTime times.n;coutpriority currentThread-Priority()currentThread-Yield(); elseif(count = 0) printf(The number of the threads can not be larger than 128!n);kernel-currentThread-Yield(); count+; 为了实现遵循“优先级调度”的抢占式调度策略,首先为Thread增加了三个变量:executeTime;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 exT);/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 private: / 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中的实现:Thread:Thread(char* threadName) name = threadName; stackTop = NULL; stack = NULL; status = JUST_CREATED; for (int i = 0; i interrupt;Scheduler *scheduler = kernel-scheduler;IntStatus oldLevel;DEBUG(dbgThread, Forking thread: name f(a): (int) func SetLevel(IntOff); scheduler-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/-voidThread: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() return time;并在SimpleThread()中进行了如下修改:static voidSimpleThread(int which) if(numOfThreads128) for(int i=0;icurrentThread-Time()-(kernel-currentThread-executeTime)+2;i+) cout * thread which looped currentThread-executeTime times.n;coutpriority currentThread-Priority()currentThread-Yield(); elseif(count = 0) printf(The number of the threads can not be larger than 128!n);kernel-currentThread-Yield(); count+; 对Scheduler.cc中进行了以下修改,实现了按照优先级进行线程的调度,返回最高优先级的线程,让其运行。Thread *Scheduler:FindNextToRun () ASSERT(kernel-interrupt-getLevel() = IntOff); if (readyList-IsEmpty() return NULL; else Thread *highestPri = readyList-RemoveFront(); for (int i =1;iNumInList();i+) if(readyList-IsEmpty() return highestPri; if(readyList-Front()-Priority()Priority() readyList-Append(highestPri);highestPri = readyList-RemoveFront(); return highestPri; 并在Run()中进行了以下修改:在Run()代码的最后加了以下语句:kernel-currentThread-setPriority(kernel-currentThread-Priority()+1);kernel-currentThread-setExTime(kernel-currentThread-executeTime+1);实验结果和结论:对实验进行的测试,首先编译通过测试:经过编译测试,程序已完成了以上要求,具体测试如下:对遵循“优先级调度”抢占式调度的实现:voidThread:SelfTest() DEBUG(dbgThread, Entering Thread:SelfTest); for(int i=0;isetPriority(3-i);t-Fork(VoidFunctionPtr) SimpleThread, (void *) numOfThreads); 对最多只有128个用户线程存在的实现:参考文献:实验项目三实验项目名称:Nachos中的文件管理系统实验项目目的: 实现多个线程同时存在内存,虚拟地址到物理地址的转换,限制程序大小,不实现缺页中断处理 不实用虚拟内存 维护二类页表 实页页表(空闲页表):操作系统维护(Machine中创建)nachos现在有多少页表是可以供用户使用 线程页表:各线程维护自己的页表参与人员及分工:乔心轲,何赵平,康小芳完成主要代码编写;崔蓉,张文进行程序的测试及维护。实验环境:n Nachos: Not Another Completely Heuristic Operating Systemn Linuxn Gcc n Windows实验内容:首先是在Machine.h中对空闲页表及其相关函数进行了声明: TranslationEntry *freePageTable; /空闲页表 TranslationEntry NextFreePage();/下一个空闲的页 int NumOfFreePage();/剩余空闲页的数目其次在Machine.cc中空闲页表进行初始化以及函数的实现: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+) freePageTablei.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 linear page table tlb = NULL; pageTable = NULL;#endif singleStep = debug; CheckEndian(); /-/Machine:NextFreePage()/-TranslationEntry Machine:NextFreePage() for(int i = 0;iNumPhysPages;i+) if(freePageTablei.valid=TRUE)return freePageTablei; /-/Machine:numOfFreePage()/-intMachine:NumOfFreePage() int num = 0; for(int i = 0;iNumPhysPages;i+) if(freePageTablei.valid=TRUE)num+; return num;对AddrSpace.cc的修改如下:AddrSpace:AddrSpace() AddrSpace:AddrSpace() if(pageTable!=NULL) for(int i=0;ifileSystem-Open(fileName); NoffHeader noffH; unsigned int size; if (executable = NULL) cerr Unable to open file fileName 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.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 room for the stack#endif numPages = divRoundUp(size, PageSize); size = numPages * PageSize; ASSERT(numPages = NumPhysPages);/ check were not trying/ to run anything too big -/ at least until we have/ virtual memory DEBUG(dbgAddr, Initializing address space: numPages , machine-NumOfFreePage()=numPages)for(int i=0;imachine-NextFreePage();pageTablei.virtualPage=temp.virtualPage;pageTablei.physicalPage=temp.physicalPage;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 virtual 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(;iReadAt(&(kernel-machine-mainMemorypageTablei.physicalPage), PageSize, noffH.code.inFileAddr+i*PageSize);coutPage pageTablei.virtualPage for code segment is used!n; cout 0) DEBUG(dbgAddr, Initializing data segment.);DEBUG(dbgAddr, noffH.initData.virtualAddr , noffH.initData.size);for(;iReadAt(&(kernel-machine-mainMemorypageTablei.physicalPage), PageSize, noffH.initData.inFileAddr+i*PageSize);coutPage pageTablei.virtualPage 0) DEBUG(dbgAddr, Initializing read only data segment.);DEBUG(dbgAddr, noffH.readonlyData.virtualAddr , noffH.readonlyData.size);for(;iReadAt( &(kernel-machine-mainMemorypageTablei.physicalPage), PageSize, noffH.readonlyData.inFileAddr+i*PageSize);coutPage pageTablei.virtualPage for readOnlydata segment is used!n; #endif elsecoutP();/只有一个读进程可以进入 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) 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(writecount=0)rsem-V();y-V();实现目录结构的多级机制:创建了一个SubFileHeader类:主要就是把FileHeader的内容拷贝过去了;然后在FileHeader中进行了如下修改:boolFileHeader:Allocate(PersistentBitmap *freeMap, int fileSize) int hdr_size;SubFileHeader *subHdr30;numBytes = fileSize;if(fileSizen); numHdrSectors = divRoundUp(fileSize, SectorSize); if (freeMap-NumClear() numHdrSectors)return FALSE;/ not enough space for (int i = 0; i FindAndSet(); return TRUE

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论