- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在写一个缓存模拟器。这个想法是给一个带有命令的输入文件,跟踪该输入模拟缓存函数的结果,以便我们可以跟踪缓存命中和未命中。我已经编写了以下代码,但似乎无法获得正确的输出。我发布我的整个代码是因为我不想对问题可能出在哪里做出假设。谁能告诉我哪里出错了?
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <strings.h>
#include "cachelab.h"
/* Always use a 64-bit variable to hold memory addresses*/
typedef unsigned long long int mem_addr_t;
/* a struct that groups cache parameters together */
typedef struct {
int s; /* 2**s cache sets */
int b; /* cacheline block size 2**b bytes */
int E; /* number of cachelines per set */
int S; /* number of sets, derived from S = 2**s */
int B; /* cacheline block size (bytes), derived from B = 2**b */
} cache_param_t;
int verbosity;
/*
* printUsage - Print usage info
*/
void printUsage(char* argv[])
{
printf("Usage: %s [-hv] -s <num> -E <num> -b <num> -t <file>\n", argv[0]);
printf("Options:\n");
printf(" -h Print this help message.\n");
printf(" -v Optional verbose flag.\n");
printf(" -s <num> Number of set index bits.\n");
printf(" -E <num> Number of lines per set.\n");
printf(" -b <num> Number of block offset bits.\n");
printf(" -t <file> Trace file.\n");
printf("\nExamples:\n");
printf(" %s -s 4 -E 1 -b 4 -t traces/yi.trace\n", argv[0]);
printf(" %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0]);
exit(0);
}
int main(int argc, char **argv)
{
cache_param_t par;
bzero(&par, sizeof(par));
char *trace_file;
char c;
while( (c=getopt(argc,argv,"s:E:b:t:vh")) != -1){
switch(c){
case 's':
par.s = atoi(optarg);
break;
case 'E':
par.E = atoi(optarg);
break;
case 'b':
par.b = atoi(optarg);
break;
case 't':
trace_file = optarg;
break;
case 'v':
verbosity = 1;
break;
case 'h':
printUsage(argv);
exit(0);
default:
printUsage(argv);
exit(1);
}
}
if (par.s == 0 || par.E == 0 || par.b == 0 || trace_file == NULL) {
printf("%s: Missing required command line argument\n", argv[0]);
printUsage(argv);
exit(1);
}
/* TODO: Compute S and B based on information passed in */
//Compute S and B, 2^s and 2^b respectively
par.S = (1 << par.s);
par.B = (1 << par.b);
/* TODO: Initialize a cache */
//Structure for a line
typedef struct {
int valid;
mem_addr_t tag;
int timestamp;
} line_st;
//Structure for a set; a pointer to an array of lines
typedef struct {
line_st *lines;
} cache_set;
//Structure for a cache; a pointer to an array of sets
typedef struct {
cache_set *sets;
} cache_t;
//allocate space for sets and for lines
cache_t cache;
cache.sets = malloc(par.S * sizeof(cache_set));
for (int i = 0; i < par.S; i++) {
cache.sets[i].lines = malloc(sizeof(line_st) * par.E);
}
//counters
int hit_count = 0;
int miss_count = 0;
int eviction_count = 0;
/* TODO: Run the trace simulation */
char act; //L,S,M
int size; //size read in from file
int TSTAMP = 0; //value for LRU
int empty = -1; //index of empty space
int H = 0; //is there a hit
int E = 0; //is there an eviction
int toEvict = 0; //keeps track of what to evict
mem_addr_t addr;
//open the file and read it in
FILE * traceFile = fopen(trace_file, "r");
if (traceFile != NULL) {
//keep going while we have additional lines
//while(feof(traceFile) == 0) {
while(fscanf(traceFile, " %c %llx,%d", &act, &addr, &size) == 3){
if (act != 'I') {
//read the next line and look for string formated as " %c %llx,%d"
//sscanf(traceFile, " %c %llx,%d", &act, &addr, &size);
//fscanf(traceFile, " %c %llx,%d", &act, &addr, &size);
//calculate address tag and set index
mem_addr_t addr_tag = addr >> (par.s + par.b);
int tag_size = (64 - (par.s + par.b));
unsigned long long temp = addr << (tag_size);
unsigned long long setid = temp >> (tag_size + par.b);
//unsigned long long setid = ((addr >> par.b) & (par.S - 1));
cache_set set = cache.sets[setid];
int low = par.E + 1;
for(int e = 0; e < par.E; e++) {
if (set.lines[e].valid == 0) {
empty = e;
}
else if (set.lines[e].valid == 1){
if (TSTAMP < low) {
low = TSTAMP;
toEvict = e;
}
if (set.lines[e].tag == addr_tag) {
hit_count++;
H = 1;
set.lines[e].timestamp = TSTAMP;
TSTAMP++;
}
}
}
//if we have a miss
if (H != 1){
miss_count++;
//if we have an empty line
if (empty > -1) {
set.lines[empty].valid = 1;
set.lines[empty].tag = addr_tag;
set.lines[empty].timestamp = TSTAMP;
TSTAMP++;
}
//if the set is full we need to evict
else if (empty < 0) {
E = 1;
set.lines[toEvict].tag = addr_tag;
set.lines[toEvict].timestamp = TSTAMP;
eviction_count++;
}
}
//if the instruction is M, we will always get a hit
if (act == 'M') {
hit_count++;
}
//if the -v flag is set print out all debug information
if (verbosity == 1) {
printf("%c ", act);
//printf("%llx,%d ", addr_tag, setid);
printf("%llx,%d ", addr, size);
if (H == 1) {
printf("Hit ");
}
else if (H != 1) {
printf("Miss ");
}
if (E == 1) {
printf("Eviction ");
}
if (act == 'M') {
printf("Hit ");
}
printf("\n");
}
empty = -1;
H = 0;
E = 0;
}
}
}
/* TODO: Clean up cache resources */
/* TODO: Print out real results */
printSummary(hit_count, miss_count, eviction_count);
return 0;
}
我正在使用以下示例输入运行我的代码:
S 00600aa0,1
S 7ff000384,4
L 7ff000384,4
L 7ff000384,4
L 00600a20,4
L 7ff000384,4
我的代码产生以下结果:
./ -v -s 2 -E 2 -b 3 -t traces/test.trace
S 600aa0,1 Miss
S 7ff000384,4 Miss
L 7ff000384,4 Hit
L 7ff000384,4 Hit
L 600a20,4 Miss Eviction
L 7ff000384,4 Miss Eviction
hits:2 misses:4 evictions:2
但这是它应该产生的:
./ -v -s 2 -E 2 -b 3 -t traces/test.trace
S 600aa0,1 miss
S 7ff000384,4 miss
L 7ff000384,4 hit
L 7ff000384,4 hit
L 600a20,4 miss eviction
L 7ff000384,4 hit
hits:3 misses:3 evictions:1
谁能告诉我哪里做错了?
编辑:
第二个测试文件:
S 00600aa0,1
I 004005b6,5
I 004005bb,5
I 004005c0,5
S 7ff000398,8
I 0040051e,1
S 7ff000390,8
I 0040051f,3
I 00400522,4
S 7ff000378,8
I 00400526,4
S 7ff000370,8
I 0040052a,7
S 7ff000384,4
I 00400531,2
I 00400581,4
L 7ff000384,4
I 00400585,2
I 00400533,7
S 7ff000388,4
I 0040053a,2
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a20,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a60,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a24,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a70,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a28,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a80,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a2c,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a90,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040057d,4
M 7ff000384,4
I 00400581,4
L 7ff000384,4
I 00400585,2
I 00400533,7
S 7ff000388,4
I 0040053a,2
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a30,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a64,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a34,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a74,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a38,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a84,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a3c,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a94,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040057d,4
M 7ff000384,4
I 00400581,4
L 7ff000384,4
I 00400585,2
I 00400533,7
S 7ff000388,4
I 0040053a,2
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a40,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a68,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a44,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a78,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a48,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a88,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a4c,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a98,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040057d,4
M 7ff000384,4
I 00400581,4
L 7ff000384,4
I 00400585,2
I 00400533,7
S 7ff000388,4
I 0040053a,2
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a50,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a6c,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a54,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a7c,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a58,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a8c,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040053c,3
L 7ff000384,4
I 0040053f,2
I 00400541,4
I 00400545,3
I 00400548,4
L 7ff000378,8
I 0040054c,3
L 7ff000388,4
I 0040054f,2
I 00400551,3
L 00600a5c,4
I 00400554,3
S 7ff00038c,4
I 00400557,3
L 7ff000388,4
I 0040055a,2
I 0040055c,4
I 00400560,3
I 00400563,4
L 7ff000370,8
I 00400567,3
L 7ff000384,4
I 0040056a,3
I 0040056d,3
L 7ff00038c,4
I 00400570,3
S 00600a9c,4
I 00400573,4
M 7ff000388,4
I 00400577,4
L 7ff000388,4
I 0040057b,2
I 0040057d,4
M 7ff000384,4
I 00400581,4
L 7ff000384,4
I 00400585,2
I 00400587,1
L 7ff000390,8
I 00400588,1
L 7ff000398,8
I 004005c5,7
L 00600aa0,1
预期值:
My simulator Reference simulator
(s,E,b) Hits Misses Evicts Hits Misses Evicts
(2,2,3) 196 42 34 201 37 29
(2,4,3) 208 30 14 212 26 10
最佳答案
那里有棘手的错误。我将中间的 for 循环更改为仅设置 empty
如果它已经是 -1,因此它将使用找到的第一个空点,然后一旦找到一个就不会再更改它空位。我还将 low
的初始化修改为 INT_MAX,并通过更改相关的 else
条件来查找最近最少使用的真实值。我还重新排序代码以在寻找逐出候选者之前寻找匹配项,因为找到匹配项会刷新缓存时间戳。您还忘记了在 Miss Eviction 的情况下增加 TSTAMP。
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <strings.h>
#include <limits.h>
//#include "cachelab.h"
/* Always use a 64-bit variable to hold memory addresses*/
typedef unsigned long long int mem_addr_t;
/* a struct that groups cache parameters together */
typedef struct
{
int s; /* 2**s cache sets */
int b; /* cacheline block size 2**b bytes */
int E; /* number of cachelines per set */
int S; /* number of sets, derived from S = 2**s */
int B; /* cacheline block size (bytes), derived from B = 2**b */
} cache_param_t;
int verbosity;
/* printUsage - Print usage info */
void printUsage( char *argv[] )
{
printf( "Usage: %s [-hv] -s <num> -E <num> -b <num> -t <file>\n", argv[0] );
printf( "Options:\n" );
printf( " -h Print this help message.\n" );
printf( " -v Optional verbose flag.\n" );
printf( " -s <num> Number of set index bits.\n" );
printf( " -E <num> Number of lines per set.\n" );
printf( " -b <num> Number of block offset bits.\n" );
printf( " -t <file> Trace file.\n" );
printf( "\nExamples:\n" );
printf( " %s -s 4 -E 1 -b 4 -t traces/yi.trace\n", argv[0] );
printf( " %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0] );
exit( 0 );
}
void printSummary( int hit_count, int miss_count, int eviction_count )
{
printf( "hits: %d misses: %d evictions: %d\n", hit_count, miss_count, eviction_count );
}
int main( int argc, char **argv )
{
cache_param_t par;
bzero( &par, sizeof ( par ) );
char *trace_file;
char c;
while ( ( c = getopt( argc, argv, "s:E:b:t:vh" ) ) != -1 )
{
switch ( c )
{
case 's':
par.s = atoi( optarg );
break;
case 'E':
par.E = atoi( optarg );
break;
case 'b':
par.b = atoi( optarg );
break;
case 't':
trace_file = optarg;
break;
case 'v':
verbosity = 1;
break;
case 'h':
printUsage( argv );
exit( 0 );
default:
printUsage( argv );
exit( 1 );
}
}
if ( par.s == 0 || par.E == 0 || par.b == 0 || trace_file == NULL )
{
printf( "%s: Missing required command line argument\n", argv[0] );
printUsage( argv );
exit( 1 );
}
/* TODO: Compute S and B based on information passed in */
//Compute S and B, 2^s and 2^b respectively
par.S = ( 1 << par.s );
par.B = ( 1 << par.b );
/* TODO: Initialize a cache */
//Structure for a line
typedef struct
{
int valid;
mem_addr_t tag;
int timestamp;
} line_st;
//Structure for a set; a pointer to an array of lines
typedef struct
{
line_st *lines;
} cache_set;
//Structure for a cache; a pointer to an array of sets
typedef struct
{
cache_set *sets;
} cache_t;
//allocate space for sets and for lines
cache_t cache;
cache.sets = malloc( par.S * sizeof ( cache_set ) );
for ( int i = 0; i < par.S; i++ )
{
cache.sets[i].lines = malloc( sizeof ( line_st ) * par.E );
}
//counters
int hit_count = 0;
int miss_count = 0;
int eviction_count = 0;
/* TODO: Run the trace simulation */
char act; //L,S,M
int size; //size read in from file
int TSTAMP = 0; //value for LRU
int empty = -1; //index of empty space
int H = 0; //is there a hit
int E = 0; //is there an eviction
mem_addr_t addr;
//open the file and read it in
FILE *traceFile = fopen( trace_file, "r" );
if ( traceFile != NULL )
{
while ( fscanf( traceFile, " %c %llx,%d", &act, &addr, &size ) == 3 )
{
int toEvict = 0; //keeps track of what to evict
if ( act != 'I' )
{
//calculate address tag and set index
mem_addr_t addr_tag = addr >> ( par.s + par.b );
int tag_size = ( 64 - ( par.s + par.b ) );
unsigned long long temp = addr << ( tag_size );
unsigned long long setid = temp >> ( tag_size + par.b );
cache_set set = cache.sets[setid];
int low = INT_MAX; // CHANGED, also added #include <limits.h>
for ( int e = 0; e < par.E; e++ ) {
if ( set.lines[e].valid == 1 ) {
// CHANGED ORDER: look for hit before eviction candidates
if ( set.lines[e].tag == addr_tag ) {
hit_count++;
H = 1;
set.lines[e].timestamp = TSTAMP;
TSTAMP++;
}
// CHANGED WHOLE ELSE: look for oldest for eviction.
else if ( set.lines[e].timestamp < low ) {
low = set.lines[e].timestamp;
toEvict = e;
}
}
// CHANGED: if we haven't yet found an empty, mark one that we found.
else if( empty == -1 ) {
empty = e;
}
}
//if we have a miss
if ( H != 1 )
{
miss_count++;
//if we have an empty line
if ( empty > -1 )
{
set.lines[empty].valid = 1;
set.lines[empty].tag = addr_tag;
set.lines[empty].timestamp = TSTAMP;
TSTAMP++;
}
//if the set is full we need to evict
else if ( empty < 0 )
{
E = 1;
set.lines[toEvict].tag = addr_tag;
set.lines[toEvict].timestamp = TSTAMP;
TSTAMP++; // CHANGED: increment TSTAMP here too
eviction_count++;
}
}
//if the instruction is M, we will always get a hit
if ( act == 'M' )
{
hit_count++;
}
//if the -v flag is set print out all debug information
if ( verbosity == 1 )
{
printf( "%c ", act );
printf( "%llx,%d", addr, size );
if ( H == 1 )
{
printf( "Hit " );
}
else if ( H != 1 )
{
printf( "Miss " );
}
if ( E == 1 )
{
printf( "Eviction " );
}
// CHANGED: don't print Hit again since 'M' is always going to print Hit above.
printf( "\n" );
}
empty = -1;
H = 0;
E = 0;
}
}
}
/* TODO: Clean up cache resources */
/* TODO: Print out real results */
printSummary( hit_count, miss_count, eviction_count );
return 0;
}
我的结果:
$ ./ca2 -s 2 -E 2 -b 3 -t f2.trace
hits: 201 misses: 37 evictions: 29
$ ./ca2 -s 2 -E 4 -b 3 -t f2.trace
hits: 212 misses: 26 evictions: 10
关于缓存模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23092307/
我使用 iOS 4.2 和 Xcode 3.2.5 创建了一个通用二进制文件。我正在尝试对应用程序进行一些自动化测试,由于 iPad 和 iPhone 版本之间的界面略有不同,因此我有单独的 UIAu
这是一个概念性的问题。如果有人能澄清背后的故事,那就太好了。 我了解模拟器和模拟器之间的区别。 模拟器:模仿设备环境(硬件、网络功能等)。与设备相比,我们更有可能得到非常接近的结果。 模拟器:使用正在
是否有任何现成的解决方案可以模拟或模拟 LDAP 服务器功能? 或者是否可以在 ubuntu 上安装 ldap 服务器(仅适用于 localhost)? 如果它不是来自 localhost 的 jsu
我正在将我的应用程序修复为通用二进制文件。模拟器上的测试似乎默认使用 iPad。对于诸如检查方向和小型 UI 更新之类的小修正,我能找到的获取 iPhone 版本的唯一方法是插入我的 iPhone 并
Emulator: emulator: WARNING: Could not connect to proxy at ::1:8080: Unknown error ! - Android 将 And
我的应用程序在 ios 4.3 模拟器中运行良好,但在 ios 5 模拟器中运行不佳。我的 iPhone 上有 ios 5,我的应用程序确实可以在 iPhone 上运行。 该应用在所有这三种环境中都可
我在 azure 上制作了移动应用程序,并将其快速启动为 xamarian.forms,并且(在未能发布下载的表 api 应用程序并决定在浏览器中编辑它之后)下载了他们提供的客户端应用程序。然后,当我
Emulator: emulator: ERROR: x86 emulation currently requires hardware acceleration! Emulator: Process
我试图在 iOS 10.3 模拟器上将任意文件从我的应用程序的沙箱保存到 iCloud Drive。 iCloud Drive 已启用并且我已登录。如果我在模拟器上打开 iCloud Drive 应用
有谁知道一个小型、快速、支持 DOM 层的 javascript 模拟器?在 C/C++ 中? 问题:我需要在爬虫应用程序中对 javascript 的基本支持,并且想知道除了以下选项之外是否还有其他
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我是 Xcode 开发新手。我在基于 Lion 的 Mac 上安装了 Xcode 4.3.1,并取消设置 ~/Library 上的隐藏标志。 我在这里读到了有关 iPhone/iPad 模拟器的信息
我已在 VisualStudio 2015 AZURE SDK 2.9、C# 中创建辅助角色 我在每个方法的开头添加了断点: public override void Run() {
全部。我已经安装了 Azure SDK 1.7。解决方案中的所有程序集都是使用“任何 CPU”设置进行编译的。但是当我在我的计算机上的 Azure 模拟器中启动解决方案时,其中之一失败了。该错误非常奇
有没有独立的 WAP 模拟器来模拟诺基亚 6600 和索尼爱立信 MIDP 手机的 waop 网站? 我正在创建一个 WAP 门户,我不想每次都将所有文件上传到网络上,然后将其加载到 Opera Mi
我已经安装了 Tizen 的 Visual Studio Code 扩展,并且(看起来)进展顺利。 但是,当我启动 Tizen 模拟器管理器时,我没有安装任何平台,并且当我尝试安装平台时,没有可用的平
我目前正在我的 jquery mobile/phonegap 应用程序中处理表单。在此表单中,我有两个选择列表。它们在我的桌面浏览器(firefox、safari、chrome)中都能正常工作。 奇怪
我尝试制作一个分辨率为 480x480 像素的模拟器。但是模拟器永远不会完成启动。它卡在 Android Logo 页面上。分辨率有限制吗? 最佳答案 模拟器 is not smart about s
我不知道如何在虚拟设备上启用快照功能。该选项是灰色的,创建或编辑虚拟设备时没有设置。我使用的是最新版本的 SDK 工具修订版 22.6.3 这是我的窗口的样子:Create new Android V
我正在尝试使用具有特定屏幕分辨率的模拟器,但是当我将屏幕参数设置为我需要的参数时,键盘消失了。这样我就没有后退按钮,主页按钮..任何想法如何解决这个问题?这是我在 AVD 管理器中设置的:屏幕分辨率:
我是一名优秀的程序员,十分优秀!