PerfectCacheMemory.hh revision 7055
110688Sandreas.hansson@arm.com/* 210688Sandreas.hansson@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 310688Sandreas.hansson@arm.com * All rights reserved. 410688Sandreas.hansson@arm.com * 510688Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 610688Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 710688Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 810688Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 910688Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 1010688Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 1110688Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 1210688Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 134486SN/A * contributors may be used to endorse or promote products derived from 144486SN/A * this software without specific prior written permission. 154486SN/A * 164486SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174486SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184486SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194486SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204486SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214486SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224486SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234486SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244486SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254486SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264486SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274486SN/A */ 284486SN/A 294486SN/A#ifndef __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 304486SN/A#define __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 314486SN/A 324486SN/A#include "mem/gems_common/Map.hh" 334486SN/A#include "mem/protocol/AccessPermission.hh" 344486SN/A#include "mem/ruby/common/Address.hh" 354486SN/A#include "mem/ruby/common/Global.hh" 364486SN/A 374486SN/Atemplate<class ENTRY> 384486SN/Astruct PerfectCacheLineState 394486SN/A{ 4010688Sandreas.hansson@arm.com PerfectCacheLineState() { m_permission = AccessPermission_NUM; } 413102SN/A AccessPermission m_permission; 423187SN/A ENTRY m_entry; 433187SN/A}; 4413892Sgabeblack@google.com 4513665Sandreas.sandberg@arm.comtemplate<class ENTRY> 4613892Sgabeblack@google.cominline std::ostream& 471366SN/Aoperator<<(std::ostream& out, const PerfectCacheLineState<ENTRY>& obj) 489338SAndreas.Sandberg@arm.com{ 4910688Sandreas.hansson@arm.com return out; 5010688Sandreas.hansson@arm.com} 5110688Sandreas.hansson@arm.com 5210688Sandreas.hansson@arm.comtemplate<class ENTRY> 5310688Sandreas.hansson@arm.comclass PerfectCacheMemory 5410688Sandreas.hansson@arm.com{ 5510688Sandreas.hansson@arm.com public: 5610688Sandreas.hansson@arm.com PerfectCacheMemory(); 5710688Sandreas.hansson@arm.com 5810688Sandreas.hansson@arm.com static void printConfig(std::ostream& out); 5910688Sandreas.hansson@arm.com 6010688Sandreas.hansson@arm.com // perform a cache access and see if we hit or not. Return true 6110688Sandreas.hansson@arm.com // on a hit. 6210688Sandreas.hansson@arm.com bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry); 6310688Sandreas.hansson@arm.com 641310SN/A // tests to see if an address is present in the cache 6510688Sandreas.hansson@arm.com bool isTagPresent(const Address& address) const; 6610688Sandreas.hansson@arm.com 6710688Sandreas.hansson@arm.com // Returns true if there is: 683187SN/A // a) a tag match on this address or there is 6910688Sandreas.hansson@arm.com // b) an Invalid line in the same cache "way" 7010688Sandreas.hansson@arm.com bool cacheAvail(const Address& address) const; 718832SAli.Saidi@ARM.com 7210688Sandreas.hansson@arm.com // find an Invalid entry and sets the tag appropriate for the address 7310688Sandreas.hansson@arm.com void allocate(const Address& address); 7410688Sandreas.hansson@arm.com 7510688Sandreas.hansson@arm.com void deallocate(const Address& address); 76 77 // Returns with the physical address of the conflicting cache line 78 Address cacheProbe(const Address& newAddress) const; 79 80 // looks an address up in the cache 81 ENTRY& lookup(const Address& address); 82 const ENTRY& lookup(const Address& address) const; 83 84 // Get/Set permission of cache block 85 AccessPermission getPermission(const Address& address) const; 86 void changePermission(const Address& address, AccessPermission new_perm); 87 88 // Print cache contents 89 void print(std::ostream& out) const; 90 91 private: 92 // Private copy constructor and assignment operator 93 PerfectCacheMemory(const PerfectCacheMemory& obj); 94 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj); 95 96 // Data Members (m_prefix) 97 Map<Address, PerfectCacheLineState<ENTRY> > m_map; 98}; 99 100template<class ENTRY> 101inline std::ostream& 102operator<<(std::ostream& out, const PerfectCacheMemory<ENTRY>& obj) 103{ 104 obj.print(out); 105 out << std::flush; 106 return out; 107} 108 109template<class ENTRY> 110inline 111PerfectCacheMemory<ENTRY>::PerfectCacheMemory() 112{ 113} 114 115template<class ENTRY> 116inline void 117PerfectCacheMemory<ENTRY>::printConfig(std::ostream& out) 118{ 119} 120 121template<class ENTRY> 122inline bool 123PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, 124 bool& block_stc, ENTRY*& entry) 125{ 126 ERROR_MSG("not implemented"); 127} 128 129// tests to see if an address is present in the cache 130template<class ENTRY> 131inline bool 132PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const 133{ 134 return m_map.exist(line_address(address)); 135} 136 137template<class ENTRY> 138inline bool 139PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const 140{ 141 return true; 142} 143 144// find an Invalid or already allocated entry and sets the tag 145// appropriate for the address 146template<class ENTRY> 147inline void 148PerfectCacheMemory<ENTRY>::allocate(const Address& address) 149{ 150 PerfectCacheLineState<ENTRY> line_state; 151 line_state.m_permission = AccessPermission_Busy; 152 line_state.m_entry = ENTRY(); 153 m_map.add(line_address(address), line_state); 154} 155 156// deallocate entry 157template<class ENTRY> 158inline void 159PerfectCacheMemory<ENTRY>::deallocate(const Address& address) 160{ 161 m_map.erase(line_address(address)); 162} 163 164// Returns with the physical address of the conflicting cache line 165template<class ENTRY> 166inline Address 167PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const 168{ 169 ERROR_MSG("cacheProbe called in perfect cache"); 170} 171 172// looks an address up in the cache 173template<class ENTRY> 174inline ENTRY& 175PerfectCacheMemory<ENTRY>::lookup(const Address& address) 176{ 177 return m_map.lookup(line_address(address)).m_entry; 178} 179 180// looks an address up in the cache 181template<class ENTRY> 182inline const ENTRY& 183PerfectCacheMemory<ENTRY>::lookup(const Address& address) const 184{ 185 return m_map.lookup(line_address(address)).m_entry; 186} 187 188template<class ENTRY> 189inline AccessPermission 190PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const 191{ 192 return m_map.lookup(line_address(address)).m_permission; 193} 194 195template<class ENTRY> 196inline void 197PerfectCacheMemory<ENTRY>::changePermission(const Address& address, 198 AccessPermission new_perm) 199{ 200 Address line_address = address; 201 line_address.makeLineAddress(); 202 PerfectCacheLineState<ENTRY>& line_state = m_map.lookup(line_address); 203 AccessPermission old_perm = line_state.m_permission; 204 line_state.m_permission = new_perm; 205} 206 207template<class ENTRY> 208inline void 209PerfectCacheMemory<ENTRY>::print(std::ostream& out) const 210{ 211} 212 213#endif // __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 214