Skip to content

Commit

Permalink
file cache tests (#25)
Browse files Browse the repository at this point in the history
* file cache tests

* memalign
  • Loading branch information
vanshcsingh authored Mar 7, 2020
1 parent d20368c commit 5962229
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MY_OPT = -g -O0
LIBS = -lm -pthread
default: main.c constants.h benchmark.h cpu_tests.h context_switch.h mem_tests.h file_contention.h
default: main.c constants.h benchmark.h cpu_tests.h context_switch.h mem_tests.h file_cache.h file_contention.h
gcc $(MY_OPT) -o test.out main.c $(LIBS) $(ARGS)
clean:
rm -f *.out
Expand Down
2 changes: 1 addition & 1 deletion constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ const uint32_t MEASUREMENT_OVERHEAD = 40;
#if !defined(ICACHE_HITS)
// empirically tested number of consecutive function calls for a function
// pointer to be in I_CACHE
const uint32_t ICACHE_HITS = 0;
const uint32_t ICACHE_HITS = 10;
#endif
61 changes: 61 additions & 0 deletions file_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <stdio.h>
#include <time.h>

#include "benchmark.h"

#define BLOCK_SIZE 4096

const long MB = 1024*1024;
const long GB = 1024*1024*1024;

// const char* FILES[] = {
// "fs/64m.o", "fs/128m.o", "fs/512m.o",
// "fs/1g.o", "fs/2g.o", "fs/6g.o",
// "fs/8g.o", "fs/12g.o", "fs/16g.o"
// };

const char* FILES[] = {
"fs/128m.o", "fs/7g.o", "fs/13g.o", "fs/15g.o",
};
#define FILE_NUM 3

void run_fileCache() {

const int iterations = 10;
const int cache_iterations = 10;
char *blockbuf = malloc(BLOCK_SIZE);
posix_memalign(&blockbuf, BLOCK_SIZE, BLOCK_SIZE);

char testname[50] = {0};

for (int i = 0; i < FILE_NUM; i++) {
const char* filename = FILES[i];

FILE* fd = fopen(filename, "r");
fseek(fd, 0L, SEEK_END);
const long filesize = ftell(fd);
const long blockcount = filesize / BLOCK_SIZE;

void test() {
// bring file pointer to the top
fseek(fd, 0, SEEK_SET);
while (fread(blockbuf, sizeof(char), BLOCK_SIZE, fd) == BLOCK_SIZE);
printf("not ok");
};

// perform operation on the cycles returned
uint64_t mod(uint64_t benchmark_result) {
return benchmark_result / blockcount;
}

sprintf(testname, "4KB block access time on %ld size file", filesize);

// run the "mod" operation on the result of every benchmark(test) call
runTestMod(benchmarkCycles, test, testname, 1, 10, mod);

fclose(fd);
}
}

63 changes: 40 additions & 23 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "page_fault.h"
#include "ram_bandwidth.h"
#include "mem_tests.h"
#include "file_cache.h"
#include "file_contention.h"

// 10000 iterations empirically adds the test's instruction address in the I-Cache
Expand Down Expand Up @@ -39,26 +40,42 @@ int main() {
// runTest(benchmark_pf, NULL, "Page Fault access time + RAM access time", ITERATIONS, TRIALS);
// runTest(benchmarkReadRamBandwidth, NULL, "RAM Bandwidth read", ITERATIONS, TRIALS);
// runTest(benchmarkWriteRamBandwidth, NULL, "RAM Bandwidth write", ITERATIONS, TRIALS);
// runTest(benchmarkContention0, NULL, "Contention with 0 processes", ITERATIONS, TRIALS);
// runTest(benchmarkContention1, NULL, "Contention with 1 processes", ITERATIONS, TRIALS);
// runTest(benchmarkContention2, NULL, "Contention with 2 processes", ITERATIONS, TRIALS);
runContention(1);
runContention(2);
runContention(3);
runContention(4);
runContention(5);
runContention(6);
runContention(7);
runContention(8);
runContention(9);
runContention(10);
runContention(20);
runContention(30);
runContention(40);
runContention(50);
runContention(60);
runContention(70);
runContention(80);
runContention(90);
runContention(100);
}

// run_memoryAccessTest(ITERATIONS, TRIALS, 100000, 1024);
// run_memoryAccessTest(ITERATIONS, TRIALS, 200000, 1024);
// run_memoryAccessTest(ITERATIONS, TRIALS, 300000, 1024);
// run_memoryAccessTest(ITERATIONS, TRIALS, 400000, 1024);
// run_memoryAccessTest(ITERATIONS, TRIALS, 500000, 1024);
// run_memoryAccessTest(m_benchmarkMeasurementOverhead, ITERATIONS, TRIALS, 600000, 1024);
// run_memoryAccessTest(m_benchmarkMeasurementOverhead, ITERATIONS, TRIALS, 700000, 1024);
// run_memoryAccessTest(m_benchmarkMeasurementOverhead, ITERATIONS, TRIALS, 800000, 1024);
// run_memoryAccessTest(m_benchmarkMeasurementOverhead, ITERATIONS, TRIALS, 900000, 1024);
// run_memoryAccessTest(m_benchmarkMeasurementOverhead, ITERATIONS, TRIALS, 1000000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, 600000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, 700000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, 800000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, 900000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, 1000000, 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, pow(2,20), 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, pow(2,21), 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, pow(2,22), 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, pow(2,21) + pow(2,22), 1024);
// run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, pow(2,23), 1024);
//run_memoryAccessTest(m_benchmarkAccessTime, ITERATIONS, TRIALS, , 1024);
run_fileCache();
// runContention(1);
// runContention(2);
// runContention(3);
// runContention(4);
// runContention(5);
// runContention(6);
// runContention(7);
// runContention(8);
// runContention(9);
// runContention(10);
// runContention(20);
// runContention(30);
// runContention(40);
// runContention(50);
// runContention(60);
}

0 comments on commit 5962229

Please sign in to comment.