// Lab 2: Server breaker // This is the code for everything except the per-thread function (which is // in server_breaker_thread.cxx). // c++ -std=c++20 -pthread -O2 server_breaker.cxx ee155_utils.cxx server_breaker_thread.cxx // We will always allocate a vector of this many lines, and then choose which // ones to actually use on any run. static const int MAX_LINES = 10000000; static const int N_ITERATIONS=5; // Top-level iterations... // Fixed by the CPU microarchitecture. static const int BYTES_PER_LINE=64; #include #include #include #include #include #include #include "ee155_utils.hxx" using namespace std; // This is all of the memory lines that we can use. // We just allocate the biggest version we might ever need. static unsigned char g_mem[MAX_LINES * BYTES_PER_LINE]; void compute_thread (int me, const vector &indices, unsigned char g_mem[], int n_stores, int n_loads, int n_line_accesses); static void pick_unique_lines (vector &indices, int n_lines); static void run (int n_lines, int n_stores, int n_loads, int n_threads, int n_line_accesses); mutex g_mut; // For debug printing. //////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { LOG ("There are "< indices; // Indices into g_mem[] of our chosen lines pick_unique_lines (indices, n_lines); // Print a summary of the upcoming run's parameters. LOG ("\nPicking "< times; for (int its=0; its threads; for (int i=0; i 0) for (int i=0; i &indices, int n_lines) { // Initialize it to integer values in [0,N_BUCKETS). default_random_engine gen; uniform_int_distribution dist(0,MAX_LINES-1); //LOG ("Picking rand in [0,"<