Open arjunhm opened 1 month ago
Issue is in evict()
.
Returns -1
if not using sleep()
should have associated sleep()
with the fact that I am using timestamps for LRU
if (c->sets[set_index].lines[i].timestamp <= min_timestamp)
. Changing <
to <=
fixes the issue. Because the time was the same?
Turns out time(NULL)
returns the seconds. naturally would run into conflicts here
switched to counter.
but it would fail if I used it like this
for (int i = 0; i < c->line_count; i++) {
Line l = c->sets[set_index].lines[i]; // storing in variable was the issue
if (l.valid == 1 && l.tag == tag) {
l.lru = lru_counter++;
c->stats->hits++;
return;
}
}
but works if I use this
for (int i = 0; i < c->line_count; i++) {
if (c->sets[set_index].lines[i].valid == 1 &&
c->sets[set_index].lines[i].tag == tag) {
c->sets[set_index].lines[i].lru = lru_counter++;
c->stats->hits++;
return;
}
}
Line l = c->sets[set_index].lines[i]
creates local copy.
instead use Line *l = &(...)
Getting segmentation fault, but works fine if
sleep(1)
is used.7295cef