Adding a g-cache to a system is pretty straightforward. You can append the following code to the script creating your simulated machine:
@cache = pre_conf_object('cache', 'g-cache') @cache.cpus = conf.cpu0 @cache.config_line_number = 256 @cache.config_line_size = 32 @cache.config_assoc = 1 @cache.config_virtual_index = 0 @cache.config_virtual_tag = 0 @cache.config_replacement_policy = 'random' @cache.penalty_read = 0 @cache.penalty_write = 0 @cache.penalty_read_next = 0 @cache.penalty_write_next = 0 @SIM_add_configuration([cache], None)
This command will tell Simics to create a new object called cache, of type g-cache. It also sets some parameters to describe the cache (number of lines, size, associativity, type of index and tag, replacement policy, and stall penalties).
Now start Simics with the -stall flag to load the configuration with the cache in a mode where cache simulation is working properly. The only thing left is to connect the cache somewhere so that it will receive memory accesses. To connect it to the main memory, execute:
@conf.phys_mem0.timing_model = conf.cache
From now on, accesses to main memory will go through the cache and cache hits/misses will be simulated. If you run the simulation for a while, you will get information about the cache with the cache.status and cache.statistics commands.