diff options
Diffstat (limited to 'src/mem/ruby/structures')
-rw-r--r-- | src/mem/ruby/structures/AbstractReplacementPolicy.cc | 74 | ||||
-rw-r--r-- | src/mem/ruby/structures/AbstractReplacementPolicy.hh | 66 | ||||
-rw-r--r-- | src/mem/ruby/structures/CacheMemory.cc | 75 | ||||
-rw-r--r-- | src/mem/ruby/structures/CacheMemory.hh | 35 | ||||
-rw-r--r-- | src/mem/ruby/structures/DirectoryMemory.cc | 8 | ||||
-rw-r--r-- | src/mem/ruby/structures/DirectoryMemory.hh | 8 | ||||
-rw-r--r-- | src/mem/ruby/structures/LRUPolicy.cc | 76 | ||||
-rw-r--r-- | src/mem/ruby/structures/LRUPolicy.hh | 48 | ||||
-rw-r--r-- | src/mem/ruby/structures/LRUReplacementPolicy.py | 41 | ||||
-rw-r--r-- | src/mem/ruby/structures/PseudoLRUPolicy.cc | 111 | ||||
-rw-r--r-- | src/mem/ruby/structures/PseudoLRUPolicy.hh | 66 | ||||
-rw-r--r-- | src/mem/ruby/structures/PseudoLRUReplacementPolicy.py | 35 | ||||
-rw-r--r-- | src/mem/ruby/structures/ReplacementPolicy.py | 43 | ||||
-rw-r--r-- | src/mem/ruby/structures/RubyCache.py | 5 | ||||
-rw-r--r-- | src/mem/ruby/structures/SConscript | 6 |
15 files changed, 87 insertions, 610 deletions
diff --git a/src/mem/ruby/structures/AbstractReplacementPolicy.cc b/src/mem/ruby/structures/AbstractReplacementPolicy.cc deleted file mode 100644 index 01eb6e517..000000000 --- a/src/mem/ruby/structures/AbstractReplacementPolicy.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2013 Advanced Micro Devices, Inc - * All rights reserved. - * - * 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. - * - * Author: Derek Hower - */ - -#include "mem/ruby/structures/AbstractReplacementPolicy.hh" - -#include "base/logging.hh" - -AbstractReplacementPolicy::AbstractReplacementPolicy(const Params * p) - : SimObject(p) -{ - m_num_sets = p->size/p->block_size/p->assoc; - m_assoc = p->assoc; - m_last_ref_ptr = new Tick*[m_num_sets]; - for (unsigned i = 0; i < m_num_sets; i++){ - m_last_ref_ptr[i] = new Tick[m_assoc]; - for (unsigned j = 0; j < m_assoc; j++){ - m_last_ref_ptr[i][j] = 0; - } - } -} - -AbstractReplacementPolicy * -ReplacementPolicyParams::create() -{ - fatal("Cannot create an AbstractReplacementPolicy"); - return NULL; -} - - - -AbstractReplacementPolicy::~AbstractReplacementPolicy() -{ - if (m_last_ref_ptr != NULL){ - for (unsigned i = 0; i < m_num_sets; i++){ - if (m_last_ref_ptr[i] != NULL){ - delete[] m_last_ref_ptr[i]; - } - } - delete[] m_last_ref_ptr; - } -} - -Tick -AbstractReplacementPolicy::getLastAccess(int64_t set, int64_t way) -{ - return m_last_ref_ptr[set][way]; -} diff --git a/src/mem/ruby/structures/AbstractReplacementPolicy.hh b/src/mem/ruby/structures/AbstractReplacementPolicy.hh deleted file mode 100644 index c118f3c11..000000000 --- a/src/mem/ruby/structures/AbstractReplacementPolicy.hh +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2007 Mark D. Hill and David A. Wood - * All rights reserved. - * - * 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_RUBY_STRUCTURES_ABSTRACTREPLACEMENTPOLICY_HH__ -#define __MEM_RUBY_STRUCTURES_ABSTRACTREPLACEMENTPOLICY_HH__ - -#include "base/types.hh" -#include "mem/ruby/common/TypeDefines.hh" -#include "params/ReplacementPolicy.hh" -#include "sim/sim_object.hh" - -class CacheMemory; - -class AbstractReplacementPolicy : public SimObject -{ - public: - typedef ReplacementPolicyParams Params; - AbstractReplacementPolicy(const Params * p); - virtual ~AbstractReplacementPolicy(); - - /* touch a block. a.k.a. update timestamp */ - virtual void touch(int64_t set, int64_t way, Tick time) = 0; - - /* returns the way to replace */ - virtual int64_t getVictim(int64_t set) const = 0; - - /* get the time of the last access */ - Tick getLastAccess(int64_t set, int64_t way); - - virtual bool useOccupancy() const { return false; } - - void setCache(CacheMemory * pCache) {m_cache = pCache;} - CacheMemory * m_cache; - - protected: - unsigned m_num_sets; /** total number of sets */ - unsigned m_assoc; /** set associativity */ - Tick **m_last_ref_ptr; /** timestamp of last reference */ -}; - -#endif // __MEM_RUBY_STRUCTURES_ABSTRACTREPLACEMENTPOLICY_HH__ diff --git a/src/mem/ruby/structures/CacheMemory.cc b/src/mem/ruby/structures/CacheMemory.cc index 5dc346388..a7aa6370b 100644 --- a/src/mem/ruby/structures/CacheMemory.cc +++ b/src/mem/ruby/structures/CacheMemory.cc @@ -65,11 +65,12 @@ CacheMemory::CacheMemory(const Params *p) m_cache_size = p->size; m_cache_assoc = p->assoc; m_replacementPolicy_ptr = p->replacement_policy; - m_replacementPolicy_ptr->setCache(this); m_start_index_bit = p->start_index_bit; m_is_instruction_only_cache = p->is_icache; m_resource_stalls = p->resourceStalls; m_block_size = p->block_size; // may be 0 at this point. Updated in init() + m_use_occupancy = dynamic_cast<WeightedLRUPolicy*>( + m_replacementPolicy_ptr) ? true : false; } void @@ -85,6 +86,15 @@ CacheMemory::init() m_cache.resize(m_cache_num_sets, std::vector<AbstractCacheEntry*>(m_cache_assoc, nullptr)); + replacement_data.resize(m_cache_num_sets, + std::vector<ReplData>(m_cache_assoc, nullptr)); + // instantiate all the replacement_data here + for (int i = 0; i < m_cache_num_sets; i++) { + for ( int j = 0; j < m_cache_assoc; j++) { + replacement_data[i][j] = + m_replacementPolicy_ptr->instantiateEntry(); + } + } } CacheMemory::~CacheMemory() @@ -170,7 +180,8 @@ CacheMemory::tryCacheAccess(Addr address, RubyRequestType type, if (loc != -1) { // Do we even have a tag match? AbstractCacheEntry* entry = m_cache[cacheSet][loc]; - m_replacementPolicy_ptr->touch(cacheSet, loc, curTick()); + m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]); + m_cache[cacheSet][loc]->setLastAccess(curTick()); data_ptr = &(entry->getDataBlk()); if (entry->m_Permission == AccessPermission_Read_Write) { @@ -198,7 +209,8 @@ CacheMemory::testCacheAccess(Addr address, RubyRequestType type, if (loc != -1) { // Do we even have a tag match? AbstractCacheEntry* entry = m_cache[cacheSet][loc]; - m_replacementPolicy_ptr->touch(cacheSet, loc, curTick()); + m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]); + m_cache[cacheSet][loc]->setLastAccess(curTick()); data_ptr = &(entry->getDataBlk()); return m_cache[cacheSet][loc]->m_Permission != @@ -252,7 +264,7 @@ CacheMemory::cacheAvail(Addr address) const } AbstractCacheEntry* -CacheMemory::allocate(Addr address, AbstractCacheEntry *entry, bool touch) +CacheMemory::allocate(Addr address, AbstractCacheEntry *entry) { assert(address == makeLineAddress(address)); assert(!isTagPresent(address)); @@ -278,13 +290,11 @@ CacheMemory::allocate(Addr address, AbstractCacheEntry *entry, bool touch) address); set[i]->m_locked = -1; m_tag_index[address] = i; - entry->setSetIndex(cacheSet); - entry->setWayIndex(i); - - if (touch) { - m_replacementPolicy_ptr->touch(cacheSet, i, curTick()); - } - + set[i]->setPosition(cacheSet, i); + // Call reset function here to set initial value for different + // replacement policies. + m_replacementPolicy_ptr->reset(replacement_data[cacheSet][i]); + set[i]->setLastAccess(curTick()); return entry; } } @@ -300,6 +310,7 @@ CacheMemory::deallocate(Addr address) int64_t cacheSet = addressToCacheSet(address); int loc = findTagInSet(cacheSet, address); if (loc != -1) { + m_replacementPolicy_ptr->invalidate(replacement_data[cacheSet][loc]); delete m_cache[cacheSet][loc]; m_cache[cacheSet][loc] = NULL; m_tag_index.erase(address); @@ -314,8 +325,16 @@ CacheMemory::cacheProbe(Addr address) const assert(!cacheAvail(address)); int64_t cacheSet = addressToCacheSet(address); - return m_cache[cacheSet][m_replacementPolicy_ptr->getVictim(cacheSet)]-> - m_Address; + std::vector<ReplaceableEntry*> candidates; + for (int i = 0; i < m_cache_assoc; i++) { + // Pass the value of replacement_data to the cache entry so that we + // can use it in the getVictim() function. + m_cache[cacheSet][i]->replacementData = replacement_data[cacheSet][i]; + candidates.push_back(static_cast<ReplaceableEntry*>( + m_cache[cacheSet][i])); + } + return m_cache[cacheSet][m_replacementPolicy_ptr-> + getVictim(candidates)->getWay()]->m_Address; } // looks an address up in the cache @@ -347,16 +366,19 @@ CacheMemory::setMRU(Addr address) int64_t cacheSet = addressToCacheSet(address); int loc = findTagInSet(cacheSet, address); - if (loc != -1) - m_replacementPolicy_ptr->touch(cacheSet, loc, curTick()); + if (loc != -1) { + m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]); + m_cache[cacheSet][loc]->setLastAccess(curTick()); + } } void CacheMemory::setMRU(const AbstractCacheEntry *e) { - uint32_t cacheSet = e->getSetIndex(); - uint32_t loc = e->getWayIndex(); - m_replacementPolicy_ptr->touch(cacheSet, loc, curTick()); + uint32_t cacheSet = e->getSet(); + uint32_t loc = e->getWay(); + m_replacementPolicy_ptr->touch(replacement_data[cacheSet][loc]); + m_cache[cacheSet][loc]->setLastAccess(curTick()); } void @@ -366,13 +388,17 @@ CacheMemory::setMRU(Addr address, int occupancy) int loc = findTagInSet(cacheSet, address); if (loc != -1) { - if (m_replacementPolicy_ptr->useOccupancy()) { - (static_cast<WeightedLRUPolicy*>(m_replacementPolicy_ptr))-> - touch(cacheSet, loc, curTick(), occupancy); + // m_use_occupancy can decide whether we are using WeightedLRU + // replacement policy. Depending on different replacement policies, + // use different touch() function. + if (m_use_occupancy) { + static_cast<WeightedLRUPolicy*>(m_replacementPolicy_ptr)->touch( + replacement_data[cacheSet][loc], occupancy); } else { m_replacementPolicy_ptr-> - touch(cacheSet, loc, curTick()); + touch(replacement_data[cacheSet][loc]); } + m_cache[cacheSet][loc]->setLastAccess(curTick()); } } @@ -413,9 +439,10 @@ CacheMemory::recordCacheContents(int cntrl, CacheRecorder* tr) const } if (request_type != RubyRequestType_NULL) { + Tick lastAccessTick; + lastAccessTick = m_cache[i][j]->getLastAccess(); tr->addRecord(cntrl, m_cache[i][j]->m_Address, - 0, request_type, - m_replacementPolicy_ptr->getLastAccess(i, j), + 0, request_type, lastAccessTick, m_cache[i][j]->getDataBlk()); warmedUpBlocks++; } diff --git a/src/mem/ruby/structures/CacheMemory.hh b/src/mem/ruby/structures/CacheMemory.hh index 16339ee55..ce5d81d04 100644 --- a/src/mem/ruby/structures/CacheMemory.hh +++ b/src/mem/ruby/structures/CacheMemory.hh @@ -35,13 +35,14 @@ #include <vector> #include "base/statistics.hh" +#include "mem/cache/replacement_policies/base.hh" +#include "mem/cache/replacement_policies/replaceable_entry.hh" #include "mem/ruby/common/DataBlock.hh" #include "mem/ruby/protocol/CacheRequestType.hh" #include "mem/ruby/protocol/CacheResourceType.hh" #include "mem/ruby/protocol/RubyRequest.hh" #include "mem/ruby/slicc_interface/AbstractCacheEntry.hh" #include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" -#include "mem/ruby/structures/AbstractReplacementPolicy.hh" #include "mem/ruby/structures/BankedArray.hh" #include "mem/ruby/system/CacheRecorder.hh" #include "params/RubyCache.hh" @@ -51,6 +52,7 @@ class CacheMemory : public SimObject { public: typedef RubyCacheParams Params; + typedef std::shared_ptr<ReplacementData> ReplData; CacheMemory(const Params *p); ~CacheMemory(); @@ -74,15 +76,10 @@ class CacheMemory : public SimObject bool cacheAvail(Addr address) const; // find an unused entry and sets the tag appropriate for the address - AbstractCacheEntry* allocate(Addr address, - AbstractCacheEntry* new_entry, bool touch); - AbstractCacheEntry* allocate(Addr address, AbstractCacheEntry* new_entry) - { - return allocate(address, new_entry, true); - } + AbstractCacheEntry* allocate(Addr address, AbstractCacheEntry* new_entry); void allocateVoid(Addr address, AbstractCacheEntry* new_entry) { - allocate(address, new_entry, true); + allocate(address, new_entry); } // Explicitly free up this address @@ -173,7 +170,11 @@ class CacheMemory : public SimObject std::unordered_map<Addr, int> m_tag_index; std::vector<std::vector<AbstractCacheEntry*> > m_cache; - AbstractReplacementPolicy *m_replacementPolicy_ptr; + /** + * We use BaseReplacementPolicy from Classic system here, hence we can use + * different replacement policies from Classic system in Ruby system. + */ + BaseReplacementPolicy *m_replacementPolicy_ptr; BankedArray dataArray; BankedArray tagArray; @@ -185,6 +186,22 @@ class CacheMemory : public SimObject int m_start_index_bit; bool m_resource_stalls; int m_block_size; + + /** + * We store all the ReplacementData in a 2-dimensional array. By doing + * this, we can use all replacement policies from Classic system. Ruby + * cache will deallocate cache entry every time we evict the cache block + * so we cannot store the ReplacementData inside the cache entry. + * Instantiate ReplacementData for multiple times will break replacement + * policy like TreePLRU. + */ + std::vector<std::vector<ReplData> > replacement_data; + + /** + * Set to true when using WeightedLRU replacement policy, otherwise, set to + * false. + */ + bool m_use_occupancy; }; std::ostream& operator<<(std::ostream& out, const CacheMemory& obj); diff --git a/src/mem/ruby/structures/DirectoryMemory.cc b/src/mem/ruby/structures/DirectoryMemory.cc index 551e3f57f..d9da05861 100644 --- a/src/mem/ruby/structures/DirectoryMemory.cc +++ b/src/mem/ruby/structures/DirectoryMemory.cc @@ -68,7 +68,7 @@ void DirectoryMemory::init() { m_num_entries = m_size_bytes / RubySystem::getBlockSizeBytes(); - m_entries = new AbstractEntry*[m_num_entries]; + m_entries = new AbstractCacheEntry*[m_num_entries]; for (int i = 0; i < m_num_entries; i++) m_entries[i] = NULL; } @@ -109,7 +109,7 @@ DirectoryMemory::mapAddressToLocalIdx(Addr address) return ret >> RubySystem::getBlockSizeBits(); } -AbstractEntry* +AbstractCacheEntry* DirectoryMemory::lookup(Addr address) { assert(isPresent(address)); @@ -120,8 +120,8 @@ DirectoryMemory::lookup(Addr address) return m_entries[idx]; } -AbstractEntry* -DirectoryMemory::allocate(Addr address, AbstractEntry *entry) +AbstractCacheEntry* +DirectoryMemory::allocate(Addr address, AbstractCacheEntry *entry) { assert(isPresent(address)); uint64_t idx; diff --git a/src/mem/ruby/structures/DirectoryMemory.hh b/src/mem/ruby/structures/DirectoryMemory.hh index bbed4f975..f879b294f 100644 --- a/src/mem/ruby/structures/DirectoryMemory.hh +++ b/src/mem/ruby/structures/DirectoryMemory.hh @@ -47,7 +47,7 @@ #include "base/addr_range.hh" #include "mem/ruby/common/Address.hh" #include "mem/ruby/protocol/DirectoryRequestType.hh" -#include "mem/ruby/slicc_interface/AbstractEntry.hh" +#include "mem/ruby/slicc_interface/AbstractCacheEntry.hh" #include "params/RubyDirectoryMemory.hh" #include "sim/sim_object.hh" @@ -76,8 +76,8 @@ class DirectoryMemory : public SimObject uint64_t getSize() { return m_size_bytes; } bool isPresent(Addr address); - AbstractEntry *lookup(Addr address); - AbstractEntry *allocate(Addr address, AbstractEntry* new_entry); + AbstractCacheEntry *lookup(Addr address); + AbstractCacheEntry *allocate(Addr address, AbstractCacheEntry* new_entry); void print(std::ostream& out) const; void recordRequestType(DirectoryRequestType requestType); @@ -89,7 +89,7 @@ class DirectoryMemory : public SimObject private: const std::string m_name; - AbstractEntry **m_entries; + AbstractCacheEntry **m_entries; // int m_size; // # of memory module blocks this directory is // responsible for uint64_t m_size_bytes; diff --git a/src/mem/ruby/structures/LRUPolicy.cc b/src/mem/ruby/structures/LRUPolicy.cc deleted file mode 100644 index 3b6d91754..000000000 --- a/src/mem/ruby/structures/LRUPolicy.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2013 Advanced Micro Devices, Inc - * All rights reserved. - * - * 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. - * - * Author: Derek Hower - */ - -#include "mem/ruby/structures/LRUPolicy.hh" - -LRUPolicy::LRUPolicy(const Params * p) - : AbstractReplacementPolicy(p) -{ -} - - -LRUPolicy::~LRUPolicy() -{ -} - -LRUPolicy * -LRUReplacementPolicyParams::create() -{ - return new LRUPolicy(this); -} - - -void -LRUPolicy::touch(int64_t set, int64_t index, Tick time) -{ - assert(index >= 0 && index < m_assoc); - assert(set >= 0 && set < m_num_sets); - - m_last_ref_ptr[set][index] = time; -} - -int64_t -LRUPolicy::getVictim(int64_t set) const -{ - Tick time, smallest_time; - int64_t smallest_index = 0; - smallest_time = m_last_ref_ptr[set][0]; - - for (unsigned i = 0; i < m_assoc; i++) { - time = m_last_ref_ptr[set][i]; - - if (time < smallest_time) { - smallest_index = i; - smallest_time = time; - } - } - - return smallest_index; -} diff --git a/src/mem/ruby/structures/LRUPolicy.hh b/src/mem/ruby/structures/LRUPolicy.hh deleted file mode 100644 index 388718319..000000000 --- a/src/mem/ruby/structures/LRUPolicy.hh +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2007 Mark D. Hill and David A. Wood - * All rights reserved. - * - * 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_RUBY_STRUCTURES_LRUPOLICY_HH__ -#define __MEM_RUBY_STRUCTURES_LRUPOLICY_HH__ - -#include "mem/ruby/structures/AbstractReplacementPolicy.hh" -#include "params/LRUReplacementPolicy.hh" - -/* Simple true LRU replacement policy */ - -class LRUPolicy : public AbstractReplacementPolicy -{ - public: - typedef LRUReplacementPolicyParams Params; - LRUPolicy(const Params * p); - ~LRUPolicy(); - - void touch(int64_t set, int64_t way, Tick time); - int64_t getVictim(int64_t set) const; -}; - -#endif // __MEM_RUBY_STRUCTURES_LRUPOLICY_HH__ diff --git a/src/mem/ruby/structures/LRUReplacementPolicy.py b/src/mem/ruby/structures/LRUReplacementPolicy.py deleted file mode 100644 index 9c36b5f51..000000000 --- a/src/mem/ruby/structures/LRUReplacementPolicy.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright (c) 2013 Advanced Micro Devices, Inc -# All rights reserved. -# -# 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. -# -# Author: Derek Hower - - - -from m5.params import * -from m5.SimObject import SimObject -from m5.objects.ReplacementPolicy import ReplacementPolicy - -class LRUReplacementPolicy(ReplacementPolicy): - type = 'LRUReplacementPolicy' - cxx_class = 'LRUPolicy' - cxx_header = 'mem/ruby/structures/LRUPolicy.hh' - - diff --git a/src/mem/ruby/structures/PseudoLRUPolicy.cc b/src/mem/ruby/structures/PseudoLRUPolicy.cc deleted file mode 100644 index e423bb58d..000000000 --- a/src/mem/ruby/structures/PseudoLRUPolicy.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2013 Advanced Micro Devices, Inc - * All rights reserved. - * - * 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. - * - * Author: Derek Hower - */ - -#include "mem/ruby/structures/PseudoLRUPolicy.hh" - -PseudoLRUPolicy::PseudoLRUPolicy(const Params * p) - : AbstractReplacementPolicy(p) -{ - // associativity cannot exceed capacity of tree representation - assert(m_num_sets > 0 && - m_assoc > 1 && - m_assoc <= (int64_t) sizeof(uint64_t)*4); - - m_trees = NULL; - m_num_levels = 0; - - m_effective_assoc = 1; - while (m_effective_assoc < m_assoc) { - // effective associativity is ceiling power of 2 - m_effective_assoc <<= 1; - } - int tmp_assoc = m_effective_assoc; - while (true) { - tmp_assoc /= 2; - if (!tmp_assoc) break; - m_num_levels++; - } - assert(m_num_levels < sizeof(unsigned int)*4); - m_trees = new uint64_t[m_num_sets]; - for (unsigned i = 0; i < m_num_sets; i++) { - m_trees[i] = 0; - } -} - -PseudoLRUPolicy * -PseudoLRUReplacementPolicyParams::create() -{ - return new PseudoLRUPolicy(this); -} - - -PseudoLRUPolicy::~PseudoLRUPolicy() -{ - if (m_trees != NULL) - delete[] m_trees; -} - -void -PseudoLRUPolicy::touch(int64_t set, int64_t index, Tick time) -{ - assert(index >= 0 && index < m_assoc); - assert(set >= 0 && set < m_num_sets); - - int tree_index = 0; - int node_val; - for (int i = m_num_levels - 1; i >= 0; i--) { - node_val = (index >> i)&1; - if (node_val) - m_trees[set] |= node_val << tree_index; - else - m_trees[set] &= ~(1 << tree_index); - tree_index = node_val ? (tree_index*2)+2 : (tree_index*2)+1; - } - m_last_ref_ptr[set][index] = time; -} - -int64_t -PseudoLRUPolicy::getVictim(int64_t set) const -{ - int64_t index = 0; - - int tree_index = 0; - int node_val; - for (unsigned i = 0; i < m_num_levels; i++){ - node_val = (m_trees[set] >> tree_index) & 1; - index += node_val ? 0 : (m_effective_assoc >> (i + 1)); - tree_index = node_val ? (tree_index * 2) + 1 : (tree_index * 2) + 2; - } - assert(index >= 0 && index < m_effective_assoc); - - /* return either the found index or the max possible index */ - /* NOTE: this is not a fair replacement when assoc is not a power of 2 */ - return (index > (m_assoc - 1)) ? m_assoc - 1 : index; -} diff --git a/src/mem/ruby/structures/PseudoLRUPolicy.hh b/src/mem/ruby/structures/PseudoLRUPolicy.hh deleted file mode 100644 index a96c802b2..000000000 --- a/src/mem/ruby/structures/PseudoLRUPolicy.hh +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2007 Mark D. Hill and David A. Wood - * Copyright (c) 2013 Advanced Micro Devices, Inc - * All rights reserved. - * - * 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_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__ -#define __MEM_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__ - -#include "mem/ruby/structures/AbstractReplacementPolicy.hh" -#include "params/PseudoLRUReplacementPolicy.hh" - -/** - * Implementation of tree-based pseudo-LRU replacement - * - * Works for any associativity between 1 and 128. - * - * Also implements associativities that are not a power of 2 by - * ignoring paths that lead to a larger index (i.e. truncating the - * tree). Note that when this occurs, the algorithm becomes less - * fair, as it will favor indicies in the larger (by index) half of - * the associative set. This is most unfair when the nearest power of - * 2 is one below the associativy, and most fair when it is one above. - */ - -class PseudoLRUPolicy : public AbstractReplacementPolicy -{ - public: - typedef PseudoLRUReplacementPolicyParams Params; - PseudoLRUPolicy(const Params * p); - ~PseudoLRUPolicy(); - - void touch(int64_t set, int64_t way, Tick time); - int64_t getVictim(int64_t set) const; - - private: - unsigned int m_effective_assoc; /** nearest (to ceiling) power of 2 */ - unsigned int m_num_levels; /** number of levels in the tree */ - uint64_t* m_trees; /** bit representation of the - * trees, one for each set */ -}; - -#endif // __MEM_RUBY_STRUCTURES_PSEUDOLRUPOLICY_HH__ diff --git a/src/mem/ruby/structures/PseudoLRUReplacementPolicy.py b/src/mem/ruby/structures/PseudoLRUReplacementPolicy.py deleted file mode 100644 index 2b892d47a..000000000 --- a/src/mem/ruby/structures/PseudoLRUReplacementPolicy.py +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (c) 2013 Advanced Micro Devices, Inc -# All rights reserved. -# -# 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. -# -# Author: Derek Hower - -from m5.objects.ReplacementPolicy import ReplacementPolicy - -class PseudoLRUReplacementPolicy(ReplacementPolicy): - type = 'PseudoLRUReplacementPolicy' - cxx_class = 'PseudoLRUPolicy' - cxx_header = 'mem/ruby/structures/PseudoLRUPolicy.hh' diff --git a/src/mem/ruby/structures/ReplacementPolicy.py b/src/mem/ruby/structures/ReplacementPolicy.py deleted file mode 100644 index 4570cc9df..000000000 --- a/src/mem/ruby/structures/ReplacementPolicy.py +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (c) 2013 Advanced Micro Devices, Inc -# All rights reserved. -# -# 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. -# -# Author: Derek Hower - -from m5.params import * -from m5.proxy import * -from m5.SimObject import SimObject - -class ReplacementPolicy(SimObject): - type = 'ReplacementPolicy' - cxx_class = 'AbstractReplacementPolicy' - cxx_header = 'mem/ruby/structures/AbstractReplacementPolicy.hh' - - block_size = Param.Int(Parent.cache_line_size, "block size in bytes") - - size = Param.MemorySize(Parent.size, "capacity in bytes") - - assoc = Param.Int(Parent.assoc, "associativity") diff --git a/src/mem/ruby/structures/RubyCache.py b/src/mem/ruby/structures/RubyCache.py index cf8410c6d..49c20ff4c 100644 --- a/src/mem/ruby/structures/RubyCache.py +++ b/src/mem/ruby/structures/RubyCache.py @@ -29,7 +29,7 @@ from m5.params import * from m5.proxy import * -from m5.objects.PseudoLRUReplacementPolicy import PseudoLRUReplacementPolicy +from m5.objects.ReplacementPolicies import * from m5.SimObject import SimObject class RubyCache(SimObject): @@ -38,8 +38,7 @@ class RubyCache(SimObject): cxx_header = "mem/ruby/structures/CacheMemory.hh" size = Param.MemorySize("capacity in bytes"); assoc = Param.Int(""); - replacement_policy = Param.ReplacementPolicy(PseudoLRUReplacementPolicy(), - "") + replacement_policy = Param.BaseReplacementPolicy(TreePLRURP(), "") start_index_bit = Param.Int(6, "index start, default 6 for 64-byte line"); is_icache = Param.Bool(False, "is instruction only cache"); block_size = Param.MemorySize("0B", "block size in bytes. 0 means default RubyBlockSize") diff --git a/src/mem/ruby/structures/SConscript b/src/mem/ruby/structures/SConscript index c39cd0e51..fdd9289f3 100644 --- a/src/mem/ruby/structures/SConscript +++ b/src/mem/ruby/structures/SConscript @@ -35,17 +35,11 @@ if env['PROTOCOL'] == 'None': SimObject('RubyCache.py') SimObject('DirectoryMemory.py') -SimObject('LRUReplacementPolicy.py') -SimObject('PseudoLRUReplacementPolicy.py') -SimObject('ReplacementPolicy.py') SimObject('RubyPrefetcher.py') SimObject('WireBuffer.py') -Source('AbstractReplacementPolicy.cc') Source('DirectoryMemory.cc') Source('CacheMemory.cc') -Source('LRUPolicy.cc') -Source('PseudoLRUPolicy.cc') Source('WireBuffer.cc') Source('PersistentTable.cc') Source('Prefetcher.cc') |