forked from jaskaran1312/dstn-assignment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlru.c
34 lines (30 loc) · 918 Bytes
/
lru.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
#include <stdio.h>
#include <stdlib.h>
#include "hardware.h"
#include "lru.h"
int64_t getMMLRU(struct Hardware *hardware) {
int64_t frameNumber;
int64_t minLRU=__INT_MAX__;
for(int i=0;i<65536;i++) {
if(hardware->mainMemory->lru[i] <= minLRU){
minLRU = hardware->mainMemory->lru[i];
frameNumber = i;
}
}
printf("Frame Number to be evicted from MM is %ld\n", frameNumber);
return frameNumber;
}
void shiftMMLRU(struct Hardware *hardware) {
printf("Start Shifted MMLRU\n");
fflush(stdout);
for(int i=0;i<65536;i++) {
hardware->mainMemory->lru[i] = hardware->mainMemory->lru[i] >> 1;
}
printf("Shifted MMLRU\n");
fflush(stdout);
return;
}
void updateMMLRU(struct Hardware *hardware, int64_t frameNumber) {
hardware->mainMemory->lru[frameNumber] = hardware->mainMemory->lru[frameNumber] | 0x8000;
return;
}