CohereSim: A Bus-based Cache Simulator  v3.3
A tool for education in computing - learn about coherence protocols, replacement policies, and SMP vs DSM
Macros | Functions | Variables
main.cc File Reference

This file processes the command line arguments, provides helper methods for processing the command line arguments, and decides what to run. More...

#include <filesystem>
#include <fstream>
#include "typedefs.h"
#include "run_modes.h"
Include dependency graph for main.cc:

Macros

#define NO_ARGS   1
 The value of 'argc' if no arguments were passed on the command line.
 
#define NUM_COLUMNS   (N_STATISTICS + 3)
 The number of columns that appear in the output statistics.
 
#define CONFIG_LINE_SIZE   (ARG_C_COUNT * 10)
 The size of the config line buffer.
 

Functions

void exitIf (bool condition, std::string msg, uint32_t config_id, uint32_t arg_index)
 Provide error message and exit code on condition. More...
 
void getConfig (int argc, char *argv[], cache_config &config)
 Parse the given arguments into a memory system configuration. More...
 
size_t getTrace (int argc, char *argv[], std::ifstream &trace_file, int arg_max_count)
 Open the trace file and read the trace limit. More...
 
void readConfigurations (std::vector< cache_config > &configs, char *configs_file_path)
 Parse the cache configurations from the given configs file. More...
 
void printStatsHeader ()
 Print the header row in the statistics output CSV.
 
void usageMsg ()
 Print the program usage method.
 
int main (int argc, char *argv[])
 The main function decides which mode to execute based on the number of arguments supplied. More...
 

Variables

std::map< std::string, coh_factory_t, ci_less > * coherence_map = nullptr
 A map from coherence protocol names to their factory functions.
 
std::map< std::string, dir_factory_t, ci_less > * directory_map = nullptr
 A map from directory protocol names to their factory functions.
 
std::map< std::string, rep_factory_t, ci_less > * replacement_map = nullptr
 A map from replacement policy names to their factory functions.
 
constexpr const char * stat_names [NUM_COLUMNS]
 CSV-friendly names for cache runtime statistics. Make sure these match up with 'bus_msg_e' and 'statistic_e'. More...
 

Detailed Description

This file processes the command line arguments, provides helper methods for processing the command line arguments, and decides what to run.

Function Documentation

◆ exitIf()

void exitIf ( bool  condition,
std::string  msg,
uint32_t  config_id,
uint32_t  arg_index 
)

Provide error message and exit code on condition.

Parameters
conditionWhether the program should print an error message and exit
msgThe error message to print
config_idThe ID of the config that caused the error
arg_indexThe argument of the config that caused the error
See also
Exit Codes

◆ getConfig()

void getConfig ( int  argc,
char *  argv[],
cache_config config 
)

Parse the given arguments into a memory system configuration.

Parameters
argcThe number of program arguments
argvThe array of program arguments
configThe configuration struct to populate

◆ getTrace()

size_t getTrace ( int  argc,
char *  argv[],
std::ifstream &  trace_file,
int  arg_max_count 
)

Open the trace file and read the trace limit.

Parameters
argcThe number of program arguments
argvThe array of program arguments
trace_fileAn ifstream that will become the trace file
arg_max_countThe number of arguments when the trace limit argument is present
Returns
The trace limit

◆ main()

int main ( int  argc,
char *  argv[] 
)

The main function decides which mode to execute based on the number of arguments supplied.

Parameters
argcThe number of command line arguments
argvAn array to the command line arguments
Returns
The program exit code
See also
Exit Codes

◆ readConfigurations()

void readConfigurations ( std::vector< cache_config > &  configs,
char *  configs_file_path 
)

Parse the cache configurations from the given configs file.

Parameters
configsThe vector to contain the configurations
configs_file_pathThe file path to the configs file

Variable Documentation

◆ stat_names

constexpr const char* stat_names[NUM_COLUMNS]
constexpr
Initial value:
= {
"config", "core", "miss rate",
"processor reads", "processor writes",
"bus reads", "bus readxs", "bus updates", "bus upgrades", "bus writes",
"read misses", "write misses",
"line flushes", "line fetches", "c2c transfers", "write backs", "memory writes",
"evictions",
"exclusions", "interventions", "invalidations"
}

CSV-friendly names for cache runtime statistics. Make sure these match up with 'bus_msg_e' and 'statistic_e'.