-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththrashing.c
30 lines (26 loc) · 889 Bytes
/
thrashing.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
#include <stdint.h>
#include <stdio.h>
#include "hardware.h"
#define COUNT 15000
/*
To detect thrashing, we are using the same LRU bits of Main Memory.
The limitation here is the number of counters and so the approximation is as follows:
1) Right shift the LRU counters after every 5000 instrctions.
2) Check for thrashing after every 50k instructions.
3) Include in Working Set if the 10 most significant bit are non zero
4) If the size of Working Set is greater than 32k, thrashing detected.
*/
short isThrashing(struct Hardware *hardware) {
int workingSetCount = 0;
for (int i = 0; i < 65536; i++) {
if (((hardware->mainMemory->lru[i] >> 6) & 0x3FF) > 0)
workingSetCount++;
}
if (workingSetCount > COUNT) {
printf("Thrashing Detected\n");
return 1;
} else {
printf("No Thrashing Detected\n");
return 0;
}
}