



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




references a data structure for the first time and is going to cause a TLB miss, then a page fault
CAT is reading a large portion of a file to the disk (which succeeds)
NET is sending a large network packet out
APP APP APP UTIL UTIL
KERNEL
HARDWARE
OPERATING SYSTEM
APP APP is running executes load/store, causes TLB miss (say the TLB is software-managed)
TLBMISS interrupt save EPC/EPC+ turn on privs. vector to TLBMISS
TLBMISS entry point: build address for PTE load PTE insert into TLB jump to EPC + turn off privileges
Retries load/store instruction (we jumped to EPC, not EPC+1) this time, it succeeds APP keeps running, oblivious
TIMER interrupt save EPC/EPC+ turn on privs. vector to TIMER
TIMER entry point: Evidently, APP has exceeded its quota
call scheduler()
function scheduler : check RunQ for another process: is there another? yes — CAT copy CPU state to u.state (registers, etc.) put EPC+1 into u.nextPC put CAT into ASID register
copy u.state into CPU + reset timer put u.nextPC into register jump to register + turn off privileges
CAT begins executing from where it last left off calls read(fd, &buf, 64K) read() is a library routine: puts address of BUF into u.base_addr puts 64K into u.count puts SYSCALL_READ into reg puts FD into reg calls SYSCALL -- interrupts machine
SYSCALL interrupt save EPC/EPC+ turn on privs. vector to SYSCALL
SYSCALL entry point: looks in reg1: SYSCALL_READ looks in reg2: FILEDES looks in u.filedes[FILEDES] for state of device call function devices[DEV].entrypoint[SYSCALL-READ] with args: OUT: u.base_addr, SIZE: u.count, DISKBLOCK: u.filedes[FILEDES].curblock
[this sets up transfers from DISK to internal buffer pool, then copies data from the buffers (once they are full) into user space, one buffer at a time, each time incrementing u.base_addr and decrementing u.count]
function devices[DEV].entrypoint[SYSCALL-READ] : sends request to DISK: get block u.filedes[FILEDES].curblock goes to sleep on u.filedes[FILEDES].curblock
copy u.state into CPU + reset timer put u.nextPC into register jump to register + turn off privileges
APP APP begins executing from where it last left off
DEVICE interrupt save EPC/EPC+ turn on privs. vector to device[DEV].intr()
device[DEV].intr entry point: happens to be DEV = disk: block BLOCKNUM is here wakeup(BLOCKNUM) anyone sleeping on BLOCKNUM? yes -- this is what CAT was waiting for awaken() sleeping kernel thread
copy CPU state to u.state put EPC+1 into u.nextPC put CAT into ASID register (to get access to CAT’s u. struct & VM space)
copy u.state into CPU + reset timer put u.kernPC into register jump to register + turn on privileges
… jumps to 1st instruction after sleep()
… in function devices[DEV].entrypoint[SYSCALL-READ] :
copy block BLOCKNUM from disk to internal buffer copyout(u.base_addr, block, blocksize) u.base_addr += blocksize; u.count -= blocksize; if (u.count == 0) { make CAT active again } else { get next block (or portion thereof) }
[assume we’re done ... u.count == 0]
CAT u.status_of_syscall = DONE move CAT from SleepQ to RunQ
[at this point, we have two choices. we can either go back to APP, who was preempted by the disk I/O, or we can restart CAT. perhaps we want to look at the timing logs -- if CAT had previously eaten up very little of its quantum, then maybe we jump straight to it. ... there is room for choices ... assume that the copyin & copyout took a while ... CAT doesn’t have much time left to it (it would execute very few instructions before ending its quantum). so we return to APP]
function scheduler : check RunQ for another process: is there another? yes — APP copy CPU state to u.state (registers, etc.) — [ may not be necessary ] put EPC+1 into u.nextPC put APP into ASID register
copy u.state into CPU + reset timer put u.nextPC into register jump to register + turn off privileges
APP APP begins executing from where it last left off
DEVICE interrupt save EPC/EPC+ turn on privs. vector to device[DEV].intr()
device[DEV].intr entry point: happens to be NUM = network controller: ready for data on PORTNUM wakeup(PORTNUM) anyone sleeping on PORTNUM? yes -- NET was waiting for this awaken( ) sleeping kernel thread
copy CPU state to u.state put EPC+1 into u.nextPC put NET into ASID register
copy u.state into CPU + reset timer put u.kernPC into register jump to register + turn on privileges
… jumps to 1st instruction after sleep()
… in function devices[DEV].entrypoint[SYSCALL_WRITE]:
copies bytes from buffer to network controller if it all fits, we can stop if the network controller can take only a portion, we go to sleep again
[if there had not been room in the driver to copy bytes in, we also would have to sleep, but at a different place.]
assume we are done.
call scheduler()
function scheduler : check RunQ for another process: is there another? yes — APP copy CPU state to u.state (registers, etc.) put EPC+1 into u.nextPC put APP into ASID register
copy u.state into CPU + reset timer put u.nextPC into register jump to register + turn off privileges
APP APP begins executing from where it last left off, again. This time, it performs another load/store that causes a TLB miss
TLBMISS interrupt save EPC/EPC+ turn on privs. vector to TLBMISS
TLBMISS entry point: build address for PTE load PTE
[oops -- the PTE says that it is currently not a valid translation -- that the data is not in memory but on disk. here is a design choice: do we actually CHECK the PTE or do we blindly put it into the TLB? checking will increase overhead of the common case by 20- 30%. MIPS solution : put it blindly into TLB]
APP insert into TLB jump to EPC + turn off privileges
Retries load/store instruction (we jumped to EPC, not EPC+1) it fails again, but this time, with a different interrupt type: this time, the mapping is in the TLB, so we don’t miss, but the mapping is INVALID, so we get a PAGE FAULT.
PAGEFAULT interrupt save EPC/EPC+ turn on privs. vector to PAGEFAULT
PAGEFAULT entry point: look at PTE -- what are its flags? says that page is on disk, not in memory
THIS IS WHERE LIFE GETS WEIRD.