It is academic misconduct to share your work with others in any form including posting it on publicly accessible web sites, such as GitHub.

Similar documents
Distributed: Monday, Nov. 30, Due: Monday, Dec. 7 at midnight

CSCI 356 Spring 2018 Project 5: Understanding Cache Memories Due: Thursday, April 5, 11:59PM

Part I: Pen & Paper Exercises, Cache

MCS-284, Fall 2018 Cache Lab: Understanding Cache Memories Assigned: Friday, 11/30 Due: Friday, 12/14, by midnight (via Moodle)

3. A Periodic Alarm: intdate.c & sigsend.c

ICS(II), Fall 2017 Cache Lab: Understanding Cache Memories Assigned: Thursday, October 26, 2017 Due: Sunday, November 19, 2017, 11:59PM

Computer Systems Principles Cache Simulator

Project #1: Tracing, System Calls, and Processes

p1: Fortune 1. Overview 2. Learning Goals 3. Logistics 4. Linux commands

CSC/ECE 506: Computer Architecture and Multiprocessing Program 3: Simulating DSM Coherence Due: Tuesday, Nov 22, 2016

COMP 3500 Introduction to Operating Systems Project 5 Virtual Memory Manager

CpSc 1111 Lab 9 2-D Arrays

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am

Computer Architecture Assignment 4 - Cache Simulator

CS354 gdb Tutorial Written by Chris Feilbach

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Carnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016

CSC/ECE 506: Architecture of Parallel Computers Program 2: Bus-Based Cache Coherence Protocols Due: Wednesday, October 25, 2017

Cache Lab Implementation and Blocking

Your submitted proj3.c must compile and run on linprog as in the following example:

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Assignment 6: The Power of Caches

CS155: Computer Security Spring Project #1. Due: Part 1: Thursday, April pm, Part 2: Monday, April pm.

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

Project 2: Buffer Manager

Creating a String Data Type in C

Your submitted proj3.c must compile and run on linprog as in the following example:

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator

OPERATING SYSTEMS ASSIGNMENT 3 MEMORY MANAGEMENT

Assignment 2: Understanding Data Cache Prefetching

Data Management, Spring 2015: Project #1

CS201: Lab #4 Writing a Dynamic Storage Allocator

EECE.2160: ECE Application Programming

Assignment 1: One-Level Cache Simulator Due: Wednesday 04/04/12 (before class)

CSE 361S Intro to Systems Software Lab #4

CS Programming Languages Fall Homework #2

CS 564, Spring 2017 BadgerDB Assignment #1: Buffer Manager

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O

Recitation 2/18/2012

Programming Assignment Multi-Threading and Debugging 2

Final Programming Project

Data Lab: Manipulating Bits

Project 1: Buffer Manager

Project 0: Implementing a Hash Table

Tips from the experts: How to waste a lot of time on this assignment

Programming Assignments

CS 356, Fall 2018 Data Lab (Part 2): Manipulating Bits Due: Mon, Sep. 17, 11:59PM

BIL220, Spring 2012 Data Lab: Manipulating Bits Assigned: Feb. 23, Due: Wed., Mar. 8, 23:59PM

Recitation 7 Caches and Blocking. 9 October 2017

15-213/18-213/15-513, Spring 2018 C Programming Lab: Assessing Your C Programming Skills

Programming Tips for CS758/858

Project 1 for CMPS 181: Implementing a Paged File Manager

CS 361S - Network Security and Privacy Spring Project #2

Project Introduction

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE-13/L: COMPUTER SYSTEMS AND C PROGRAMMING WINTER 2014

- b: size of block in bytes. - s: number of sets in the cache (or total number of sets between split caches). - n: associativity of cache.

CS 2604 Minor Project 1 DRAFT Fall 2000

COMP Assignment 1

ASSIGNMENT TWO: PHONE BOOK

Project 2 Reliable Transport

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM

Project 0: Implementing a Hash Table

Programming Assignment 2 ( 100 Points )

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20.

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Final Project: LC-3 Simulator

CS 385 Operating Systems Fall 2011 Homework Assignment 5 Process Synchronization and Communications

Tips from the experts: How to waste a lot of time on this assignment

Programming Assignment 1

CMU : Advanced Computer Architecture Handout 5: Cache Prefetching Competition ** Due 10/11/2005 **

1 Introduction. 2 Logistics. 3 Hand Out Instructions

Shell Project Part 1 (140 points)

CS451 - Assignment 3 Perceptron Learning Algorithm

Lab 1 Introduction to UNIX and C

EECS 213, Spring 2013 Data Lab: Manipulating Bits

COMP 321: Introduction to Computer Systems

CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11:59PM

CS 2505 Fall 2013 Data Lab: Manipulating Bits Assigned: November 20 Due: Friday December 13, 11:59PM Ends: Friday December 13, 11:59PM

CS-281, Spring 2011 Data Lab: Manipulating Bits Assigned: Jan. 17, Due: Mon., Jan. 31, 11:59PM

CSE 361S Intro to Systems Software Final Project

15-213/18-213/15-513, Fall 2017 C Programming Lab: Assessing Your C Programming Skills

Assignment 3 ITCS-6010/8010: Cloud Computing for Data Analysis

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

CS155: Computer Security Spring Project #1

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Lab 1 Implementing a Simon Says Game

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM

Project 4: Implementing Malloc Introduction & Problem statement

1 Lab 2: C Programming II

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Assignment 1: Understanding Branch Prediction

CS 135, Fall 2010 Project 4: Code Optimization Assigned: November 30th, 2010 Due: December 12,, 2010, 12noon

CS 3114 Data Structures and Algorithms DRAFT Project 2: BST Generic

Lab 09 - Virtual Memory

Transcription:

p4: Cache Simulator 1. Logistics 1. This project must be done individually. It is academic misconduct to share your work with others in any form including posting it on publicly accessible web sites, such as GitHub. It is academic misconduct for you to copy or use some or all of a program that has been written by someone else. 2. All work for this project is to be done on one of the CS department's instructional Linux machines. You're welcome to remotely login using ssh or MobaXterm as was shown in lecture (or any other way that you figure out on your own). 3. All projects in this course are graded on CS department's instructional Linux machines. It is your responsibility to make sure that your code runs as you expect on these machines. 2. Learning Goals This assignment has 2 parts. The purpose of the first part is to understand more about how caches work and learn a bit about simulation along the way. In second part of the assignment, you will work on developing a small cache simulator. This will make you an expert in the basics of caches and further strengthen your C programming skills. 3. Getting the Required Files Copy the tar file /p/course/cs354-skrentny/public/code/p4/cachelab.tgz to your private working directory. Next enter the following command in your current working directory: tar -zxvf cachelab.tgz This should create a directory named cachelab which has the directories part1 and part2 required for the two parts of the assignment. Verify the contents of the cachelab directory as show below. [haseeb@espresso] (47)$ ls cachelab/ cachelab.tgz [haseeb@espresso] (48)$ ls cachelab part1/ part2/ [haseeb@espresso] (49)$ ls cachelab/part1 p4questions.txt

[haseeb@espresso] (50)$ ls cachelab/part2 csim.c csim-ref* Makefile README test-csim* traces/ Next copy the directory "pin-fw" into your "cachelab/part1" directory. This could take a couple of minutes. [haseeb@espresso] (63)$ ls part1/ part2/ [haseeb@espresso] (64)$ cp -r /p/course/cs354-skrentny/public/code/p4/pin-fw part1/ [haseeb@espresso] (65)$ ls part1/ p4questions.txt pin-fw/ 4. Part 1 - cache analysis with pin: NOTE: It is recommended that you complete part 1 of the assignment before moving on to part 2. For this part, you will use a dynamic binary instrumentation framework called pin to measure cache performance statistics of an executable program by specifying certain cache parameters. Specifically you will use pin to run simulations and answer questions in the file "p4questions.txt". NOTE: You will not be able to run pin on your personal machine. It is recommended that you complete part 1 on one of the CSL machines (either physically or remotely via ssh). pin runs the executable to internally produce a series of address traces. These are the ordered set of memory addresses that a program reads from or writes to as it runs. Each address may represent a read for an instruction fetch, or a read/write to some data variable stored in memory. The address traces are then used internally by the cache simulator tool in pin. The cache simulator is a program that acts as if it is a cache, and for each trace, it does a lookup to determine if that address causes a cache hit or a cache miss. The simulator keeps track of the hits/misses, and finally prints these statistics for you. To run a simulation, from inside your "part1" directory, you will use a command line of the format: pin-fw/pin -injection child -t pin-fw/source/tools/memory/obj-ia32/allcache.so -is <c apacity> -ia <associativity> -ib <block-size> -ds <capacity> -da <associativity> -db <block-size> -- <your-exe> In this command, you would need to replace <your-exe> with the name of your executable file. The simulator presumes a separate I-cache and D-cache. The I-cache holds only the machine code instructions, as read when doing an instruction fetch. The D-cache holds all other data read or written while a program runs. There are 6 cache parameters, 3 each for I-cache and D-cache. Capacity: -is <capacity> -ds <capacity>

This sets the total capacity in bytes for the cache. For all your simulations (in part 1) use a 16KB or 16384 bytes size for both the I-cache and the D-cache. -is 16384 -ds 16384 Associativity: -ia <associativity> -da <associativity> This sets the set associativity of the cache. For all your simulations (in part 1) use an associativity of 1 (direct-mapped) for both I-cache and the D-cache. -ia 1 -da 1 Block size: -ib <block-size> and -db <block-size> This sets the block size in bytes for the cache. For all your simulations (in part 1) use a block size of 64 bytes for the I-cache. -ib 64 The block size for the D-cache -db <block-size> is the parameter that you will be changing to answer the questions in the file "p4questions.txt". So your final command to run a simulation, from inside your "part1" directory, on an executable will look like: pin-fw/pin -injection child -t pin-fw/source/tools/memory/obj-ia32/allcache.so -is 16 384 -ia 1 -ib 64 -ds 16384 -da 1 -db <block-size> -- <your-exe> In order to answer the questions in "p4questions.txt" you will need to write 3 very small and simple programs "cache1d.c", "cache2drows.c" and "cache2dcols.c", and then compile them into executables as you have done in previous programs like: gcc -o cache1d cache1d.c -Wall -m32 -std=gnu99 cache1d.c: Declare a global array of integers of size 100,000 outside (and prior) to the main() function, so that this array will be on the data segment. Use a for loop in the main() function to iterate over the entire array and set the value of each element in the array as the index. arr[i] = i; Do not print to the console or do anything extra. All this program does is iterate over the global array to set its values. Use the executable from this program to answer questions in the section cache1d of "p4questions.txt".

cache2drows.c and cache2dcols.c: "cache2drows.c" is similar to the above program except our global array is now a 2-dimensional integer array of dimensions 3000 rows x 500 columns. In our main() function we will iterate over the array with a nested loop in a row-wise order, where the inner loop works its way through the elements of single row of the array, and the outer loop iterates through the rows. In this order of traversal you will set every element of the array as: arr2d[row][col] = row + col; "cache2dcols.c" does the exact same thing except the iteration is in a column-wise order, where the inner loop works its way through the elements of a single column of the array, and the outer loop iterates through the columns. Use the executables from these programs to answer questions in the remaining sections of "p4questions.txt". 5. Part 2 - cache simulator csim: You will write a cache simulator in "csim.c" that takes a valgrind memory trace as input, simulates the hit/miss/eviction behavior of a cache memory on this trace, and outputs the total number of hits, misses and evictions. 5.1 Reference trace files The "cachelab/part2/traces" directory contains a collection of reference trace files that we will use to evaluate the correctness of the cache simulator that you will write in the next section. The trace files are generated by a Linux program called Valgrind. For example, typing: valgrind --log-fd=1 --tool=lackey -v --trace-mem=yes ls -l on the command line runs the executable program ls -l, captures a trace of each of its memory accesses in the order they occur, and prints them on stdout. Valgrind memory traces have the following form: I 0400d7d4,8 M 0421c7f0,4 L 04f6b868,8 S 7ff0005c8,8 Each line denotes one or two memory accesses. The format of each line is [space]operation[space]address,size The operation field denotes the type of memory access: I denotes an instruction load, L a data load, S a data store, and M a data modify (i.e. a data load followed by a data store). You will consider only memory accesses to data (L/S/M) and ignore instruction fetch (I) while working on your simulator. The address field specifies a 64-bit hexadecimal memory address. The size field specifies the number of bytes accessed by the operation. In this course we have dealt with

32-bit computers. Only for part 2 of this assignment, we use 64-bit computer traces - all the addresses for accessing memory are 64-bit addresses. NOTE: You will not have to generate any traces on your own. You need to work only with the traces provided to you in "cachelab/part2/traces". 5.2 Writing the cache simulator csim: We have provided you with the binary executable of a reference cache simulator, called "csim-ref", that simulates the behavior of a cache with arbitrary size and associativity on a valgrind trace file. It uses the LRU (least-recently used) replacement policy when choosing which cache line to evict. You can use "csim-ref" to compare your implementation. The reference simulator takes the following command-line arguments:./csim-ref [-hv] -s <s> -E <E> -b <b> -t <tracefile> -h: Optional help flag that prints usage info -v: Optional verbose flag that displays trace info -s <s>: Number of set index bits (S = 2^s is the number of sets) -E <E>: Associativity (number of cache lines per set) -b <b>: Number of block bits (B = 2^b is the block size) -t <tracefile>: Name of the valgrind trace to replay The command-line arguments are based on the notation (s, E, and b). For example, the following command gives us the output:./csim-ref -s 4 -E 1 -b 4 -t traces/yi.trace hits:4 misses:5 evictions:3 The same example in verbose mode:./csim-ref -s 4 -E 1 -b 4 -t traces/yi.trace -v L 10,1 miss M 20,1 miss hit L 22,1 hit S 18,1 hit L 110,1 miss eviction L 210,1 miss eviction M 12,1 miss eviction hit hits:4 misses:5 evictions:3 You can use this verbose output from "csim-ref" while debugging your code ("csim.c"). The hit / miss / eviction in the verbose output above indicates if that particular memory access (L/S/M) specified by the trace file led to hit/miss/eviction in cache. We have provided you with skeleton code in file "csim.c". Your job is to complete the implementation so that it outputs the correct number of hits, misses and evictions. It is highly

recommended that you support the verbose output (using the -v option) in your implementation of "csim.c". It would help you in debugging your code. No points will be deducted if you chose not to. 5.3 Testing csim: Once you have made your changes to file "csim.c" and want to test your implementation, do the following: make clean make./csim -s 4 -E 1 -b 4 -t traces/yi.trace hits:4 misses:5 evictions:3 NOTE: Please do not print anything else. Notice that the output from "csim" matches the output from "csim-ref". To work correctly your simulator must match the output of "csim-ref" for arbitrary traces and values of s, E, and b. To check your implementation in "csim.c" against "csim-ref", you can use the program "test-csim" and run the following command:./test-csim The output will show you how your implementation in "csim.c" compares against "csim-ref". The maximum score possible using the "test-csim" program is 48. 5.4 Guidelines: Some important points regarding the implementation in "csim.c": You should carefully read the skeleton code and the comments in "csim.c". Make sure you understand the various variable types that are provided to you in the skeleton code namely cache_t, cache_set_t, and cache_line_t. You will need to decide how to implement the LRU policy for your cache. Two possible implementations are: List: Move the most recently used cache line to the head of the list. Evict the tail of the list as the least recently used. Counter: Every cache line has a counter. An access to a line would set its value to 1 greater than the current maximum value of all counters in its set. The line with the smallest counter value or least recently used is evicted. Based on the choice you make, you would need to add an extra field to the cache_line_t struct. Starting from main() function, the flow is described below in brief: Parse the command line arguments. This is already done for you. void initcache():this function should allocate the data structures to hold information about the sets and cache lines using malloc() depending on the values of parameters S (S = 2 s ) and E. You need to complete this function.

void replaytrace(char* trace_fn): This function parses the input trace file. This part is already done for you. It should call the accessdata()function. You need to complete the missing code in this function. void accessdata(mem_addr_t addr): This function is the core of implementation which should use the data structures that were allocated in initcache() function to model the cache hits, misses and evictions. You need to complete this function. The most crucial thing is to update the global variables hit_count, miss_count, eviction_count inside this function appropriately. You should implement Least-Recently-Used (LRU) cache replacement policy. void freecache(): This function should free up any memory you allocated using malloc() in initcache() function. This is crucial to avoid memory leaks in the code. You need to complete this function. printsummary(hit_count, miss_count, eviction_count): This function prints the statistics in the desired format. This is already implemented for you. 6. Requirements Your program must follow these Style Guidelines. Your program must follow these Commenting Guidelines. You can keep the file header and function header comments we've put in the skeleton code of csim.c but you must comment the rest of your code inside the functions where necessary. Your programs must operate exactly as specified. We'll compile your programs with gcc -Wall -m32 -std=gnu99 in part 1, and the Makefile in part2 on the CS Linux lab machines. It is your responsibility to ensure that your programs compile on these machines, without warnings or errors. Points are deducted if compiling your programs on the CS Linux lab machines produces warnings and/or errors. 7. Submitting Your Work Submit the following source files under Project 4 in Assignments on Canvas on or before the deadline: 1. cache1d.c 2. cache2drows.c 3. cache2dcols.c 4. p4questions.txt 5. csim.c It is your responsibility to ensure your submission is complete with the correct file names having the correct contents. The following points will seem obvious to most, but we've found we must explicitly state them otherwise some students will request special treatment for their carelessness: You will only receive credit for the files that you submit. You will not receive credit for files that you do not submit. Forgetting to submit, not submitting all the listed files, or submitting executable files or other wrong files will result in you losing credit for the assignment. Do not zip, compress or submit your files in a folder. Submit only the text files as listed.

Make sure your file names exactly match those listed. If you resubmit your work, Canvas will modify the file names by appending a hyphen and a number (e.g., cache1d-1.c) and these Canvas modified names are accepted for grading. Repeated Submission: You may resubmit your work repeatedly until the deadline has passed. We strongly encourage you to use Canvas as a place to store a back up copy of your work. If you resubmit, you must resubmit all of your work rather than updating just some of the files.