Search code examples
gem5

How to output the data in the cache set when the cache is replaced?


I want to learn more about the cache replacement algorithm. For example, I want to know when the cache is replaced, what data is replaced, and what data is brought to the cache. It is a good choice to output this information using the debug flag in gem5. I use classic cache. I created a debug flag to output this information. But I found that when performing the replacement algorithm, it is easy to output the data in which set and way, but it is difficult to output the data in the cacheline. Because I found that only valid, invalid, set, way information is recorded in the replacement algorithm.

  1. I later found uint8_t *data in gem5/src/mem/cache/cache_blk.hh. This should be cache block data, but why is there only one byte, isn't a cachline 64 bytes?
  2. What I don't understand is that when replacing, it will first find the set where the data is located according to the address. Then look for a cacheline based on the replacement algorithm. But I found that the getPossibleEntries function of the gem5/src/mem/cache/tags/indexing_policies/set_associative.cc file, return sets[extractSet(addr)]; sometimes returns four addresses, sometimes 8 are returned. Shouldn't it always return every cacheline of the cache set where the address is located? That is 8 addresses?

By the way, I use the DerivO3CPU Thanks for all related answers.


Solution

  • As a general note, there is a debug flag called CacheRepl. You may want to print whatever information you need from replacements using it.

    1 - The data pointer is a pointer to the first byte of the data. It is not a string; it does not have a null marker at the end. This means that you cannot %s it right off the bat; you need to iterate through every byte using the blkSize (cache line size) to print it with %x (e.g., for (int i = 0; i < blkSize; i++) printf("%x ", blk->data[i])).

    The following question can help if you want to print it as a string: Convert C++ byte array to a C string

    2 - When you print anything in the Replacement Policy (RP), every object that uses that given RP will print. This includes prefetchers, buffers, tags, etc.

    I don't know what is your system configuration, but you probably have at least two different tables that use the RandomRP: at least one with a 4-way associativity, and at least one with a 8-way associativity. When there are four addresses, these are the candidates for the 4-way associative table. When there are 8, it is the 8-way associative.

    If, for example, you want to study the replacement information of the L2 cache, and you know that it is the only table that is 8-way associative, then you can just ignore the results that only have four addresses, since they'd refer to the replacement of other tables.