From 3bd54db68d25cb6b75daf7205bebb370ea8b05b7 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Tue, 10 Sep 2024 12:54:27 +0100 Subject: [PATCH] mem-cache: Do not require p.size and p.entry_size in IP template This commit is adjusting the constructor to relax template requirements. In this way child classes are free to provide their own way of calculating the number of entries and the shifting required to extract the set Why do we need this? Up to this patch we have been configuring the indexing policy by setting up the cache/table size (in bytes) and the entry size. Those parameters make a lot of sense in caching structures where: a) We want to configure the caching structure using the amount of storage (in bytes) provided (e.g. 4kB of Cache) b) the content of a single entry is addressable therefore we need the entry size to know how many bits in the indexing process we need to shift to extract the set In those cases the number of cache entries is derived from the formula num_entries = size / entry_size The adoption of the IndexingPolicy for different kinds of caching structures (e.g. prefetcher tables) make this way of configuring the IP a bit quirky. For some tables directly setting the number of entries is a far more intuitive way of configuring the IP, instead of allocating the desired number of entries by working things out with the formula above Change-Id: Ic7994c129196d6ba83dc99ce397ad43393d35252 Signed-off-by: Giacomo Travaglini --- src/mem/cache/tags/indexing_policies/base.hh | 12 +++++++----- .../cache/tags/indexing_policies/set_associative.cc | 2 +- .../tags/indexing_policies/skewed_associative.cc | 3 ++- src/mem/cache/tags/tagged_entry.hh | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mem/cache/tags/indexing_policies/base.hh b/src/mem/cache/tags/indexing_policies/base.hh index 32465df5dc..7bd3496b2c 100644 --- a/src/mem/cache/tags/indexing_policies/base.hh +++ b/src/mem/cache/tags/indexing_policies/base.hh @@ -109,14 +109,16 @@ class IndexingPolicyTemplate : public SimObject /** * Construct and initialize this policy. */ - IndexingPolicyTemplate(const Params &p) + IndexingPolicyTemplate(const Params &p, + uint32_t num_entries, + int set_shift) : SimObject(p), assoc(p.assoc), - numSets(p.size / (p.entry_size * assoc)), - setShift(floorLog2(p.entry_size)), setMask(numSets - 1), sets(numSets), + numSets(num_entries / assoc), + setShift(set_shift), setMask(numSets - 1), sets(numSets), tagShift(setShift + floorLog2(numSets)) { - fatal_if(!isPowerOf2(numSets), "# of sets must be non-zero and a power " \ - "of 2"); + fatal_if(!isPowerOf2(numSets), + "# of sets must be non-zero and a power of 2"); fatal_if(assoc <= 0, "associativity must be greater than zero"); // Make space for the entries diff --git a/src/mem/cache/tags/indexing_policies/set_associative.cc b/src/mem/cache/tags/indexing_policies/set_associative.cc index 36011f10ef..fd250a0ac1 100644 --- a/src/mem/cache/tags/indexing_policies/set_associative.cc +++ b/src/mem/cache/tags/indexing_policies/set_associative.cc @@ -52,7 +52,7 @@ namespace gem5 { SetAssociative::SetAssociative(const Params &p) - : BaseIndexingPolicy(p) + : BaseIndexingPolicy(p, p.size / p.entry_size, floorLog2(p.entry_size)) { } diff --git a/src/mem/cache/tags/indexing_policies/skewed_associative.cc b/src/mem/cache/tags/indexing_policies/skewed_associative.cc index 76e7acabca..bef191adf0 100644 --- a/src/mem/cache/tags/indexing_policies/skewed_associative.cc +++ b/src/mem/cache/tags/indexing_policies/skewed_associative.cc @@ -42,7 +42,8 @@ namespace gem5 { SkewedAssociative::SkewedAssociative(const Params &p) - : BaseIndexingPolicy(p), msbShift(floorLog2(numSets) - 1) + : BaseIndexingPolicy(p, p.size / p.entry_size, floorLog2(p.entry_size)), + msbShift(floorLog2(numSets) - 1) { if (assoc > NUM_SKEWING_FUNCTIONS) { warn_once("Associativity higher than number of skewing functions. " \ diff --git a/src/mem/cache/tags/tagged_entry.hh b/src/mem/cache/tags/tagged_entry.hh index 1a1d773371..41a780f279 100644 --- a/src/mem/cache/tags/tagged_entry.hh +++ b/src/mem/cache/tags/tagged_entry.hh @@ -85,7 +85,7 @@ class TaggedSetAssociative : public TaggedIndexingPolicy public: PARAMS(TaggedSetAssociative); TaggedSetAssociative(const Params &p) - : TaggedIndexingPolicy(p) + : TaggedIndexingPolicy(p, p.size / p.entry_size, floorLog2(p.entry_size)) {} std::vector