diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..24c6130 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "cachesim.h": "c", + "cstdlib": "c", + "math.h": "c" + } +} \ No newline at end of file diff --git a/Outputs/part1.txt b/Outputs/part1.txt new file mode 100644 index 0000000..420701c --- /dev/null +++ b/Outputs/part1.txt @@ -0,0 +1,38 @@ +login-20-26:/CS5375$ gcc cachesim.c -o cachesim +login-20-26:/CS5375$ ./cachesim direct ./trace_for_students/trace.hpcg + +================================== +Cache type: Direct-Mapped Cache +================================== +Cache Hits: 1301327 +Cache Misses: 198673 +Cache Hit Rate: 86.755135% +Cache Miss Rate: 13.244867% +login-20-26:/CS5375$ ./cachesim direct ./trace_for_students/trace.stream + +================================== +Cache type: Direct-Mapped Cache +================================== +Cache Hits: 1059918 +Cache Misses: 2174137 +Cache Hit Rate: 32.773651% +Cache Miss Rate: 67.226341% +login-20-26:/CS5375$ ./cachesim direct ./trace_for_students/trace.stream_10 + +================================== +Cache type: Direct-Mapped Cache +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate: 0.000000% +Cache Miss Rate: 100.000000% +login-20-26:/CS5375$ ./cachesim direct ./trace_for_students/trace.stream_20 + +================================== +Cache type: Direct-Mapped Cache +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate: 20.000000% +Cache Miss Rate: 80.000000% +login-20-26:/CS5375$ diff --git a/Outputs/part2_Q1_tracehpcg.txt b/Outputs/part2_Q1_tracehpcg.txt new file mode 100644 index 0000000..ef49f24 --- /dev/null +++ b/Outputs/part2_Q1_tracehpcg.txt @@ -0,0 +1,159 @@ +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.hpcg +Select 1 to execute Question 1 or 2 to Question 2 :1 +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1288305 +Cache Misses: 211695 +Cache Hit Rate : 85.887001038% +Cache Miss Rate : 14.112999916% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1271623 +Cache Misses: 228377 +Cache Hit Rate : 84.774864197% +Cache Miss Rate : 15.225132942% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1277153 +Cache Misses: 222847 +Cache Hit Rate : 85.143531799% +Cache Miss Rate : 14.856466293% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1278586 +Cache Misses: 221414 +Cache Hit Rate : 85.239067078% +Cache Miss Rate : 14.760933876% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1299112 +Cache Misses: 200888 +Cache Hit Rate : 86.607467651% +Cache Miss Rate : 13.392533302% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1281291 +Cache Misses: 218709 +Cache Hit Rate : 85.419395447% +Cache Miss Rate : 14.580599785% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1287229 +Cache Misses: 212771 +Cache Hit Rate : 85.815269470% +Cache Miss Rate : 14.184732437% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1288697 +Cache Misses: 211303 +Cache Hit Rate : 85.913131714% +Cache Miss Rate : 14.086866379% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1429196 +Cache Misses: 70804 +Cache Hit Rate : 95.279731750% +Cache Miss Rate : 4.720266342% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1341934 +Cache Misses: 158066 +Cache Hit Rate : 89.462265015% +Cache Miss Rate : 10.537733078% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1348062 +Cache Misses: 151938 +Cache Hit Rate : 89.870796204% +Cache Miss Rate : 10.129199982% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1344947 +Cache Misses: 155053 +Cache Hit Rate : 89.663139343% +Cache Miss Rate : 10.336867332% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q1_tracestream.txt b/Outputs/part2_Q1_tracestream.txt new file mode 100644 index 0000000..50db7de --- /dev/null +++ b/Outputs/part2_Q1_tracestream.txt @@ -0,0 +1,159 @@ +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream +Select 1 to execute Question 1 or 2 to Question 2 :1 +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1054393 +Cache Misses: 2179662 +Cache Hit Rate : 32.602817535% +Cache Miss Rate : 67.397186279% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1047765 +Cache Misses: 2186290 +Cache Hit Rate : 32.397872925% +Cache Miss Rate : 67.602127075% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1048044 +Cache Misses: 2186011 +Cache Hit Rate : 32.406501770% +Cache Miss Rate : 67.593505859% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 1047903 +Cache Misses: 2186152 +Cache Hit Rate : 32.402141571% +Cache Miss Rate : 67.597862244% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1068994 +Cache Misses: 2165061 +Cache Hit Rate : 33.054290771% +Cache Miss Rate : 66.945709229% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1062504 +Cache Misses: 2171551 +Cache Hit Rate : 32.853614807% +Cache Miss Rate : 67.146385193% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1062487 +Cache Misses: 2171568 +Cache Hit Rate : 32.853092194% +Cache Miss Rate : 67.146911621% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 1062604 +Cache Misses: 2171451 +Cache Hit Rate : 32.856708527% +Cache Miss Rate : 67.143287659% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1082336 +Cache Misses: 2151719 +Cache Hit Rate : 33.466838837% +Cache Miss Rate : 66.533157349% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1059297 +Cache Misses: 2174758 +Cache Hit Rate : 32.754451752% +Cache Miss Rate : 67.245552063% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1062298 +Cache Misses: 2171757 +Cache Hit Rate : 32.847248077% +Cache Miss Rate : 67.152755737% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 1061428 +Cache Misses: 2172627 +Cache Hit Rate : 32.820343018% +Cache Miss Rate : 67.179656982% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q1_tracestream_10.txt b/Outputs/part2_Q1_tracestream_10.txt new file mode 100644 index 0000000..1543dce --- /dev/null +++ b/Outputs/part2_Q1_tracestream_10.txt @@ -0,0 +1,159 @@ +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream_10 +Select 1 to execute Question 1 or 2 to Question 2 :1 +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q1_tracestream_20.txt b/Outputs/part2_Q1_tracestream_20.txt new file mode 100644 index 0000000..8040d80 --- /dev/null +++ b/Outputs/part2_Q1_tracestream_20.txt @@ -0,0 +1,160 @@ + +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream_20 +Select 1 to execute Question 1 or 2 to Question 2 :1 +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 3 +Cache Misses: 17 +Cache Hit Rate : 15.000000954% +Cache Miss Rate : 85.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 3 +Cache Misses: 17 +Cache Hit Rate : 15.000000954% +Cache Miss Rate : 85.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 3 +Cache Misses: 17 +Cache Hit Rate : 15.000000954% +Cache Miss Rate : 85.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 1 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 16 BYTES cache line size ========== +================================== +Cache Hits: 3 +Cache Misses: 17 +Cache Hit Rate : 15.000000954% +Cache Miss Rate : 85.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 2 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 32 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : 3 +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION FOR 128 BYTES cache line size ========== +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q2_tracehpcg.txt b/Outputs/part2_Q2_tracehpcg.txt new file mode 100644 index 0000000..1c2b991 --- /dev/null +++ b/Outputs/part2_Q2_tracehpcg.txt @@ -0,0 +1,172 @@ + +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.hpcg +Select 1 to execute Question 1 or 2 to Question 2 :2 +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1313931 +Cache Misses: 186069 +Cache Hit Rate : 87.595397949% +Cache Miss Rate : 12.404600143% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1267220 +Cache Misses: 232780 +Cache Hit Rate : 84.481338501% +Cache Miss Rate : 15.518667221% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1268209 +Cache Misses: 231791 +Cache Hit Rate : 84.547271729% +Cache Miss Rate : 15.452733994% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1294809 +Cache Misses: 205191 +Cache Hit Rate : 86.320602417% +Cache Miss Rate : 13.679400444% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1321396 +Cache Misses: 178604 +Cache Hit Rate : 88.093063354% +Cache Miss Rate : 11.906932831% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1298104 +Cache Misses: 201896 +Cache Hit Rate : 86.540260315% +Cache Miss Rate : 13.459733009% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1304418 +Cache Misses: 195582 +Cache Hit Rate : 86.961196899% +Cache Miss Rate : 13.038800240% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1303147 +Cache Misses: 196853 +Cache Hit Rate : 86.876464844% +Cache Miss Rate : 13.123533249% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1325088 +Cache Misses: 174912 +Cache Hit Rate : 88.339195251% +Cache Miss Rate : 11.660799980% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1317601 +Cache Misses: 182399 +Cache Hit Rate : 87.840065002% +Cache Miss Rate : 12.159933090% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1316971 +Cache Misses: 183029 +Cache Hit Rate : 87.798065186% +Cache Miss Rate : 12.201933861% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1317500 +Cache Misses: 182500 +Cache Hit Rate : 87.833335876% +Cache Miss Rate : 12.166666985% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q2_tracestream.txt b/Outputs/part2_Q2_tracestream.txt new file mode 100644 index 0000000..330b556 --- /dev/null +++ b/Outputs/part2_Q2_tracestream.txt @@ -0,0 +1,172 @@ + +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream +Select 1 to execute Question 1 or 2 to Question 2 :2 +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1074026 +Cache Misses: 2160029 +Cache Hit Rate : 33.209888458% +Cache Miss Rate : 66.790115356% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1044174 +Cache Misses: 2189881 +Cache Hit Rate : 32.286834717% +Cache Miss Rate : 67.713165283% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1037124 +Cache Misses: 2196931 +Cache Hit Rate : 32.068843842% +Cache Miss Rate : 67.931159973% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1059596 +Cache Misses: 2174459 +Cache Hit Rate : 32.763698578% +Cache Miss Rate : 67.236305237% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= + ================================== +Cache Hits: 1075782 +Cache Misses: 2158273 +Cache Hit Rate : 33.264183044% +Cache Miss Rate : 66.735816956% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1062040 +Cache Misses: 2172015 +Cache Hit Rate : 32.839267731% +Cache Miss Rate : 67.160728455% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1061980 +Cache Misses: 2172075 +Cache Hit Rate : 32.837409973% +Cache Miss Rate : 67.162582397% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1060219 +Cache Misses: 2173836 +Cache Hit Rate : 32.782958984% +Cache Miss Rate : 67.217041016% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= + ================================== +Cache Hits: 1076565 +Cache Misses: 2157490 +Cache Hit Rate : 33.288394928% +Cache Miss Rate : 66.711601257% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1070154 +Cache Misses: 2163901 +Cache Hit Rate : 33.090164185% +Cache Miss Rate : 66.909835815% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1070184 +Cache Misses: 2163871 +Cache Hit Rate : 33.091087341% +Cache Miss Rate : 66.908912659% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 1070219 +Cache Misses: 2163836 +Cache Hit Rate : 33.092170715% +Cache Miss Rate : 66.907829285% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q2_tracestream_10.txt b/Outputs/part2_Q2_tracestream_10.txt new file mode 100644 index 0000000..c959e26 --- /dev/null +++ b/Outputs/part2_Q2_tracestream_10.txt @@ -0,0 +1,172 @@ + +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream_10 +Select 1 to execute Question 1 or 2 to Question 2 :2 +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part2_Q2_tracestream_20.txt b/Outputs/part2_Q2_tracestream_20.txt new file mode 100644 index 0000000..8cf4813 --- /dev/null +++ b/Outputs/part2_Q2_tracestream_20.txt @@ -0,0 +1,172 @@ + +login-20-25:/CS5375$ ./part2 direct ./trace_for_students/trace.stream_20 +Select 1 to execute Question 1 or 2 to Question 2 :2 +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 1 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 2 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 1 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 2 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 4 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 1 + +For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize 3 + +Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: 8 + +====== STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size======= +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +===========XXXX EXECUTION ENDED XXXX ========== +Select 1 to continue the test cases, any other to exit: 0 + +login-20-25:/CS5375$ diff --git a/Outputs/part3.txt b/Outputs/part3.txt new file mode 100644 index 0000000..9885e24 --- /dev/null +++ b/Outputs/part3.txt @@ -0,0 +1,81 @@ +login-20-25:/CS5375$ clear +login-20-25:/CS5375$ part3.c -o part3 -lm +-bash: part3.c: command not found +login-20-25:/CS5375$ gcc part3.c -o part3 -lm +login-20-25:/CS5375$ ./part3 direct ./trace_for_students/trace.hpcg + +================================== +Cache type: l1 +================================== +Cache Hits: 1317655 +Cache Misses: 182345 +Cache Hit Rate : 87.843666077% +Cache Miss Rate : 12.156332970% + + +================================== +Cache type: l2 +================================== +Cache Hits: 1327929 +Cache Misses: 172071 +Cache Hit Rate : 88.528594971% +Cache Miss Rate : 11.471399307% + +login-20-25:/CS5375$ ./part3 direct ./trace_for_students/trace.stream + +================================== +Cache type: l1 +================================== +Cache Hits: 1070061 +Cache Misses: 2163994 +Cache Hit Rate : 33.087287903% +Cache Miss Rate : 66.912719727% + + +================================== +Cache type: l2 +================================== +Cache Hits: 1077514 +Cache Misses: 2156541 +Cache Hit Rate : 33.317737579% +Cache Miss Rate : 66.682258606% + +login-20-25:/CS5375$ ./part3 direct ./trace_for_students/trace.stream_10 + +================================== +Cache type: l1 +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + + +================================== +Cache type: l2 +================================== +Cache Hits: 0 +Cache Misses: 10 +Cache Hit Rate : 0.000000000% +Cache Miss Rate : 100.000000000% + +login-20-25:/CS5375$ ./part3 direct ./trace_for_students/trace.stream_20 + +================================== +Cache type: l1 +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + + +================================== +Cache type: l2 +================================== +Cache Hits: 4 +Cache Misses: 16 +Cache Hit Rate : 20.000000000% +Cache Miss Rate : 80.000000000% + +login-20-25:/CS5375$ diff --git a/Report.docx b/Report.docx new file mode 100644 index 0000000..e69de29 diff --git a/cachesim.c b/cachesim.c index da1c0c6..afd0895 100644 --- a/cachesim.c +++ b/cachesim.c @@ -14,6 +14,7 @@ int main(int argc, char *argv[]) { + if (argc != 3) { printf("Usage: %s \n", argv[0]); return 1; @@ -29,38 +30,42 @@ int main(int argc, char *argv[]) #endif char* trace_file_name = argv[2]; - struct direct_mapped_cache d_cache; + struct direct_mapped_cache dir_cache; char mem_request[20]; uint64_t address; FILE *fp; - /* Initialization */ + /* variable_set_up */ for (int i=0; i> (unsigned)log2(NUM_BLOCKS); #ifdef DBG - printf("Memory address: %llu, Block address: %llu, Index: %llu, Tag: %llu ", address, block_addr, index, tag); + printf("The Memory address: %llu, The Block address: %llu, Index is: %llu, Tag is: %llu ", address, block_addr, index, tag); #endif if (cache->valid_field[index] && cache->tag_field[index] == tag) { /* Cache hit */ diff --git a/cachesim.exe b/cachesim.exe new file mode 100644 index 0000000..9f8af02 Binary files /dev/null and b/cachesim.exe differ diff --git a/hack.c b/hack.c new file mode 100644 index 0000000..6857b83 --- /dev/null +++ b/hack.c @@ -0,0 +1,443 @@ +/* + * CS3375 Computer Architecture + * Course Project + * Cache Simulator Design and Development + * FALL 2017 + * By Yong Chen + */ + +#include +#include +#include +#include +#include + +char *trace_file_name; + +uint64_t convert_address(char memory_addr[]) +/* Converts the physical 32-bit address in the trace file to the "binary" \\ + * (a uint64 that can have bitwise operations on it) */ +{ + uint64_t binary = 0; + int i = 0; + + while (memory_addr[i] != '\n') + { + if (memory_addr[i] <= '9' && memory_addr[i] >= '0') + { + binary = (binary * 16) + (memory_addr[i] - '0'); + } + else + { + if (memory_addr[i] == 'a' || memory_addr[i] == 'A') + { + binary = (binary * 16) + 10; + } + if (memory_addr[i] == 'b' || memory_addr[i] == 'B') + { + binary = (binary * 16) + 11; + } + if (memory_addr[i] == 'c' || memory_addr[i] == 'C') + { + binary = (binary * 16) + 12; + } + if (memory_addr[i] == 'd' || memory_addr[i] == 'D') + { + binary = (binary * 16) + 13; + } + if (memory_addr[i] == 'e' || memory_addr[i] == 'E') + { + binary = (binary * 16) + 14; + } + if (memory_addr[i] == 'f' || memory_addr[i] == 'F') + { + binary = (binary * 16) + 15; + } + } + i++; + } + +#ifdef DBG + printf("%s converted to %llu\n", memory_addr, binary); +#endif + return binary; +} + +void readFileAndDoCacheHitOrMiss(int totalNumberOfBlocks, int nway, int blockSize) +{ + // Every thing is ready , just call the file and do the hit + int numberOfSets = totalNumberOfBlocks / nway; + struct direct_mapped_cache + { + unsigned valid_field[totalNumberOfBlocks]; /* Valid field */ + unsigned dirty_field[totalNumberOfBlocks]; /* Dirty field; since we don't distinguish writes and \\ + reads in this project yet, this field doesn't really matter */ + uint64_t tag_field[totalNumberOfBlocks]; /* Tag field */ + int hits; /* Hit count */ + int misses; /* Miss count */ + }; + struct direct_mapped_cache d_cache; + /* Initialization */ + for (int i = 0; i < totalNumberOfBlocks; i++) + { + d_cache.valid_field[i] = 0; + d_cache.dirty_field[i] = 0; + d_cache.tag_field[i] = 0; + } + d_cache.hits = 0; + d_cache.misses = 0; + + char mem_request[20]; + FILE *fp; + fp = fopen(trace_file_name, "r"); + uint64_t address; + + // printf("%s IS THE FILENAME", trace_file_name); + while (fgets(mem_request, 20, fp) != NULL) + { + // printf("%s", mem_request); + address = convert_address(mem_request); + uint64_t block_addr = address >> (unsigned)log2(blockSize); + int setNumber = block_addr % numberOfSets; + uint64_t tag = block_addr >> (unsigned)log2(numberOfSets); + int startIndex = ((int)setNumber) * nway; + + int endIndex = startIndex + nway - 1; + + int hitMade = 0; + int isAnySpaceEmpty = 0; + int nwayTemp = nway; + int loopIndex = startIndex; + int i = 0; + // printf("Coming the tag %d \n",tag); + for (int j = startIndex; j <= endIndex; j++) + { + // printf("\n\n\n **** At Index: %d Valid Field %d TagField %d",j,d_cache.valid_field[j],d_cache.tag_field[j]); + } + // printf("*********************"); + while (nwayTemp > 0) + { + i++; + // printf("%d ***********", loopIndex); + if (d_cache.valid_field[loopIndex] && d_cache.tag_field[loopIndex] == tag) + { /* Cache hit */ + d_cache.hits += 1; + hitMade = 1; + break; + } + if (d_cache.valid_field[loopIndex] == 0) + { + isAnySpaceEmpty = 1; + } + + loopIndex += 1; + nwayTemp--; + } + + if (hitMade == 0) + { + // printf("Hit was zero for the index %d", hitMade); + d_cache.misses += 1; + if (isAnySpaceEmpty > 0) + { + // printf("Going on empty"); + nwayTemp = nway; + loopIndex = startIndex; + while (nwayTemp > 0) + { + if (d_cache.valid_field[loopIndex] == 0) + { + // printf("\nInserting at the index : %d ", loopIndex); + d_cache.valid_field[loopIndex] = 1; + d_cache.tag_field[loopIndex] = tag; + break; + } + + loopIndex += 1; + nwayTemp--; + } + } + else + { + // pick a random index and replace + + int randomIndex = (rand() % (endIndex - startIndex + 1)) + startIndex; + // printf("Picking a rand variable %d",randomIndex); + d_cache.valid_field[randomIndex] = 1; + d_cache.tag_field[randomIndex] = tag; + } + } + } + // printf("\n\n\n==================================\n"); + // printf("Cache type:n-Mapped Cache\n with no of rows: %d, number of sets: %d", totalNumberOfBlocks, numberOfSets); + printf("==================================\n"); + printf("Cache Hits: %d\n", d_cache.hits); + printf("Cache Misses: %d\n", d_cache.misses); + printf("Cache Hit Rate : %0.1f%%\n", ((float)d_cache.hits / (float)(d_cache.hits + d_cache.misses))*100); + printf("Cache Miss Rate : %0.1f%%\n", ((float)d_cache.misses / (float)(d_cache.hits + d_cache.misses))*100); + printf("\n"); + fclose(fp); +} + +void startProcess(int cacheSize, int totalNumberOfBlocks, int nway, int blockSize) +{ + // printf("The below output is for cache with %dKB and %d bytes and %d way associative ", cacheSize, blockSize, nway); + readFileAndDoCacheHitOrMiss(totalNumberOfBlocks, nway, blockSize); +} + +void performNwayAssociativeMappingforPart1() +{ + int continueSelect = 0; + int t=1; + for(int i=1;i<=3;i++) + { + + int j=1; + while(j<=8){ + long cacheSize = 32 * 1024; + int totalNumberOfBlocks = 0; + int ca = 0; + printf("For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : %d\n",i); + // scanf("%d", &ca); + ca = i; + int selection = 0; + printf("Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: %d",j); + // scanf("%d", &selection); + selection = j; + switch (ca) + { + case 1: + printf("\n\n*********** STARTING EXECUTION FOR 16 BYTES cache line size **************** \n"); + totalNumberOfBlocks = (int)cacheSize / 16; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 16); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 16); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 16); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 16); + break; + default: + break; + } + + break; + case 2: + printf("\n\n*********** STARTING EXECUTION FOR 32 BYTES cache line size **************** \n"); + totalNumberOfBlocks = (int)cacheSize / 32; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 32); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 32); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 32); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 32); + break; + default: + break; + } + + break; + case 3: + printf("\n\n*********** STARTING FOR 128 BYTES cache line size **************** \n"); + totalNumberOfBlocks = (int)cacheSize / 128; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 128); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 128); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 128); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 1628); + break; + default: + break; + } + + break; + } + + + + + printf("=============== EXECUTION ENDED ===============\n"); + + + if(i==3 && j==8) + printf("Select 1 to continue , any other to exit: 0\n\n"); + else + printf("Select 1 to continue , any other to exit: 1\n\n"); + if(j==1) + j=2; + else if(j==2) + j=4; + else if (j==4) + j=8; + else + j=9; + + + } + + } + + + +} +void performNwayAssociativeMappingforPart2() +{ + + int continueSelect = 0; + for(int i=1;i<=3;i++) + { + + int j=1; + while(j<=8){ + long cacheSize = 16 * 1024; + int totalNumberOfBlocks = 0; + int ca = 0; + printf("For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize %d \n \n",i); + // scanf("%d", &ca); + ca=i; + int selection; + printf("Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: %d",j); + // scanf("%d", &selection); + selection=j; + + switch (ca) + { + case 1: + cacheSize = 16 * 1024; + totalNumberOfBlocks = (int)cacheSize / 64; + printf("\n\n*********** STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size=======\n"); + switch (selection) + { + case 8: + startProcess(16, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(16, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(16, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(16, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + + break; + case 2: + printf("\n\n*********** STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size=======\n"); + cacheSize = 32 * 1024; + totalNumberOfBlocks = (int)cacheSize / 64; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + break; + case 3: + printf("\n\n*********** STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size=======\n"); + cacheSize = 64 * 1024; + totalNumberOfBlocks = (int)cacheSize / 64; + switch (selection) + { + case 8: + startProcess(64, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(64, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(64, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(64, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + break; + + default: + break; + } + + + printf("===========XXXX EXECUTION ENDED XXXX ==========\n"); + + + if(i==3 && j==8) + printf("Select 1 to continue , any other to exit: 0\n\n"); + else + printf("Select 1 to continue , any other to exit: 1\n\n"); + if(j==1) + j=2; + else if(j==2) + j=4; + else if (j==4) + j=8; + else + j=9; + } + + + } + + + +} + +int main(int argc, char *argv[]) +{ + trace_file_name = argv[2]; + int switchCase = 0; + printf("Select 1 to execute Question 1 or 2 to Question 2 :"); + scanf("%d", &switchCase); + + switch (switchCase) + { + case 1: + performNwayAssociativeMappingforPart1(); + break; + + case 2: + performNwayAssociativeMappingforPart2(); + break; + } +} \ No newline at end of file diff --git a/hack.exe b/hack.exe new file mode 100644 index 0000000..634ebc4 Binary files /dev/null and b/hack.exe differ diff --git a/part2.c b/part2.c new file mode 100644 index 0000000..bf56c38 --- /dev/null +++ b/part2.c @@ -0,0 +1,398 @@ +/* + * CS3375 Computer Architecture + * Course Project + * Cache Simulator Design and Development + * FALL 2017 + * By Yong Chen + */ + +#include +#include +#include +#include +#include + +char *trace_file_name; + +uint64_t convert_address(char memory_addr[]) +/* Conversion of the physical 32-bit address in the trace file to the "binary" \\ + * (a uint64 that can have bitwise operations on it) */ +{ + uint64_t binary = 0; + int i = 0; + + while (memory_addr[i] != '\n') + { + if (memory_addr[i] <= '9' && memory_addr[i] >= '0') + { + binary = (binary * 16) + (memory_addr[i] - '0'); + } + else + { + if (memory_addr[i] == 'a' || memory_addr[i] == 'A') + { + binary = (binary * 16) + 10; + } + if (memory_addr[i] == 'b' || memory_addr[i] == 'B') + { + binary = (binary * 16) + 11; + } + if (memory_addr[i] == 'c' || memory_addr[i] == 'C') + { + binary = (binary * 16) + 12; + } + if (memory_addr[i] == 'd' || memory_addr[i] == 'D') + { + binary = (binary * 16) + 13; + } + if (memory_addr[i] == 'e' || memory_addr[i] == 'E') + { + binary = (binary * 16) + 14; + } + if (memory_addr[i] == 'f' || memory_addr[i] == 'F') + { + binary = (binary * 16) + 15; + } + } + i++; + } + +#ifdef DBG + printf("%s converted to %llu\n", memory_addr, binary); +#endif + return binary; +} + +void readFileAndDoCacheHitOrMiss(int totalNumberOfBlocks, int nway, int blockSize) +{ + // Every thing is setup now , just call the file and do the hit + int numberOfSets = totalNumberOfBlocks / nway; + struct direct_mapped_cache + { + unsigned valid_field[totalNumberOfBlocks]; /* Valid field */ + unsigned dirty_field[totalNumberOfBlocks]; /* Dirty field; since we don't distinguish writes and \\ + reads in this project yet, this field doesn't really matter */ + uint64_t tag_field[totalNumberOfBlocks]; /* Tag field */ + int hits; /* Hit count */ + int misses; /* Miss count */ + }; + struct direct_mapped_cache dir_cache; + /* Setup */ + for (int i = 0; i < totalNumberOfBlocks; i++) + { + dir_cache.valid_field[i] = 0; + dir_cache.dirty_field[i] = 0; + dir_cache.tag_field[i] = 0; + } + dir_cache.hits = 0; + dir_cache.misses = 0; + + char mem_request[20]; + FILE *fp; + fp = fopen(trace_file_name, "r"); + uint64_t address; + + // printf("%s IS_THE_FILENAME", trace_file_name); + while (fgets(mem_request, 20, fp) != NULL) + { + // printf("%s", mem_request); + address = convert_address(mem_request); + uint64_t block_addr = address >> (unsigned)log2(blockSize); + int setNumber = block_addr % numberOfSets; + uint64_t tag = block_addr >> (unsigned)log2(numberOfSets); + int startIndex = ((int)setNumber) * nway; + + int endIndex = startIndex + nway - 1; + + int hitMade = 0; + int isAnySpaceEmpty = 0; + int nwayTemp = nway; + int loopIndex = startIndex; + int i = 0; + // printf("Coming_the_tag %d \n",tag); + for (int j = startIndex; j <= endIndex; j++) + { + // printf("\n\n\n **** At Index: %d Valid Field %d TagField %d",j,d_cache.valid_field[j],d_cache.tag_field[j]); + } + // printf("*********************"); + while (nwayTemp > 0) + { + i++; + // printf("%d ***********", loopIndex); + if (dir_cache.valid_field[loopIndex] && dir_cache.tag_field[loopIndex] == tag) + { /* Cache hit */ + dir_cache.hits += 1; + hitMade = 1; + break; + } + if (dir_cache.valid_field[loopIndex] == 0) + { + isAnySpaceEmpty = 1; + } + + loopIndex += 1; + nwayTemp--; + } + + if (hitMade == 0) + { + // printf("Hit_is_zero for the index %d", hitMade); + dir_cache.misses += 1; + if (isAnySpaceEmpty > 0) + { + // printf("Going on empty"); + nwayTemp = nway; + loopIndex = startIndex; + while (nwayTemp > 0) + { + if (dir_cache.valid_field[loopIndex] == 0) + { + // printf("\nInserting_in_at_the_index : %d ", loopIndex); + dir_cache.valid_field[loopIndex] = 1; + dir_cache.tag_field[loopIndex] = tag; + break; + } + + loopIndex += 1; + nwayTemp--; + } + } + else + { + // pick any index and replace + + int randomIndex = (rand() % (endIndex - startIndex + 1)) + startIndex; + // printf("Choosing_the_random_variable %d",randomIndex); + dir_cache.valid_field[randomIndex] = 1; + dir_cache.tag_field[randomIndex] = tag; + } + } + } + // printf("\n\n\n==================================\n"); + // printf("Cache type:n-Mapped Cache\n with no of rows: %d, number of sets: %d", totalNumberOfBlocks, numberOfSets); + printf("==================================\n"); + printf("Cache Hits: %d\n", dir_cache.hits); + printf("Cache Misses: %d\n", dir_cache.misses); + printf("Cache Hit Rate : %0.1f%%\n", ((float)dir_cache.hits / (float)(dir_cache.hits + dir_cache.misses))*100); + printf("Cache Miss Rate : %0.1f%%\n", ((float)dir_cache.misses / (float)(dir_cache.hits + dir_cache.misses))*100); + printf("\n"); + fclose(fp); +} + +void startProcess(int cacheSize, int totalNumberOfBlocks, int nway, int blockSize) +{ + // printf("Following_output is for cache with %dKB and %d bytes and %d way associative ", cacheSize, blockSize, nway); + readFileAndDoCacheHitOrMiss(totalNumberOfBlocks, nway, blockSize); +} + +void performNwayAssociativeMappingforPart1() +{ + int continueSelect = 0; + do + { + long cacheSize = 32 * 1024; + int totalNumberOfBlocks = 0; + int ca = 0; + printf("For execution over 32KB Cache size, Click 1 for 16 bytes cache line size, 2 for 32 bytes cache line size, 3 for 128 bytes cache line size : \n"); + scanf("%d", &ca); + int selection = 0; + printf("Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: "); + scanf("%d", &selection); + switch (ca) + { + case 1: + printf("\n\n############### STARTING_THE_EXECUTION_OF_16_BYTES_cache_line_size **************** \n"); + totalNumberOfBlocks = (int)cacheSize / 16; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 16); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 16); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 16); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 16); + break; + default: + break; + } + + break; + case 2: + printf("\n\n*********** START_THE_EXECUTION_OF_32_BYTES_cache_line_size #################### \n"); + totalNumberOfBlocks = (int)cacheSize / 32; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 32); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 32); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 32); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 32); + break; + default: + break; + } + + break; + case 3: + printf("\n\n+++++++++++++++++++++EXECUTION_START_OF_128_BYTES_cache_line_size +++++++++++++++++++\n"); + totalNumberOfBlocks = (int)cacheSize / 128; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 128); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 128); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 128); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 1628); + break; + default: + break; + } + + break; + } + printf("=============== END_OF_EXECUTION ===============\n"); + + + + printf("Select 1 to continue , any other to exit: "); + scanf("%d",&continueSelect); + } while (continueSelect==1); + + + +} +void performNwayAssociativeMappingforPart2() +{ + + int continueSelect = 0; + do + { + long cacheSize = 16 * 1024; + int totalNumberOfBlocks = 0; + int ca = 0; + printf("For execution over 64Bytes Cache line size ,Click 1 for 16KB Cachesize, 2 for 32KB Cachesize, 3 for 64KB Cachesize \n \n"); + scanf("%d", &ca); + int selection; + printf("Select 1 for fully associative execution, 2 for 2 way execution, 4 for 4 way execution, 8 for 8 way execution: "); + scanf("%d", &selection); + + switch (ca) + { + case 1: + totalNumberOfBlocks = (int)cacheSize / 64; + printf("\n\n*^^^^^^^^^^^^^^^^ STARTING EXECUTION OF 16kb cache size and 64 bytes cache line size/block size ^^^^^^^^^^^^^\n"); + switch (selection) + { + case 8: + startProcess(16, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(16, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(16, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(16, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + + break; + case 2: + printf("\n\n$$$$$$$$$$$$$$$$ STARTING EXECUTION OF 32kb cache size and 64 bytes cache line size/block size $$$$$$$$$$$$$$$$\n"); + cacheSize = 32 * 1024; + totalNumberOfBlocks = (int)cacheSize / 64; + switch (selection) + { + case 8: + startProcess(32, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(32, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(32, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(32, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + break; + case 3: + printf("\n\n*********** STARTING EXECUTION OF 64kb cache size and 64 bytes cache line size/block size=======\n"); + cacheSize = 64 * 1024; + totalNumberOfBlocks = (int)cacheSize / 64; + switch (selection) + { + case 8: + startProcess(64, totalNumberOfBlocks, 8, 64); + break; + case 4: + startProcess(64, totalNumberOfBlocks, 4, 64); + break; + case 2: + startProcess(64, totalNumberOfBlocks, 2, 64); + break; + case 1: + startProcess(64, totalNumberOfBlocks, totalNumberOfBlocks, 64); + break; + + default: + break; + } + break; + + default: + break; + } + + + printf("Select 1 to continue , any other to exit: "); + scanf("%d",&continueSelect); + } while (continueSelect==1); + + + +} + +int main(int argc, char *argv[]) +{ + trace_file_name = argv[2]; + int switchCase = 0; + printf("Select 1 to execute Question 1 or 2 to Question 2 :"); + scanf("%d", &switchCase); + + switch (switchCase) + { + case 1: + performNwayAssociativeMappingforPart1(); + break; + + case 2: + performNwayAssociativeMappingforPart2(); + break; + } +} diff --git a/part2.exe b/part2.exe new file mode 100644 index 0000000..71cea91 Binary files /dev/null and b/part2.exe differ diff --git a/part3.c b/part3.c new file mode 100644 index 0000000..e97603e --- /dev/null +++ b/part3.c @@ -0,0 +1,288 @@ +#include +#include +#include +#include +#include + +char *trace_file_name; + +struct L1Cache +{ + unsigned valid_field[1024]; + unsigned dirty_field[1024]; + uint64_t tag_field[1024]; + char data_field[1024][64]; + int hits; + int misses; +}; + +struct L2Cache +{ + unsigned valid_field[16384]; + unsigned dirty_field[16384]; + uint64_t tag_field[16384]; + char data_field[16384][64]; + int hits; + int misses; +}; + +uint64_t convert_address(char memory_addr[]) +/* Conversion of physical 32-bit address in the trace file to the "binary" \\ + * (a uint64 that can have bitwise operations on it) */ +{ + uint64_t binary = 0; + int i = 0; + + while (memory_addr[i] != '\n') + { + if (memory_addr[i] <= '9' && memory_addr[i] >= '0') + { + binary = (binary * 16) + (memory_addr[i] - '0'); + } + else + { + if (memory_addr[i] == 'a' || memory_addr[i] == 'A') + { + binary = (binary * 16) + 10; + } + if (memory_addr[i] == 'b' || memory_addr[i] == 'B') + { + binary = (binary * 16) + 11; + } + if (memory_addr[i] == 'c' || memory_addr[i] == 'C') + { + binary = (binary * 16) + 12; + } + if (memory_addr[i] == 'd' || memory_addr[i] == 'D') + { + binary = (binary * 16) + 13; + } + if (memory_addr[i] == 'e' || memory_addr[i] == 'E') + { + binary = (binary * 16) + 14; + } + if (memory_addr[i] == 'f' || memory_addr[i] == 'F') + { + binary = (binary * 16) + 15; + } + } + i++; + } + +#ifdef DBG + printf("%s converted to %llu\n", memory_addr, binary); +#endif + return binary; +} + +int isDataExistsInCacheL1(uint64_t address, int nway, struct L1Cache *l1) +{ + uint64_t block_addr = address >> (unsigned)log2(64); + int setNumber = block_addr % 512; + uint64_t tag = block_addr >> (unsigned)log2(512); + int startIndex = ((int)setNumber) * nway; + int nwayTemp = nway; + int loopIndex = startIndex; + while (nwayTemp > 0) + { + if (l1->valid_field[loopIndex] && l1->tag_field[loopIndex] == tag) + { + return 1; + } + loopIndex += 1; + nwayTemp--; + } + return 0; +} +int isDataExistsInCacheL2(uint64_t address, int nway, struct L2Cache *l2) +{ + uint64_t block_addr = address >> (unsigned)log2(64); + int setNumber = block_addr % 2048; + uint64_t tag = block_addr >> (unsigned)log2(2048); + int startIndex = ((int)setNumber) * nway; + int nwayTemp = nway; + int loopIndex = startIndex; + while (nwayTemp > 0) + { + if (l2->valid_field[loopIndex] && l2->tag_field[loopIndex] == tag) + { + return 1; + } + loopIndex += 1; + nwayTemp--; + } + return 0; +} +void insertDataInL1Cache(uint64_t address, int nway, struct L1Cache *l1) +{ + uint64_t block_addr = address >> (unsigned)log2(64); + int setNumber = block_addr % 512; + uint64_t tag = block_addr >> (unsigned)log2(512); + int startIndex = ((int)setNumber) * nway; + int nwayTemp = nway; + int loopIndex = startIndex; + int isAnySpaceEmpty = 0; + int endIndex = startIndex + nway - 1; + while (nwayTemp > 0) + { + if (l1->valid_field[loopIndex] == 0) + { + isAnySpaceEmpty = 1; + } + loopIndex++; + nwayTemp--; + } + if (isAnySpaceEmpty > 0) + { + nwayTemp = nway; + loopIndex = startIndex; + while (nwayTemp > 0) + { + if (l1->valid_field[loopIndex] == 0) + { + l1->valid_field[loopIndex] = 1; + l1->tag_field[loopIndex] = tag; + break; + } + + loopIndex += 1; + nwayTemp--; + } + } + else + { + int randomIndex = (rand() % (endIndex - startIndex + 1)) + startIndex; + // printf("Picking a rand variable %d",randomIndex); + l1->valid_field[randomIndex] = 1; + l1->tag_field[randomIndex] = tag; + } +} +void insertDataInL2Cache(uint64_t address, int nway, struct L2Cache *l2) +{ + + uint64_t block_addr = address >> (unsigned)log2(64); + int setNumber = block_addr % 2048; + uint64_t tag = block_addr >> (unsigned)log2(2048); + int startIndex = ((int)setNumber) * nway; + int nwayTemp = nway; + int loopIndex = startIndex; + int isAnySpaceEmpty = 0; + int endIndex = startIndex + nway - 1; + while (nwayTemp > 0) + { + if (l2->valid_field[loopIndex] == 0) + { + isAnySpaceEmpty = 1; + } + loopIndex++; + nwayTemp--; + } + if (isAnySpaceEmpty > 0) + { + nwayTemp = nway; + loopIndex = startIndex; + while (nwayTemp > 0) + { + if (l2->valid_field[loopIndex] == 0) + { + l2->valid_field[loopIndex] = 1; + l2->tag_field[loopIndex] = tag; + break; + } + + loopIndex += 1; + nwayTemp--; + } + } + else + { + int randomIndex = (rand() % (endIndex - startIndex + 1)) + startIndex; + // printf("Picking a rand variable %d",randomIndex); + l2->valid_field[randomIndex] = 1; + l2->tag_field[randomIndex] = tag; + } +} + +int main(int argc, char *argv[]) +{ + FILE *fp; + trace_file_name = argv[2]; + char mem_request[20]; + uint64_t address; + struct L1Cache l1; + struct L2Cache l2; + int numberOfBlocksinl1 = 1024; + int numberOfBocksinl2 = 16384; + int l1nway = 2; + int l2nway = 8; + int numberOfSetsl1 = 512; + int numberOfSetsl2 = 2048; + for (int i = 0; i < numberOfBlocksinl1; i++) + { + l1.valid_field[i] = 0; + l1.dirty_field[i] = 0; + l1.tag_field[i] = 0; + } + for (int i = 0; i < numberOfBocksinl2; i++) + { + l2.valid_field[i] = 0; + l2.dirty_field[i] = 0; + l2.tag_field[i] = 0; + } + + l1.hits = 0; + l1.misses = 0; + l2.hits = 0; + l2.misses = 0; + + fp = fopen(trace_file_name, "r"); + + if (strncmp(argv[1], "direct", 6) == 0) + { + while (fgets(mem_request, 20, fp) != NULL) + { + address = convert_address(mem_request); + int dataInL1 = isDataExistsInCacheL1(address, l1nway, &l1); + if (dataInL1 == 1) + { + l1.hits++; + l2.hits++; + } + else + { + l1.misses++; + int dataInL2 = isDataExistsInCacheL2(address, l2nway, &l2); + if (dataInL2) + { + l2.hits += 1; + } + else + { + l2.misses++; + insertDataInL2Cache(address, l2nway, &l2); + } + insertDataInL1Cache(address, l1nway, &l1); + } + } + printf("\n**********************************\n"); + printf("Cache type: l1\n"); + printf("************************************n"); + printf("Nof_Cache Hits: %d\n", l1.hits); + printf("Nof_Cache Misses: %d\n", l1.misses); + printf("Nof_Cache Hit Rate : %0.3f%%\n", ((float)l1.hits / (float)(l1.hits + l1.misses)) * 100); + printf("Nof_Cache Miss Rate : %0.3f%%\n", ((float)l1.misses / (float)(l1.hits + l1.misses)) * 100); + printf("\n"); + printf("\n+++++++++++++++++++++++++++++++\n"); + printf("Cache type: l2\n"); + printf("++++++++++++++++++++++++++++++++++\n"); + printf("Nof_Cache Hits: %d\n", l2.hits); + printf("Nof_Cache Misses: %d\n", l2.misses); + printf("Nof_Cache Hit Rate : %0.3f%%\n", ((float)l2.hits / (float)(l2.hits + l2.misses)) * 100); + printf("Nof_Cache Miss Rate : %0.3f%%\n", ((float)l2.misses / (float)(l2.hits + l2.misses)) * 100); + printf("\n"); + } + + fclose(fp); + + return 0; +} diff --git a/work.exe b/work.exe new file mode 100644 index 0000000..4ebe4ae Binary files /dev/null and b/work.exe differ