Wednesday, April 9, 2014

VpnToPhyPage(int vpn)
InsertToTLB(int vpn, int phyPage)
int VpnToPhyPage(int vpn)
{
IptEntry* iptPtr = hashIPT(vpn, currentThread->pid)->next;
// loop while there is any entry and is mismatch
while ((iptPtr) &&
( ((int)(iptPtr->vPage)!=vpn) ||
((int)(iptPtr->pid) != currentThread->pid) )
)
{
iptPtr = iptPtr->next;
}
// if entry found then return its physical page otherwise -1
if (iptPtr) return iptPtr->phyPage;
return -1;
}
void InsertToTLB(int vpn, int phyPage)
{
int i = 0; // entry in the TLB
static int FIFOPointer = 0;
// Find any empty space in TLB
for (; iif (machine->tlb[i].valid == false) break;
}
if (i>=TLBSize) i = FIFOPointer;
FIFOPointer = (i+1) % TLBSize;
... (Rest of code given)
}
CZ2005 LAB 3 REPORT SS2 2014
4
int clockAlgorithm(void)
int clockAlgorithm(void)
{
int phyPage;
static int clockPointer = 0;
while (! (
( memoryTable[clockPointer].valid == false) ||
( !memoryTable[clockPointer].dirty && memoryTable[clockPointer].clockCounter == OLD_ENOUGH) ||
( memoryTable[clockPointer].dirty && memoryTable[clockPointer].clockCounter == OLD_ENOUGH + DIRTY_ALLOWANCE)
) )
{
memoryTable[clockPointer].clockCounter++;
clockPointer = (clockPointer + 1) % NumPhysPages;
}
phyPage = clockPointer;
clockPointer = (clockPointer + 1) % NumPhysPages;
return phyPage;
}



No comments:

Post a Comment