Fixed eviction time, which caused each value to be evicted

This commit is contained in:
TuDatTr
2020-12-20 18:38:38 +01:00
parent af44e30b65
commit cee998af6b
4 changed files with 8 additions and 183 deletions

View File

@@ -10,6 +10,7 @@
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include "cachelab.h"
int v = 0; /* verbose */
@@ -41,9 +42,9 @@ void print_help() {
}
void init() {
cache = (struct cache_line **) malloc(S*sizeof(struct cache_line *));
cache = (struct cache_line **) malloc(S * sizeof(struct cache_line *));
for (int i = 0; i < S; i++) {
struct cache_line* cache_set = (struct cache_line *) malloc(E*sizeof(struct cache_line));
struct cache_line* cache_set = (struct cache_line *) malloc(E * sizeof(struct cache_line));
cache[i] = cache_set;
for (int j = 0; j < E; j++) {
cache_set[j].v = 0;
@@ -51,6 +52,7 @@ void init() {
cache_set[j].time = 0;
}
}
printf("cache: %ld, cache_set: %ld, cache_line: %ld\n", sizeof(cache), sizeof(cache[0]), sizeof(cache[0][0]));
}
void clean() {
@@ -64,11 +66,13 @@ void clean() {
void accessMem (int addr) {
unsigned int set = ((addr >> b) & ((1LL << s) - 1));
unsigned int tag = addr >> (b + s);
struct cache_line *cache_set = cache[set];
unsigned long evic_time = 0;
unsigned long evic_time = ULONG_MAX;
unsigned int evic_line = 0;
for (int i = 0; i < E; i++) {
if (cache_set[i].tag == tag && cache_set[i].v != 0){
if (cache_set[i].tag == tag && cache_set[i].v == 1){
if (v) { printf("hit "); }
hit++;
cache_set[i].time = time;
@@ -164,11 +168,6 @@ int main(int argc, char *argv[]) {
init();
trace();
for (int i = 0; i < S; i++) {
for (int j = 0; j < E; j++) {
// printf("cache[%d][%d]: %c %x %ul\n", i, j, cache[i][j].v, cache[i][j].tag, cache[i][j].time);
}
}
clean();
printSummary(hit, miss, eviction);

0
src/trace.tmp Normal file
View File