-
Notifications
You must be signed in to change notification settings - Fork 0
/
hat.c
58 lines (53 loc) · 1.89 KB
/
hat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "hat.h"
bool HAT_Init() {
ASSERT_PRINT("Entering:HAT_Init()\n");
HAT = calloc(NumOfPagesInMM, sizeof (IPT_t));
int i = 0;
for (i = 0; i < NumOfPagesInMM; i++) {
HAT[i] = 0;
}
if (!HAT)
return FALSE;
else
return TRUE;
ASSERT_PRINT("Exiting:HAT_Init()\n");
}
int HAT_PRIVATE_Hash(MemoryAddress_t memoryAddress) {
ASSERT_PRINT("Entering:HAT_PRIVATE_Hash(pid:%d,addr:%d)\n", memoryAddress.processID, memoryAddress.pageNumber);
ASSERT_PRINT("Exiting:HAT_PRIVATE_Hash(pid:%d,addr:%d)\n", memoryAddress.processID, memoryAddress.pageNumber);
return (memoryAddress.processID+1 * memoryAddress.pageNumber+1) % NumOfPagesInMM;
}
IPT_t_p HAT_GetEntry(MemoryAddress_t memoryAddress) {
ASSERT_PRINT("Entering:HAT_GetEntry(pid:%d,addr:%d)\n", memoryAddress.processID, memoryAddress.pageNumber);
int index = HAT_PRIVATE_Hash(memoryAddress);
if(HAT[index]==0)
{
HAT[index] = IPT[index];
}
ASSERT_PRINT("Exiting:HAT_GetEntry(pid:%d,addr:%d)\n", memoryAddress.processID, memoryAddress.pageNumber);
return IPT[index];
}
void HAT_Print()
{
ASSERT_PRINT("Entering: HAT_Print()\n");
int i=0;
for (i = 0; i < NumOfPagesInMM; i++) {
int j=0;
if(HAT[i] == 0)
fprintf(outFile,"\nHAT[%d])Null",i);
else
{
IPT_t_p entery = HAT[i];
fprintf(outFile,"\nHAT[%d])",i);
while(entery!=NULL)
{
fprintf(outFile,"PID:%d,PageNumber:%d,Frame:%d,Dirty:%s,Reference:%s ",entery->processID,entery->pageNumber,entery->frame,(entery->dirtyBit)?"true":"false",(entery->referenceBit)?"true":"false");
if(entery->next!=NULL)
fprintf(outFile,"-->");
entery = entery->next;
}
fprintf(outFile,"\n");
}
}
ASSERT_PRINT("Exiting: HAT_Print()\n");
}