北京大学操作系统实习JOS lab4实验报告

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Í\ûßJOSž`,Û!¥J00848231,zhangchitc@gmail.comApril27,2011Contents1Introduction32User-levelEnvironmentCreationandCooperativeMultitasking32.1Round-RobinScheduling.......................32.2SystemCallsforEnvironmentCreation..............83Copy-on-WriteFork123.1User-levelpagefaulthandling....................123.1.1SettingthePageFaultHandler...............123.1.2NormalandExceptionStacksinUserEnvironments..133.1.3InvokingtheUserPageFaultHandler...........163.1.4User-modePageFaultEntrypoint.............193.1.5Testing.............................243.2ImplementingCopy-on-WriteFork.................254PreemptiveMultitaskingandInter-Processcommunication(IPC)324.1ClockInterruptsandPreemption..................324.1.1Interruptdiscipline......................324.1.2HandlingClockInterrupts.................344.2Inter-Processcommunication(IPC).................354.2.1IPCinJOS...........................354.2.2SendingandReceivingMessages..............354.2.3TransferringPages......................351Í\ûߞ`¥J,008482314.2.4ImplementingIPC......................362Í\ûߞ`¥J,008482311Introduction(žŒ-;Â†N-р'fµ×Ü™„JOSž`ü (µ„;uïå~0F/Ù!žŒ„üÜ܂lab1„üæ= @åÙ́eE„…¹ˆ…TG÷µ„,Œà²I ùŽíղㄈæÆ2User-levelEnvironmentCreationandCooperativeMultitaskingÙ*è„MIT‡c²ã„ÔƒæÆ Æ‚„2¥ýԃZÓã„èʙwe/ˆð¾2.1Round-RobinSchedulingExercise1.Implementround-robinschedulinginsched_yield()asdescribedabove.Don’tforgettomodifysyscall()todispatchsys_yield().Modifykern/init.ctocreatethree(ormore!)environmentsthatallruntheprogramuser/yield.c.Youshouldseetheenvironmentsswitchbackandforthbetweeneachotherfivetimesbeforeterminating,likethis:...Hello,Iamenvironment00001001.Hello,Iamenvironment00001002.Hello,Iamenvironment00001003.Backinenvironment00001001,iteration0.Backinenvironment00001002,iteration0.Backinenvironment00001003,iteration0.Backinenvironment00001001,iteration1.Backinenvironment00001002,iteration1.Backinenvironment00001003,iteration1....Aftertheyieldprogramsexit,theidleenvironmentshouldrunandinvoketheJOSkerneldebugger.Ifanyofthisdoesnothappen,thenfixyourcodebeforeproceeding.schedyield()ýpԃ€U ô¥4ã†kern/sched.c:schedyield()1void2sched_yield(void)3{4structEnv*curenvptr=curenv;56if(curenv==NULL)7curenvptr=envs;89intround=0;3Í\ûߞ`¥J,0084823110for(curenvptr++;roundNENV;round++,curenvptr++){1112if(curenvptr=envs+NENV){13curenvptr=envs+1;14}1516if(curenvptr-env_status==ENV_RUNNABLE)17env_run(curenvptr);18}1920//Runthespecialidleenvironmentwhennothingelseisrunnable.21if(envs[0].env_status==ENV_RUNNABLE)22env_run(&envs[0]);23else{24cprintf(Destroyedallenvironments-nothingmoretodo!\n);25while(1)26monitor(NULL);27}28}6î9kern/syscall.cû øs„Ñ:6 6(kern/init.c-ûß/¨Kúuseridleåúuseryield Ù*(7 „Ÿý1/\”!sysyield()„ûß( vböSpøs„ˆo:kern/init.c:i386init()1//Shouldalwayshaveanidleprocessasfirstone.2ENV_CREATE(user_idle);3ENV_CREATE(user_yield);4ENV_CREATE(user_yield);5ENV_CREATE(user_yield);£H/¨JOS”åSpú ˆoè à:/(RoundRobinVeb @åz”å/nš„ qemu-hdaobj/kern/kernel.img-serialmon:stdio6828decimalis15254octal!Hooray!Passedalltestcasesforstdlib!!Physicalmemory:66556Kavailable,base=640K,extended=65532Kcheck_page_alloc()succeeded!page_check()succeeded!check_boot_pgdir()succeeded!enabledinterrupts:12Setuptimerinterruptsvia8259Aenabledinterrupts:012unmaskedtimerinterrupt[00000000]newenv00001000[00000000]newenv00001001[00000000]newenv00001002[00000000]newenv00001003Hello,Iamenvironment00001001.Hello,Iamenvironment00001002.Hello,Iamenvironment00001003.Backinenvironment00001001,iteration0.Backinenvironment00001002,iteration0.Backinenvironment00001003,iteration0.Backinenvironment00001001,iteration1.Backinenvironment00001002,iteration1.Backinenvironment00001003,iteration1.Backinenvironment00001001,iteration2.Backinenvironment00001002,iteration2.Backinenvironment00001003,iteration2.Backinenvironment00001001,iteration3.4Í\ûߞ`¥J,00848231Backinenvironment00001002,iteration3.Backinenvironment00001003,iteration3.Backinenvironment00001001,iteration4.Alldoneinenvironment00001001.[00001001]exitinggracefully[00001001]freeenv00001001Backinenvironment00001002,iteration4.Alldoneinenvironment00001002.[00001002]exitinggracefully[00001002]freeenv00001002Backinenvironment00001003,iteration4.Alldoneinenvironment00001003.[00001003]exitinggracefully[00001003]freeenv00001003WelcometotheJOSkernelmonitor!Type’help’foralistofcommands.QuestionInyourimplementationofenv_run()youshouldhavecalledlcr3().Beforeandafterthecalltolcr3(),yourcodemakesreferences(atleastitshould)tothevariablee,theargumenttoenv_run.Uponloadingthe%cr3register,theaddressingcontextusedbytheMMUisinstantlychanged.Butavirtualaddress(namelye)hasmeaningrelativetoagivenaddresscontext--theaddresscontextspecifiesthephysicaladdresstowhichthevirtualaddressmaps.Whycanthepointerebedereferencedbothbeforeandaftertheaddressingswitch?ìHeÞ~ envrun()̄wSãkern/env.c:envrun()1void2env_run(structEnv*e)3{4if(curenv!=e){5curenv=e;6curenv-env_runs++;7lcr3(curenv-env_cr3);8}

1 / 41
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功