From d0539fe7cbad4c2c717767629fe070882bb86a17 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Tue, 12 Mar 2024 13:54:59 +0000 Subject: [PATCH] mem-cache: Define a PartitionManager to handle partitioning This is a first step towards offloading some of the partitioning logic to the partitioning manager. We start with this patch by replacing the static readPacketPartitionId into a virtual method owned by the manager. The issue with readPacketPartitionId as of now is that it relies on the fixed PartitionFieldExtention. We want user to be able to extract the partitionId more flexibly and this requires using a SimObject Change-Id: I3bd2e81e2a97c55fc83548956fc59f422c8049a6 Signed-off-by: Giacomo Travaglini --- src/mem/cache/Cache.py | 3 + src/mem/cache/base.cc | 6 +- src/mem/cache/base.hh | 9 ++- src/mem/cache/tags/Tags.py | 4 + src/mem/cache/tags/base.cc | 6 +- src/mem/cache/tags/base.hh | 3 + src/mem/cache/tags/base_set_assoc.hh | 5 +- .../PartitioningPolicies.py | 19 ++++- .../tags/partitioning_policies/SConscript | 1 + .../partition_manager.hh | 77 +++++++++++++++++++ 10 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 src/mem/cache/tags/partitioning_policies/partition_manager.hh diff --git a/src/mem/cache/Cache.py b/src/mem/cache/Cache.py index 874182a9f8..853be2343a 100644 --- a/src/mem/cache/Cache.py +++ b/src/mem/cache/Cache.py @@ -117,6 +117,9 @@ class BaseCache(ClockedObject): "Setting multiple policies will enforce all of them individually " "in order", ) + partitioning_manager = Param.PartitionManager( + NULL, "Cache partitioning manager" + ) compressor = Param.BaseCacheCompressor(NULL, "Cache compressor.") replace_expansions = Param.Bool( diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc index 095dea5e63..df0243a0fb 100644 --- a/src/mem/cache/base.cc +++ b/src/mem/cache/base.cc @@ -58,7 +58,7 @@ #include "mem/cache/prefetch/base.hh" #include "mem/cache/queue_entry.hh" #include "mem/cache/tags/compressed_tags.hh" -#include "mem/cache/tags/partitioning_policies/partition_fields_extension.hh" +#include "mem/cache/tags/partitioning_policies/partition_manager.hh" #include "mem/cache/tags/super_blk.hh" #include "params/BaseCache.hh" #include "params/WriteAllocator.hh" @@ -87,6 +87,7 @@ BaseCache::BaseCache(const BaseCacheParams &p, unsigned blk_size) writeBuffer("write buffer", p.write_buffers, p.mshrs, p.name), tags(p.tags), compressor(p.compressor), + partitionManager(p.partitioning_manager), prefetcher(p.prefetcher), writeAllocator(p.write_allocator), writebackClean(p.writeback_clean), @@ -1642,7 +1643,8 @@ BaseCache::allocateBlock(const PacketPtr pkt, PacketList &writebacks) } // get partitionId from Packet - const auto partition_id = partitioning_policy::readPacketPartitionID(pkt); + const auto partition_id = partitionManager ? + partitionManager->readPacketPartitionID(pkt) : 0; // Find replacement victim std::vector evict_blks; CacheBlk *victim = tags->findVictim(addr, is_secure, blk_size_bits, diff --git a/src/mem/cache/base.hh b/src/mem/cache/base.hh index c2d9bc8a7b..af440e8b1e 100644 --- a/src/mem/cache/base.hh +++ b/src/mem/cache/base.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2013, 2015-2016, 2018-2019, 2023 ARM Limited + * Copyright (c) 2012-2013, 2015-2016, 2018-2019, 2023-2024 Arm Limited * All rights reserved. * * The license below extends only to copyright in the software and shall @@ -84,6 +84,10 @@ namespace prefetch { class Base; } +namespace partitioning_policy +{ + class PartitionManager; +} class MSHR; class RequestPort; class QueueEntry; @@ -351,6 +355,9 @@ class BaseCache : public ClockedObject /** Compression method being used. */ compression::Base* compressor; + /** Partitioning manager */ + partitioning_policy::PartitionManager* partitionManager; + /** Prefetcher */ prefetch::Base *prefetcher; diff --git a/src/mem/cache/tags/Tags.py b/src/mem/cache/tags/Tags.py index 3dbd526b35..17df7f4780 100644 --- a/src/mem/cache/tags/Tags.py +++ b/src/mem/cache/tags/Tags.py @@ -79,6 +79,10 @@ class BaseTags(ClockedObject): Parent.partitioning_policies, "Partitioning policies" ) + partitioning_manager = Param.PartitionManager( + Parent.partitioning_manager, "Cache partitioning manager" + ) + # Set the indexing entry size as the block size entry_size = Param.Int( Parent.cache_line_size, "Indexing entry size in bytes" diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index c7e529ef0c..efd72eeb9f 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -50,7 +50,7 @@ #include "base/types.hh" #include "mem/cache/replacement_policies/replaceable_entry.hh" #include "mem/cache/tags/indexing_policies/base.hh" -#include "mem/cache/tags/partitioning_policies/partition_fields_extension.hh" +#include "mem/cache/tags/partitioning_policies/partition_manager.hh" #include "mem/request.hh" #include "sim/core.hh" #include "sim/sim_exit.hh" @@ -64,6 +64,7 @@ BaseTags::BaseTags(const Params &p) size(p.size), lookupLatency(p.tag_latency), system(p.system), indexingPolicy(p.indexing_policy), partitioningPolicies(p.partitioning_policies), + partitionManager(p.partitioning_manager), warmupBound((p.warmup_percentage/100.0) * (p.size / p.block_size)), warmedUp(false), numBlocks(p.size / p.block_size), dataBlks(new uint8_t[p.size]), // Allocate data storage in one big chunk @@ -114,7 +115,8 @@ BaseTags::insertBlock(const PacketPtr pkt, CacheBlk *blk) stats.occupancies[requestor_id]++; // Insert block with tag, src requestor id, task id and PartitionId - const auto partition_id = partitioning_policy::readPacketPartitionID(pkt); + const auto partition_id = partitionManager ? + partitionManager->readPacketPartitionID(pkt) : 0; blk->insert(extractTag(pkt->getAddr()), pkt->isSecure(), requestor_id, pkt->req->taskId(), partition_id); diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh index 307159ae1d..ba121db2f6 100644 --- a/src/mem/cache/tags/base.hh +++ b/src/mem/cache/tags/base.hh @@ -93,6 +93,9 @@ class BaseTags : public ClockedObject std::vector partitioningPolicies; + /** Partitioning manager */ + partitioning_policy::PartitionManager *partitionManager; + /** * The number of tags that need to be touched to meet the warmup * percentage. diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh index db5fe605a7..18fecde199 100644 --- a/src/mem/cache/tags/base_set_assoc.hh +++ b/src/mem/cache/tags/base_set_assoc.hh @@ -59,7 +59,7 @@ #include "mem/cache/replacement_policies/replaceable_entry.hh" #include "mem/cache/tags/base.hh" #include "mem/cache/tags/indexing_policies/base.hh" -#include "mem/cache/tags/partitioning_policies/partition_fields_extension.hh" +#include "mem/cache/tags/partitioning_policies/partition_manager.hh" #include "mem/packet.hh" #include "params/BaseSetAssoc.hh" @@ -207,8 +207,9 @@ class BaseSetAssoc : public BaseTags // Notify partitioning policies of acquisition of ownership for (auto & partitioning_policy : partitioningPolicies) { // get partitionId from Packet + assert(partitionManager); const auto partitionId = - partitioning_policy::readPacketPartitionID(pkt); + partitionManager->readPacketPartitionID(pkt); partitioning_policy->notifyAcquire(partitionId); } diff --git a/src/mem/cache/tags/partitioning_policies/PartitioningPolicies.py b/src/mem/cache/tags/partitioning_policies/PartitioningPolicies.py index 74ef6c5113..fbc5a39458 100644 --- a/src/mem/cache/tags/partitioning_policies/PartitioningPolicies.py +++ b/src/mem/cache/tags/partitioning_policies/PartitioningPolicies.py @@ -1,5 +1,14 @@ -# Copyright (c) 2024 ARM Limited -# All rights reserved. +# Copyright (c) 2024 Arm Limited +# All rights reserved +# +# The license below extends only to copyright in the software and shall +# not be construed as granting a license to any other intellectual +# property including but not limited to intellectual property relating +# to a hardware implementation of the functionality of the software +# licensed hereunder. You may use the software subject to the license +# terms below provided that you ensure that this notice is replicated +# unmodified and in its entirety in all distributions of the software, +# modified or unmodified, in source code or in binary form. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are @@ -32,6 +41,12 @@ from m5.proxy import Parent from m5.SimObject import SimObject +class PartitionManager(SimObject): + type = "PartitionManager" + cxx_header = "mem/cache/tags/partitioning_policies/partition_manager.hh" + cxx_class = "gem5::partitioning_policy::PartitionManager" + + class BasePartitioningPolicy(SimObject): type = "BasePartitioningPolicy" cxx_header = "mem/cache/tags/partitioning_policies/base_pp.hh" diff --git a/src/mem/cache/tags/partitioning_policies/SConscript b/src/mem/cache/tags/partitioning_policies/SConscript index 37c75f4de6..c79cbce71e 100644 --- a/src/mem/cache/tags/partitioning_policies/SConscript +++ b/src/mem/cache/tags/partitioning_policies/SConscript @@ -38,6 +38,7 @@ Import('*') SimObject('PartitioningPolicies.py', sim_objects=[ + 'PartitionManager', 'BasePartitioningPolicy', 'MaxCapacityPartitioningPolicy', 'WayPolicyAllocation', diff --git a/src/mem/cache/tags/partitioning_policies/partition_manager.hh b/src/mem/cache/tags/partitioning_policies/partition_manager.hh new file mode 100644 index 0000000000..968d5705d8 --- /dev/null +++ b/src/mem/cache/tags/partitioning_policies/partition_manager.hh @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Arm Limited + * All rights reserved + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MEM_CACHE_TAGS_PARTITIONING_MANAGER_HH__ +#define __MEM_CACHE_TAGS_PARTITIONING_MANAGER_HH__ + +#include "mem/packet.hh" +#include "params/PartitionManager.hh" +#include "sim/sim_object.hh" + +namespace gem5 +{ + +namespace partitioning_policy +{ + +class PartitionManager : public SimObject +{ + public: + PARAMS(PartitionManager); + PartitionManager(const Params &p) + : SimObject(p) + {} + + /** + * PartitionManager interface to retrieve PartitionID from a packet; + * This base implementation returns zero by default. + * + * @param pkt pointer to packet (PacketPtr) + * @return packet PartitionID. + */ + virtual uint64_t + readPacketPartitionID(PacketPtr pkt) const + { + return 0; + }; +}; + +} // namespace partitioning_policy + +} // namespace gem5 + +#endif // __MEM_CACHE_TAGS_PARTITIONING_MANAGER_HH__