コード例 #1
0
int main(int argSize, char ** argArray)
{
	unsigned repeat = 1, input;
	
	while (repeat == 1)
	{
		input = 5;
		printf("Main memory to Cache mapping:\n");
		printf("-----------------------------\n");
		printf("1) Set parameters\n");
		printf("2) Read from cache\n");
		printf("3) Write to cache\n");
		printf("4) Snapshot of cache\n");
		printf("5) Exit\n\n");
		printf("Enter selection: ");
		scanf("%u", &input);
		switch (input)
		{
			case 1:
				inputData();
				break;
			case 2:
				accessCache(1);
				break;
			case 3:
				accessCache(2);
				break;
			case 4:
				printLine();
				break;
			case 5:
				printf("Goodbye.\n");
				resetData();
				repeat = 0;
				break;
			default:
				printf("Please enter 1, 2, 3, 4 or 5...\n\n");
		}
	}
	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: charlesweng/school
int main ()
{
	int blocksize = 8;
	int cachesize = 32;
	int type = 1;

	Cache* myCache;
	myCache = createAndInitialize(blocksize, cachesize, type);
	printCache(myCache);
	printTagArray(myCache);
	int i;
	for (i = 0; i < 64; i++)
	{
		accessCache(myCache, i);
	}
	printTagArray(myCache);
}
コード例 #3
0
ファイル: csim.c プロジェクト: GHScan/DailyProjects
int main(int argc, char *argv[]) {
    int opt = 0;
    int setBitCount = 1, blockBitCount = 1, associativity = 1;
    while ((opt = getopt(argc, argv, "hvs:E:b:t:")) != -1) {
        switch(opt) {
            case 'h':
                printf(
                        "Usage: %s [-hv] -s <num> -E <num> -b <num> -t <file>\n"
                        "Options:\n"
                        "-h         Print this help message.\n"
                        "-v         Optional verbose flag.\n"
                        "-s <num>   Number of set index bits.\n"
                        "-E <num>   Number of lines per set.\n"
                        "-b <num>   Number of block offset bits.\n"
                        "-t <file>  Trace file.\n"
                        "\n"
                        "Examples:\n"
                        "linux>  %s -s 4 -E 1 -b 4 -t traces/yi.trace\n"
                        "linux>  %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0], argv[0], argv[0]);
                break;
            case 'v':
                g_isVerbose = 1;
                break;
            case 's':
                setBitCount = atoi(optarg);
                break;
            case 'E':
                associativity = atoi(optarg);
                break;
            case 'b':
                blockBitCount = atoi(optarg);
                break;
            case 't': {
                FILE *traceFile = fopen(optarg, "r");
                dup2(fileno(traceFile), fileno(stdin));
                fclose(traceFile);
              } break;
            default:
                break;
        }
    }

    Cache* cache = setupCache(setBitCount, associativity, blockBitCount, &onCacheHit, &onCacheMiss, &onCacheEviction);
    {
        char buf[32] = "";
        long long addr;
        int size;
        while (scanf("%s %llx,%d", buf, &addr, &size) == 3) {
            printf("%s %llx,%d", buf, addr, size);
            switch (buf[0]) {
                case 'I':
                    break;
                case 'L':
                    accessCache(cache, addr, size);
                    break;
                case 'S':
                    accessCache(cache, addr, size);
                    break;
                case 'M':
                    accessCache(cache, addr, size);
                    accessCache(cache, addr, size);
                    break;
            }
            puts("");
        }
    }
    cleanupCache(cache);

    printSummary(g_hitCount, g_missCount, g_evictionCount);
    return 0;
}
コード例 #4
0
ファイル: trace.c プロジェクト: bking11/CacheSimulator
/* TODO: read trace file function */
struct progOutput* readFile(char * filename, struct Cache * cache, int repPol, int checkSeenBefore){
  FILE *ifp;
  ifp = fopen(filename, "r");
  char mode[2];
  char address[10];



  if (ifp == NULL) {
    fprintf(stderr, "Can't open input file\n");
    exit(1);
  }

  struct progOutput *output = malloc(sizeof(struct progOutput));



  int k = 0;

  output->accessTypes = malloc(sizeof(char * ) * 1000000);
  output->accessAdresses = malloc(sizeof(char * ) * 1000000);





  output->lines = malloc(sizeof(int) * 1000000);

  for(k = 0; k < MAX_HISTORY_LENGTH; k++){
    output->accessAdresses[k] = malloc(sizeof(char) * 100);
    output->accessTypes[k] = malloc(sizeof(char) * 100);
  }



  output->size = 0;

  int totalReads = 0;
  int totalWrites = 0;

  float missCounter =0.0;
  float totalCounter = 0.0;

  while (fscanf(ifp, "%s %s", mode, address) != EOF) {

    //printf("%s %s ", mode, address);

    memcpy(output->accessTypes[output->size], mode, 2);
    memcpy(output->accessAdresses[output->size], address, 10);


    int ret = accessCache(cache, mode, address, repPol, &totalReads, &totalWrites, checkSeenBefore);

    if(ret == 0){
      totalCounter += 1.0;
      output->lines[output->size] = 0;
      output->size+=1;
      //printf("hit\n");
    }else if(ret == 2){//compulsory
      missCounter += 1.0;
      totalCounter += 1.0;
      output->lines[output->size] = 2;
      output->size+=1;//
      //printf("compulsory\n");

    }else if(ret == 3){//conflict
      missCounter += 1.0;
      totalCounter += 1.0;
      output->lines[output->size] = 3;
      output->size+=1;
      //printf("conflict\n");
    }else {//capacity
      missCounter += 1.0;
      totalCounter += 1.0;
      output->lines[output->size] = 1;
      output->size+=1;
      //printf("capacity\n");
    }
    //if(	(int) strtol(address, NULL, 0) == (int) strtol("0x1ffffde8", NULL, 0) || (int) strtol(address, NULL, 0) == (int) strtol("0x1ffffe48", NULL, 0)){
    //  char c = getchar();
    //}
  }
  fclose(ifp);
  output->totalReads = totalReads;
  output->totalWrites = totalWrites;
  output->missRatio = (missCounter/totalCounter);
  //printf("Reads %d Writes %d Ratio %f\n", totalReads, totalWrites, );
  return output;
}