From 3100418fb124a9fbcf0874ad7026a9cbec0e2f54 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Fri, 5 Apr 2024 10:35:41 +0100 Subject: [PATCH 1/3] mem-cache: Store totalBlockCount directly in MaxCapacity pp In this way we actually need to store one unsigned integer instead of two. We also won't need to recompute the total number of cache blocks whenever we will adapt this policy to be dynamically modified Change-Id: Ia8cf906539d1891b6cdb821f2a74628127dc68c6 Signed-off-by: Giacomo Travaglini --- .../tags/partitioning_policies/max_capacity_pp.cc | 12 +++++------- .../tags/partitioning_policies/max_capacity_pp.hh | 9 ++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc index 35ceb13a3b..47cd085869 100644 --- a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc +++ b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc @@ -52,8 +52,9 @@ namespace partitioning_policy MaxCapacityPartitioningPolicy::MaxCapacityPartitioningPolicy (const MaxCapacityPartitioningPolicyParams ¶ms): - BasePartitioningPolicy(params), cacheSize(params.cache_size), - blkSize(params.blk_size), partitionIDs(params.partition_ids), + BasePartitioningPolicy(params), + totalBlockCount(params.cache_size / params.blk_size), + partitionIDs(params.partition_ids), capacities(params.capacities) { // check if ids and capacities vectors are the same length @@ -62,9 +63,6 @@ MaxCapacityPartitioningPolicy::MaxCapacityPartitioningPolicy "capacities arrays are not equal lengths"); } - // calculate total cache block count to use when creating allocation maps - const uint64_t total_block_cnt = this->cacheSize / this->blkSize; - // check allocations and create map for (auto i = 0; i < this->partitionIDs.size(); i++) { const uint64_t partition_id = this->partitionIDs[i]; @@ -77,13 +75,13 @@ MaxCapacityPartitioningPolicy::MaxCapacityPartitioningPolicy cap_frac); } - const uint64_t allocated_block_cnt = cap_frac * total_block_cnt; + const uint64_t allocated_block_cnt = cap_frac * totalBlockCount; partitionIdMaxCapacity.emplace(partition_id, allocated_block_cnt); DPRINTF(PartitionPolicy, "Configured MaxCapacity Partitioning Policy " "for PartitionID: %d to use portion of size %f (%d cache blocks " "of %d total)\n", partition_id, cap_frac, allocated_block_cnt, - total_block_cnt); + totalBlockCount); } } diff --git a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh index ba4dadebe5..b8fe12bcdc 100644 --- a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh +++ b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh @@ -81,14 +81,9 @@ class MaxCapacityPartitioningPolicy : public BasePartitioningPolicy private: /** - * Cache size in number of bytes + * Total number of cache blocks */ - const uint64_t cacheSize; - - /** - * Cache block size in number of bytes - */ - const uint64_t blkSize; + const uint64_t totalBlockCount; /** * Vector of partitionIDs the policy operates on From fdcfc28cf4aaea6fbb50bc350b5d5861ac82d6a8 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Fri, 5 Apr 2024 10:46:40 +0100 Subject: [PATCH 2/3] mem-cache: Allow dynamic configuration of MaxCapacity pp This will allow gem5 to configure the maximum capacity of a partition dynamically during simulation, rather than having it statically defined at construction time Change-Id: Ib55c9990a6bc2930abaf2438c13337acc643520f Signed-off-by: Giacomo Travaglini --- .../partitioning_policies/max_capacity_pp.cc | 36 +++++++++++-------- .../partitioning_policies/max_capacity_pp.hh | 8 +++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc index 47cd085869..2180cc12b2 100644 --- a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc +++ b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.cc @@ -68,24 +68,30 @@ MaxCapacityPartitioningPolicy::MaxCapacityPartitioningPolicy const uint64_t partition_id = this->partitionIDs[i]; const double cap_frac = capacities[i]; - // check Capacity Fraction (cap_frac) is actually a fraction in [0,1] - if (!(cap_frac >= 0 && cap_frac <= 1)) { - fatal("MaxCapacity Partitioning Policy for PartitionID %d has " - "Capacity Fraction %f outside of [0,1] range", partition_id, - cap_frac); - } - - const uint64_t allocated_block_cnt = cap_frac * totalBlockCount; - partitionIdMaxCapacity.emplace(partition_id, allocated_block_cnt); - - DPRINTF(PartitionPolicy, "Configured MaxCapacity Partitioning Policy " - "for PartitionID: %d to use portion of size %f (%d cache blocks " - "of %d total)\n", partition_id, cap_frac, allocated_block_cnt, - totalBlockCount); - + // Configure partition + configurePartition(partition_id, cap_frac); } } +void +MaxCapacityPartitioningPolicy::configurePartition(uint64_t partition_id, + double cap_frac) +{ + // check Capacity Fraction (cap_frac) is actually a fraction in [0,1] + panic_if(!(cap_frac >= 0 && cap_frac <= 1), + "MaxCapacity Partitioning Policy for PartitionID %d has " + "Capacity Fraction %f outside of [0,1] range", partition_id, + cap_frac); + + const uint64_t allocated_block_cnt = cap_frac * totalBlockCount; + partitionIdMaxCapacity.emplace(partition_id, allocated_block_cnt); + + DPRINTF(PartitionPolicy, "Configured MaxCapacity Partitioning Policy " + "for PartitionID: %d to use portion of size %f (%d cache blocks " + "of %d total)\n", partition_id, cap_frac, allocated_block_cnt, + totalBlockCount); +} + void MaxCapacityPartitioningPolicy::filterByPartition( std::vector &entries, diff --git a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh index b8fe12bcdc..669a2202da 100644 --- a/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh +++ b/src/mem/cache/tags/partitioning_policies/max_capacity_pp.hh @@ -79,6 +79,14 @@ class MaxCapacityPartitioningPolicy : public BasePartitioningPolicy void notifyRelease(const uint64_t partition_id) override; + /** + * Set the maximum capacity (as a fraction) for the provided partition + * + * param partion_id partition to be configured + * param cap_frac max capacity for the partition (0 < cap_frac < 1) + */ + void configurePartition(uint64_t partition_id, double cap_frac); + private: /** * Total number of cache blocks From b232204b4937f8ab3808a765591048a577198e10 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Fri, 5 Apr 2024 16:52:23 +0100 Subject: [PATCH 3/3] mem-cache: Allow dynamic configuration of the Way pp Change-Id: I1ba9266b24ebc9563f9380fcf155cdc436b2e376 Signed-off-by: Giacomo Travaglini --- src/mem/cache/tags/partitioning_policies/way_pp.cc | 14 +++++++++++++- src/mem/cache/tags/partitioning_policies/way_pp.hh | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/mem/cache/tags/partitioning_policies/way_pp.cc b/src/mem/cache/tags/partitioning_policies/way_pp.cc index ab68b934ff..8a675d0454 100644 --- a/src/mem/cache/tags/partitioning_policies/way_pp.cc +++ b/src/mem/cache/tags/partitioning_policies/way_pp.cc @@ -70,7 +70,7 @@ WayPartitioningPolicy::WayPartitioningPolicy "associativity is %d", alloc_id, way, cache_assoc); if (this->partitionIdWays[alloc_id].count(way) == 0) { - this->partitionIdWays[alloc_id].emplace(way); + addWayToPartition(alloc_id, way); } else { // do not add duplicate allocation to policy and warn warn("Duplicate Way Partitioning Policy allocation for " @@ -86,6 +86,18 @@ WayPartitioningPolicy::WayPartitioningPolicy } } +void +WayPartitioningPolicy::addWayToPartition(uint64_t partition_id, unsigned way) +{ + partitionIdWays[partition_id].emplace(way); +} + +void +WayPartitioningPolicy::removeWayToPartition(uint64_t partition_id, unsigned way) +{ + partitionIdWays[partition_id].erase(way); +} + void WayPartitioningPolicy::filterByPartition( std::vector &entries, diff --git a/src/mem/cache/tags/partitioning_policies/way_pp.hh b/src/mem/cache/tags/partitioning_policies/way_pp.hh index ef623689a5..bb8fb06998 100644 --- a/src/mem/cache/tags/partitioning_policies/way_pp.hh +++ b/src/mem/cache/tags/partitioning_policies/way_pp.hh @@ -85,6 +85,9 @@ class WayPartitioningPolicy : public BasePartitioningPolicy void notifyRelease(const uint64_t partition_id) override {}; + void addWayToPartition(uint64_t partition_id, unsigned way); + void removeWayToPartition(uint64_t partition_id, unsigned way); + private: /** * Map of policied PartitionIDs and their associated cache ways