缓存模拟器WriteBack与WriteThrough和WriteAllocate与WriteNoAllocate

时间:2015-05-09 21:52:00

标签: caching

我正在实现一个缓存模拟器,用户可以在其中指定write_allocate或write_no_allocate,write_back或write_through,以及其他变量,如关联性和块大小。我们只是跟踪数据/指令访问,未命中和替换的数量,而不是跟踪“内存”。

对于更简单的测试用例,我得到了正确的结果,但是对于更大的跟踪文件,这会发生变化。常见的错误是我通常注册的失误和替换太少(使用相同的数字),所以很明显有些时候它应该是一个未命中+替换它将它解释为命中。我希望有人可以检查我的逻辑关于write_back vs write_through和write_allocate vs write_no_allocate。我的init,搜索,插入和删除方法肯定是正确的(我很确定),但这是我的performAccess方法,它杀了我。这是我对instruction_loads的伪代码,其中LRU_head是缓存中每个集合的cache_line“head”数组,您可以在其中指定您关心索引的集合。

If(INSTRUCTION_LOAD){

inst_accesess++;
if(LRU_head[index] == NULL) //miss no replacement
    inst_misses++;
    constructed = makeLine(tag);
    //insert constructed into set with correct index

    else if (search == false){ //miss, maybe replacement
    inst_misses++;
    constructedLine = makeLine(tag);
    if(room_in_set(index) == true){
    //insert constructed into set with correct index
    }
    else{ //LRU line will be evicted to make room
    inst_replacements++;
    //delete an entry based on Least Recently Used
    //insert constructed into that now vacated spot
    }

    else{ //hit
    //delete and insert it to make it most recently used element for LRU purposes
    }
}

我想澄清的是write_alloc vs write_no_allocate是否应该只影响data_store命令的未命中/替换,而write_back vs write_through应该只影响在刷新缓存时或者当一行被驱逐时复制回内存的单词腾出空间?我获得了数据和指令命令的正确访问次数,但它是未命中/替换,虽然我认为这些应该非常简单。

0 个答案:

没有答案